72 lines
2.2 KiB
PHP
72 lines
2.2 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;
|
|
|
|
// Mock Input with stream for InteractionSystem blocking prompt
|
|
$stream = fopen('php://memory', 'r+');
|
|
fwrite($stream, "T\n"); // Select 'Target' (Talk)
|
|
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();
|
|
|
|
// Manually create and set player for test environment
|
|
$player = new \Game\Model\Player("TestHero", 100, 10, 5);
|
|
$stateManager->setPlayer($player);
|
|
|
|
echo "Player Initialized.\n";
|
|
|
|
// 1. Simulate meeting NPC (Starts Dialogue)
|
|
echo "Dispatching Interaction Event...\n";
|
|
$dispatcher->dispatch(new Event('AttemptInteractEvent', ['npcId' => 'VILLAGER_1']));
|
|
|
|
echo "Checking output...\n";
|
|
$display = $output->fetch();
|
|
echo $display;
|
|
|
|
if (strpos($display, '你好啊,年轻人') !== false) {
|
|
echo "SUCCESS: Dialogue triggered.\n";
|
|
} else {
|
|
echo "FAILURE: Dialogue text not found.\n";
|
|
}
|
|
|
|
// 2. Simulate User Input: Select Option 0 (via Event, since InputHandler is not running loop)
|
|
echo "Dispatching Choice 0...\n";
|
|
$dispatcher->dispatch(new Event('DialogueChoice', ['choice' => '0']));
|
|
|
|
$display = $output->fetch();
|
|
echo $display;
|
|
|
|
if (strpos($display, '真的吗?那太好了') !== false) {
|
|
echo "SUCCESS: Dialogue advanced.\n";
|
|
} else {
|
|
echo "FAILURE: Dialogue advancement failed.\n";
|
|
}
|
|
|
|
// 3. Simulate User Input: Select Option 0 (Accept Quest)
|
|
echo "Dispatching Choice 0 (Accept)...\n";
|
|
$dispatcher->dispatch(new Event('DialogueChoice', ['choice' => '0']));
|
|
|
|
$display = $output->fetch();
|
|
echo $display;
|
|
|
|
if (strpos($display, '接受任务') !== false) {
|
|
echo "SUCCESS: Quest accepted.\n";
|
|
} else {
|
|
echo "FAILURE: Quest acceptance message not found.\n";
|
|
}
|