fanren/tests/test_npc_interaction.php
2025-12-22 18:07:05 +08:00

49 lines
1.5 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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());