Files
BreakEscape/planning_notes/npc/hostile/FORMAT_REVIEW.md
Z. Cliffe Schreuders 660105421a Add Hostile NPC mode
Fix NPC interaction and event handling issues

- Added a visual problem-solution summary for debugging NPC event handling.
- Resolved cooldown bug in NPCManager by implementing explicit null/undefined checks.
- Modified PersonChatMinigame to prioritize event parameters over state restoration.
- Updated security guard dialogue in Ink scenarios to improve interaction flow.
- Adjusted vault key parameters in npc-patrol-lockpick.json for consistency.
- Changed inventory stylesheet references to hud.css in test HTML files for better organization.

feat(combat): Integrate chair kicking with punch mechanic

Update chair interaction to use the punch system instead of direct kicking:

**Changes to interactions.js:**
- Modified swivel chair interaction to trigger player punch instead of
  directly applying kick velocity
- Simplified chair interaction handler to just call playerCombat.punch()

**Changes to player-combat.js:**
- Extended checkForHits() to detect chairs in punch range and direction
- Added kickChair() method that applies the same velocity calculation:
  - Calculates direction from player to chair
  - Applies 1200 px/s kick force in that direction
  - Triggers spin direction calculation for visual rotation
  - Adds visual feedback (flash chair, light screen shake)
- Chairs now respond to punch AOE damage like hostile NPCs

Now clicking a chair or pressing 'E' near it triggers a punch, and if the
chair is in punch range and facing direction, it gets kicked with the
original velocity physics. Multiple chairs can be kicked with one punch.

feat(combat): Implement hostile NPC behavior and final integration (Phase 6-7)

Complete hostile NPC combat system with chase behavior and integration:

**Phase 6: Hostile NPC Behavior**
- Modified npc-behavior.js determineState() to check hostile state from npcHostileSystem
- Implemented updateHostileBehavior() with chase and attack logic:
  - NPCs chase player when hostile and in aggro range
  - NPCs stop and attack when in attack range
  - NPCs use directional movement with proper animations
  - Integration with npcCombat system for attack attempts
- Added KO state check to prevent KO'd NPCs from acting

**Phase 7: Final Integration**
- Modified player.js to disable movement when player is KO
- Added visual KO effect (50% alpha) to NPC sprites in npc-hostile.js
- Connected all combat systems end-to-end:
  - Ink dialogue → hostile tag → hostile state → chase behavior → combat
  - Player interaction → punch → NPC damage → KO → visual feedback
  - NPC chase → attack → player damage → HP UI → game over

Full combat loop now functional: hostile NPCs chase and attack player,
player can punch hostile NPCs, complete visual/audio feedback, game over on KO.

feat(combat): Add feedback, UI, and combat mechanics (Phase 2-5)

Implement comprehensive combat feedback, UI, and mechanics:

**Phase 2: Enhanced Feedback Systems**
- damage-numbers.js: Floating damage numbers with object pooling
- screen-effects.js: Screen flash and shake for combat feedback
- sprite-effects.js: Sprite tinting, flashing, and visual effects
- attack-telegraph.js: Visual indicators for incoming NPC attacks

**Phase 3: UI Components**
- health-ui.js: Player health display as hearts (5 hearts, shows when damaged)
- npc-health-bars.js: Health bars above hostile NPCs with color coding
- game-over-screen.js: KO screen with restart/main menu options

**Phase 4-5: Combat Mechanics**
- player-combat.js: Player punch system with AOE directional damage
- npc-combat.js: NPC attack system with telegraph and cooldowns
- Modified interactions.js to trigger punch on hostile NPC interaction
- Integrated all systems into game.js create() and update() loops

Combat now functional with complete visual/audio feedback pipeline.
Player can punch hostile NPCs, NPCs can attack player, health tracking works.

feat(combat): Add hostile NPC system foundation (Phase 0-1)

Implement core hostile NPC combat system infrastructure:

- Add #hostile tag handler to chat-helpers.js for Ink integration
- Fix security-guard.ink to use proper hub pattern with -> hub instead of -> END
- Add #hostile:security_guard tags to hostile conversation paths
- Create combat configuration system (combat-config.js)
- Create combat event constants (combat-events.js)
- Implement player health tracking system with HP and KO state
- Implement NPC hostile state management with HP tracking
- Add combat debug utilities for testing
- Add error handling utilities for validation
- Integrate combat systems into game.js create() method
- Create test-hostile.ink for testing hostile tag system

This establishes the foundation for hostile NPC behavior, allowing NPCs to
become hostile through Ink dialogue and tracking health for both player and NPCs.

docs(npc): Apply codebase-verified corrections to hostile NPC plans

Apply critical corrections based on actual codebase verification:

CORRECTIONS.md (Updated):
-  Confirms #exit_conversation tag ALREADY IMPLEMENTED
  * Location: person-chat-minigame.js line 537
  * No handler needed in chat-helpers.js
-  Hostile tag still needs implementation in chat-helpers.js
- Provides exact code for hostile tag handler
- Clarifies tag format: #hostile:npcId or #hostile (uses current NPC)
- Updated action items to reflect what's already working

INTEGRATION_UPDATES.md (New):
- Comprehensive correction document
- Issue 1 Corrected: Exit conversation already works
- Issue 6 Corrected: Punch mechanics are interaction-based with AOE
- Details interaction-based punch targeting:
  * Player clicks hostile NPC OR presses 'E' nearby
  * Punch animation plays in facing direction
  * Damage applies to ALL NPCs in range + direction (AOE)
  * Can hit multiple enemies if grouped (strategic gameplay)
- Provides complete implementation examples
- Removes complexity of target selection systems
- Uses existing interaction patterns

quick_start.md (Updated):
- Removed exit_conversation handler (already exists)
- Updated hostile tag handler code
- Added punch mechanics design section
- Clarified interaction-based targeting
- Added troubleshooting for exit_conversation

Key Findings:
 Exit conversation tag works out of the box
 Punch targeting uses existing interaction system (simpler!)
 AOE punch adds strategic depth without complexity
 Only ONE critical task remains: Add hostile tag to chat-helpers.js

Impact:
- Less work required (don't need exit_conversation handler)
- Simpler implementation (use existing interaction patterns)
- Better gameplay (AOE punches, directional attacks)
- Clear path forward with exact code examples

docs(npc): Add critical corrections and codebase integration review

Add comprehensive review of hostile NPC plans against actual codebase:

CORRECTIONS.md:
- Identifies critical Ink pattern error (-> END vs -> hub)
- Documents correct hub-based conversation pattern
- Provides corrected examples for all Ink files
- Explains why -> hub is required after #exit_conversation

FORMAT_REVIEW.md:
- Validates JSON scenario format against existing scenarios
- Reviews NPC object structure and required fields
- Documents correct Ink hub pattern from helper-npc.ink
- Proposes hostile configuration object for NPC customization
- Provides complete format reference and checklists

review2/integration_review.md:
- Comprehensive codebase analysis by Explore agent
- Identifies 2 critical blockers requiring immediate attention:
  * Missing tag handlers for #hostile and #exit_conversation
  * Incorrect Ink pattern (-> END) in planning documents
- Documents 4 important integration differences:
  * Initialization in game.js not main.js
  * Event dispatcher already exists (window.eventDispatcher)
  * Room transition behavior needs design decision
  * Multi-hostile NPC targeting needs design decision
- Confirms 8 systems are fully compatible with plan
- Provides existing code patterns to follow
- Corrects integration sequence

review2/quick_start.md:
- Step-by-step guide for Phase 0-1 implementation
- Includes complete code examples for critical systems
- Browser console test procedures
- Common issues and solutions
- Success criteria checklist

Key Findings:
 90% compatible with existing codebase
 Must add tag handlers to chat-helpers.js before implementation
 Must fix all Ink examples to use -> hub not -> END
⚠️ Should follow game.js initialization pattern not main.js
⚠️ Should use existing window.eventDispatcher
⚠️ Need design decisions on room transitions and multi-targeting

All critical issues documented with solutions ready.
Implementation can proceed with high confidence after corrections applied.

docs(npc): Add comprehensive planning documents for hostile NPC system

Add detailed implementation plans for hostile NPC feature including:
- Complete implementation plan with phase-by-phase breakdown
- Architecture overview with system diagrams and data flows
- Detailed TODO list with 200+ actionable tasks
- Phase 0 foundation with design decisions and base components
- Enhanced combat feedback implementation guide
- Implementation roadmap with 6-day schedule

Add comprehensive review documents:
- Implementation review with risk assessment and recommendations
- Technical review analyzing code patterns and best practices
- UX review covering player experience and game feel

Key features planned:
- NPC hostile state triggered via Ink tags
- Player health system with heart-based UI
- NPC health bars and combat mechanics
- Punch combat for both player and NPCs
- Strong visual/audio feedback for combat
- Game over system and KO states
- Attack telegraphing for fairness
- Enhanced NPC chase behavior with LOS
- Debug utilities and error handling
- Comprehensive testing strategy
2025-11-14 19:47:54 +00:00

10 KiB

Format Review - JSON Scenarios and Ink Files

Review Summary

This document reviews all JSON scenario and Ink file examples in the planning documents against the actual codebase formats.


1. Ink File Format Review

Correct Pattern (from helper-npc.ink)

Hub Pattern:

=== start ===
# speaker:npc
Initial dialogue
-> hub

=== hub ===
+ [Choice 1]
    -> knot1
+ [Choice 2]
    -> knot2
+ [Exit choice]
    # speaker:npc
    Goodbye message
    #exit_conversation
    -> hub

=== knot1 ===
# speaker:npc
Dialogue
-> hub

Key Rules:

  1. Always -> hub (NEVER -> END)
  2. #exit_conversation tag to close UI
  3. Even after #exit_conversation, use -> hub
  4. Hub is the central conversation state
  5. start knot is entry point, immediately goes to hub

Issues Found in Planning Documents

implementation_plan.md (Lines ~605-625):

  • Shows # exit_conversation followed by -> END
  • Should be # exit_conversation followed by -> hub

phase0_foundation.md (Test Ink File):

  • Shows -> END in multiple places
  • Should be -> hub everywhere

Corrected in: CORRECTIONS.md


2. JSON Scenario Format Review

Correct NPC Format (from npc-patrol-lockpick.json)

Complete NPC Definition:

{
  "id": "security_guard",
  "displayName": "Security Guard",
  "npcType": "person",
  "position": { "x": 5, "y": 4 },
  "spriteSheet": "hacker-red",
  "spriteTalk": "assets/characters/hacker-red-talk.png",
  "spriteConfig": {
    "idleFrameStart": 20,
    "idleFrameEnd": 23
  },
  "storyPath": "scenarios/ink/security-guard.json",
  "currentKnot": "start",
  "behavior": {
    "patrol": {
      "enabled": true,
      "route": [
        { "x": 2, "y": 3 },
        { "x": 8, "y": 3 }
      ],
      "speed": 40,
      "pauseTime": 10
    }
  },
  "los": {
    "enabled": true,
    "range": 150,
    "angle": 140,
    "visualize": true
  },
  "eventMappings": [
    {
      "eventPattern": "lockpick_used_in_view",
      "targetKnot": "on_lockpick_used",
      "conversationMode": "person-chat",
      "cooldown": 0
    }
  ]
}

Required Fields:

  • id - Unique NPC identifier (string)
  • displayName - Name shown to player (string)
  • npcType - Type of NPC (usually "person" for sprite NPCs)
  • position - { x, y } in pixels or tiles depending on context
  • spriteSheet - Name of sprite sheet (without extension)
  • storyPath - Path to compiled Ink JSON file
  • currentKnot - Starting knot (usually "start")

Optional Fields:

  • spriteTalk - Path to talking sprite variant
  • spriteConfig - Animation frame configuration
    • idleFrameStart - First frame of idle animation
    • idleFrameEnd - Last frame of idle animation
    • idleFrame - Single frame for static idle (alternative)
  • behavior - Behavior configuration object
    • facePlayer - Boolean or object with distance
    • patrol - Patrol configuration
  • los - Line of sight configuration
    • enabled - Boolean
    • range - Detection range in pixels
    • angle - Field of view angle in degrees
    • visualize - Show debug visualization
  • eventMappings - Array of event-to-conversation mappings
    • eventPattern - Event name to listen for
    • targetKnot - Ink knot to jump to
    • conversationMode - Type of conversation ("person-chat", "phone", etc.)
    • cooldown - Cooldown in milliseconds

📝 Review of Planning Document Examples

phase0_foundation.md Test NPC (Lines 352-362):

{
  "id": "test_npc",
  "displayName": "Test Dummy",
  "npcType": "person",
  "spriteSheet": "hacker",
  "storyPath": "scenarios/ink/test-hostile.json",
  "currentKnot": "start",
  "position": { "x": 100, "y": 100 },
  "roomId": "test_room"
}

Review:

  • Has all required fields
  • Correct JSON structure
  • ⚠️ Has roomId field - this is not needed in the NPC object itself
    • NPCs are defined inside room objects in the scenario
    • The room context is implicit
  • ⚠️ Missing optional but useful fields:
    • spriteConfig for idle animation
    • Could add minimal behavior for testing
    • Could add minimal los for hostile testing

Corrected Example:

{
  "id": "test_npc",
  "displayName": "Test Dummy",
  "npcType": "person",
  "position": { "x": 100, "y": 100 },
  "spriteSheet": "hacker",
  "spriteConfig": {
    "idleFrameStart": 20,
    "idleFrameEnd": 23
  },
  "storyPath": "scenarios/ink/test-hostile.json",
  "currentKnot": "start",
  "behavior": {
    "patrol": {
      "enabled": false
    }
  }
}

3. Complete Scenario Structure

Correct Full Scenario Format

From npc-patrol-lockpick.json:

{
  "scenario_brief": "Brief description",
  "endGoal": "Goal description",
  "startRoom": "room_id",

  "player": {
    "id": "player",
    "displayName": "Player Name",
    "spriteSheet": "hacker",
    "spriteTalk": "assets/characters/hacker-talk.png",
    "spriteConfig": {
      "idleFrameStart": 20,
      "idleFrameEnd": 23
    }
  },

  "rooms": {
    "room_id": {
      "type": "room_type",
      "connections": {
        "north": "other_room_id"
      },
      "npcs": [
        { /* NPC objects here */ }
      ],
      "objects": [
        { /* Object definitions here */ }
      ]
    }
  }
}

Top-Level Fields:

  • scenario_brief - Description shown to player
  • endGoal - Win condition description
  • startRoom - ID of starting room
  • startItemsInInventory - Array of items (optional)
  • player - Player configuration (optional)
  • rooms - Object with room definitions

Room Fields:

  • type - Room tilemap type (e.g., "room_office", "room_reception")
  • connections - Object mapping directions to room IDs
    • Valid directions: "north", "south", "east", "west"
  • locked - Boolean (optional)
  • lockType - "key", "pin", "password", etc. (if locked)
  • requires - Key ID or password/PIN (if locked)
  • keyPins - Array of lock pins for lockpicking (if lockType is "key")
  • difficulty - "easy", "medium", "hard" (for lockpicking)
  • door_sign - Text shown on door (optional)
  • npcs - Array of NPC objects
  • objects - Array of object definitions

4. New NPC Fields for Hostile System

Proposed Addition

For NPCs that can become hostile, add optional hostile configuration:

{
  "id": "tough_guard",
  "displayName": "Elite Guard",
  "npcType": "person",
  "position": { "x": 5, "y": 5 },
  "spriteSheet": "hacker-red",
  "storyPath": "scenarios/ink/tough-guard.json",
  "currentKnot": "start",
  "behavior": {
    "patrol": {
      "enabled": true,
      "speed": 100
    }
  },
  "los": {
    "enabled": true,
    "range": 200,
    "angle": 120
  },
  "hostile": {
    "maxHP": 150,
    "attackDamage": 15,
    "attackRange": 60,
    "attackCooldown": 1500,
    "chaseSpeed": 140
  }
}

New hostile Object Fields:

  • maxHP - Maximum health points (default: 100 from config)
  • attackDamage - Damage per attack (default: 10 from config)
  • attackRange - Attack range in pixels (default: 50 from config)
  • attackCooldown - Cooldown between attacks in ms (default: 2000 from config)
  • chaseSpeed - Movement speed when chasing in pixels/second (default: 120 from config)

Notes:

  • All fields are optional
  • If not specified, defaults from COMBAT_CONFIG are used
  • Allows per-NPC customization of combat stats
  • Can be added to any existing NPC without breaking anything

5. Summary of Issues and Corrections

Issues Found

  1. Ink Pattern: Planning docs show -> END after #exit_conversation

    • Fix: Always use -> hub (see CORRECTIONS.md)
  2. ⚠️ Test NPC JSON: Includes roomId field

    • Fix: Remove roomId (NPCs are already inside room objects)
    • Enhancement: Add spriteConfig for completeness
  3. JSON Structure: Overall structure matches codebase

    • All required fields present
    • Correct nesting and format

Corrections Applied

  • Created CORRECTIONS.md with detailed Ink pattern fixes
  • This document provides correct JSON format reference
  • Updated test NPC example above with corrections

6. Checklist for Implementation

When implementing the hostile NPC feature:

Ink Files

  • Never use -> END anywhere
  • Always use -> hub to return to hub
  • Use #exit_conversation tag to close UI
  • After #exit_conversation, still use -> hub
  • Test all conversation paths return to hub
  • Verify #hostile:npcId tag works as expected

JSON Scenarios

  • NPCs defined inside rooms.{roomId}.npcs array
  • All required fields present (id, displayName, npcType, position, spriteSheet, storyPath, currentKnot)
  • Don't add roomId to NPC objects (redundant)
  • Add spriteConfig for proper idle animations
  • Add los configuration for hostile NPCs
  • Add eventMappings for lockpick detection if needed
  • Optionally add hostile object for custom combat stats
  • Verify JSON is valid (no trailing commas, proper quotes)

Testing

  • Create test scenario with test NPC
  • Verify conversation loads without errors
  • Test hostile tag triggers hostile state
  • Verify conversation exits properly with #exit_conversation
  • Check no Ink errors in console
  • Verify NPC state persists correctly

7. References

Good Examples to Follow:

  • /scenarios/ink/helper-npc.ink - Perfect hub pattern
  • /scenarios/npc-patrol-lockpick.json - Complete NPC scenario

Files Needing Updates:

  • /scenarios/ink/security-guard.ink - Has 8 -> END that need fixing

Planning Documents:

  • CORRECTIONS.md - Detailed corrections for Ink patterns
  • implementation_plan.md - Main implementation guide (note Ink corrections)
  • phase0_foundation.md - Foundation setup (note JSON/Ink corrections)

Conclusion

Format Compliance

Format Status Notes
JSON Scenario Structure Correct Matches existing patterns
NPC Object Format Mostly Correct Minor improvement: remove roomId
Ink Hub Pattern Incorrect in docs Fixed in CORRECTIONS.md
Event Tags Correct Proper tag usage
Required Fields Complete All fields present
Optional Fields ⚠️ Could improve Add spriteConfig, hostile config

Action Items

  1. Read CORRECTIONS.md first before implementing any Ink files
  2. Use this document as JSON format reference
  3. Follow helper-npc.ink as the canonical Ink example
  4. Test thoroughly with a simple test scenario first
  5. Validate JSON before loading (use JSON linter)

With these corrections applied, all formats will match the existing codebase patterns and work correctly.