48 lines
1.5 KiB
PHP
48 lines
1.5 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("ShopTest", 100, 10, 5);
|
|
$player->gainGold(200); // 给玩家一些金币用于测试
|
|
$stateManager->setPlayer($player);
|
|
$stateManager->setCurrentTileId('TOWN_01');
|
|
|
|
echo "=== NPC商店功能测试 ===\n\n";
|
|
|
|
// 获取NPC仓库
|
|
$npcRepo = $container->getNpcRepository();
|
|
$npc = $npcRepo->createNPC('BLACKSMITH');
|
|
|
|
if (!$npc) {
|
|
die("❌ 无法创建铁匠NPC\n");
|
|
}
|
|
|
|
echo "1. 创建NPC: {$npc->getName()}\n";
|
|
echo " 是否有商店: " . ($npc->hasShop ? '是' : '否') . "\n";
|
|
echo " 商店库存数量: " . count($npc->shopInventory) . "\n\n";
|
|
|
|
echo "2. 玩家初始状态:\n";
|
|
echo " - 金币: {$player->getGold()}\n";
|
|
echo " - 背包物品数: " . count($player->getInventory()) . "\n\n";
|
|
|
|
echo "3. NPC商店数据验证:\n";
|
|
foreach ($npc->shopInventory as $itemId => $data) {
|
|
echo " - 商品ID: {$itemId}, 价格: {$data['price']}\n";
|
|
}
|
|
|
|
echo "\n=== 测试完成 ===\n"; |