diff --git a/OpenRA.Mods.Common/Traits/Render/WithDeathAnimation.cs b/OpenRA.Mods.Common/Traits/Render/WithDeathAnimation.cs index 7de3a51334..b5588cbdf5 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithDeathAnimation.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithDeathAnimation.cs @@ -18,7 +18,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits.Render { [Desc("This actor has a death animation.")] - public class WithDeathAnimationInfo : ITraitInfo, Requires + public class WithDeathAnimationInfo : ConditionalTraitInfo, Requires { [Desc("Sequence prefix to play when this actor is killed by a warhead.")] [SequenceReference(null, true)] public readonly string DeathSequence = "die"; @@ -58,25 +58,24 @@ namespace OpenRA.Mods.Common.Traits.Render : new Dictionary(); } - public object Create(ActorInitializer init) { return new WithDeathAnimation(init.Self, this); } + public override object Create(ActorInitializer init) { return new WithDeathAnimation(init.Self, this); } } - public class WithDeathAnimation : INotifyKilled, INotifyCrushed + public class WithDeathAnimation : ConditionalTrait, INotifyKilled, INotifyCrushed { - public readonly WithDeathAnimationInfo Info; readonly RenderSprites rs; bool crushed; public WithDeathAnimation(Actor self, WithDeathAnimationInfo info) + : base(info) { - Info = info; rs = self.Trait(); } public void Killed(Actor self, AttackInfo e) { // Actors with Crushable trait will spawn CrushedSequence. - if (crushed) + if (crushed || IsTraitDisabled) return; var palette = Info.DeathSequencePalette; diff --git a/OpenRA.Mods.Common/Traits/Sound/DeathSounds.cs b/OpenRA.Mods.Common/Traits/Sound/DeathSounds.cs index 7938a53ba9..ece9345009 100644 --- a/OpenRA.Mods.Common/Traits/Sound/DeathSounds.cs +++ b/OpenRA.Mods.Common/Traits/Sound/DeathSounds.cs @@ -16,7 +16,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits.Sound { [Desc("Sounds to play when killed.")] - public class DeathSoundsInfo : ITraitInfo + public class DeathSoundsInfo : ConditionalTraitInfo { [Desc("Death notification voice.")] [VoiceReference] public readonly string Voice = "Die"; @@ -28,19 +28,21 @@ namespace OpenRA.Mods.Common.Traits.Sound "If empty, this will be used as the default sound for all death types.")] public readonly HashSet DeathTypes = new HashSet(); - public object Create(ActorInitializer init) { return new DeathSounds(this); } + public override object Create(ActorInitializer init) { return new DeathSounds(this); } } - public class DeathSounds : INotifyKilled + public class DeathSounds : ConditionalTrait, INotifyKilled { - readonly DeathSoundsInfo info; - - public DeathSounds(DeathSoundsInfo info) { this.info = info; } + public DeathSounds(DeathSoundsInfo info) + : base(info) { } public void Killed(Actor self, AttackInfo e) { - if (info.DeathTypes.Count == 0 || e.Damage.DamageTypes.Overlaps(info.DeathTypes)) - self.PlayVoiceLocal(info.Voice, info.VolumeMultiplier); + if (IsTraitDisabled) + return; + + if (Info.DeathTypes.Count == 0 || e.Damage.DamageTypes.Overlaps(Info.DeathTypes)) + self.PlayVoiceLocal(Info.Voice, Info.VolumeMultiplier); } } }