diff --git a/OpenRA.Mods.RA/GainsExperience.cs b/OpenRA.Mods.RA/GainsExperience.cs index 2c57b0b864..6636bf8948 100644 --- a/OpenRA.Mods.RA/GainsExperience.cs +++ b/OpenRA.Mods.RA/GainsExperience.cs @@ -16,86 +16,75 @@ * You should have received a copy of the GNU General Public License * along with OpenRA. If not, see . */ -#endregion - -using OpenRA.GameRules; -using OpenRA.Traits; -using System.Linq; -using System.Collections.Generic; -using OpenRA.Mods.RA.Effects; -namespace OpenRA.Mods.RA -{ - public class GainsExperienceInfo : ITraitInfo - { - //public readonly float[] CostThreshold = {2,4,8}; - public readonly float[] CostThreshold = {1, 1.5f, 2}; - public readonly float[] FirepowerModifier = {1.2f, 1.5f, 2}; - public readonly float[] ArmorModifier = {1.2f, 1.5f, 2}; - public readonly float[] SpeedModifier = {1.2f, 1.5f, 2}; - public object Create(Actor self) { return new GainsExperience(self, this); } - } - - public class GainsExperience: IFirepowerModifier, ISpeedModifier, IDamageModifier - { - readonly Actor self; - readonly List Levels; - readonly GainsExperienceInfo Info; - public GainsExperience(Actor self, GainsExperienceInfo info) - { - this.self = self; - this.Info = info; - System.Console.WriteLine(self.Info.Name); - var cost = self.Info.Traits.Get().Cost; - Levels = Info.CostThreshold.Select(t => t*cost).ToList(); - } - - [Sync] - int Experience = 0; - [Sync] - int Level = 0; - - public void GiveExperience(int amount) - { - // Already at max level - if (Level == Levels.Count() - 1) - return; - - Experience += amount; - - if (Experience > Levels[Level]) - { - Level++; - - // TODO: Show an effect or play a sound or something - System.Console.WriteLine("{0} became Level {1}",self.Info.Name, Level); - - self.World.AddFrameEndTask(w => - { - w.Add(new CrateEffect(self, "speed")); - }); - } - } - - public float GetDamageModifier( WarheadInfo warhead ) - { - if (Level == 0) - return 1.0f; - - return 1/Info.ArmorModifier[Level - 1]; - } - public float GetFirepowerModifier() - { - if (Level == 0) - return 1.0f; - - return Info.FirepowerModifier[Level - 1] ; - } - public float GetSpeedModifier() - { - if (Level == 0) - return 1.0f; - - return Info.SpeedModifier[Level - 1] ; - } - } +#endregion + +using System.Collections.Generic; +using System.Linq; +using OpenRA.GameRules; +using OpenRA.Mods.RA.Effects; +using OpenRA.Traits; + +namespace OpenRA.Mods.RA +{ + public class GainsExperienceInfo : ITraitInfo + { + //public readonly float[] CostThreshold = {2,4,8}; + public readonly float[] CostThreshold = { 1, 1.5f, 2 }; + public readonly float[] FirepowerModifier = { 1.2f, 1.5f, 2 }; + public readonly float[] ArmorModifier = { 1.2f, 1.5f, 2 }; + public readonly float[] SpeedModifier = { 1.2f, 1.5f, 2 }; + public object Create(Actor self) { return new GainsExperience(self, this); } + } + + public class GainsExperience : IFirepowerModifier, ISpeedModifier, IDamageModifier + { + readonly Actor self; + readonly List Levels; + readonly GainsExperienceInfo Info; + public GainsExperience(Actor self, GainsExperienceInfo info) + { + this.self = self; + this.Info = info; + var cost = self.Info.Traits.Get().Cost; + Levels = Info.CostThreshold.Select(t => t * cost).ToList(); + } + + [Sync] + int Experience = 0; + [Sync] + int Level = 0; + + public void GiveExperience(int amount) + { + Experience += amount; + + while (Level < Levels.Count() - 1 && Experience > Levels[Level]) + { + Level++; + + // TODO: Show an effect or play a sound or something + Log.Write("{0} became Level {1}".F(self.Info.Name, Level)); + + self.World.AddFrameEndTask(w => + { + w.Add(new CrateEffect(self, "speed")); + }); + } + } + + public float GetDamageModifier(WarheadInfo warhead) + { + return Level > 0 ? 1 / Info.ArmorModifier[Level - 1] : 1; + } + + public float GetFirepowerModifier() + { + return Level > 0 ? Info.FirepowerModifier[Level - 1] : 1; + } + + public float GetSpeedModifier() + { + return Level > 0 ? Info.SpeedModifier[Level - 1] : 1; + } + } } diff --git a/OpenRA.Mods.RA/GivesExperience.cs b/OpenRA.Mods.RA/GivesExperience.cs index 3d7acef53e..b73f503b07 100644 --- a/OpenRA.Mods.RA/GivesExperience.cs +++ b/OpenRA.Mods.RA/GivesExperience.cs @@ -18,9 +18,8 @@ */ #endregion -using OpenRA.Traits; -using System.Linq; - +using OpenRA.Traits; + namespace OpenRA.Mods.RA { class GivesExperienceInfo : TraitInfo { public readonly int Experience = -1; } @@ -32,16 +31,17 @@ namespace OpenRA.Mods.RA if (e.DamageState == DamageState.Dead) { // Prevent TK from giving exp - //if (self.Owner == e.Attacker.Owner) - // return; - - var exp = 0; - if (self.Info.Traits.Get() != null) - exp = self.Info.Traits.Get().Cost; - if (self.Info.Traits.Get().Experience >= 0) - exp = self.Info.Traits.Get().Experience; - - var killer = e.Attacker.traits.WithInterface().FirstOrDefault(); + //if (e.Attacker == null || e.Attacker.Owner.Stances[ self.Owner ] == Stance.Ally ) + // return; + + var info = self.Info.Traits.Get(); + var valued = self.Info.Traits.GetOrDefault(); + + var exp = info.Experience >= 0 + ? info.Experience + : valued != null ? valued.Cost : 0; + + var killer = e.Attacker.traits.GetOrDefault(); if (killer != null) killer.GiveExperience(exp); }