Fix NPC guarding heartbeat crash from missing patrol metadata
Reported evidence: at 12:50:02 in Newland Desert:0, following Strickadvy's death and players zoning, repeated Failed npc heartbeat ArgumentOutOfRangeException at List.get_Item -> BrainContext.SetCurrentPath line 1040 -> EstablishPath.EvaluatePath line 121 -> guarding behavior tree -> PlayfieldCell.HeartbeatCell line 576. Environment/build and affected NPC IDs were not supplied. Scope: reproduce the patrol movement-mode indexing failure, fix coherent fallback/custom patrol state and patrol advancement boundaries, and verify focused regressions plus engine build. Do not assume the adjacent death/zoning events caused the crash. Acceptance: guarding NPCs without matching authored patrol data can return to spawn without throwing; custom/empty/single-waypoint paths have safe metadata/index state; timed final waypoints wrap correctly; existing authored movement modes are preserved. User authorized committing and opening a pull request via /open-pr; deployment is not authorized. Verified outcome: a concrete BrainContext regression compiled against the original HEAD source reproduces the exact List.get_Item -> SetCurrentPath line 1040 exception. Fallback waypoints previously omitted both movement-mode and wait metadata. Custom paths also omitted metadata and incorrectly started at index 1; timed advancement omitted final-waypoint wrap. BrainContext now initializes coherent fallback/custom metadata, snapshots caller paths, safely handles empty paths, wraps timed advancement and ignores obsolete waits after path replacement. Authored path ordering/modes are retained. Four patrol regressions pass; combined behavior-tree/ActiveNano suite passes 179 tests. PlayfieldEngine build passes with zero warnings/errors; git diff --check passes. Full test-project rebuild passes with existing unrelated warnings. Committed as dcd31f132 on fix/npc-patrol-heartbeat-crash and pushed. Pull request #2564: https://git.project-rk.com/prk/engines/pulls/2564 (base develop). No live environment reproduction or deployment performed; adjacent death/zoning causality is not confirmed.
Checklist
3 of 3 complete- Reproduce guarding crash with concrete BrainContext regression tests.
- Keep fallback/custom/authored patrol metadata and advancement indices coherent; verify boundary regressions.
- Run behavior-tree regression suite and PlayfieldEngine build.
- Area
- Project Rubi-Ka
- Project
- engines
- Kind
- Bug
- Task ID
tsk_xfz8te7fde- Updated