Implement potion pool (小绿瓶) system
- Add potionPool property to Player (initial: 1000 HP)
- Add addPotionPool(), consumePotionPool(), hasPotionPool() methods
- Modify Battle.php to add healing drops directly to pool instead of inventory
- Update InventoryPanel.php useItem() to consume from pool
- Update InventoryPanel.php autoHeal() to use pool system
- Add pool display in inventory header and stats panel
- Healing items no longer take inventory space after drops
🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
5249b36b7f
commit
8014ba64e6
|
|
@ -24,6 +24,9 @@ class Player extends Actor
|
||||||
public int $maxPartners = 2; // 最多可携带同伴数
|
public int $maxPartners = 2; // 最多可携带同伴数
|
||||||
public array $partners = []; // 已招募的同伴
|
public array $partners = []; // 已招募的同伴
|
||||||
|
|
||||||
|
// Player特有的小绿瓶回复池
|
||||||
|
public int $potionPool = 1000; // 小绿瓶初始回复量
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 增加灵石
|
* 增加灵石
|
||||||
*/
|
*/
|
||||||
|
|
@ -44,6 +47,32 @@ class Player extends Actor
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加小绿瓶回复量
|
||||||
|
*/
|
||||||
|
public function addPotionPool(int $amount): void
|
||||||
|
{
|
||||||
|
$this->potionPool += $amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从小绿瓶扣除回复量(返回实际扣除的量)
|
||||||
|
*/
|
||||||
|
public function consumePotionPool(int $amount): int
|
||||||
|
{
|
||||||
|
$consumed = min($amount, $this->potionPool);
|
||||||
|
$this->potionPool -= $consumed;
|
||||||
|
return $consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查小绿瓶是否有足够的回复量
|
||||||
|
*/
|
||||||
|
public function hasPotionPool(int $amount): bool
|
||||||
|
{
|
||||||
|
return $this->potionPool >= $amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Player特有的经验获取,升级时会恢复生命值
|
* Player特有的经验获取,升级时会恢复生命值
|
||||||
|
|
|
||||||
|
|
@ -1082,8 +1082,22 @@ class Battle
|
||||||
// 掉落 - 从掉落表中随机掉落物品
|
// 掉落 - 从掉落表中随机掉落物品
|
||||||
foreach ($enemy->dropTable as $drop) {
|
foreach ($enemy->dropTable as $drop) {
|
||||||
if (rand(1, 100) <= $drop['rate']) {
|
if (rand(1, 100) <= $drop['rate']) {
|
||||||
$this->player->addItem($drop['item']);
|
$item = $drop['item'];
|
||||||
$allDrops[] = $drop['item'];
|
// 如果是回复品(消耗品且有heal属性),直接添加到小绿瓶池
|
||||||
|
if ($item['type'] === 'consume' && isset($item['heal']) && $item['heal'] > 0) {
|
||||||
|
$this->player->addPotionPool($item['heal']);
|
||||||
|
// 显示为小绿瓶增加
|
||||||
|
$allDrops[] = [
|
||||||
|
'name' => '小绿瓶',
|
||||||
|
'type' => 'potion_pool',
|
||||||
|
'heal' => $item['heal'],
|
||||||
|
'quantity' => 1
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
// 其他物品正常添加到背包
|
||||||
|
$this->player->addItem($item);
|
||||||
|
$allDrops[] = $item;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,8 @@ class InventoryPanel
|
||||||
$out->writeln("╔════════════════════════════╗");
|
$out->writeln("╔════════════════════════════╗");
|
||||||
$out->writeln("║ 背 包 [{$categoryName}] ║");
|
$out->writeln("║ 背 包 [{$categoryName}] ║");
|
||||||
$out->writeln("║ 第 {$page} / {$totalPages} 页 ║");
|
$out->writeln("║ 第 {$page} / {$totalPages} 页 ║");
|
||||||
|
$out->writeln("╠════════════════════════════╣");
|
||||||
|
$out->writeln("║ 🟢 小绿瓶: {$player->potionPool} ║");
|
||||||
$out->writeln("╚════════════════════════════╝");
|
$out->writeln("╚════════════════════════════╝");
|
||||||
|
|
||||||
if (empty($items)) {
|
if (empty($items)) {
|
||||||
|
|
@ -238,14 +240,22 @@ class InventoryPanel
|
||||||
|
|
||||||
// 使用消耗品进行恢复
|
// 使用消耗品进行恢复
|
||||||
if ($target === 'player') {
|
if ($target === 'player') {
|
||||||
$actualHeal = $player->heal($item['heal']);
|
// 从小绿瓶池获取实际恢复量
|
||||||
$out->writeln("你使用了 {$item['name']},恢复了 {$actualHeal} HP!(当前: {$player->hp}/{$maxHp})");
|
$healAmount = $item['heal'];
|
||||||
|
$actualPotionHeal = $player->consumePotionPool($healAmount);
|
||||||
|
$actualHeal = $player->heal($actualPotionHeal);
|
||||||
|
$out->writeln("你使用了 {$item['name']},从小绿瓶中恢复了 {$actualHeal} HP!(当前: {$player->hp}/{$maxHp})");
|
||||||
|
$out->writeln("小绿瓶剩余: {$player->potionPool}");
|
||||||
} else {
|
} else {
|
||||||
// 恢复队友
|
// 恢复队友
|
||||||
$partnerStats = $target->getStats();
|
$partnerStats = $target->getStats();
|
||||||
$partnerMaxHp = $partnerStats['maxHp'];
|
$partnerMaxHp = $partnerStats['maxHp'];
|
||||||
$actualHeal = $target->heal($item['heal']);
|
// 从小绿瓶池获取实际恢复量
|
||||||
$out->writeln("你使用了 {$item['name']} 来恢复 {$target->name},恢复了 {$actualHeal} HP!(当前: {$target->hp}/{$partnerMaxHp})");
|
$healAmount = $item['heal'];
|
||||||
|
$actualPotionHeal = $player->consumePotionPool($healAmount);
|
||||||
|
$actualHeal = $target->heal($actualPotionHeal);
|
||||||
|
$out->writeln("你使用了 {$item['name']} 来恢复 {$target->name},从小绿瓶中恢复了 {$actualHeal} HP!(当前: {$target->hp}/{$partnerMaxHp})");
|
||||||
|
$out->writeln("小绿瓶剩余: {$player->potionPool}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decrease quantity or remove
|
// Decrease quantity or remove
|
||||||
|
|
@ -426,8 +436,9 @@ class InventoryPanel
|
||||||
$inventoryIndex = $selected['index'];
|
$inventoryIndex = $selected['index'];
|
||||||
$item = $selected['item'];
|
$item = $selected['item'];
|
||||||
|
|
||||||
// 使用药品
|
// 使用药品,从小绿瓶池里扣除
|
||||||
$actualHeal = $player->heal($item['heal']);
|
$actualPotionHeal = $player->consumePotionPool($item['heal']);
|
||||||
|
$actualHeal = $player->heal($actualPotionHeal);
|
||||||
$totalHealed += $actualHeal;
|
$totalHealed += $actualHeal;
|
||||||
$itemsUsed++;
|
$itemsUsed++;
|
||||||
$healLog[] = "玩家: +{$actualHeal} HP";
|
$healLog[] = "玩家: +{$actualHeal} HP";
|
||||||
|
|
@ -490,8 +501,9 @@ class InventoryPanel
|
||||||
$inventoryIndex = $selected['index'];
|
$inventoryIndex = $selected['index'];
|
||||||
$item = $selected['item'];
|
$item = $selected['item'];
|
||||||
|
|
||||||
// 使用药品回复队友
|
// 使用药品回复队友,从小绿瓶池里扣除
|
||||||
$actualHeal = $partner->heal($item['heal']);
|
$actualPotionHeal = $player->consumePotionPool($item['heal']);
|
||||||
|
$actualHeal = $partner->heal($actualPotionHeal);
|
||||||
$totalHealed += $actualHeal;
|
$totalHealed += $actualHeal;
|
||||||
$itemsUsed++;
|
$itemsUsed++;
|
||||||
$healLog[] = "{$partner->name}: +{$actualHeal} HP";
|
$healLog[] = "{$partner->name}: +{$actualHeal} HP";
|
||||||
|
|
@ -739,7 +751,7 @@ class InventoryPanel
|
||||||
$reset = Colors::RESET;
|
$reset = Colors::RESET;
|
||||||
|
|
||||||
$out->writeln("╔════════════════════════════════════════════════════════╗");
|
$out->writeln("╔════════════════════════════════════════════════════════╗");
|
||||||
$out->writeln("║ {$cyan}角色属性{$reset} Lv.{$player->level} | {$green}💰 {$player->spiritStones}{$reset} 灵石 ║");
|
$out->writeln("║ {$cyan}角色属性{$reset} Lv.{$player->level} | {$green}💰 {$player->spiritStones}{$reset} 灵石 | 🟢 {$player->potionPool} ║");
|
||||||
$out->writeln("╠════════════════════════════════════════════════════════╣");
|
$out->writeln("╠════════════════════════════════════════════════════════╣");
|
||||||
|
|
||||||
// First row: HP (current/max), patk, matk
|
// First row: HP (current/max), patk, matk
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user