77 lines
2.9 KiB
PHP
77 lines
2.9 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;
|
|
|
|
$input = new ArrayInput([]);
|
|
$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("HanLi", 100, 10, 5);
|
|
$player->gainGold(50); // 给玩家一些初始金币
|
|
$stateManager->setPlayer($player);
|
|
$stateManager->setCurrentTileId('TOWN_01');
|
|
|
|
echo "=== 《凡人修仙传》任务对话树测试 ===\n\n";
|
|
|
|
// 获取任务对话数据
|
|
$questRepo = $container->getQuestRepository();
|
|
$questData = $questRepo->find('QUEST_001');
|
|
|
|
echo "1. 任务对话数据测试:\n";
|
|
echo " - 任务: {$questData['name']}\n";
|
|
echo " - 对话结构类型: " . (isset($questData['dialogue']['root']) ? '对话树格式' : '简单格式') . "\n";
|
|
|
|
if (isset($questData['dialogue']['root'])) {
|
|
echo " - 根节点文本: " . substr($questData['dialogue']['root']['text'], 0, 30) . "...\n";
|
|
echo " - 选项数量: " . count($questData['dialogue']['root']['options']) . "\n";
|
|
|
|
foreach ($questData['dialogue']['root']['options'] as $index => $option) {
|
|
echo " - 选项 {$index}: {$option['text']} -> {$option['next']}\n";
|
|
}
|
|
}
|
|
|
|
// 检查DialogueService
|
|
echo "\n2. 对话服务测试:\n";
|
|
$dialogueService = new \Game\System\DialogueService($dispatcher, $stateManager, $input, $output, $helperSet);
|
|
echo " - DialogueService 创建成功\n";
|
|
|
|
// 检查对话树是否能正确启动
|
|
echo "\n3. 对话树启动测试:\n";
|
|
try {
|
|
$dialogueService->startDialogue($questData['dialogue']);
|
|
echo " - 对话树启动成功\n";
|
|
echo " - 当前节点: {$dialogueService->currentNodeId}\n";
|
|
} catch (Exception $e) {
|
|
echo " - 对话树启动失败: " . $e->getMessage() . "\n";
|
|
}
|
|
|
|
// 测试对话处理
|
|
echo "\n4. 对话处理测试:\n";
|
|
$initialActiveQuests = count($player->getActiveQuests());
|
|
echo " - 初始进行中任务数: {$initialActiveQuests}\n";
|
|
|
|
// 模拟选择接受任务
|
|
$dispatcher->dispatch(new Event('StartDialogueEvent', ['dialogue' => $questData['dialogue']]));
|
|
|
|
// 这里我们直接测试任务接受事件
|
|
$dispatcher->dispatch(new Event('QuestAcceptRequest', ['questId' => 'QUEST_001']));
|
|
|
|
$finalActiveQuests = count($player->getActiveQuests());
|
|
echo " - 最终进行中任务数: {$finalActiveQuests}\n";
|
|
echo " - 任务接受成功: " . ($finalActiveQuests > $initialActiveQuests ? '是' : '否') . "\n";
|
|
|
|
echo "\n输出消息:\n";
|
|
echo $output->fetch() . "\n";
|
|
|
|
echo "=== 对话树测试完成 ===\n"; |