59 lines
2.1 KiB
PHP
59 lines
2.1 KiB
PHP
<?php
|
||
require __DIR__ . '/../vendor/autoload.php';
|
||
|
||
use Game\Core\ServiceContainer;
|
||
use Game\Event\Event;
|
||
use Game\Model\Item;
|
||
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("ItemTest", 50, 10, 5);
|
||
$stateManager->setPlayer($player);
|
||
$stateManager->setCurrentTileId('TOWN_01');
|
||
|
||
echo "=== 物品使用功能测试 ===\n\n";
|
||
|
||
// 添加测试物品
|
||
$potion = new Item(1, "小型治疗药水", "potion", "恢复20点生命", 10, ['heal' => 20]);
|
||
$weapon = new Item(2, "铁剑", "weapon", "攻击+5", 50, [], 'weapon', ['attack' => 5]);
|
||
|
||
$player->addItem($potion);
|
||
$player->addItem($weapon);
|
||
|
||
echo "1. 初始状态:\n";
|
||
echo " - 生命值: {$player->getHealth()}/{$player->getMaxHealth()}\n";
|
||
echo " - 攻击力: {$player->getAttack()}\n";
|
||
echo " - 背包物品数: " . count($player->getInventory()) . "\n\n";
|
||
|
||
// 扣血测试药水
|
||
$player->takeDamage(30);
|
||
echo "2. 受到30点伤害后:\n";
|
||
echo " - 生命值: {$player->getHealth()}/{$player->getMaxHealth()}\n\n";
|
||
|
||
// 测试使用药水
|
||
echo "3. 使用药水 (编号0)...\n";
|
||
$dispatcher->dispatch(new Event('UseItemEvent', ['itemIndex' => 0]));
|
||
echo " - 生命值: {$player->getHealth()}/{$player->getMaxHealth()}\n";
|
||
echo " - 背包物品数: " . count($player->getInventory()) . "\n\n";
|
||
|
||
// 测试装备武器
|
||
echo "4. 装备武器 (编号0,因为药水已被使用)...\n";
|
||
$dispatcher->dispatch(new Event('EquipItemEvent', ['itemIndex' => 0]));
|
||
echo " - 攻击力: {$player->getAttack()}\n";
|
||
echo " - 背包物品数: " . count($player->getInventory()) . "\n";
|
||
$equipment = $player->getEquipment();
|
||
echo " - 武器槽: " . ($equipment['weapon'] ? $equipment['weapon']->name : '空') . "\n\n";
|
||
|
||
echo "=== 测试完成 ===\n";
|