fanren/tests/test_new_quest_core.php
2025-12-24 21:10:08 +08:00

129 lines
4.7 KiB
PHP
Raw 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;
$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->setLevel(5); // 设置等级为5满足所有任务条件
$player->gainGold(50); // 给玩家一些初始金币
$stateManager->setPlayer($player);
$stateManager->setCurrentTileId('TOWN_01');
echo "=== 《凡人修仙传》新任务系统核心功能测试 ===\n\n";
// 测试1: 检查任务数据结构
echo "1. 任务数据结构测试:\n";
$questRepo = $container->getQuestRepository();
$questData = $questRepo->find('QUEST_001');
if (isset($questData['nodes'])) {
echo " - 任务节点结构: ✅\n";
echo " - 节点数量: " . count($questData['nodes']) . "\n";
foreach ($questData['nodes'] as $nodeId => $node) {
echo " - 节点 {$nodeId}: 类型={$node['type']}\n";
}
} else {
echo " - 任务节点结构: ❌\n";
}
// 测试2: 检查ConditionEngine
echo "\n2. 条件引擎测试:\n";
$conditionEngine = new \Game\System\ConditionEngine();
$conditions = $questData['nodes']['START']['preConditions'] ?? [];
$playerSatisfies = $conditionEngine->checkConditions($player, $conditions);
echo " - 玩家满足前置条件: " . ($playerSatisfies ? '✅' : '❌') . "\n";
// 测试3: 检查Evaluator
echo "\n3. 目标评估器测试:\n";
$evaluator = new \Game\System\Evaluator();
$objectiveNode = $questData['nodes']['ACCEPT'];
$objectiveResult = $evaluator->evaluateObjective($player, $objectiveNode['goal']);
echo " - 目标评估结果: " . ($objectiveResult ? '完成' : '未完成') . "\n";
// 测试4: 检查ActionExecutor
echo "\n4. 动作执行器测试:\n";
$actionExecutor = new \Game\System\ActionExecutor($dispatcher);
$initialGold = $player->getGold();
$initialXp = $player->getCurrentXp();
$rewardNode = $questData['nodes']['REWARD'];
if (isset($rewardNode['actions'])) {
$actionExecutor->executeActions($player, $rewardNode['actions']);
$finalGold = $player->getGold();
$finalXp = $player->getCurrentXp();
echo " - 金币变化: {$initialGold} -> {$finalGold}\n";
echo " - 经验变化: {$initialXp} -> {$finalXp}\n";
echo " - 动作执行: ✅\n";
}
// 测试5: 任务接受流程
echo "\n5. 任务接受流程测试:\n";
$initialActiveNodes = count($player->getActiveQuestNodes());
echo " - 初始活跃节点: {$initialActiveNodes}\n";
$dispatcher->dispatch(new Event('QuestAcceptRequest', ['questId' => 'QUEST_001']));
$currentNodes = $player->getActiveQuestNodes();
echo " - 接受后活跃节点: " . count($currentNodes) . "\n";
if (isset($currentNodes['QUEST_001'])) {
echo " - QUEST_001当前节点: {$currentNodes['QUEST_001']}\n";
}
// 测试6: 任务完成流程
echo "\n6. 任务完成流程测试:\n";
// 将任务节点更新到目标节点
$player->updateQuestNode('QUEST_001', 'ACCEPT');
// 模拟目标完成(这里我们直接跳过实际的收集过程)
$dispatcher->dispatch(new Event('QuestProgressEvent', [
'questId' => 'QUEST_001'
]));
$afterProgressNodes = $player->getActiveQuestNodes();
echo " - 完成目标后节点: " . ($afterProgressNodes['QUEST_001'] ?? '未找到') . "\n";
// 检查是否已完成
$completedQuests = $player->getCompletedQuests();
echo " - 已完成任务数: " . count($completedQuests) . "\n";
if (in_array('QUEST_001', $completedQuests)) {
echo " - QUEST_001已完成: ✅\n";
} else {
echo " - QUEST_001已完成: ❌\n";
}
// 测试7: 对话选择功能
echo "\n7. 对话选择功能测试:\n";
// 重新接受一个任务
$dispatcher->dispatch(new Event('QuestAcceptRequest', ['questId' => 'QUEST_002']));
$currentNodes = $player->getActiveQuestNodes();
if (isset($currentNodes['QUEST_002'])) {
echo " - QUEST_002接受成功当前节点: {$currentNodes['QUEST_002']}\n";
// 模拟对话选择
$dispatcher->dispatch(new Event('DialogueChoice', [
'choiceIndex' => 1, // 选择"太危险了,我不去。"
'questId' => 'QUEST_002'
]));
$afterChoiceNodes = $player->getActiveQuestNodes();
echo " - 选择后节点: " . ($afterChoiceNodes['QUEST_002'] ?? '未找到') . "\n";
}
echo "\n输出消息:\n";
echo $output->fetch() . "\n";
echo "=== 核心功能测试完成 ===\n";