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

@@ -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;
}
}
}