diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index 7719f3510d..b46ba20325 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -361,6 +361,8 @@ + + diff --git a/OpenRA.Mods.Common/Traits/GivesExperience.cs b/OpenRA.Mods.Common/Traits/GivesExperience.cs index aa997653fa..385c8341c4 100644 --- a/OpenRA.Mods.Common/Traits/GivesExperience.cs +++ b/OpenRA.Mods.Common/Traits/GivesExperience.cs @@ -9,6 +9,7 @@ */ #endregion +using System.Linq; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -54,9 +55,16 @@ namespace OpenRA.Mods.Common.Traits ? info.Experience : valued != null ? valued.Cost : 0; + var experienceModifier = self.TraitsImplementing().Select(x => x.GetGivesExperienceModifier()); + Util.ApplyPercentageModifiers(exp, experienceModifier); + var killer = e.Attacker.TraitOrDefault(); if (killer != null) - killer.GiveExperience(Util.ApplyPercentageModifiers(exp, new[] { info.ActorExperienceModifier })); + { + var killerExperienceModifier = e.Attacker.TraitsImplementing() + .Select(x => x.GetGainsExperienceModifier()).Append(info.ActorExperienceModifier); + killer.GiveExperience(Util.ApplyPercentageModifiers(exp, killerExperienceModifier)); + } var attackerExp = e.Attacker.Owner.PlayerActor.TraitOrDefault(); if (attackerExp != null) diff --git a/OpenRA.Mods.Common/Traits/Multipliers/GainsExperienceMultiplier.cs b/OpenRA.Mods.Common/Traits/Multipliers/GainsExperienceMultiplier.cs new file mode 100644 index 0000000000..cb3f86ebc6 --- /dev/null +++ b/OpenRA.Mods.Common/Traits/Multipliers/GainsExperienceMultiplier.cs @@ -0,0 +1,36 @@ +#region Copyright & License Information +/* + * Copyright 2007-2017 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using OpenRA.Traits; + +namespace OpenRA.Mods.Common.Traits +{ + [Desc("Modifies the experience gathered by this actor.")] + public class GainsExperienceMultiplierInfo : ConditionalTraitInfo + { + [FieldLoader.Require] + [Desc("Percentage modifier to apply.")] + public readonly int Modifier = 100; + + public override object Create(ActorInitializer init) { return new GainsExperienceMultiplier(this); } + } + + public class GainsExperienceMultiplier : ConditionalTrait, IGainsExperienceModifier + { + public GainsExperienceMultiplier(GainsExperienceMultiplierInfo info) + : base(info) { } + + int IGainsExperienceModifier.GetGainsExperienceModifier() + { + return IsTraitDisabled ? 100 : Info.Modifier; + } + } +} diff --git a/OpenRA.Mods.Common/Traits/Multipliers/GivesExperienceMultiplier.cs b/OpenRA.Mods.Common/Traits/Multipliers/GivesExperienceMultiplier.cs new file mode 100644 index 0000000000..516cf9a1d0 --- /dev/null +++ b/OpenRA.Mods.Common/Traits/Multipliers/GivesExperienceMultiplier.cs @@ -0,0 +1,36 @@ +#region Copyright & License Information +/* + * Copyright 2007-2017 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using OpenRA.Traits; + +namespace OpenRA.Mods.Common.Traits +{ + [Desc("Modifies the experience given by this actor.")] + public class GivesExperienceMultiplierInfo : ConditionalTraitInfo + { + [FieldLoader.Require] + [Desc("Percentage modifier to apply.")] + public readonly int Modifier = 100; + + public override object Create(ActorInitializer init) { return new GivesExperienceMultiplier(this); } + } + + public class GivesExperienceMultiplier : ConditionalTrait, IGivesExperienceModifier + { + public GivesExperienceMultiplier(GivesExperienceMultiplierInfo info) + : base(info) { } + + int IGivesExperienceModifier.GetGivesExperienceModifier() + { + return IsTraitDisabled ? 100 : Info.Modifier; + } + } +} diff --git a/OpenRA.Mods.Common/TraitsInterfaces.cs b/OpenRA.Mods.Common/TraitsInterfaces.cs index 4ca8e0c36e..67fea93cc4 100644 --- a/OpenRA.Mods.Common/TraitsInterfaces.cs +++ b/OpenRA.Mods.Common/TraitsInterfaces.cs @@ -227,4 +227,10 @@ namespace OpenRA.Mods.Common.Traits [RequireExplicitImplementation] public interface IPowerModifier { int GetPowerModifier(); } + + [RequireExplicitImplementation] + public interface IGivesExperienceModifier { int GetGivesExperienceModifier(); } + + [RequireExplicitImplementation] + public interface IGainsExperienceModifier { int GetGainsExperienceModifier(); } }