Merge pull request #12705 from pchote/tweak-killself
Fix KillsSelf trait.
This commit is contained in:
@@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public readonly bool RemoveInstead = false;
|
public readonly bool RemoveInstead = false;
|
||||||
|
|
||||||
[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 = { 250 };
|
public readonly int[] Delay = { 0 };
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new KillsSelf(init.Self, this); }
|
public override object Create(ActorInitializer init) { return new KillsSelf(init.Self, this); }
|
||||||
}
|
}
|
||||||
@@ -34,18 +34,35 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
lifetime = Util.RandomDelay(self.World, info.Delay);
|
lifetime = Util.RandomDelay(self.World, info.Delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddedToWorld(Actor self)
|
protected override void TraitEnabled(Actor self)
|
||||||
|
{
|
||||||
|
// Actors can be created without being added to the world
|
||||||
|
// We want to make sure that this only triggers once they are inserted into the world
|
||||||
|
if (lifetime == 0 && self.IsInWorld)
|
||||||
|
Kill(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
void INotifyAddedToWorld.AddedToWorld(Actor self)
|
||||||
{
|
{
|
||||||
if (!IsTraitDisabled)
|
if (!IsTraitDisabled)
|
||||||
TraitEnabled(self);
|
TraitEnabled(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void TraitEnabled(Actor self)
|
void ITick.Tick(Actor self)
|
||||||
{
|
{
|
||||||
if (self.IsDead)
|
if (!self.IsInWorld || self.IsDead || IsTraitDisabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (lifetime > 0)
|
if (!self.World.Map.Contains(self.Location))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (lifetime-- <= 0)
|
||||||
|
Kill(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Kill(Actor self)
|
||||||
|
{
|
||||||
|
if (self.IsDead)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (Info.RemoveInstead || !self.Info.HasTraitInfo<HealthInfo>())
|
if (Info.RemoveInstead || !self.Info.HasTraitInfo<HealthInfo>())
|
||||||
@@ -53,22 +70,5 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
else
|
else
|
||||||
self.Kill(self);
|
self.Kill(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ITick.Tick(Actor self)
|
|
||||||
{
|
|
||||||
if (self.IsDead || IsTraitDisabled)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!self.World.Map.Contains(self.Location))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (lifetime-- == 0)
|
|
||||||
{
|
|
||||||
if (Info.RemoveInstead || !self.Info.HasTraitInfo<HealthInfo>())
|
|
||||||
self.Dispose();
|
|
||||||
else
|
|
||||||
self.Kill(self);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user