diff --git a/OpenRA.Mods.RA/GivesExperience.cs b/OpenRA.Mods.RA/GivesExperience.cs index 813cdd4934..85df386107 100644 --- a/OpenRA.Mods.RA/GivesExperience.cs +++ b/OpenRA.Mods.RA/GivesExperience.cs @@ -13,21 +13,32 @@ using OpenRA.Traits; namespace OpenRA.Mods.RA { [Desc("This actor gives experience to a GainsExperience actor when they are killed.")] - class GivesExperienceInfo : TraitInfo + class GivesExperienceInfo : ITraitInfo { [Desc("If -1, use the value of the unit cost.")] public readonly int Experience = -1; + + [Desc("Grant experience for team-kills.")] + public readonly bool FriendlyFire = false; + + public object Create(ActorInitializer init) { return new GivesExperience(init.self, this); } } class GivesExperience : INotifyKilled { + readonly GivesExperienceInfo info; + + public GivesExperience(Actor self, GivesExperienceInfo info) + { + this.info = info; + } + public void Killed(Actor self, AttackInfo e) { // Prevent TK from giving exp - if (e.Attacker == null || e.Attacker.Destroyed || e.Attacker.Owner.Stances[self.Owner] == Stance.Ally) + if (e.Attacker == null || e.Attacker.Destroyed || (!info.FriendlyFire && e.Attacker.Owner.Stances[self.Owner] == Stance.Ally)) return; - var info = self.Info.Traits.Get(); var valued = self.Info.Traits.GetOrDefault(); // Default experience is 100 times our value