Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Actor {
- private static final ArrayList<ItemSlot> BOTH_HANDS = [MAIN_HAND, OFF_HAND]
- private static final ArrayList<ItemSlot> BOTH_RINGS = [RING_RIGHT, RING_LEFT]
- // items
- Collection<Item> inventory = []
- Map<ItemSlot, Item> equipment = [:]
- void useOrEquip(int itemId, ItemSlot targetSlot) {
- Item item = inventory.find { it.id == itemId }
- if (item) {
- switch (item.type) {
- case ItemType.EQUIPABLE:
- List<ItemSlot> slotsToEmpty
- ItemSlot destination = item.slot
- if (item.isTwoHanded) {
- slotsToEmpty = BOTH_HANDS
- destination = MAIN_HAND
- } else if (equipment.get(MAIN_HAND).isTwoHanded && targetSlot in BOTH_HANDS) {
- slotsToEmpty = [MAIN_HAND]
- destination
- } else if ((equipment.keySet().containsAll(BOTH_HANDS) && targetSlot in BOTH_HANDS)
- || (equipment.keySet().containsAll(BOTH_RINGS) && targetSlot in BOTH_RINGS)) {
- slotsToEmpty = [targetSlot]
- destination = targetSlot
- } else {
- slotsToEmpty = [item.slot]
- }
- slotsToEmpty.each { inventory.add(equipment.remove(it)) }
- inventory.remove item
- equipment.put destination, item
- break
- case ItemType.USABLE:
- break
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement