Merge two ifs into one in SpawnActorOnDeath
This commit is contained in:
@@ -84,8 +84,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
BuildingInfo buildingInfo;
|
BuildingInfo buildingInfo;
|
||||||
Armament[] armaments;
|
Armament[] armaments;
|
||||||
|
|
||||||
bool anyArmaments;
|
|
||||||
|
|
||||||
public Explodes(ExplodesInfo info, Actor self)
|
public Explodes(ExplodesInfo info, Actor self)
|
||||||
: base(info)
|
: base(info)
|
||||||
{
|
{
|
||||||
@@ -96,7 +94,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
buildingInfo = self.Info.TraitInfoOrDefault<BuildingInfo>();
|
buildingInfo = self.Info.TraitInfoOrDefault<BuildingInfo>();
|
||||||
armaments = self.TraitsImplementing<Armament>().ToArray();
|
armaments = self.TraitsImplementing<Armament>().ToArray();
|
||||||
anyArmaments = armaments.Length > 0;
|
|
||||||
|
|
||||||
base.Created(self);
|
base.Created(self);
|
||||||
}
|
}
|
||||||
@@ -106,14 +103,13 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (IsTraitDisabled || !self.IsInWorld)
|
if (IsTraitDisabled || !self.IsInWorld)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var sharedRandom = self.World.SharedRandom.Next(100);
|
if (self.World.SharedRandom.Next(100) > Info.Chance)
|
||||||
if (sharedRandom > Info.Chance)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!Info.DeathTypes.IsEmpty && !e.Damage.DamageTypes.Overlaps(Info.DeathTypes))
|
if (!Info.DeathTypes.IsEmpty && !e.Damage.DamageTypes.Overlaps(Info.DeathTypes))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var weapon = ChooseWeaponForExplosion(self, sharedRandom);
|
var weapon = ChooseWeaponForExplosion(self);
|
||||||
if (weapon == null)
|
if (weapon == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -134,11 +130,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
weapon.Impact(Target.FromPos(self.CenterPosition), source);
|
weapon.Impact(Target.FromPos(self.CenterPosition), source);
|
||||||
}
|
}
|
||||||
|
|
||||||
WeaponInfo ChooseWeaponForExplosion(Actor self, int sharedRandom)
|
WeaponInfo ChooseWeaponForExplosion(Actor self)
|
||||||
{
|
{
|
||||||
if (!anyArmaments)
|
if (armaments.Length == 0)
|
||||||
return Info.WeaponInfo;
|
return Info.WeaponInfo;
|
||||||
else if (sharedRandom > Info.LoadedChance)
|
else if (self.World.SharedRandom.Next(100) > Info.LoadedChance)
|
||||||
return Info.EmptyWeaponInfo;
|
return Info.EmptyWeaponInfo;
|
||||||
|
|
||||||
// PERF: Avoid LINQ
|
// PERF: Avoid LINQ
|
||||||
|
|||||||
@@ -77,10 +77,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
void INotifyKilled.Killed(Actor self, AttackInfo e)
|
void INotifyKilled.Killed(Actor self, AttackInfo e)
|
||||||
{
|
{
|
||||||
if (!enabled || IsTraitDisabled)
|
if (!enabled || IsTraitDisabled || !self.IsInWorld)
|
||||||
return;
|
|
||||||
|
|
||||||
if (!self.IsInWorld)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (self.World.SharedRandom.Next(100) > Info.Probability)
|
if (self.World.SharedRandom.Next(100) > Info.Probability)
|
||||||
|
|||||||
Reference in New Issue
Block a user