hanli/test/Test.php
hant cb4b955bca Implement Server-Sent Events (SSE) for real-time battle streaming
Redesign web battle system from buffered to streaming architecture:

Backend Changes:
- New SSEOutput class for real-time event streaming to clients
- GameSession::streamBattle() for SSE-based battle execution
- Enhanced Screen::delay() to support SSE timing and buffering modes
- New /api/game/battle-stream endpoint handling SSE connections

Frontend Changes:
- Enhanced sendInput() to detect battle command (input "1")
- New streamBattle() function using EventSource for SSE connections
- Real-time log display matching terminal experience
- Event handlers for start, message, complete, error events

Benefits:
✓ Real-time streaming instead of waiting for complete battle
✓ Web frontend experience identical to terminal
✓ Lightweight implementation without WebSocket
✓ Automatic browser reconnection support
✓ ANSI colors fully preserved
✓ Backward compatible for non-battle screens

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-07 10:50:30 +08:00

90 lines
3.3 KiB
PHP

<?php
use Game\Entities\Item;
require __DIR__ . '/../vendor/autoload.php';
$monster = \Game\Entities\Monster::create(6);
dd($monster->getRandomEquipmentDrops(100));
//$player = new \Game\Entities\Player();
$weaponTemplate = [
'fixed_primary' => [
'patk' => ['base' => [4, 10, 18, 30], 'growth' => 1.5],
'matk' => ['base' => [2, 5, 10, 18], 'growth' => 0.8],
],
'random_primary_pool' => [
'crit' => ['weight' => 40, 'base' => [1, 3, 5, 10], 'growth' => 0.3],
'critdmg' => ['weight' => 40, 'base' => [3, 8, 14, 24], 'growth' => 0.7],
'matk' => ['weight' => 20, 'base' => [2, 5, 10, 18], 'growth' => 0.8],
],
'random_primary_count' => [
'common' => [0, 0], 'rare' => [0, 1], 'epic' => [1, 1], 'legendary' => [1, 2]
],
'affix_weights' => ['patk' => 30, 'matk' => 20, 'crit' => 25, 'critdmg' => 25, 'hp' => 10],
];
$armorTemplate = [
'fixed_primary' => [
'pdef' => ['base' => [2, 6, 12, 20], 'growth' => 0.6],
'mdef' => ['base' => [1, 4, 8, 15], 'growth' => 0.5],
],
'random_primary_pool' => [
'hp' => ['weight' => 100, 'base' => [10, 25, 45, 75], 'growth' => 3.5],
],
'random_primary_count' => [
'common' => [0, 0], 'rare' => [0, 1], 'epic' => [1, 1], 'legendary' => [1, 1],
],
'affix_weights' => ['pdef' => 30, 'mdef' => 30, 'hp' => 40, 'patk' => 5, 'matk' => 5],
];
$ringTemplate = [
'fixed_primary' => [
'crit' => ['base' => [2, 5, 8, 12], 'growth' => 0.4],
],
'random_primary_pool' => [
'critdmg' => ['weight' => 40, 'base' => [5, 12, 20, 35], 'growth' => 0.8],
'patk' => ['weight' => 30, 'base' => [2, 6, 12, 20], 'growth' => 0.8],
'matk' => ['weight' => 30, 'base' => [2, 6, 12, 20], 'growth' => 0.8],
],
'random_primary_count' => [
'common' => [0, 0], 'rare' => [0, 1], 'epic' => [1, 1], 'legendary' => [1, 2],
],
'affix_weights' => ['crit' => 30, 'critdmg' => 30, 'patk' => 20, 'matk' => 20],
];
$necklaceTemplate = [
'fixed_primary' => [
'hp' => ['base' => [15, 35, 60, 100], 'growth' => 4.0],
],
'random_primary_pool' => [
'pdef' => ['weight' => 25, 'base' => [1, 5, 10, 18], 'growth' => 0.5],
'mdef' => ['weight' => 25, 'base' => [1, 5, 10, 18], 'growth' => 0.5],
'critdmg' => ['weight' => 50, 'base' => [3, 8, 15, 25], 'growth' => 0.5],
],
'random_primary_count' => [
'common' => [0, 0], 'rare' => [0, 1], 'epic' => [1, 1], 'legendary' => [1, 2],
],
'affix_weights' => ['hp' => 30, 'pdef' => 20, 'mdef' => 20, 'crit' => 15, 'critdmg' => 15],
];
$bootsTemplate = [
'fixed_primary' => [
'pdef' => ['base' => [1, 4, 8, 15], 'growth' => 0.4],
'mdef' => ['base' => [1, 3, 6, 12], 'growth' => 0.3],
],
'random_primary_pool' => [
'hp' => ['weight' => 60, 'base' => [8, 20, 35, 60], 'growth' => 2.5],
'crit' => ['weight' => 40, 'base' => [1, 3, 5, 8], 'growth' => 0.2],
],
'random_primary_count' => [
'common' => [0, 0], 'rare' => [0, 1], 'epic' => [1, 1], 'legendary' => [1, 2],
],
'affix_weights' => ['pdef' => 25, 'mdef' => 25, 'hp' => 30, 'crit' => 20],
];
$res = Item::createSpell(1, 'common', 10);
// dd($monster->getRandomEquipmentDrops(100));
\Game\Core\SpellCalculator::calculateHeal();