Make WithTurretAttackAnimation conditional

This commit is contained in:
reaperrr
2017-09-16 20:50:18 +02:00
committed by abcdefg30
parent 02b1530300
commit 76da40bbda

View File

@@ -14,7 +14,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render namespace OpenRA.Mods.Common.Traits.Render
{ {
public class WithTurretAttackAnimationInfo : ITraitInfo, Requires<WithSpriteTurretInfo>, Requires<ArmamentInfo> public class WithTurretAttackAnimationInfo : ConditionalTraitInfo, Requires<WithSpriteTurretInfo>, Requires<ArmamentInfo>
{ {
[Desc("Armament name")] [Desc("Armament name")]
public readonly string Armament = "primary"; public readonly string Armament = "primary";
@@ -31,38 +31,39 @@ namespace OpenRA.Mods.Common.Traits.Render
[Desc("Should the animation be delayed relative to preparation or actual attack?")] [Desc("Should the animation be delayed relative to preparation or actual attack?")]
public readonly AttackDelayType DelayRelativeTo = AttackDelayType.Preparation; public readonly AttackDelayType DelayRelativeTo = AttackDelayType.Preparation;
public object Create(ActorInitializer init) { return new WithTurretAttackAnimation(init, this); } public override object Create(ActorInitializer init) { return new WithTurretAttackAnimation(init, this); }
} }
public class WithTurretAttackAnimation : ITick, INotifyAttack public class WithTurretAttackAnimation : ConditionalTrait<WithTurretAttackAnimationInfo>, ITick, INotifyAttack
{ {
readonly WithTurretAttackAnimationInfo info;
readonly WithSpriteTurret wst; readonly WithSpriteTurret wst;
readonly Armament armament;
int tick; int tick;
public WithTurretAttackAnimation(ActorInitializer init, WithTurretAttackAnimationInfo info) public WithTurretAttackAnimation(ActorInitializer init, WithTurretAttackAnimationInfo info)
: base(info)
{ {
this.info = info; armament = init.Self.TraitsImplementing<Armament>()
.Single(a => a.Info.Name == info.Armament);
wst = init.Self.TraitsImplementing<WithSpriteTurret>() wst = init.Self.TraitsImplementing<WithSpriteTurret>()
.Single(st => st.Info.Turret == info.Turret); .Single(st => st.Info.Turret == info.Turret);
} }
void PlayAttackAnimation(Actor self) void PlayAttackAnimation(Actor self)
{ {
if (!string.IsNullOrEmpty(info.Sequence)) if (!string.IsNullOrEmpty(Info.Sequence))
wst.PlayCustomAnimation(self, info.Sequence); wst.PlayCustomAnimation(self, Info.Sequence);
} }
void INotifyAttack.Attacking(Actor self, Target target, Armament a, Barrel barrel) void INotifyAttack.Attacking(Actor self, Target target, Armament a, Barrel barrel)
{ {
if (a.Info.Name != info.Armament) if (IsTraitDisabled || a != armament)
return; return;
if (info.DelayRelativeTo == AttackDelayType.Attack) if (Info.DelayRelativeTo == AttackDelayType.Attack)
{ {
if (info.Delay > 0) if (Info.Delay > 0)
tick = info.Delay; tick = Info.Delay;
else else
PlayAttackAnimation(self); PlayAttackAnimation(self);
} }
@@ -70,13 +71,13 @@ namespace OpenRA.Mods.Common.Traits.Render
void INotifyAttack.PreparingAttack(Actor self, Target target, Armament a, Barrel barrel) void INotifyAttack.PreparingAttack(Actor self, Target target, Armament a, Barrel barrel)
{ {
if (a.Info.Name != info.Armament) if (IsTraitDisabled || a != armament)
return; return;
if (info.DelayRelativeTo == AttackDelayType.Preparation) if (Info.DelayRelativeTo == AttackDelayType.Preparation)
{ {
if (info.Delay > 0) if (Info.Delay > 0)
tick = info.Delay; tick = Info.Delay;
else else
PlayAttackAnimation(self); PlayAttackAnimation(self);
} }
@@ -84,7 +85,7 @@ namespace OpenRA.Mods.Common.Traits.Render
void ITick.Tick(Actor self) void ITick.Tick(Actor self)
{ {
if (info.Delay > 0 && --tick == 0) if (!IsTraitDisabled && Info.Delay > 0 && --tick == 0)
PlayAttackAnimation(self); PlayAttackAnimation(self);
} }
} }