game/prompt/06_fix_hp_logic.md

1.3 KiB

Role

You are a Senior Flutter Developer working on "Colosseum's Choice". You need to fix a critical bug in the HP Calculation Logic within the Character model.

Problem

  1. Sudden Death: Unequipping an item subtracts the HP bonus from Current HP. If Current HP is low, the player dies instantly.
  2. Accidental Revive: Equipping an item adds the HP bonus to Current HP. If the player is dead (0 HP), this revives them.

Solution

  1. Unequip Logic: Do NOT subtract the bonus. Instead, check if Current HP > New Total Max HP. If so, set Current HP = New Total Max HP. (Clamp logic).
  2. Equip Logic: Only add the HP bonus to Current HP if the player is Alive (hp > 0).

Required Changes

Please generate the updated code for the following file.


1. lib/models/character.dart (Fix)

Methods to Update:

  • equip(Item item):
    • Handle swapping (unequip old item first).
    • Add new item to equipment.
    • Fix: Only execute hp += item.hpBonus if hp > 0 (Player is alive).
  • unequip(Item item):
    • Remove item from equipment.
    • Fix: Do NOT do hp -= hpBonus. Instead, calculate totalMaxHp (which uses the updated equipment list) and ensure hp does not exceed it (if (hp > totalMaxHp) hp = totalMaxHp;).

Output Format

Please provide the complete code for lib/models/character.dart.