Make EjectOnDeath conditional
This commit is contained in:
committed by
Paul Chote
parent
0bff9e9119
commit
ea2794b417
@@ -16,7 +16,7 @@ using OpenRA.Traits;
|
|||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
[Desc("Eject a ground soldier or a paratrooper while in the air.")]
|
[Desc("Eject a ground soldier or a paratrooper while in the air.")]
|
||||||
public class EjectOnDeathInfo : ITraitInfo
|
public class EjectOnDeathInfo : ConditionalTraitInfo
|
||||||
{
|
{
|
||||||
[ActorReference]
|
[ActorReference]
|
||||||
[Desc("Name of the unit to eject. This actor type needs to have the Parachutable trait defined.")]
|
[Desc("Name of the unit to eject. This actor type needs to have the Parachutable trait defined.")]
|
||||||
@@ -37,23 +37,19 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[Desc("Risks stuck units when they don't have the Paratrooper trait.")]
|
[Desc("Risks stuck units when they don't have the Paratrooper trait.")]
|
||||||
public readonly bool AllowUnsuitableCell = false;
|
public readonly bool AllowUnsuitableCell = false;
|
||||||
|
|
||||||
public object Create(ActorInitializer init) { return new EjectOnDeath(init.Self, this); }
|
public override object Create(ActorInitializer init) { return new EjectOnDeath(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IPreventsEjectOnDeath { bool PreventsEjectOnDeath(Actor self); }
|
public interface IPreventsEjectOnDeath { bool PreventsEjectOnDeath(Actor self); }
|
||||||
|
|
||||||
public class EjectOnDeath : INotifyKilled
|
public class EjectOnDeath : ConditionalTrait<EjectOnDeathInfo>, INotifyKilled
|
||||||
{
|
{
|
||||||
readonly EjectOnDeathInfo info;
|
|
||||||
|
|
||||||
public EjectOnDeath(Actor self, EjectOnDeathInfo info)
|
public EjectOnDeath(Actor self, EjectOnDeathInfo info)
|
||||||
{
|
: base(info) { }
|
||||||
this.info = info;
|
|
||||||
}
|
|
||||||
|
|
||||||
void INotifyKilled.Killed(Actor self, AttackInfo e)
|
void INotifyKilled.Killed(Actor self, AttackInfo e)
|
||||||
{
|
{
|
||||||
if (self.Owner.WinState == WinState.Lost || !self.World.Map.Contains(self.Location))
|
if (IsTraitDisabled || self.Owner.WinState == WinState.Lost || !self.World.Map.Contains(self.Location))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (var condition in self.TraitsImplementing<IPreventsEjectOnDeath>())
|
foreach (var condition in self.TraitsImplementing<IPreventsEjectOnDeath>())
|
||||||
@@ -62,18 +58,18 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
var r = self.World.SharedRandom.Next(1, 100);
|
var r = self.World.SharedRandom.Next(1, 100);
|
||||||
|
|
||||||
if (r <= 100 - info.SuccessRate)
|
if (r <= 100 - Info.SuccessRate)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var cp = self.CenterPosition;
|
var cp = self.CenterPosition;
|
||||||
var inAir = !self.IsAtGroundLevel();
|
var inAir = !self.IsAtGroundLevel();
|
||||||
if ((inAir && !info.EjectInAir) || (!inAir && !info.EjectOnGround))
|
if ((inAir && !Info.EjectInAir) || (!inAir && !Info.EjectOnGround))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var pilot = self.World.CreateActor(false, info.PilotActor.ToLowerInvariant(),
|
var pilot = self.World.CreateActor(false, Info.PilotActor.ToLowerInvariant(),
|
||||||
new TypeDictionary { new OwnerInit(self.Owner), new LocationInit(self.Location) });
|
new TypeDictionary { new OwnerInit(self.Owner), new LocationInit(self.Location) });
|
||||||
|
|
||||||
if (info.AllowUnsuitableCell || IsSuitableCell(self, pilot))
|
if (Info.AllowUnsuitableCell || IsSuitableCell(self, pilot))
|
||||||
{
|
{
|
||||||
if (inAir)
|
if (inAir)
|
||||||
{
|
{
|
||||||
@@ -82,7 +78,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
w.Add(pilot);
|
w.Add(pilot);
|
||||||
pilot.QueueActivity(new Parachute(pilot, cp));
|
pilot.QueueActivity(new Parachute(pilot, cp));
|
||||||
});
|
});
|
||||||
Game.Sound.Play(SoundType.World, info.ChuteSound, cp);
|
Game.Sound.Play(SoundType.World, Info.ChuteSound, cp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user