Add GrantsCondition to KillsSelf
This commit is contained in:
committed by
reaperrr
parent
18c6fe09db
commit
370ee0841f
@@ -21,12 +21,17 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[Desc("The amount of time (in ticks) before the actor dies. Two values indicate a range between which a random value is chosen.")]
|
[Desc("The amount of time (in ticks) before the actor dies. Two values indicate a range between which a random value is chosen.")]
|
||||||
public readonly int[] Delay = { 0 };
|
public readonly int[] Delay = { 0 };
|
||||||
|
|
||||||
|
[GrantedConditionReference]
|
||||||
|
[Desc("The condition to grant moments before suiciding.")]
|
||||||
|
public readonly string GrantsCondition = null;
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new KillsSelf(init.Self, this); }
|
public override object Create(ActorInitializer init) { return new KillsSelf(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
class KillsSelf : ConditionalTrait<KillsSelfInfo>, INotifyAddedToWorld, ITick
|
class KillsSelf : ConditionalTrait<KillsSelfInfo>, INotifyCreated, INotifyAddedToWorld, ITick
|
||||||
{
|
{
|
||||||
int lifetime;
|
int lifetime;
|
||||||
|
ConditionManager conditionManager;
|
||||||
|
|
||||||
public KillsSelf(Actor self, KillsSelfInfo info)
|
public KillsSelf(Actor self, KillsSelfInfo info)
|
||||||
: base(info)
|
: base(info)
|
||||||
@@ -42,6 +47,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
Kill(self);
|
Kill(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void INotifyCreated.Created(Actor self)
|
||||||
|
{
|
||||||
|
conditionManager = self.TraitOrDefault<ConditionManager>();
|
||||||
|
}
|
||||||
|
|
||||||
void INotifyAddedToWorld.AddedToWorld(Actor self)
|
void INotifyAddedToWorld.AddedToWorld(Actor self)
|
||||||
{
|
{
|
||||||
if (!IsTraitDisabled)
|
if (!IsTraitDisabled)
|
||||||
@@ -65,6 +75,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (self.IsDead)
|
if (self.IsDead)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (conditionManager != null && !string.IsNullOrEmpty(Info.GrantsCondition))
|
||||||
|
conditionManager.GrantCondition(self, Info.GrantsCondition);
|
||||||
|
|
||||||
if (Info.RemoveInstead || !self.Info.HasTraitInfo<HealthInfo>())
|
if (Info.RemoveInstead || !self.Info.HasTraitInfo<HealthInfo>())
|
||||||
self.Dispose();
|
self.Dispose();
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user