From 7090c29e8cd45c34250da05baf8ab768dcec7748 Mon Sep 17 00:00:00 2001 From: Arufonsu <17498701+Arufonsu@users.noreply.github.com> Date: Thu, 8 Jan 2026 23:47:14 -0300 Subject: [PATCH] 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> --- Intersect.Server.Core/Entities/Npc.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Intersect.Server.Core/Entities/Npc.cs b/Intersect.Server.Core/Entities/Npc.cs index 118855cdbb..bc1e510455 100644 --- a/Intersect.Server.Core/Entities/Npc.cs +++ b/Intersect.Server.Core/Entities/Npc.cs @@ -837,6 +837,24 @@ public override void Update(long timeMs) var targetY = 0; var targetZ = 0; + // If target is on a different instance, clear it immediately + if (tempTarget != null && tempTarget.MapInstanceId != MapInstanceId) + { + RemoveTarget(); + tempTarget = null; + + // Also clear aggro center since target is unreachable + if (AggroCenterMap != null) + { + AggroCenterMap = null; + AggroCenterX = 0; + AggroCenterY = 0; + AggroCenterZ = 0; + mPathFinder?.SetTarget(null); + mResetting = false; + } + } + if (tempTarget != null && (tempTarget.IsDead || !InRangeOf(tempTarget, Options.Instance.Map.MapWidth * 2) || !CanTarget(tempTarget))) { _ = TryFindNewTarget(Timing.Global.Milliseconds, tempTarget.Id, !CanTarget(tempTarget));