[GH-ISSUE #2714] [Issue]: Game combat — speed-stat crowd-control (Frozen/Stunned) never applied; crit keys off defender not d20; NPC name collisions #1360

Closed
opened 2026-10-21 05:32:17 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @kolacheee on GitHub (Jun 21, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2714

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Game combat has correctness bugs: all speed-stat crowd-control (Frozen/Stunned/Chilled/Entangled, etc.) is cosmetic — never actually applied to initiative/turns — and the critical-hit "natural 20" check keys off the defender's defense modifier instead of the raw d20. Separately, startingNpcs are reconciled by model-provided name with no de-duplication, so duplicate/empty names collide in avatars and journal lookups.

Expected behavior

A Frozen/Stunned combatant should lose/skip its turn; crit chance should depend on rolling a natural 20; and NPCs with duplicate/empty names should be disambiguated rather than crossing each other's portraits/journal data.

Actual behavior

  1. Crowd-control is cosmetic. Combat only reads status effects where effect.stat === "attack", "defense", or "hp". rollInitiative computes order from raw c.speed and never consults statusEffects; no path reads a stat:"speed" modifier. But the elemental-reaction/Genshin/HSR tables inflict their control as stat:"speed" effects (Frozen {modifier:-99,stat:"speed"}, Stunned {-5}, Chilled {-2}, Entangled {-4}, etc.). So a Frozen/Stunned enemy still rolls full initiative and acts every round — damage multipliers from reactions apply, but the disabling half silently fails, making CC builds feel broken/unwinnable.
  2. Crit keys off the defender. attackRoll = d20 + floor(attacker.attack/3). The first crit condition is attackRoll - defenseMod >= 20 where defenseMod = floor(defender.defense/3) — a property of the defender. The raw d20 is never retained, so the "natural 20" check is (attacker d20 + attacker attackMod − defender defenseMod) >= 20 — an arbitrary quantity. Crit frequency depends on attacker attack vs defender defense, not on rolling a 20.
  3. NPC name collisions. applyGameSetupPayload maps startingNpcs to records with a UUID id but the human identity is the model-provided name (fallback NPC i). Avatar URLs derive purely from the slugified name and lookups/journal reconciliation match by normalized name, with no de-dup. Two NPCs with the same/empty name get distinct UUIDs but identical avatar slugs and collide under name-keyed lookups — portraits/journal data cross between them.

How it breaks the pipeline

Code trace (staging @ b826f8f4):

  • (1) packages/server/src/services/game/combat.service.ts:369 (attack), :374 (defense), :439 (hp tick), :303-317 (rollInitiative uses raw c.speed); statusEffects of stat:"speed" defined in element-reactions.service.ts:77,93,134,191,320,367,399,407.
  • (2) combat.service.ts:328 (attackRoll), :331 (defenseMod from defender), :338 (crit condition); raw d20 discarded.
  • (3) game.routes.ts:3062-3078 (NPC map, name identity), :2531-2537 (buildNpcAvatarUrl slug), :2543-2547 (findNpcRecordByName); validation only checks non-empty array at :2450.

Steps to reproduce

  1. Start a combat and apply a Frozen/Stunned-applying reaction → the enemy still appears in the next round's initiative and acts despite the "Frozen" status.
  2. Repeatedly resolveAttack with a high-attack attacker vs a low-defense defender → crit rate vastly exceeds 1/20 and varies with defender.defense.
  3. Have setup produce two startingNpcs with the same/blank name → both resolve to the same avatar slug and collide in findNpcRecordByName.

Suggested fix

  • In rollInitiative, fold active stat:"speed" status modifiers into effective speed (clamp ≥ 0) and treat effectiveSpeed ≤ 0 / a Frozen marker as "skips turn" in the per-combatant loop.
  • Capture the raw d20 (rawAttackD20) and base the nat-20 crit on rawAttackD20 === 20; keep the margin-based crit separate.
  • De-duplicate/validate NPC names when applying startingNpcs (reject/rename blanks and collisions) and/or key avatars and reconciliation off the stable NPC id rather than the display name.

Environment

  • Marinara Engine version: 2.0.0 (staging @ b826f8f4)
  • Install type: source
  • OS + version: All (code-level defect, platform-independent)
  • Browser or app shell: All

Additional context

Found via a systematic multi-agent audit of Game Mode. Combat-correctness + NPC-identity bugs that make CC builds and combat outcomes feel broken. Part of a set of game-mode issues filed together.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @kolacheee on GitHub (Jun 21, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2714 Originally assigned to: @SpicyMarinara on GitHub. ## Summary Game combat has correctness bugs: all speed-stat crowd-control (Frozen/Stunned/Chilled/Entangled, etc.) is **cosmetic** — never actually applied to initiative/turns — and the critical-hit "natural 20" check keys off the **defender's** defense modifier instead of the raw d20. Separately, `startingNpcs` are reconciled by model-provided name with no de-duplication, so duplicate/empty names collide in avatars and journal lookups. ## Expected behavior A Frozen/Stunned combatant should lose/skip its turn; crit chance should depend on rolling a natural 20; and NPCs with duplicate/empty names should be disambiguated rather than crossing each other's portraits/journal data. ## Actual behavior 1. **Crowd-control is cosmetic.** Combat only reads status effects where `effect.stat === "attack"`, `"defense"`, or `"hp"`. `rollInitiative` computes order from raw `c.speed` and never consults `statusEffects`; no path reads a `stat:"speed"` modifier. But the elemental-reaction/Genshin/HSR tables inflict their control as `stat:"speed"` effects (Frozen `{modifier:-99,stat:"speed"}`, Stunned `{-5}`, Chilled `{-2}`, Entangled `{-4}`, etc.). So a Frozen/Stunned enemy still rolls full initiative and acts every round — damage multipliers from reactions apply, but the disabling half silently fails, making CC builds feel broken/unwinnable. 2. **Crit keys off the defender.** `attackRoll = d20 + floor(attacker.attack/3)`. The first crit condition is `attackRoll - defenseMod >= 20` where `defenseMod = floor(defender.defense/3)` — a property of the **defender**. The raw d20 is never retained, so the "natural 20" check is `(attacker d20 + attacker attackMod − defender defenseMod) >= 20` — an arbitrary quantity. Crit frequency depends on attacker attack vs defender defense, not on rolling a 20. 3. **NPC name collisions.** `applyGameSetupPayload` maps `startingNpcs` to records with a UUID `id` but the human identity is the model-provided `name` (fallback `NPC i`). Avatar URLs derive purely from the slugified name and lookups/journal reconciliation match by normalized name, with no de-dup. Two NPCs with the same/empty name get distinct UUIDs but identical avatar slugs and collide under name-keyed lookups — portraits/journal data cross between them. ## How it breaks the pipeline Code trace (staging @ `b826f8f4`): - (1) `packages/server/src/services/game/combat.service.ts:369` (`attack`), `:374` (`defense`), `:439` (`hp` tick), `:303-317` (`rollInitiative` uses raw `c.speed`); `statusEffects` of `stat:"speed"` defined in `element-reactions.service.ts:77,93,134,191,320,367,399,407`. - (2) `combat.service.ts:328` (`attackRoll`), `:331` (`defenseMod` from defender), `:338` (crit condition); raw d20 discarded. - (3) `game.routes.ts:3062-3078` (NPC map, name identity), `:2531-2537` (`buildNpcAvatarUrl` slug), `:2543-2547` (`findNpcRecordByName`); validation only checks non-empty array at `:2450`. ## Steps to reproduce 1. Start a combat and apply a Frozen/Stunned-applying reaction → the enemy still appears in the next round's initiative and acts despite the "Frozen" status. 2. Repeatedly `resolveAttack` with a high-attack attacker vs a low-defense defender → crit rate vastly exceeds 1/20 and varies with `defender.defense`. 3. Have setup produce two `startingNpcs` with the same/blank name → both resolve to the same avatar slug and collide in `findNpcRecordByName`. ## Suggested fix - In `rollInitiative`, fold active `stat:"speed"` status modifiers into effective speed (clamp ≥ 0) and treat effectiveSpeed ≤ 0 / a Frozen marker as "skips turn" in the per-combatant loop. - Capture the raw d20 (`rawAttackD20`) and base the nat-20 crit on `rawAttackD20 === 20`; keep the margin-based crit separate. - De-duplicate/validate NPC names when applying `startingNpcs` (reject/rename blanks and collisions) and/or key avatars and reconciliation off the stable NPC `id` rather than the display name. ## Environment - Marinara Engine version: 2.0.0 (staging @ `b826f8f4`) - Install type: source - OS + version: All (code-level defect, platform-independent) - Browser or app shell: All ## Additional context Found via a systematic multi-agent audit of Game Mode. Combat-correctness + NPC-identity bugs that make CC builds and combat outcomes feel broken. Part of a set of game-mode issues filed together. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
Author
Owner

@SpicyMarinara commented on GitHub (Jun 21, 2026):

Fixed in b48c9953. Combat initiative now folds active speed status modifiers into effective speed and skips turn-blocking statuses like Frozen/Stunned/Imprisoned; critical hits now use the raw attack d20 for natural 20s; setup NPC names are de-duplicated on apply so duplicate model names do not collide in name-keyed avatar/journal lookups.

<!-- gh-comment-id:4761655398 --> @SpicyMarinara commented on GitHub (Jun 21, 2026): Fixed in b48c9953. Combat initiative now folds active speed status modifiers into effective speed and skips turn-blocking statuses like Frozen/Stunned/Imprisoned; critical hits now use the raw attack d20 for natural 20s; setup NPC names are de-duplicated on apply so duplicate model names do not collide in name-keyed avatar/journal lookups.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#1360
No description provided.