Add Condition support to WithDeathAnimation / DeathSounds.

This commit is contained in:
Paul Chote
2017-01-10 22:18:45 +00:00
parent 7249ca7f88
commit ba9927d34e
2 changed files with 15 additions and 14 deletions

View File

@@ -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<RenderSpritesInfo>
public class WithDeathAnimationInfo : ConditionalTraitInfo, Requires<RenderSpritesInfo>
{
[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<string, string[]>();
}
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<WithDeathAnimationInfo>, INotifyKilled, INotifyCrushed
{
public readonly WithDeathAnimationInfo Info;
readonly RenderSprites rs;
bool crushed;
public WithDeathAnimation(Actor self, WithDeathAnimationInfo info)
: base(info)
{
Info = info;
rs = self.Trait<RenderSprites>();
}
public void Killed(Actor self, AttackInfo e)
{
// Actors with Crushable trait will spawn CrushedSequence.
if (crushed)
if (crushed || IsTraitDisabled)
return;
var palette = Info.DeathSequencePalette;