2.3 KiB
2.3 KiB
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 theItemclass. - 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> equipmenttoMap<EquipmentSlot, Item> equipment = {};. - Stat Logic: Update
totalAtk/totalMaxHpto iterate overequipment.values. - Method
equip(Item newItem):- Check
newItem.slot. - If
equipment[newItem.slot]exists:- Move the existing item to
inventory.
- Move the existing item to
- Remove
newItemfrominventory. - Set
equipment[newItem.slot] = newItem.
- Check
- Method
unequip(Item item):- Check if inventory has space.
- Remove from
equipment. - 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:
equipItemnow just callsplayer.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.
- If
Output Format
Please provide the complete code for the 4 modified files.