From fd83cbf60fd30a0461e7c36751897c32510925dd Mon Sep 17 00:00:00 2001 From: reaperrr Date: Fri, 9 Mar 2018 21:28:53 +0100 Subject: [PATCH] Fix WithTurretAimAnimation disabled handling The old sequence was not recovering when this trait lost its required condition while the aim anim was running. Now it doesn't unconditionally return, but instead checks what the current sequence is and resets to base turret sequence if AimAnim is disabled. --- .../Traits/Render/WithTurretAimAnimation.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Render/WithTurretAimAnimation.cs b/OpenRA.Mods.Common/Traits/Render/WithTurretAimAnimation.cs index 9fa8ddbaf8..a7c6e1b366 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithTurretAimAnimation.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithTurretAimAnimation.cs @@ -34,7 +34,7 @@ namespace OpenRA.Mods.Common.Traits.Render { var turretAttackAnim = ai.TraitInfos().Any(t => t.Turret == Turret); if (turretAttackAnim) - throw new YamlException("WithTurretAimAnimation is currently not compatible with WithTurretAttackAnimation."); + throw new YamlException("WithTurretAimAnimation is currently not compatible with WithTurretAttackAnimation. Don't use them on the same turret."); base.RulesetLoaded(rules, ai); } @@ -45,6 +45,7 @@ namespace OpenRA.Mods.Common.Traits.Render readonly AttackBase attack; readonly Armament armament; readonly WithSpriteTurret wst; + string sequence; public WithTurretAimAnimation(ActorInitializer init, WithTurretAimAnimationInfo info) : base(info) @@ -54,20 +55,22 @@ namespace OpenRA.Mods.Common.Traits.Render .Single(a => a.Info.Name == info.Armament); wst = init.Self.TraitsImplementing() .Single(st => st.Info.Turret == info.Turret); + + sequence = wst.Info.Sequence; } void ITick.Tick(Actor self) { - if (IsTraitDisabled) + if (IsTraitDisabled && sequence == wst.Info.Sequence) return; - var sequence = wst.Info.Sequence; - if (!string.IsNullOrEmpty(Info.Sequence) && attack.IsAiming) + sequence = wst.Info.Sequence; + if (!IsTraitDisabled && !string.IsNullOrEmpty(Info.Sequence) && attack.IsAiming) sequence = Info.Sequence; var prefix = (armament.IsReloading && !string.IsNullOrEmpty(Info.ReloadPrefix)) ? Info.ReloadPrefix : ""; - if (!string.IsNullOrEmpty(prefix) && sequence != (prefix + sequence)) + if (!IsTraitDisabled && !string.IsNullOrEmpty(prefix) && sequence != (prefix + sequence)) sequence = prefix + sequence; wst.DefaultAnimation.ReplaceAnim(sequence);