From 8014ba64e6da2adf43282b027f57b19af2844d13 Mon Sep 17 00:00:00 2001 From: hant Date: Sun, 7 Dec 2025 18:51:21 +0800 Subject: [PATCH] =?UTF-8?q?Implement=20potion=20pool=20(=E5=B0=8F=E7=BB=BF?= =?UTF-8?q?=E7=93=B6)=20system?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- src/Entities/Player.php | 29 +++++++++++++++++++++++++++++ src/Modules/Battle.php | 18 ++++++++++++++++-- src/Modules/InventoryPanel.php | 30 +++++++++++++++++++++--------- 3 files changed, 66 insertions(+), 11 deletions(-) diff --git a/src/Entities/Player.php b/src/Entities/Player.php index 04b0f91..7dec19c 100644 --- a/src/Entities/Player.php +++ b/src/Entities/Player.php @@ -24,6 +24,9 @@ class Player extends Actor public int $maxPartners = 2; // ๆœ€ๅคšๅฏๆบๅธฆๅŒไผดๆ•ฐ public array $partners = []; // ๅทฒๆ‹›ๅ‹Ÿ็š„ๅŒไผด + // Player็‰นๆœ‰็š„ๅฐ็ปฟ็“ถๅ›žๅคๆฑ  + public int $potionPool = 1000; // ๅฐ็ปฟ็“ถๅˆๅง‹ๅ›žๅค้‡ + /** * ๅขžๅŠ ็ต็Ÿณ */ @@ -44,6 +47,32 @@ class Player extends Actor 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็‰นๆœ‰็š„็ป้ชŒ่Žทๅ–๏ผŒๅ‡็บงๆ—ถไผšๆขๅค็”Ÿๅ‘ฝๅ€ผ diff --git a/src/Modules/Battle.php b/src/Modules/Battle.php index 04d008c..6bd7074 100644 --- a/src/Modules/Battle.php +++ b/src/Modules/Battle.php @@ -1082,8 +1082,22 @@ class Battle // ๆމ่ฝ - ไปŽๆމ่ฝ่กจไธญ้šๆœบๆމ่ฝ็‰ฉๅ“ foreach ($enemy->dropTable as $drop) { if (rand(1, 100) <= $drop['rate']) { - $this->player->addItem($drop['item']); - $allDrops[] = $drop['item']; + $item = $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; + } } } } diff --git a/src/Modules/InventoryPanel.php b/src/Modules/InventoryPanel.php index 0e2c4f1..d20a5ee 100644 --- a/src/Modules/InventoryPanel.php +++ b/src/Modules/InventoryPanel.php @@ -69,6 +69,8 @@ class InventoryPanel $out->writeln("โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—"); $out->writeln("โ•‘ ่ƒŒ ๅŒ… [{$categoryName}] โ•‘"); $out->writeln("โ•‘ ็ฌฌ {$page} / {$totalPages} ้กต โ•‘"); + $out->writeln("โ• โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ฃ"); + $out->writeln("โ•‘ ๐ŸŸข ๅฐ็ปฟ็“ถ: {$player->potionPool} โ•‘"); $out->writeln("โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•"); if (empty($items)) { @@ -238,14 +240,22 @@ class InventoryPanel // ไฝฟ็”จๆถˆ่€—ๅ“่ฟ›่กŒๆขๅค 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 { // ๆขๅค้˜Ÿๅ‹ $partnerStats = $target->getStats(); $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 @@ -426,8 +436,9 @@ class InventoryPanel $inventoryIndex = $selected['index']; $item = $selected['item']; - // ไฝฟ็”จ่ฏๅ“ - $actualHeal = $player->heal($item['heal']); + // ไฝฟ็”จ่ฏๅ“๏ผŒไปŽๅฐ็ปฟ็“ถๆฑ ้‡Œๆ‰ฃ้™ค + $actualPotionHeal = $player->consumePotionPool($item['heal']); + $actualHeal = $player->heal($actualPotionHeal); $totalHealed += $actualHeal; $itemsUsed++; $healLog[] = "็Žฉๅฎถ: +{$actualHeal} HP"; @@ -490,8 +501,9 @@ class InventoryPanel $inventoryIndex = $selected['index']; $item = $selected['item']; - // ไฝฟ็”จ่ฏๅ“ๅ›žๅค้˜Ÿๅ‹ - $actualHeal = $partner->heal($item['heal']); + // ไฝฟ็”จ่ฏๅ“ๅ›žๅค้˜Ÿๅ‹๏ผŒไปŽๅฐ็ปฟ็“ถๆฑ ้‡Œๆ‰ฃ้™ค + $actualPotionHeal = $player->consumePotionPool($item['heal']); + $actualHeal = $partner->heal($actualPotionHeal); $totalHealed += $actualHeal; $itemsUsed++; $healLog[] = "{$partner->name}: +{$actualHeal} HP"; @@ -739,7 +751,7 @@ class InventoryPanel $reset = Colors::RESET; $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("โ• โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ฃ"); // First row: HP (current/max), patk, matk