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
9.3 KiB
Corrections to Planning Documents
Issue: Incorrect Ink Pattern Usage
Problem
Several planning documents show examples using -> END after #exit_conversation, which is incorrect based on the existing codebase patterns.
Correct Pattern
Based on existing Ink files (e.g., helper-npc.ink), the correct pattern is:
=== some_knot ===
# speaker:npc
Dialogue here...
# exit_conversation
-> hub
NOT:
=== some_knot ===
# speaker:npc
Dialogue here...
# exit_conversation
-> END
Key Principle
NEVER use -> END in our Ink files. ALWAYS use -> hub to return to the hub, even after #exit_conversation.
The #exit_conversation tag tells the game engine to close the conversation UI, but the Ink flow still needs to resolve to a valid state (the hub).
Exit Conversation Tag - Already Implemented ✅
Good News: The #exit_conversation tag is already handled in the codebase.
Location: /js/minigames/person-chat/person-chat-minigame.js line 537:
const shouldExit = result?.tags?.some(tag => tag.includes('exit_conversation'));
When this tag is detected, the minigame:
- Shows the NPC's final response
- Schedules the conversation to close
- Saves the NPC conversation state
- Exits the minigame
No additional handler needed for #exit_conversation - it works out of the box.
Hostile Tag - Needs Implementation ❌
Required: The #hostile tag needs to be added to the tag processing system.
Location: /js/minigames/helpers/chat-helpers.js
Where to Add: In the processGameActionTags() function switch statement (around line 60), add:
case 'hostile': {
const npcId = param || window.currentConversationNPCId;
if (!npcId) {
result.message = '⚠️ hostile tag missing NPC ID';
console.warn(result.message);
break;
}
console.log(`🔴 Processing hostile tag for NPC: ${npcId}`);
// Set NPC to hostile state
if (window.npcHostileSystem) {
window.npcHostileSystem.setNPCHostile(npcId, true);
result.success = true;
result.message = `⚠️ ${npcId} is now hostile!`;
} else {
result.message = '⚠️ Hostile system not initialized';
console.warn(result.message);
}
// Emit event for other systems
if (window.eventDispatcher) {
window.eventDispatcher.emit('npc_became_hostile', { npcId });
}
break;
}
Tag Format:
#hostile:npcId- Make specific NPC hostile#hostile- Make current conversation NPC hostile (useswindow.currentConversationNPCId)
Files Needing Correction
1. implementation_plan.md
Lines 613, 623 - Example code shows:
# hostile:security_guard
# exit_conversation
-> END
Should be:
# hostile:security_guard
# exit_conversation
-> hub
Line 627 - Instructions say:
Replace
-> ENDwith either-> hubor# exit_conversation+-> END
Should say:
Replace
-> ENDwith either-> hub(to continue conversation) or# exit_conversation+-> hub(to exit conversation)
2. phase0_foundation.md
Test Ink File Example - Shows:
=== test_hostile ===
# speaker:test_npc
This will trigger hostile mode!
# hostile:security_guard
# exit_conversation
You should now be in combat.
-> END
=== test_exit ===
# speaker:test_npc
This will exit cleanly.
# exit_conversation
Goodbye!
-> END
Should be:
=== test_hostile ===
# speaker:test_npc
Triggering hostile state for security guard!
Watch out - they're coming for you!
# hostile:security_guard
# exit_conversation
-> hub
=== test_exit ===
# speaker:test_npc
Exiting the conversation cleanly.
Goodbye, and good luck!
# exit_conversation
-> hub
Note: The dialogue should come BEFORE the #exit_conversation tag, as the conversation closes when that tag is processed. Text after the tag won't be shown.
3. implementation_roadmap.md
Phase 7.2 section - References exit_conversation tag handler needing to be added. This should be removed since it already exists.
Corrected Security Guard Ink Pattern
Here's the correct pattern for updating security-guard.ink:
Current (Incorrect)
=== hostile_response ===
# speaker:security_guard
~ influence -= 30
That's it. You just made a big mistake.
SECURITY! CODE VIOLATION IN THE CORRIDOR!
# display:guard-aggressive
-> END
Corrected
=== hostile_response ===
# speaker:security_guard
~ influence -= 30
That's it. You just made a big mistake.
SECURITY! CODE VIOLATION IN THE CORRIDOR!
# display:guard-aggressive
# hostile:security_guard
# exit_conversation
-> hub
Current (Incorrect)
=== escalate_conflict ===
# speaker:security_guard
~ influence -= 40
You've crossed the line! This is a lockdown!
INTRUDER ALERT! INTRUDER ALERT!
# display:guard-alarm
-> END
Corrected
=== escalate_conflict ===
# speaker:security_guard
~ influence -= 40
You've crossed the line! This is a lockdown!
INTRUDER ALERT! INTRUDER ALERT!
# display:guard-alarm
# hostile:security_guard
# exit_conversation
-> hub
Additional Security Guard Updates Needed
The current security-guard.ink file has 8 instances of -> END that need to be addressed:
Lines needing updates:
- Line 83:
explain_drop(low influence path) - Line 99:
claim_official(low influence path) - Line 119:
explain_situation(low influence path) - Line 134:
explain_files(low influence path) - Line 150:
explain_audit(low influence path) - Line 159:
hostile_response - Line 167:
escalate_conflict - Line 180:
back_down
Decision Matrix
For each -> END, decide:
- Should conversation continue? → Use
-> hub - Should conversation exit cleanly? → Use
# exit_conversation+-> hub - Should NPC become hostile? → Use
# hostile:security_guard+# exit_conversation+-> hub
Recommendations
Hostile paths (lines 159, 167):
- Add
# hostile:security_guardtag - Add
# exit_conversationtag - Change
-> ENDto-> hub
Negative outcome paths that should exit (lines 83, 99, 119, 134, 150):
- These are "you've been caught/failed" paths
- Add
# exit_conversationtag - Change
-> ENDto-> hub - Player can still re-talk to NPC if needed
Back down path (line 180):
- This seems like it should exit conversation
- Add
# exit_conversationtag - Change
-> ENDto-> hub
Corrected Test Ink File
File: /scenarios/ink/test-hostile.ink
// test-hostile.ink
// Simple test for hostile tag system
VAR test_count = 0
=== start ===
# speaker:test_npc
~ test_count += 1
Welcome to the hostile tag test.
-> hub
=== hub ===
+ [Test hostile tag]
-> test_hostile
+ [Test exit conversation]
-> test_exit
+ [Loop back to start]
-> start
=== test_hostile ===
# speaker:test_npc
This will trigger hostile mode for the security guard!
Watch out - they're coming for you!
# hostile:security_guard
# exit_conversation
-> hub
=== test_exit ===
# speaker:test_npc
This will exit the conversation cleanly.
Goodbye, and good luck!
# exit_conversation
-> hub
Summary of Corrections
- Never use
-> END- Always use-> hub - Exit pattern:
# exit_conversationfollowed by-> hub(already works!) - Hostile pattern:
# hostile:npcId+# exit_conversation+-> hub - Hub pattern: All conversation paths eventually return to hub
- Multiple exits: A conversation can have multiple exit points, all using the same pattern
- Exit conversation already implemented: No need to add handler, it already exists in person-chat-minigame.js
Why This Pattern?
From analyzing helper-npc.ink and person-chat-minigame.js:
- The hub acts as a central conversation state
#exit_conversationis a tag that tells the game engine to close the UI- This tag is already detected in person-chat-minigame.js
- The Ink story still needs to resolve to a valid state (the hub)
- Returning to hub after exit means the NPC state is properly saved
- If player talks to NPC again, conversation starts at
startknot, not hub - This pattern allows for proper state management and prevents Ink errors
Action Items
When implementing:
- ✅ Read this corrections document first
- ✅ Never use
-> ENDin any Ink file - ✅ Follow the corrected patterns above
- ❌ Don't add exit_conversation handler - it already exists!
- ✅ Do add hostile tag handler to chat-helpers.js
- ✅ Test each conversation path thoroughly
- ✅ Verify
#exit_conversationcloses the UI (should work already) - ✅ Verify returning to hub doesn't cause issues
- ✅ Update security-guard.ink according to recommendations
- ✅ Create test-hostile.ink with corrected pattern
References
- Good Example:
/scenarios/ink/helper-npc.ink- Perfect hub pattern usage - Needs Fixing:
/scenarios/ink/security-guard.ink- Has 8-> ENDinstances - Exit Tag Implementation:
/js/minigames/person-chat/person-chat-minigame.jsline 537 - Tag Processing:
/js/minigames/helpers/chat-helpers.js- Add hostile case here - Pattern Source: Lines 68-71 of
helper-npc.ink:+ [Thanks, I'm good for now.] # speaker:npc Alright then. Let me know if you need anything else! #exit_conversation -> hub
This is the canonical pattern we should follow everywhere.