Remove DamageWarhead.DeathType in favor of DamageWarhead.DamageTypes

This commit is contained in:
penev92
2015-04-30 13:43:27 +03:00
parent c76fb51b14
commit 32bb70abca
6 changed files with 57 additions and 31 deletions

View File

@@ -8,10 +8,7 @@
*/ */
#endregion #endregion
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using OpenRA.Effects;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.GameRules namespace OpenRA.GameRules
@@ -24,9 +21,6 @@ namespace OpenRA.GameRules
[Desc("Types of damage that this warhead causes. Leave empty for no damage.")] [Desc("Types of damage that this warhead causes. Leave empty for no damage.")]
public readonly string[] DamageTypes = new string[0]; public readonly string[] DamageTypes = new string[0];
[Desc("Infantry death animation to use.")]
public readonly string DeathType = "1";
[FieldLoader.LoadUsing("LoadVersus")] [FieldLoader.LoadUsing("LoadVersus")]
[Desc("Damage percentage versus each armortype. 0% = can't target.")] [Desc("Damage percentage versus each armortype. 0% = can't target.")]
public readonly Dictionary<string, int> Versus; public readonly Dictionary<string, int> Versus;

View File

@@ -19,36 +19,36 @@ namespace OpenRA.Mods.Cnc.Traits
[ActorReference] public readonly string ViceroidActor = "vice"; [ActorReference] public readonly string ViceroidActor = "vice";
public readonly int Probability = 10; public readonly int Probability = 10;
public readonly string Owner = "Creeps"; public readonly string Owner = "Creeps";
public readonly string DeathType = "6"; public readonly string DeathType = "TiberiumDeath";
public object Create(ActorInitializer init) { return new SpawnViceroid(this); } public object Create(ActorInitializer init) { return new SpawnViceroid(this); }
} }
class SpawnViceroid : INotifyKilled class SpawnViceroid : INotifyKilled
{ {
readonly SpawnViceroidInfo spawnViceroidInfo; readonly SpawnViceroidInfo info;
public SpawnViceroid(SpawnViceroidInfo info) { spawnViceroidInfo = info; } public SpawnViceroid(SpawnViceroidInfo info) { this.info = info; }
public void Killed(Actor self, AttackInfo e) public void Killed(Actor self, AttackInfo e)
{ {
if (!self.World.LobbyInfo.GlobalSettings.Creeps) return; if (!self.World.LobbyInfo.GlobalSettings.Creeps) return;
if (e.Warhead == null || e.Warhead.DeathType != spawnViceroidInfo.DeathType) return; if (e.Warhead == null || !e.Warhead.DamageTypes.Contains(info.DeathType)) return;
if (self.World.SharedRandom.Next(100) > spawnViceroidInfo.Probability) return; if (self.World.SharedRandom.Next(100) > info.Probability) return;
self.World.AddFrameEndTask(w => self.World.AddFrameEndTask(w =>
{ {
var td = new TypeDictionary var td = new TypeDictionary
{ {
new LocationInit(self.Location), new LocationInit(self.Location),
new OwnerInit(self.World.Players.First(p => p.InternalName == spawnViceroidInfo.Owner)) new OwnerInit(self.World.Players.First(p => p.InternalName == info.Owner))
}; };
var facing = self.TraitOrDefault<IFacing>(); var facing = self.TraitOrDefault<IFacing>();
if (facing != null) if (facing != null)
td.Add(new FacingInit(facing.Facing)); td.Add(new FacingInit(facing.Facing));
w.CreateActor(spawnViceroidInfo.ViceroidActor, td); w.CreateActor(info.ViceroidActor, td);
}); });
} }
} }

View File

@@ -9,7 +9,6 @@
#endregion #endregion
using System.Linq; using System.Linq;
using OpenRA.GameRules;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
@@ -29,24 +28,25 @@ namespace OpenRA.Mods.Common.Traits
public class Explodes : INotifyKilled 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) public void Killed(Actor self, AttackInfo e)
{ {
if (!self.IsInWorld) if (!self.IsInWorld)
return; return;
if (self.World.SharedRandom.Next(100) > explodesInfo.Chance) if (self.World.SharedRandom.Next(100) > info.Chance)
return; 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; return;
var weaponName = ChooseWeaponForExplosion(self); var weaponName = ChooseWeaponForExplosion(self);
if (weaponName != null) if (weaponName == null)
{ return;
var weapon = e.Attacker.World.Map.Rules.Weapons[weaponName.ToLowerInvariant()]; var weapon = e.Attacker.World.Map.Rules.Weapons[weaponName.ToLowerInvariant()];
if (weapon.Report != null && weapon.Report.Any()) if (weapon.Report != null && weapon.Report.Any())
Sound.Play(weapon.Report.Random(e.Attacker.World.SharedRandom), self.CenterPosition); Sound.Play(weapon.Report.Random(e.Attacker.World.SharedRandom), self.CenterPosition);
@@ -54,12 +54,11 @@ namespace OpenRA.Mods.Common.Traits
// Use .FromPos since this actor is killed. Cannot use Target.FromActor // Use .FromPos since this actor is killed. Cannot use Target.FromActor
weapon.Impact(Target.FromPos(self.CenterPosition), e.Attacker, Enumerable.Empty<int>()); weapon.Impact(Target.FromPos(self.CenterPosition), e.Attacker, Enumerable.Empty<int>());
} }
}
string ChooseWeaponForExplosion(Actor self) string ChooseWeaponForExplosion(Actor self)
{ {
var shouldExplode = self.TraitsImplementing<IExplodeModifier>().All(a => a.ShouldExplode(self)); var shouldExplode = self.TraitsImplementing<IExplodeModifier>().All(a => a.ShouldExplode(self));
return shouldExplode ? explodesInfo.Weapon : explodesInfo.EmptyWeapon; return shouldExplode ? info.Weapon : info.EmptyWeapon;
} }
} }
} }

View File

@@ -8,6 +8,9 @@
*/ */
#endregion #endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Effects; using OpenRA.Mods.Common.Effects;
using OpenRA.Traits; using OpenRA.Traits;
@@ -18,17 +21,39 @@ namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Sequence to play when this actor is killed by a warhead.")] [Desc("Sequence to play when this actor is killed by a warhead.")]
public readonly string DeathSequence = "die"; public readonly string DeathSequence = "die";
[Desc("The palette used for `DeathSequence`.")]
public readonly string DeathSequencePalette = "player"; public readonly string DeathSequencePalette = "player";
[Desc("Custom death animation palette is a player palette BaseName")] [Desc("Custom death animation palette is a player palette BaseName")]
public readonly bool DeathPaletteIsPlayerPalette = true; public readonly bool DeathPaletteIsPlayerPalette = true;
[Desc("Should DeathType-specific sequences be used (sequence name = DeathSequence + DeathType).")] [Desc("Should DeathType-specific sequences be used (sequence name = DeathSequence + DeathType).")]
public readonly bool UseDeathTypeSuffix = true; public readonly bool UseDeathTypeSuffix = true;
[Desc("Sequence to play when this actor is crushed.")] [Desc("Sequence to play when this actor is crushed.")]
public readonly string CrushedSequence = "die-crushed"; public readonly string CrushedSequence = "die-crushed";
[Desc("The palette used for `CrushedSequence`.")]
public readonly string CrushedSequencePalette = "effect"; public readonly string CrushedSequencePalette = "effect";
[Desc("Custom crushed animation palette is a player palette BaseName")] [Desc("Custom crushed animation palette is a player palette BaseName")]
public readonly bool CrushedPaletteIsPlayerPalette = false; 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); } public object Create(ActorInitializer init) { return new WithDeathAnimation(init.Self, this); }
} }
@@ -52,7 +77,14 @@ namespace OpenRA.Mods.Common.Traits
var sequence = Info.DeathSequence; var sequence = Info.DeathSequence;
if (Info.UseDeathTypeSuffix) 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; var palette = Info.DeathSequencePalette;
if (Info.DeathPaletteIsPlayerPalette) if (Info.DeathPaletteIsPlayerPalette)

View File

@@ -22,7 +22,8 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Multiply volume with this factor.")] [Desc("Multiply volume with this factor.")]
public readonly float VolumeMultiplier = 1f; 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 readonly string[] DeathTypes = { };
public object Create(ActorInitializer init) { return new DeathSounds(this); } public object Create(ActorInitializer init) { return new DeathSounds(this); }
@@ -40,8 +41,7 @@ namespace OpenRA.Mods.Common.Traits
if (e.Warhead == null) if (e.Warhead == null)
return; return;
if (info.DeathTypes.Contains(e.Warhead.DeathType) || (!info.DeathTypes.Any() && if (info.DeathTypes.Intersect(e.Warhead.DamageTypes).Any())
!self.Info.Traits.WithInterface<DeathSoundsInfo>().Any(dsi => dsi.DeathTypes.Contains(e.Warhead.DeathType))))
self.PlayVoiceLocal(info.DeathSound, info.VolumeMultiplier); self.PlayVoiceLocal(info.DeathSound, info.VolumeMultiplier);
} }
} }

View File

@@ -225,6 +225,7 @@
Huntable: Huntable:
ScriptTriggers: ScriptTriggers:
DeathSounds: DeathSounds:
DeathTypes: 1, 2, 3, 4
Parachutable: Parachutable:
FallRate: 130 FallRate: 130
GainsStatUpgrades: GainsStatUpgrades: