Skip to content

Commit 1973d72

Browse files
Arufonsupandinocoder
authored andcommitted
fix: NPCs disappearing when targets enter different map instances
When a player aggros an NPC and then enters a different map instance (dungeon, dies, etc.), the NPC would attempt to reset and chase an unreachable target. This caused NPCs to become stuck in a reset loop or disappear from their spawn map entirely. The fix clears the NPC's target and aggro center immediately when the target switches to a different MapInstanceId, preventing the NPC from attempting to path to or reset towards an unreachable location. Fixes #2769 Signed-off-by: Arufonsu <17498701+Arufonsu@users.noreply.github.com>
1 parent 4891f3c commit 1973d72

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

  • Intersect.Server.Core/Entities

Intersect.Server.Core/Entities/Npc.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,24 @@ public override void Update(long timeMs)
837837
var targetY = 0;
838838
var targetZ = 0;
839839

840+
// If target is on a different instance, clear it immediately
841+
if (tempTarget != null && tempTarget.MapInstanceId != MapInstanceId)
842+
{
843+
RemoveTarget();
844+
tempTarget = null;
845+
846+
// Also clear aggro center since target is unreachable
847+
if (AggroCenterMap != null)
848+
{
849+
AggroCenterMap = null;
850+
AggroCenterX = 0;
851+
AggroCenterY = 0;
852+
AggroCenterZ = 0;
853+
mPathFinder?.SetTarget(null);
854+
mResetting = false;
855+
}
856+
}
857+
840858
if (tempTarget != null && (tempTarget.IsDead || !InRangeOf(tempTarget, Options.Instance.Map.MapWidth * 2) || !CanTarget(tempTarget)))
841859
{
842860
_ = TryFindNewTarget(Timing.Global.Milliseconds, tempTarget.Id, !CanTarget(tempTarget));

0 commit comments

Comments
 (0)