64 lines
2.1 KiB
PHP
64 lines
2.1 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("AutoSaveTest", 100, 10, 5);
|
|
$stateManager->setPlayer($player);
|
|
$stateManager->setCurrentTileId('TOWN_01');
|
|
|
|
echo "=== 自动保存功能测试 ===\n\n";
|
|
|
|
// 删除旧存档
|
|
$savePath = __DIR__ . '/../save/player.json';
|
|
if (file_exists($savePath)) {
|
|
unlink($savePath);
|
|
echo "✓ 已清理旧存档\n";
|
|
}
|
|
|
|
echo "\n1. 测试地图移动触发自动保存...\n";
|
|
$dispatcher->dispatch(new Event('MapMoveEvent', ['newTileId' => 'FOREST_01']));
|
|
if (file_exists($savePath)) {
|
|
echo "✓ 地图移动后自动保存成功\n";
|
|
$data = json_decode(file_get_contents($savePath), true);
|
|
echo " - 当前位置: " . $data['world']['currentTileId'] . "\n";
|
|
} else {
|
|
echo "✗ 自动保存失败\n";
|
|
}
|
|
|
|
echo "\n2. 测试升级触发自动保存...\n";
|
|
$player->gainXp(80);
|
|
$dispatcher->dispatch(new Event('LevelUpEvent', ['newLevel' => 2]));
|
|
if (file_exists($savePath)) {
|
|
$data = json_decode(file_get_contents($savePath), true);
|
|
echo "✓ 升级后自动保存成功\n";
|
|
echo " - 当前等级: " . $data['player']['level'] . "\n";
|
|
echo " - 当前经验: " . $data['player']['currentXp'] . "\n";
|
|
} else {
|
|
echo "✗ 自动保存失败\n";
|
|
}
|
|
|
|
echo "\n3. 测试任务接受触发自动保存...\n";
|
|
$dispatcher->dispatch(new Event('QuestAcceptRequest', ['questId' => 'KILL_GOBLIN']));
|
|
if (file_exists($savePath)) {
|
|
echo "✓ 任务接受后自动保存成功\n";
|
|
} else {
|
|
echo "✗ 自动保存失败\n";
|
|
}
|
|
|
|
echo "\n=== 测试完成 ===\n";
|