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

93 lines
3.0 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;
$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 "=== NPC与任务关联测试 ===\n\n";
// 测试1: 检查任务与NPC的关联
echo "1. 检查任务与NPC关联:\n";
$questRepo = $container->getQuestRepository();
$npcRepo = $container->getNpcRepository();
// 获取VILLAGER_1相关的任务
$villagerQuests = $questRepo->getQuestsByNpc('VILLAGER_1');
echo " - VILLAGER_1关联的任务: " . implode(', ', $villagerQuests) . "\n";
// 获取MODOCTOR相关的任务
$doctorQuests = $questRepo->getQuestsByNpc('MODOCTOR');
echo " - MODOCTOR关联的任务: " . implode(', ', $doctorQuests) . "\n";
// 检查任务数据中的NPC ID
$quest1 = $questRepo->find('QUEST_001');
if (isset($quest1['npcId'])) {
echo " - QUEST_001的NPC: {$quest1['npcId']}\n";
} else {
echo " - QUEST_001没有NPC关联\n";
}
$quest3 = $questRepo->find('QUEST_003');
if (isset($quest3['npcId'])) {
echo " - QUEST_003的NPC: {$quest3['npcId']}\n";
} else {
echo " - QUEST_003没有NPC关联\n";
}
// 测试2: 检查NPC是否存在
echo "\n2. 检查NPC数据:\n";
$villager = $npcRepo->createNPC('VILLAGER_1');
if ($villager) {
echo " - VILLAGER_1存在: {$villager->getName()}\n";
} else {
echo " - VILLAGER_1不存在\n";
}
$doctor = $npcRepo->createNPC('MODOCTOR');
if ($doctor) {
echo " - MODOCTOR存在: {$doctor->getName()}\n";
} else {
echo " - MODOCTOR不存在\n";
}
// 测试3: 模拟NPC交互
echo "\n3. 模拟NPC交互测试:\n";
$initialActiveQuests = count($player->getActiveQuests());
echo " - 初始活跃任务数: {$initialActiveQuests}\n";
// 模拟与VILLAGER_1的交互
$dispatcher->dispatch(new Event('StartInteractionEvent', ['npcId' => 'VILLAGER_1']));
$afterInteractionQuests = count($player->getActiveQuests());
echo " - 与VILLAGER_1交互后任务数: {$afterInteractionQuests}\n";
// 检查是否接受了任务
$activeQuestNodes = $player->getActiveQuestNodes();
echo " - 活跃任务节点: " . count($activeQuestNodes) . "\n";
foreach ($activeQuestNodes as $questId => $nodeId) {
echo " - 任务{$questId}节点: {$nodeId}\n";
}
echo "\n输出消息:\n";
echo $output->fetch() . "\n";
echo "=== 关联测试完成 ===\n";