Fix KillSelf behaviour for out-of-world actors.
This commit is contained in:
@@ -34,36 +34,37 @@ namespace OpenRA.Mods.Common.Traits
|
||||
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)
|
||||
TraitEnabled(self);
|
||||
}
|
||||
|
||||
protected override void TraitEnabled(Actor self)
|
||||
{
|
||||
if (self.IsDead)
|
||||
return;
|
||||
|
||||
if (lifetime > 0)
|
||||
return;
|
||||
|
||||
if (Info.RemoveInstead || !self.Info.HasTraitInfo<HealthInfo>())
|
||||
self.Dispose();
|
||||
else
|
||||
self.Kill(self);
|
||||
}
|
||||
|
||||
void ITick.Tick(Actor self)
|
||||
{
|
||||
if (self.IsDead || IsTraitDisabled)
|
||||
if (!self.IsInWorld || self.IsDead || IsTraitDisabled)
|
||||
return;
|
||||
|
||||
if (!self.World.Map.Contains(self.Location))
|
||||
return;
|
||||
|
||||
if (lifetime-- == 0)
|
||||
if (lifetime-- <= 0)
|
||||
Kill(self);
|
||||
}
|
||||
|
||||
void Kill(Actor self)
|
||||
{
|
||||
if (self.IsDead)
|
||||
return;
|
||||
|
||||
if (Info.RemoveInstead || !self.Info.HasTraitInfo<HealthInfo>())
|
||||
self.Dispose();
|
||||
else
|
||||
@@ -71,4 +72,3 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user