Fix traits implementing INotifyKilled

This commit is contained in:
penev92
2015-07-04 16:15:56 +03:00
parent 351cf254e7
commit 41cdc57ea5
4 changed files with 18 additions and 7 deletions

View File

@@ -9,6 +9,7 @@
#endregion
using System.Linq;
using OpenRA.Mods.Common.Warheads;
using OpenRA.Primitives;
using OpenRA.Traits;
@@ -33,9 +34,12 @@ namespace OpenRA.Mods.Cnc.Traits
public void Killed(Actor self, AttackInfo e)
{
if (!self.World.LobbyInfo.GlobalSettings.Creeps) return;
if (e.Warhead == null || !e.Warhead.DamageTypes.Contains(info.DeathType)) return;
if (self.World.SharedRandom.Next(100) > info.Probability) return;
var warhead = e.Warhead as DamageWarhead;
if (warhead == null || !warhead.DamageTypes.Contains(info.DeathType))
return;
self.World.AddFrameEndTask(w =>
{
var td = new TypeDictionary

View File

@@ -9,6 +9,7 @@
#endregion
using System.Linq;
using OpenRA.Mods.Common.Warheads;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
@@ -40,7 +41,8 @@ namespace OpenRA.Mods.Common.Traits
if (self.World.SharedRandom.Next(100) > info.Chance)
return;
if (info.DeathType != null && e.Warhead != null && !info.DeathType.Intersect(e.Warhead.DamageTypes).Any())
var warhead = e.Warhead as DamageWarhead;
if (info.DeathType != null && warhead != null && !info.DeathType.Intersect(warhead.DamageTypes).Any())
return;
var weaponName = ChooseWeaponForExplosion(self);

View File

@@ -12,6 +12,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Effects;
using OpenRA.Mods.Common.Warheads;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
@@ -72,16 +73,17 @@ namespace OpenRA.Mods.Common.Traits
{
// Killed by some non-standard means. This includes being crushed
// by a vehicle (Actors with Crushable trait will spawn CrushedSequence instead).
if (e.Warhead == null)
if (e.Warhead == null || !(e.Warhead is DamageWarhead))
return;
var sequence = Info.DeathSequence;
if (Info.UseDeathTypeSuffix)
{
var damageType = e.Warhead.DamageTypes.Intersect(Info.DeathTypes.Keys).FirstOrDefault();
var warhead = e.Warhead as DamageWarhead;
var damageType = 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)));
.F(self.Info.Name, string.Join(", ", warhead.DamageTypes)));
sequence += Info.DeathTypes[damageType];
}

View File

@@ -9,6 +9,7 @@
#endregion
using System.Linq;
using OpenRA.Mods.Common.Warheads;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
@@ -37,11 +38,13 @@ namespace OpenRA.Mods.Common.Traits
public void Killed(Actor self, AttackInfo e)
{
var warhead = e.Warhead as DamageWarhead;
// Killed by some non-standard means
if (e.Warhead == null)
if (warhead == null)
return;
if (info.DeathTypes.Intersect(e.Warhead.DamageTypes).Any())
if (info.DeathTypes.Intersect(warhead.DamageTypes).Any())
self.PlayVoiceLocal(info.Voice, info.VolumeMultiplier);
}
}