fix: handle null maps when deactivating creature AI (#2629)
An uncontrolled creature with `Map == null` throws in `BaseAI.Deactivate()` when the condition reaches `Map.GetSector()`. A controlled creature with a null map avoids the exception but leaves its AI timer running. Treat a null map like `Map.Internal` in the existing stop condition. This stops the timer without dereferencing the missing map and leaves the existing valid-map condition and return-home scheduling unchanged. Addresses only the null-map `Deactivate()` item in #2627; the other audit items remain separate. No era-specific rules are changed.
This commit is contained in:
parent
51d2e998fc
commit
75f326bfdd
2 changed files with 34 additions and 1 deletions
|
|
@ -0,0 +1,33 @@
|
|||
using Server;
|
||||
using Xunit;
|
||||
|
||||
namespace UOContent.Tests.Mobiles.AI;
|
||||
|
||||
[Collection("Sequential UOContent Tests")]
|
||||
public class AIDeactivationTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(false, false)]
|
||||
[InlineData(false, true)]
|
||||
[InlineData(true, false)]
|
||||
[InlineData(true, true)]
|
||||
public void Deactivate_WithoutWorldMap_StopsTimer(bool internalMap, bool controlled)
|
||||
{
|
||||
var creature = new PetTestStub();
|
||||
try
|
||||
{
|
||||
creature.Controlled = controlled;
|
||||
creature.Map = internalMap ? Map.Internal : null;
|
||||
creature.AIObject.Activate();
|
||||
Assert.True(creature.AIObject.AITimer.Running);
|
||||
|
||||
creature.AIObject.Deactivate();
|
||||
|
||||
Assert.False(creature.AIObject.AITimer.Running);
|
||||
}
|
||||
finally
|
||||
{
|
||||
creature.Delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1102,7 +1102,7 @@ public abstract partial class BaseAI
|
|||
|
||||
public virtual void Deactivate()
|
||||
{
|
||||
if (Mobile.Map == Map.Internal || !Mobile.Controlled && !Mobile.Map.GetSector(Mobile.Location).Active)
|
||||
if (Mobile.Map == null || Mobile.Map == Map.Internal || !Mobile.Controlled && !Mobile.Map.GetSector(Mobile.Location).Active)
|
||||
{
|
||||
AITimer.Stop();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue