Fix: NPCs spawned under a target couldn't attack#946
Fix: NPCs spawned under a target couldn't attack#946HarleyGilpin wants to merge 4 commits intoGregHib:mainfrom
Conversation
GregHib
left a comment
There was a problem hiding this comment.
Thanks for the contribution! Admittedly this does need a proper architecture solution but this will be a nice short term fix
Thanks for your feed back, I moved step-out logic from CombatMovement into Movement. Since "step out from under a character target" is a movement concern rather than a combat concern, the logic was moved to Movement (the base class) where it applies to all modes automatically. The shape == -2 guard scopes it to character targets only, and the shouldQueueStepOut() hook lets CombatMovement skip queuing a random step when both characters are already in active combat movement, clearing the stale steps and letting normal recalculation take over instead. |
Bug Fix: NPCs spawned under a target couldn't attack
Summary
NPCs spawned under a target couldn't attack because Interact mode (used for the initial attack interaction) had no logic to step out from under the target, unlike
CombatMovementwhich explicitly handles this case.Root Cause
When an NPC with
allowed_under = falseis on the same tile as its target, the following chain of failures occurs:Movement.arrived()false(overlap check fails)calculate()super.tick()cantReach()Fix
Interact.kt(tick()): Before the normalcalculate()/processInteraction()flow, check if the NPC is under its target and not allowed there. If so, mirrorCombatMovement.stepOut()behavior:super.tick()to execute the stepThis lets the NPC move out from under the target on the first tick, allowing combat to initialize normally on the second tick.
Test
CombatMovementTest.kt: Creates a guard NPC spawned at the same tile as a player, callsinteractPlayer(player, "Attack"), ticks twice, and verifies the NPC has moved away and transitioned toCombatMovement.Demo
Screencast_20260410_061246.webm