Add interface IPreventsEjectOnDeath.
This commit is contained in:
@@ -17,11 +17,26 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
public bool IsValidTarget(ActorInfo actorInfo, Actor saboteur) { return true; }
|
public bool IsValidTarget(ActorInfo actorInfo, Actor saboteur) { return true; }
|
||||||
|
|
||||||
public object Create(ActorInitializer init) { return new Demolishable(); }
|
[Desc("If true and this actor has EjectOnDeath, no actor will be spawned.")]
|
||||||
|
public readonly bool PreventsEjectOnDeath = false;
|
||||||
|
|
||||||
|
public object Create(ActorInitializer init) { return new Demolishable(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Demolishable : IDemolishable
|
public class Demolishable : IDemolishable, IPreventsEjectOnDeath
|
||||||
{
|
{
|
||||||
|
readonly DemolishableInfo info;
|
||||||
|
|
||||||
|
public Demolishable(Actor self, DemolishableInfo info)
|
||||||
|
{
|
||||||
|
this.info = info;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool PreventsEjectOnDeath(Actor self)
|
||||||
|
{
|
||||||
|
return info.PreventsEjectOnDeath;
|
||||||
|
}
|
||||||
|
|
||||||
public void Demolish(Actor self, Actor saboteur)
|
public void Demolish(Actor self, Actor saboteur)
|
||||||
{
|
{
|
||||||
self.Kill(saboteur);
|
self.Kill(saboteur);
|
||||||
|
|||||||
@@ -15,7 +15,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 : TraitInfo<EjectOnDeath>
|
public class EjectOnDeathInfo : ITraitInfo
|
||||||
{
|
{
|
||||||
[ActorReference]
|
[ActorReference]
|
||||||
public readonly string PilotActor = "E1";
|
public readonly string PilotActor = "E1";
|
||||||
@@ -26,17 +26,31 @@ 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 interface IPreventsEjectOnDeath { bool PreventsEjectOnDeath(Actor self); }
|
||||||
|
|
||||||
public class EjectOnDeath : INotifyKilled
|
public class EjectOnDeath : INotifyKilled
|
||||||
{
|
{
|
||||||
|
readonly EjectOnDeathInfo info;
|
||||||
|
|
||||||
|
public EjectOnDeath(Actor self, EjectOnDeathInfo info)
|
||||||
|
{
|
||||||
|
this.info = info;
|
||||||
|
}
|
||||||
|
|
||||||
public void Killed(Actor self, AttackInfo e)
|
public void Killed(Actor self, AttackInfo e)
|
||||||
{
|
{
|
||||||
if (self.Owner.WinState == WinState.Lost || !self.World.Map.Contains(self.Location))
|
if (self.Owner.WinState == WinState.Lost || !self.World.Map.Contains(self.Location))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
foreach (var condition in self.TraitsImplementing<IPreventsEjectOnDeath>())
|
||||||
|
if (condition.PreventsEjectOnDeath(self))
|
||||||
|
return;
|
||||||
|
|
||||||
var r = self.World.SharedRandom.Next(1, 100);
|
var r = self.World.SharedRandom.Next(1, 100);
|
||||||
var info = self.Info.Traits.Get<EjectOnDeathInfo>();
|
|
||||||
|
|
||||||
if (r <= 100 - info.SuccessRate)
|
if (r <= 100 - info.SuccessRate)
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user