1.3 KiB
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
- Sudden Death: Unequipping an item subtracts the HP bonus from Current HP. If Current HP is low, the player dies instantly.
- Accidental Revive: Equipping an item adds the HP bonus to Current HP. If the player is dead (0 HP), this revives them.
Solution
- Unequip Logic: Do NOT subtract the bonus. Instead, check if
Current HP > New Total Max HP. If so, setCurrent HP = New Total Max HP. (Clamp logic). - 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.hpBonusifhp > 0(Player is alive).
unequip(Item item):- Remove item from
equipment. - Fix: Do NOT do
hp -= hpBonus. Instead, calculatetotalMaxHp(which uses the updated equipment list) and ensurehpdoes not exceed it (if (hp > totalMaxHp) hp = totalMaxHp;).
- Remove item from
Output Format
Please provide the complete code for lib/models/character.dart.