Implement ReloadAmmoDelay multiplier.
This commit is contained in:
committed by
reaperrr
parent
c9ff54bfd5
commit
d36973138c
@@ -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<ReloadAmmoDelayMultiplierInfo>, IReloadAmmoModifier
|
||||||
|
{
|
||||||
|
public ReloadAmmoDelayMultiplier(ReloadAmmoDelayMultiplierInfo info)
|
||||||
|
: base(info) { }
|
||||||
|
|
||||||
|
int IReloadAmmoModifier.GetReloadAmmoModifier() { return IsTraitDisabled ? 100 : Info.Modifier; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -46,6 +46,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public class ReloadAmmoPool : PausableConditionalTrait<ReloadAmmoPoolInfo>, ITick, INotifyCreated, INotifyAttack, ISync
|
public class ReloadAmmoPool : PausableConditionalTrait<ReloadAmmoPoolInfo>, ITick, INotifyCreated, INotifyAttack, ISync
|
||||||
{
|
{
|
||||||
AmmoPool ammoPool;
|
AmmoPool ammoPool;
|
||||||
|
IReloadAmmoModifier[] modifiers;
|
||||||
|
|
||||||
[Sync]
|
[Sync]
|
||||||
int remainingTicks;
|
int remainingTicks;
|
||||||
@@ -56,6 +57,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
void INotifyCreated.Created(Actor self)
|
void INotifyCreated.Created(Actor self)
|
||||||
{
|
{
|
||||||
ammoPool = self.TraitsImplementing<AmmoPool>().Single(ap => ap.Info.Name == Info.AmmoPool);
|
ammoPool = self.TraitsImplementing<AmmoPool>().Single(ap => ap.Info.Name == Info.AmmoPool);
|
||||||
|
modifiers = self.TraitsImplementing<IReloadAmmoModifier>().ToArray();
|
||||||
remainingTicks = Info.Delay;
|
remainingTicks = Info.Delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +81,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
if (!ammoPool.FullAmmo() && --remainingTicks == 0)
|
if (!ammoPool.FullAmmo() && --remainingTicks == 0)
|
||||||
{
|
{
|
||||||
remainingTicks = reloadDelay;
|
remainingTicks = Util.ApplyPercentageModifiers(reloadDelay, modifiers.Select(m => m.GetReloadAmmoModifier()));
|
||||||
if (!string.IsNullOrEmpty(sound))
|
if (!string.IsNullOrEmpty(sound))
|
||||||
Game.Sound.PlayToPlayer(SoundType.World, self.Owner, sound, self.CenterPosition);
|
Game.Sound.PlayToPlayer(SoundType.World, self.Owner, sound, self.CenterPosition);
|
||||||
|
|
||||||
|
|||||||
@@ -361,6 +361,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[RequireExplicitImplementation]
|
[RequireExplicitImplementation]
|
||||||
public interface IReloadModifier { int GetReloadModifier(); }
|
public interface IReloadModifier { int GetReloadModifier(); }
|
||||||
|
|
||||||
|
[RequireExplicitImplementation]
|
||||||
|
public interface IReloadAmmoModifier { int GetReloadAmmoModifier(); }
|
||||||
|
|
||||||
[RequireExplicitImplementation]
|
[RequireExplicitImplementation]
|
||||||
public interface IInaccuracyModifier { int GetInaccuracyModifier(); }
|
public interface IInaccuracyModifier { int GetInaccuracyModifier(); }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user