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;

View File

@@ -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<string> DeathTypes = new HashSet<string>();
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<DeathSoundsInfo>, 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);
}
}
}