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.")]
|
||||
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); }
|
||||
}
|
||||
|
||||
class KillsSelf : ConditionalTrait<KillsSelfInfo>, INotifyAddedToWorld, ITick
|
||||
class KillsSelf : ConditionalTrait<KillsSelfInfo>, INotifyCreated, INotifyAddedToWorld, ITick
|
||||
{
|
||||
int lifetime;
|
||||
ConditionManager conditionManager;
|
||||
|
||||
public KillsSelf(Actor self, KillsSelfInfo info)
|
||||
: base(info)
|
||||
@@ -42,6 +47,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
Kill(self);
|
||||
}
|
||||
|
||||
void INotifyCreated.Created(Actor self)
|
||||
{
|
||||
conditionManager = self.TraitOrDefault<ConditionManager>();
|
||||
}
|
||||
|
||||
void INotifyAddedToWorld.AddedToWorld(Actor self)
|
||||
{
|
||||
if (!IsTraitDisabled)
|
||||
@@ -65,6 +75,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (self.IsDead)
|
||||
return;
|
||||
|
||||
if (conditionManager != null && !string.IsNullOrEmpty(Info.GrantsCondition))
|
||||
conditionManager.GrantCondition(self, Info.GrantsCondition);
|
||||
|
||||
if (Info.RemoveInstead || !self.Info.HasTraitInfo<HealthInfo>())
|
||||
self.Dispose();
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user