49 lines
1.5 KiB
PHP
49 lines
1.5 KiB
PHP
<?php
|
||
require __DIR__ . '/../vendor/autoload.php';
|
||
|
||
use Game\Core\ServiceContainer;
|
||
use Game\Event\Event;
|
||
use Symfony\Component\Console\Input\ArrayInput;
|
||
use Symfony\Component\Console\Output\BufferedOutput;
|
||
use Symfony\Component\Console\Helper\HelperSet;
|
||
use Symfony\Component\Console\Helper\QuestionHelper;
|
||
|
||
// Mock Input with stream
|
||
$stream = fopen('php://memory', 'r+');
|
||
fwrite($stream, "0\n0\n"); // 选择对话选项0,然后再选0接受任务
|
||
rewind($stream);
|
||
|
||
$input = new ArrayInput([]);
|
||
$input->setStream($stream);
|
||
$input->setInteractive(true);
|
||
|
||
$output = new BufferedOutput();
|
||
$helperSet = new HelperSet(['question' => new QuestionHelper()]);
|
||
|
||
$container = new ServiceContainer($input, $output, $helperSet);
|
||
$dispatcher = $container->registerServices();
|
||
$stateManager = $container->getStateManager();
|
||
|
||
// 创建测试玩家
|
||
$player = new \Game\Model\Player("TestHero", 100, 10, 5);
|
||
$stateManager->setPlayer($player);
|
||
|
||
// 设置地图位置到新手村
|
||
$stateManager->setCurrentTileId('TOWN_01');
|
||
|
||
echo "=== 测试开始 ===\n";
|
||
echo "当前位置: " . $stateManager->getCurrentTile()->name . "\n";
|
||
echo "NPC列表: " . implode(', ', $stateManager->getCurrentTile()->npcIds) . "\n\n";
|
||
|
||
// 触发与NPC交谈
|
||
echo "触发 StartInteractionEvent...\n";
|
||
$dispatcher->dispatch(new Event('AttemptTalkEvent'));
|
||
|
||
// 获取输出
|
||
$display = $output->fetch();
|
||
echo "\n=== 输出结果 ===\n";
|
||
echo $display;
|
||
$dispatcher->dispatch(new Event('StartInteractionEvent', ['npcId' => 'VILLAGER_1']));
|
||
dd($stateManager->getPendingNpcSelection());
|
||
|