Remove DamageWarhead.DeathType in favor of DamageWarhead.DamageTypes
This commit is contained in:
@@ -9,7 +9,6 @@
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
@@ -29,37 +28,37 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public class Explodes : INotifyKilled
|
||||
{
|
||||
readonly ExplodesInfo explodesInfo;
|
||||
readonly ExplodesInfo info;
|
||||
|
||||
public Explodes(ExplodesInfo info) { explodesInfo = info; }
|
||||
public Explodes(ExplodesInfo info) { this.info = info; }
|
||||
|
||||
public void Killed(Actor self, AttackInfo e)
|
||||
{
|
||||
if (!self.IsInWorld)
|
||||
return;
|
||||
|
||||
if (self.World.SharedRandom.Next(100) > explodesInfo.Chance)
|
||||
if (self.World.SharedRandom.Next(100) > info.Chance)
|
||||
return;
|
||||
|
||||
if (explodesInfo.DeathType != null && e.Warhead != null && !explodesInfo.DeathType.Contains(e.Warhead.DeathType))
|
||||
if (info.DeathType != null && e.Warhead != null && !info.DeathType.Intersect(e.Warhead.DamageTypes).Any())
|
||||
return;
|
||||
|
||||
var weaponName = ChooseWeaponForExplosion(self);
|
||||
if (weaponName != null)
|
||||
{
|
||||
var weapon = e.Attacker.World.Map.Rules.Weapons[weaponName.ToLowerInvariant()];
|
||||
if (weapon.Report != null && weapon.Report.Any())
|
||||
Sound.Play(weapon.Report.Random(e.Attacker.World.SharedRandom), self.CenterPosition);
|
||||
if (weaponName == null)
|
||||
return;
|
||||
|
||||
// Use .FromPos since this actor is killed. Cannot use Target.FromActor
|
||||
weapon.Impact(Target.FromPos(self.CenterPosition), e.Attacker, Enumerable.Empty<int>());
|
||||
}
|
||||
var weapon = e.Attacker.World.Map.Rules.Weapons[weaponName.ToLowerInvariant()];
|
||||
if (weapon.Report != null && weapon.Report.Any())
|
||||
Sound.Play(weapon.Report.Random(e.Attacker.World.SharedRandom), self.CenterPosition);
|
||||
|
||||
// Use .FromPos since this actor is killed. Cannot use Target.FromActor
|
||||
weapon.Impact(Target.FromPos(self.CenterPosition), e.Attacker, Enumerable.Empty<int>());
|
||||
}
|
||||
|
||||
string ChooseWeaponForExplosion(Actor self)
|
||||
{
|
||||
var shouldExplode = self.TraitsImplementing<IExplodeModifier>().All(a => a.ShouldExplode(self));
|
||||
return shouldExplode ? explodesInfo.Weapon : explodesInfo.EmptyWeapon;
|
||||
return shouldExplode ? info.Weapon : info.EmptyWeapon;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common.Effects;
|
||||
using OpenRA.Traits;
|
||||
|
||||
@@ -18,17 +21,39 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Sequence to play when this actor is killed by a warhead.")]
|
||||
public readonly string DeathSequence = "die";
|
||||
|
||||
[Desc("The palette used for `DeathSequence`.")]
|
||||
public readonly string DeathSequencePalette = "player";
|
||||
|
||||
[Desc("Custom death animation palette is a player palette BaseName")]
|
||||
public readonly bool DeathPaletteIsPlayerPalette = true;
|
||||
|
||||
[Desc("Should DeathType-specific sequences be used (sequence name = DeathSequence + DeathType).")]
|
||||
public readonly bool UseDeathTypeSuffix = true;
|
||||
|
||||
[Desc("Sequence to play when this actor is crushed.")]
|
||||
public readonly string CrushedSequence = "die-crushed";
|
||||
|
||||
[Desc("The palette used for `CrushedSequence`.")]
|
||||
public readonly string CrushedSequencePalette = "effect";
|
||||
|
||||
[Desc("Custom crushed animation palette is a player palette BaseName")]
|
||||
public readonly bool CrushedPaletteIsPlayerPalette = false;
|
||||
|
||||
[FieldLoader.LoadUsing("LoadDeathTypes")]
|
||||
[Desc("Death animation to use for each damage type (defined on the warheads).",
|
||||
"Is only used if UseDeathTypeSuffix is `True`.")]
|
||||
public readonly Dictionary<string, int> DeathTypes = new Dictionary<string, int>();
|
||||
|
||||
public static object LoadDeathTypes(MiniYaml yaml)
|
||||
{
|
||||
var md = yaml.ToDictionary();
|
||||
|
||||
return md.ContainsKey("DeathTypes")
|
||||
? md["DeathTypes"].ToDictionary(my => FieldLoader.GetValue<int>("(value)", my.Value))
|
||||
: new Dictionary<string, int>();
|
||||
}
|
||||
|
||||
public object Create(ActorInitializer init) { return new WithDeathAnimation(init.Self, this); }
|
||||
}
|
||||
|
||||
@@ -52,7 +77,14 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
var sequence = Info.DeathSequence;
|
||||
if (Info.UseDeathTypeSuffix)
|
||||
sequence += e.Warhead.DeathType;
|
||||
{
|
||||
var damageType = e.Warhead.DamageTypes.Intersect(Info.DeathTypes.Keys).FirstOrDefault();
|
||||
if (damageType == null)
|
||||
throw new Exception("Actor type `{0}` does not define a death animation for weapon with damage types `{1}`!"
|
||||
.F(self.Info.Name, string.Join(", ", e.Warhead.DamageTypes)));
|
||||
|
||||
sequence += Info.DeathTypes[damageType];
|
||||
}
|
||||
|
||||
var palette = Info.DeathSequencePalette;
|
||||
if (Info.DeathPaletteIsPlayerPalette)
|
||||
|
||||
@@ -22,7 +22,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
[Desc("Multiply volume with this factor.")]
|
||||
public readonly float VolumeMultiplier = 1f;
|
||||
|
||||
[Desc("DeathTypes that this should be used for. If empty, this will be used as the default sound.")]
|
||||
[Desc("Damage types that this should be used for (defined on the warheads).",
|
||||
"If empty, this will be used as the default sound for all death types.")]
|
||||
public readonly string[] DeathTypes = { };
|
||||
|
||||
public object Create(ActorInitializer init) { return new DeathSounds(this); }
|
||||
@@ -40,8 +41,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (e.Warhead == null)
|
||||
return;
|
||||
|
||||
if (info.DeathTypes.Contains(e.Warhead.DeathType) || (!info.DeathTypes.Any() &&
|
||||
!self.Info.Traits.WithInterface<DeathSoundsInfo>().Any(dsi => dsi.DeathTypes.Contains(e.Warhead.DeathType))))
|
||||
if (info.DeathTypes.Intersect(e.Warhead.DamageTypes).Any())
|
||||
self.PlayVoiceLocal(info.DeathSound, info.VolumeMultiplier);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user