87 lines
3.1 KiB
PHP
87 lines
3.1 KiB
PHP
<?php
|
|
require __DIR__ . '/../vendor/autoload.php';
|
|
|
|
use Game\Core\ServiceContainer;
|
|
use Game\Event\Event;
|
|
use Game\Model\Quest;
|
|
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";
|
|
|
|
// 测试任务接受
|
|
echo "1. 任务接受测试:\n";
|
|
$questService = new \Game\System\QuestService($dispatcher, $stateManager, $container->getQuestRepository());
|
|
|
|
// 手动添加一个任务到玩家
|
|
$questData = $container->getQuestRepository()->find('QUEST_001');
|
|
$quest = new Quest(
|
|
$questData['id'],
|
|
$questData['name'],
|
|
$questData['description'],
|
|
$questData['type'],
|
|
$questData['target'],
|
|
$questData['rewards'],
|
|
$questData['triggerType'] ?? null,
|
|
$questData['triggerValue'] ?? null,
|
|
$questData['dialogue'] ?? []
|
|
);
|
|
|
|
$player->addActiveQuest($quest);
|
|
echo " - 添加任务: {$quest->getTitle()}\n";
|
|
echo " - 任务类型: {$quest->getType()}\n";
|
|
echo " - 目标: " . ($quest->getTarget()['count'] ?? '未知') . "\n\n";
|
|
|
|
// 测试任务进度更新
|
|
echo "2. 任务进度更新测试:\n";
|
|
$player->updateQuestProgress('QUEST_001', 5);
|
|
$activeQuests = $player->getActiveQuests();
|
|
$currentQuest = $activeQuests['QUEST_001'];
|
|
echo " - 当前进度: {$currentQuest->getCurrentCount()}/{$quest->getTarget()['count']}\n\n";
|
|
|
|
// 测试任务完成
|
|
echo "3. 任务完成测试:\n";
|
|
// 完成任务
|
|
for ($i = 0; $i < 5; $i++) {
|
|
$player->updateQuestProgress('QUEST_001', 1);
|
|
}
|
|
$currentQuest = $player->getActiveQuests()['QUEST_001'];
|
|
echo " - 任务是否完成: " . ($currentQuest->isCompleted() ? '是' : '否') . "\n";
|
|
echo " - 最终进度: {$currentQuest->getCurrentCount()}/{$quest->getTarget()['count']}\n\n";
|
|
|
|
// 测试任务交付
|
|
echo "4. 任务交付测试:\n";
|
|
$initialGold = $player->getGold();
|
|
$initialXp = $player->getCurrentXp();
|
|
echo " - 交付前金币: {$initialGold}, 经验: {$initialXp}\n";
|
|
|
|
// 触发任务交付
|
|
$dispatcher->dispatch(new Event('QuestTurnInConfirm', ['questId' => 'QUEST_001']));
|
|
|
|
$finalGold = $player->getGold();
|
|
$finalXp = $player->getCurrentXp();
|
|
echo " - 交付后金币: {$finalGold}, 经验: {$finalXp}\n";
|
|
echo " - 金币增加: " . ($finalGold - $initialGold) . "\n";
|
|
echo " - 经验增加: " . ($finalXp - $initialXp) . "\n";
|
|
echo " - 是否在完成列表: " . (in_array('QUEST_001', $player->getCompletedQuests()) ? '是' : '否') . "\n\n";
|
|
|
|
echo "输出消息:\n";
|
|
echo $output->fetch() . "\n";
|
|
|
|
echo "=== 任务系统交互测试完成 ===\n"; |