Add support for a FallbackSequence in WithDeathAnimation
Used when the actor is killed by non-standard means, like suicide.
This commit is contained in:
@@ -45,6 +45,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
"Is only used if UseDeathTypeSuffix is `True`.")]
|
"Is only used if UseDeathTypeSuffix is `True`.")]
|
||||||
public readonly Dictionary<string, int> DeathTypes = new Dictionary<string, int>();
|
public readonly Dictionary<string, int> DeathTypes = new Dictionary<string, int>();
|
||||||
|
|
||||||
|
[Desc("Sequence to use when the actor is killed by some non-standard means (e.g. suicide).")]
|
||||||
|
[SequenceReference] public readonly string FallbackSequence = null;
|
||||||
|
|
||||||
public static object LoadDeathTypes(MiniYaml yaml)
|
public static object LoadDeathTypes(MiniYaml yaml)
|
||||||
{
|
{
|
||||||
var md = yaml.ToDictionary();
|
var md = yaml.ToDictionary();
|
||||||
@@ -57,10 +60,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public object Create(ActorInitializer init) { return new WithDeathAnimation(init.Self, this); }
|
public object Create(ActorInitializer init) { return new WithDeathAnimation(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class WithDeathAnimation : INotifyKilled
|
public class WithDeathAnimation : INotifyKilled, INotifyCrushed
|
||||||
{
|
{
|
||||||
public readonly WithDeathAnimationInfo Info;
|
public readonly WithDeathAnimationInfo Info;
|
||||||
readonly RenderSprites rs;
|
readonly RenderSprites rs;
|
||||||
|
bool crushed;
|
||||||
|
|
||||||
public WithDeathAnimation(Actor self, WithDeathAnimationInfo info)
|
public WithDeathAnimation(Actor self, WithDeathAnimationInfo info)
|
||||||
{
|
{
|
||||||
@@ -70,11 +74,23 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public void Killed(Actor self, AttackInfo e)
|
public void Killed(Actor self, AttackInfo e)
|
||||||
{
|
{
|
||||||
// Killed by some non-standard means. This includes being crushed
|
// Actors with Crushable trait will spawn CrushedSequence.
|
||||||
// by a vehicle (Actors with Crushable trait will spawn CrushedSequence instead).
|
if (crushed)
|
||||||
if (e.Warhead == null || !(e.Warhead is DamageWarhead))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
var palette = Info.DeathSequencePalette;
|
||||||
|
if (Info.DeathPaletteIsPlayerPalette)
|
||||||
|
palette += self.Owner.InternalName;
|
||||||
|
|
||||||
|
// Killed by some non-standard means
|
||||||
|
if (e.Warhead == null || !(e.Warhead is DamageWarhead))
|
||||||
|
{
|
||||||
|
if (Info.FallbackSequence != null)
|
||||||
|
SpawnDeathAnimation(self, Info.FallbackSequence, palette);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var sequence = Info.DeathSequence;
|
var sequence = Info.DeathSequence;
|
||||||
if (Info.UseDeathTypeSuffix)
|
if (Info.UseDeathTypeSuffix)
|
||||||
{
|
{
|
||||||
@@ -86,10 +102,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
sequence += Info.DeathTypes[damageType];
|
sequence += Info.DeathTypes[damageType];
|
||||||
}
|
}
|
||||||
|
|
||||||
var palette = Info.DeathSequencePalette;
|
|
||||||
if (Info.DeathPaletteIsPlayerPalette)
|
|
||||||
palette += self.Owner.InternalName;
|
|
||||||
|
|
||||||
SpawnDeathAnimation(self, sequence, palette);
|
SpawnDeathAnimation(self, sequence, palette);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,5 +113,12 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
w.Add(new Corpse(w, self.CenterPosition, rs.GetImage(self), sequence, palette));
|
w.Add(new Corpse(w, self.CenterPosition, rs.GetImage(self), sequence, palette));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void INotifyCrushed.OnCrush(Actor self, Actor crusher, HashSet<string> crushClasses)
|
||||||
|
{
|
||||||
|
crushed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void INotifyCrushed.WarnCrush(Actor self, Actor crusher, HashSet<string> crushClasses) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user