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
- Deleted the `CUTSCENE_IMPROVEMENTS.md` file as it contained outdated information.
- Refactored the game canvas visibility management in `game.js` and `minigame-manager.js` to streamline the handling of cut-scene visibility.
- Updated `PersonChatMinigame` to simplify the handling of the `canEscConversation` parameter.
- Adjusted `NPCManager` to pass relevant parameters for minigame initialization without relying on deprecated settings.
- Added functionality to hide the main game canvas and inventory during minigames based on scenario settings.
- Enhanced the MinigameFramework to track and manage visibility states for the game canvas and inventory.
- Updated PersonChatMinigame to conditionally hide close and cancel buttons based on the new `canEscConversation` parameter.
- Modified NPCManager to pass new parameters for minigame initialization, including visibility and conversation settings.
- Updated scenario configuration to support hiding the game during minigames and disabling escape key functionality.
- Added a new security guard NPC with conversation flow for lockpicking attempts.
- Integrated influence system to determine NPC reactions based on player choices.
- Created a new JSON scenario for the security guard's behavior and interactions.
- Refactored lockpicking system to allow NPC interruptions during attempts.
- Developed a test scenario to visualize NPC patrol and line-of-sight detection.
- Added a debug panel for testing line-of-sight visualization in the game.
- Introduced a data-driven global variable system to manage narrative state across NPC interactions.
- Added support for global variables in scenario JSON, allowing for easy extension and management.
- Implemented synchronization of global variables between Ink stories and the game state, ensuring real-time updates across conversations.
- Enhanced state persistence, allowing global variables to survive page reloads and be restored during conversations.
- Created comprehensive documentation and testing guides to facilitate usage and verification of the new system.
- Introduced new NPC inventory system allowing NPCs to hold and give items to players.
- Updated ContainerMinigame to support NPC mode, displaying NPC avatars and available items.
- Enhanced chat and conversation systems to sync NPC item states with Ink variables, improving narrative interactions.
- Added event listeners for item changes, ensuring dynamic updates during conversations.
- Implemented new methods in NPCGameBridge for item giving and inventory display, streamlining item interactions.
- Added support for optional background image paths in PersonChatMinigame, PersonChatPortraits, and PersonChatUI, allowing for more dynamic visual presentations during conversations.
- Updated NPCManager to handle background image paths in timed conversations, improving narrative context.
- Enhanced canvas rendering logic to accommodate background images, ensuring proper scaling and alignment with character sprites.
- Added functionality to schedule timed conversations in NPCManager, allowing NPCs to automatically initiate dialogues after a specified delay.
- Updated PersonChatMinigame to handle multiple dialogue lines and speakers, improving the display logic for accumulated dialogue.
- Modified scenario JSON and Ink files to include timed conversation configurations for NPCs, enhancing narrative flow.
- Created a new JSON scenario file for testing NPC sprite functionality.
- Implemented a simple HTTP server with caching headers for development purposes.
- Added an HTML page for testing NPC interactions, including system checks and game controls.
- Introduced a separate HTML page for testing item delivery through person chat interactions.
- Created SoundManager class for handling audio playback using Phaser's sound system.
- Added methods for preloading, initializing, and playing sounds with volume control.
- Integrated UI sound helpers for easier sound attachment to DOM elements.
- Updated game.js to initialize sound manager and preload sounds.
- Modified interactions.js, unlock-system.js, and panels.js to play appropriate sounds on interactions.
- Created SOUND_SYSTEM_QUICK_REFERENCE.md for documentation on sound system usage.
- Optimized NPCBarkSystem and NPCManager with caching and event listener cleanup.
- Added event emissions for NPC interactions in core game systems:
- Unlock System: door_unlocked, item_unlocked, door_unlock_attempt
- Interactions System: object_interacted
- Inventory System: item_picked_up:*
- Minigame Framework: minigame_completed, minigame_failed
- Created event-triggered reactions for the helper NPC:
- Added knots for lockpick pickup, success, failure, door unlock, and object interaction.
- Implemented state tracking and context-aware responses.
- Updated event mappings in scenario JSON for the helper NPC to respond to various events.
- Fixed global variable references in event emission code to ensure proper event dispatching.
- Added debug logging to verify event emissions and NPC reactions.
- Documented implementation details and testing instructions for new features.
- Added NPCGameBridge class to facilitate interactions between NPCs and game state.
- Implemented methods for unlocking doors, giving items, setting objectives, revealing secrets, adding notes, triggering events, and discovering rooms.
- Introduced a helper NPC that can assist players by unlocking the CEO's office and providing items based on trust levels.
- Created comprehensive documentation for the NPC Game Bridge implementation.
- Updated scenario JSON to include the new helper NPC and its interactions.
- Added Ink story for the helper NPC demonstrating its capabilities.
- Created a generic NPC script with conversation handling.
- Developed an Alice NPC script demonstrating branching dialogue and state tracking.
- Implemented a test NPC script for development purposes.
- Added JSON representations for the NPC scripts.
- Created an HTML test interface for NPC integration testing.
- Included event handling and bark systems for NPC interactions.