Advertisement
Guest User

Untitled

a guest
May 26th, 2015
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. class Actor {
  2. private static final ArrayList<ItemSlot> BOTH_HANDS = [MAIN_HAND, OFF_HAND]
  3. private static final ArrayList<ItemSlot> BOTH_RINGS = [RING_RIGHT, RING_LEFT]
  4. // items
  5. Collection<Item> inventory = []
  6. Map<ItemSlot, Item> equipment = [:]
  7.  
  8.  
  9.  
  10. void useOrEquip(int itemId, ItemSlot targetSlot) {
  11. Item item = inventory.find { it.id == itemId }
  12. if (item) {
  13. switch (item.type) {
  14. case ItemType.EQUIPABLE:
  15. List<ItemSlot> slotsToEmpty
  16. ItemSlot destination = item.slot
  17. if (item.isTwoHanded) {
  18. slotsToEmpty = BOTH_HANDS
  19. destination = MAIN_HAND
  20. } else if (equipment.get(MAIN_HAND).isTwoHanded && targetSlot in BOTH_HANDS) {
  21. slotsToEmpty = [MAIN_HAND]
  22. destination
  23. } else if ((equipment.keySet().containsAll(BOTH_HANDS) && targetSlot in BOTH_HANDS)
  24. || (equipment.keySet().containsAll(BOTH_RINGS) && targetSlot in BOTH_RINGS)) {
  25. slotsToEmpty = [targetSlot]
  26. destination = targetSlot
  27. } else {
  28. slotsToEmpty = [item.slot]
  29. }
  30. slotsToEmpty.each { inventory.add(equipment.remove(it)) }
  31. inventory.remove item
  32. equipment.put destination, item
  33. break
  34. case ItemType.USABLE:
  35. break
  36. }
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement