mirror of
https://github.com/cliffe/BreakEscape.git
synced 2026-02-20 13:50:46 +00:00
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
418 lines
14 KiB
HTML
418 lines
14 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>NPC Interaction Test</title>
|
|
<link rel="stylesheet" href="css/main.css">
|
|
<link rel="stylesheet" href="css/panels.css">
|
|
<link rel="stylesheet" href="css/modals.css">
|
|
<link rel="stylesheet" href="css/hud.css">
|
|
<link rel="stylesheet" href="css/person-chat-minigame.css">
|
|
<link rel="stylesheet" href="css/npc-interactions.css">
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
padding: 20px;
|
|
background-color: #222;
|
|
color: #fff;
|
|
font-family: Arial, sans-serif;
|
|
}
|
|
.test-container {
|
|
max-width: 1200px;
|
|
margin: 0 auto;
|
|
}
|
|
h1 {
|
|
color: #4da6ff;
|
|
border-bottom: 2px solid #4da6ff;
|
|
padding-bottom: 10px;
|
|
}
|
|
.test-section {
|
|
background-color: #333;
|
|
border: 2px solid #4da6ff;
|
|
border-radius: 4px;
|
|
padding: 15px;
|
|
margin: 15px 0;
|
|
}
|
|
.test-button {
|
|
background-color: #4da6ff;
|
|
color: #000;
|
|
border: none;
|
|
padding: 10px 20px;
|
|
margin: 5px;
|
|
cursor: pointer;
|
|
font-weight: bold;
|
|
border-radius: 4px;
|
|
font-size: 14px;
|
|
}
|
|
.test-button:hover {
|
|
background-color: #6dbfff;
|
|
}
|
|
.test-output {
|
|
background-color: #222;
|
|
border: 1px solid #666;
|
|
border-radius: 4px;
|
|
padding: 10px;
|
|
margin-top: 10px;
|
|
font-family: monospace;
|
|
font-size: 12px;
|
|
max-height: 400px;
|
|
overflow-y: auto;
|
|
white-space: pre-wrap;
|
|
word-wrap: break-word;
|
|
}
|
|
.status {
|
|
display: inline-block;
|
|
padding: 3px 8px;
|
|
border-radius: 3px;
|
|
font-weight: bold;
|
|
margin: 0 5px;
|
|
}
|
|
.status.ok {
|
|
background-color: #4db84d;
|
|
color: white;
|
|
}
|
|
.status.error {
|
|
background-color: #d9534f;
|
|
color: white;
|
|
}
|
|
.status.warning {
|
|
background-color: #f0ad4e;
|
|
color: black;
|
|
}
|
|
#gameContainer {
|
|
margin-top: 20px;
|
|
border: 2px solid #666;
|
|
background-color: #000;
|
|
}
|
|
.instructions {
|
|
background-color: #1a3a1a;
|
|
border-left: 4px solid #4db84d;
|
|
padding: 10px;
|
|
margin: 10px 0;
|
|
border-radius: 3px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="test-container">
|
|
<h1>🎭 NPC Interaction System Test</h1>
|
|
|
|
<div class="instructions">
|
|
<strong>Test Procedure:</strong>
|
|
<ol>
|
|
<li>Click "Load NPC Test Scenario" to start the game</li>
|
|
<li>Walk the player character near either NPC</li>
|
|
<li>Look for "Press E to talk to [NPC Name]" prompt at the bottom</li>
|
|
<li>Press E to trigger the conversation</li>
|
|
<li>Verify the conversation UI appears with portraits and dialogue</li>
|
|
</ol>
|
|
</div>
|
|
|
|
<div class="test-section">
|
|
<h2>🔧 System Checks</h2>
|
|
<button class="test-button" onclick="checkNPCSystem()">Check NPC System</button>
|
|
<button class="test-button" onclick="checkNPCProximity()">Check Proximity Detection</button>
|
|
<button class="test-button" onclick="listNPCs()">List All NPCs</button>
|
|
<button class="test-button" onclick="testInteractionPrompt()">Test Interaction Prompt</button>
|
|
<button class="test-button" onclick="clearConsole()">Clear Output</button>
|
|
<div id="systemOutput" class="test-output">Waiting for tests...</div>
|
|
</div>
|
|
|
|
<div class="test-section">
|
|
<h2>🎮 Game Controls</h2>
|
|
<button class="test-button" onclick="startGame()">Load NPC Test Scenario</button>
|
|
<button class="test-button" onclick="resetGame()">Reset Game</button>
|
|
<div id="gameOutput" class="test-output">Game status: Ready</div>
|
|
</div>
|
|
|
|
<div class="test-section">
|
|
<h2>📊 Debug Info</h2>
|
|
<button class="test-button" onclick="showDebugInfo()">Show Full Debug Info</button>
|
|
<button class="test-button" onclick="manuallyTriggerInteraction()">Manually Trigger E-Key</button>
|
|
<div id="debugOutput" class="test-output">Debug info will appear here...</div>
|
|
</div>
|
|
|
|
<div id="gameContainer"></div>
|
|
</div>
|
|
|
|
<script type="module">
|
|
import('./js/main.js').then(() => {
|
|
updateGameStatus('Game module loaded');
|
|
});
|
|
|
|
window.testFunctions = {
|
|
checkNPCSystem,
|
|
checkNPCProximity,
|
|
listNPCs,
|
|
testInteractionPrompt,
|
|
clearConsole,
|
|
startGame,
|
|
resetGame,
|
|
showDebugInfo,
|
|
manuallyTriggerInteraction
|
|
};
|
|
|
|
function log(message, type = 'info') {
|
|
console.log(`[${type.toUpperCase()}] ${message}`);
|
|
}
|
|
|
|
function output(text, elementId = 'systemOutput') {
|
|
const elem = document.getElementById(elementId);
|
|
if (elem) {
|
|
elem.textContent += text + '\n';
|
|
elem.scrollTop = elem.scrollHeight;
|
|
}
|
|
}
|
|
|
|
function clearOutput(elementId = 'systemOutput') {
|
|
const elem = document.getElementById(elementId);
|
|
if (elem) {
|
|
elem.textContent = '';
|
|
}
|
|
}
|
|
|
|
function checkNPCSystem() {
|
|
clearOutput('systemOutput');
|
|
output('🔍 Checking NPC System...\n');
|
|
|
|
const checks = [
|
|
{ name: 'window.npcManager', check: () => window.npcManager },
|
|
{ name: 'window.player', check: () => window.player },
|
|
{ name: 'window.MinigameFramework', check: () => window.MinigameFramework },
|
|
{ name: 'window.checkNPCProximity', check: () => window.checkNPCProximity },
|
|
{ name: 'window.tryInteractWithNearest', check: () => window.tryInteractWithNearest }
|
|
];
|
|
|
|
let passed = 0;
|
|
let failed = 0;
|
|
|
|
checks.forEach(({ name, check }) => {
|
|
try {
|
|
const result = check();
|
|
if (result) {
|
|
output(`✅ ${name}`);
|
|
passed++;
|
|
} else {
|
|
output(`❌ ${name} - exists but is falsy`);
|
|
failed++;
|
|
}
|
|
} catch (e) {
|
|
output(`❌ ${name} - ${e.message}`);
|
|
failed++;
|
|
}
|
|
});
|
|
|
|
output(`\n📊 Results: ${passed} passed, ${failed} failed`);
|
|
}
|
|
|
|
function checkNPCProximity() {
|
|
clearOutput('systemOutput');
|
|
output('🔍 Checking NPC Proximity Detection...\n');
|
|
|
|
if (!window.npcManager) {
|
|
output('❌ npcManager not available');
|
|
return;
|
|
}
|
|
|
|
output(`NPCs registered: ${window.npcManager.npcs.size}\n`);
|
|
|
|
if (window.npcManager.npcs.size === 0) {
|
|
output('⚠️ No NPCs registered. Load a scenario first.\n');
|
|
return;
|
|
}
|
|
|
|
if (!window.player) {
|
|
output('❌ Player not available');
|
|
return;
|
|
}
|
|
|
|
output(`Player position: (${window.player.x}, ${window.player.y})\n`);
|
|
|
|
// Calculate distances to all NPCs
|
|
let found = false;
|
|
window.npcManager.npcs.forEach((npc) => {
|
|
if (npc._sprite) {
|
|
const dx = npc._sprite.x - window.player.x;
|
|
const dy = npc._sprite.y - window.player.y;
|
|
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
const inRange = distance <= 64;
|
|
|
|
output(`${inRange ? '✅' : '⚠️'} ${npc.displayName} (${npc.id})`);
|
|
output(` Position: (${npc._sprite.x}, ${npc._sprite.y})`);
|
|
output(` Distance: ${distance.toFixed(2)}px (${inRange ? 'IN RANGE' : 'OUT OF RANGE'})`);
|
|
output(` Type: ${npc.npcType}`);
|
|
output(` Sprite active: ${npc._sprite.active}\n`);
|
|
|
|
if (inRange) found = true;
|
|
}
|
|
});
|
|
|
|
if (found) {
|
|
output('🎯 At least one NPC is in range!\n');
|
|
} else {
|
|
output('⚠️ No NPCs are in range. Move player closer.\n');
|
|
}
|
|
|
|
// Manually run proximity check
|
|
if (window.checkNPCProximity) {
|
|
output('Running checkNPCProximity()...\n');
|
|
window.checkNPCProximity();
|
|
|
|
const prompt = document.getElementById('npc-interaction-prompt');
|
|
if (prompt) {
|
|
output(`✅ Prompt created: "${prompt.querySelector('.prompt-text').textContent}"`);
|
|
} else {
|
|
output('⚠️ No prompt created');
|
|
}
|
|
}
|
|
}
|
|
|
|
function listNPCs() {
|
|
clearOutput('systemOutput');
|
|
output('📋 NPC Listing\n');
|
|
|
|
if (!window.npcManager) {
|
|
output('❌ npcManager not available');
|
|
return;
|
|
}
|
|
|
|
const count = window.npcManager.npcs.size;
|
|
output(`Total NPCs: ${count}\n`);
|
|
|
|
if (count === 0) {
|
|
output('No NPCs registered.');
|
|
return;
|
|
}
|
|
|
|
window.npcManager.npcs.forEach((npc, id) => {
|
|
output(`\n📌 ${npc.displayName} (${id})`);
|
|
output(` Type: ${npc.npcType}`);
|
|
output(` Phone ID: ${npc.phoneId || 'none'}`);
|
|
output(` Story: ${npc.storyPath || 'none'}`);
|
|
output(` Room: ${npc.roomId || 'none'}`);
|
|
|
|
if (npc._sprite) {
|
|
output(` Sprite: YES @ (${npc._sprite.x}, ${npc._sprite.y})`);
|
|
output(` Active: ${npc._sprite.active}`);
|
|
} else {
|
|
output(` Sprite: NO`);
|
|
}
|
|
});
|
|
}
|
|
|
|
function testInteractionPrompt() {
|
|
clearOutput('systemOutput');
|
|
output('🧪 Testing Interaction Prompt\n');
|
|
|
|
if (!window.npcManager) {
|
|
output('❌ npcManager not available');
|
|
return;
|
|
}
|
|
|
|
const npcs = Array.from(window.npcManager.npcs.values());
|
|
if (npcs.length === 0) {
|
|
output('❌ No NPCs to test');
|
|
return;
|
|
}
|
|
|
|
const testNpc = npcs[0];
|
|
output(`Testing with: ${testNpc.displayName}\n`);
|
|
|
|
// Manually create prompt
|
|
output('Creating prompt...\n');
|
|
if (window.updateNPCInteractionPrompt) {
|
|
window.updateNPCInteractionPrompt(testNpc);
|
|
|
|
const prompt = document.getElementById('npc-interaction-prompt');
|
|
if (prompt) {
|
|
output('✅ Prompt created');
|
|
output(` Element: ${prompt.id}`);
|
|
output(` Text: ${prompt.querySelector('.prompt-text').textContent}`);
|
|
output(` NPC ID: ${prompt.dataset.npcId}\n`);
|
|
|
|
output('Prompt is visible on screen\n');
|
|
|
|
// Clear it
|
|
output('Clearing prompt...\n');
|
|
window.updateNPCInteractionPrompt(null);
|
|
|
|
if (!document.getElementById('npc-interaction-prompt')) {
|
|
output('✅ Prompt cleared successfully');
|
|
} else {
|
|
output('❌ Prompt still exists');
|
|
}
|
|
} else {
|
|
output('❌ Prompt not created');
|
|
}
|
|
} else {
|
|
output('❌ updateNPCInteractionPrompt not available');
|
|
}
|
|
}
|
|
|
|
function clearConsole() {
|
|
clearOutput('systemOutput');
|
|
output('🗑️ Output cleared');
|
|
}
|
|
|
|
function startGame() {
|
|
clearOutput('gameOutput');
|
|
output('🎮 Loading NPC Test Scenario...', 'gameOutput');
|
|
|
|
// Redirect to scenario_select with test scenario
|
|
window.location.href = 'scenario_select.html?scenario=npc-sprite-test';
|
|
}
|
|
|
|
function resetGame() {
|
|
clearOutput('gameOutput');
|
|
output('🔄 Resetting game...', 'gameOutput');
|
|
|
|
// Reload page
|
|
location.reload();
|
|
}
|
|
|
|
function showDebugInfo() {
|
|
clearOutput('debugOutput');
|
|
const info = {
|
|
'Player': window.player ? `(${window.player.x}, ${window.player.y})` : 'Not loaded',
|
|
'NPC Manager': window.npcManager ? `${window.npcManager.npcs.size} NPCs` : 'Not loaded',
|
|
'Current Prompt': document.getElementById('npc-interaction-prompt') ? 'Yes' : 'No',
|
|
'MinigameFramework': window.MinigameFramework ? 'Loaded' : 'Not loaded',
|
|
'E-Key Handler': window.tryInteractWithNearest ? 'Ready' : 'Not ready'
|
|
};
|
|
|
|
output('📊 DEBUG INFO\n');
|
|
Object.entries(info).forEach(([key, value]) => {
|
|
output(`${key}: ${value}`);
|
|
});
|
|
}
|
|
|
|
function manuallyTriggerInteraction() {
|
|
clearOutput('debugOutput');
|
|
output('🎯 Manually triggering E-Key interaction...\n');
|
|
|
|
if (!window.tryInteractWithNearest) {
|
|
output('❌ tryInteractWithNearest not available');
|
|
return;
|
|
}
|
|
|
|
try {
|
|
window.tryInteractWithNearest();
|
|
output('✅ Interaction triggered');
|
|
} catch (e) {
|
|
output(`❌ Error: ${e.message}`);
|
|
}
|
|
}
|
|
|
|
function updateGameStatus(msg) {
|
|
const elem = document.getElementById('gameOutput');
|
|
if (elem) {
|
|
elem.textContent = `📊 ${msg}`;
|
|
}
|
|
}
|
|
|
|
window.updateGameStatus = updateGameStatus;
|
|
</script>
|
|
</body>
|
|
</html>
|