ModernUO/Projects/UOContent.Tests/Tests/Mobiles/AI/AIDeactivationTests.cs
Robert Dickey 75f326bfdd
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.
2026-09-11 17:26:47 -07:00

33 lines
839 B
C#

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();
}
}
}