game/prompt/05_equipment_slot_refactor.md

66 lines
2.3 KiB
Markdown

# Role
You are a Senior Flutter Developer working on "Colosseum's Choice".
You need to refactor the **Equipment System** to enforce **Slot-based restrictions**.
# Current Problem
Currently, `equipment` is a `List<Item>`, allowing the player to equip multiple weapons or armors simultaneously.
# Solution
Refactor the code to use an `Enum` based Map system: `Map<EquipmentSlot, Item>`.
- **Slots:** `weapon`, `armor`, `accessory`.
- **Rule:** Only one item per slot. Equipping a new item into an occupied slot should **SWAP** them (Old item goes to Inventory, New item goes to Equipment).
# Required Changes
Please generate the updated code for the following files.
---
## 1. `lib/models/item.dart` (Update)
- **Enum:** Create `enum EquipmentSlot { weapon, armor, accessory }`.
- **Class:** Add `final EquipmentSlot slot;` to the `Item` class.
- **Constructor:** Update to require `slot`.
- **Helper:** Add a getter `String get typeName` (returns "Weapon", "Armor", etc. based on enum).
## 2. `lib/models/character.dart` (Update)
- **Field Change:** Change `List<Item> equipment` to `Map<EquipmentSlot, Item> equipment = {};`.
- **Stat Logic:** Update `totalAtk` / `totalMaxHp` to iterate over `equipment.values`.
- **Method `equip(Item newItem)`:**
1. Check `newItem.slot`.
2. If `equipment[newItem.slot]` exists:
- Move the _existing_ item to `inventory`.
3. Remove `newItem` from `inventory`.
4. Set `equipment[newItem.slot] = newItem`.
- **Method `unequip(Item item)`:**
1. Check if inventory has space.
2. Remove from `equipment`.
3. Add to `inventory`.
## 3. `lib/providers/battle_provider.dart` (Update)
- **Item Generation (`_onVictory`):**
- When generating random items, assign appropriate slots.
- Example: "Sword" -> `EquipmentSlot.weapon`, "Plate" -> `EquipmentSlot.armor`.
- **Equip Logic:** `equipItem` now just calls `player.equip(item)` (Swap logic is inside Character).
## 4. `lib/screens/inventory_screen.dart` (Update)
- **Equipped Area (UI Change):**
- Instead of a ListView, create a **Row with 3 fixed Cards** (Weapon / Armor / Accessory).
- **Loop:** Iterate through `EquipmentSlot.values`.
- **Content:**
- If `player.equipment[slot]` exists: Show Item Icon & Name. Tap to Unequip.
- If null: Show "Empty [Slot Name]" placeholder.
---
# Output Format
Please provide the complete code for the 4 modified files.