diff --git a/OpenRA.Mods.Common/Traits/Multipliers/ReloadAmmoDelayMultiplier.cs b/OpenRA.Mods.Common/Traits/Multipliers/ReloadAmmoDelayMultiplier.cs new file mode 100644 index 0000000000..a439d3d723 --- /dev/null +++ b/OpenRA.Mods.Common/Traits/Multipliers/ReloadAmmoDelayMultiplier.cs @@ -0,0 +1,31 @@ +#region Copyright & License Information +/* + * Copyright 2007-2019 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 + +namespace OpenRA.Mods.Common.Traits +{ + [Desc("Modifies the reload time of ammo pools on this actor.")] + public class ReloadAmmoDelayMultiplierInfo : ConditionalTraitInfo + { + [FieldLoader.Require] + [Desc("Percentage modifier to apply.")] + public readonly int Modifier = 100; + + public override object Create(ActorInitializer init) { return new ReloadAmmoDelayMultiplier(this); } + } + + public class ReloadAmmoDelayMultiplier : ConditionalTrait, IReloadAmmoModifier + { + public ReloadAmmoDelayMultiplier(ReloadAmmoDelayMultiplierInfo info) + : base(info) { } + + int IReloadAmmoModifier.GetReloadAmmoModifier() { return IsTraitDisabled ? 100 : Info.Modifier; } + } +} diff --git a/OpenRA.Mods.Common/Traits/ReloadAmmoPool.cs b/OpenRA.Mods.Common/Traits/ReloadAmmoPool.cs index cf9a6284a8..a036cd2f6d 100644 --- a/OpenRA.Mods.Common/Traits/ReloadAmmoPool.cs +++ b/OpenRA.Mods.Common/Traits/ReloadAmmoPool.cs @@ -46,6 +46,7 @@ namespace OpenRA.Mods.Common.Traits public class ReloadAmmoPool : PausableConditionalTrait, ITick, INotifyCreated, INotifyAttack, ISync { AmmoPool ammoPool; + IReloadAmmoModifier[] modifiers; [Sync] int remainingTicks; @@ -56,6 +57,7 @@ namespace OpenRA.Mods.Common.Traits void INotifyCreated.Created(Actor self) { ammoPool = self.TraitsImplementing().Single(ap => ap.Info.Name == Info.AmmoPool); + modifiers = self.TraitsImplementing().ToArray(); remainingTicks = Info.Delay; } @@ -79,7 +81,7 @@ namespace OpenRA.Mods.Common.Traits { if (!ammoPool.FullAmmo() && --remainingTicks == 0) { - remainingTicks = reloadDelay; + remainingTicks = Util.ApplyPercentageModifiers(reloadDelay, modifiers.Select(m => m.GetReloadAmmoModifier())); if (!string.IsNullOrEmpty(sound)) Game.Sound.PlayToPlayer(SoundType.World, self.Owner, sound, self.CenterPosition); diff --git a/OpenRA.Mods.Common/TraitsInterfaces.cs b/OpenRA.Mods.Common/TraitsInterfaces.cs index c46fba9ea8..9f8af4ea1d 100644 --- a/OpenRA.Mods.Common/TraitsInterfaces.cs +++ b/OpenRA.Mods.Common/TraitsInterfaces.cs @@ -361,6 +361,9 @@ namespace OpenRA.Mods.Common.Traits [RequireExplicitImplementation] public interface IReloadModifier { int GetReloadModifier(); } + [RequireExplicitImplementation] + public interface IReloadAmmoModifier { int GetReloadAmmoModifier(); } + [RequireExplicitImplementation] public interface IInaccuracyModifier { int GetInaccuracyModifier(); }