Browse Source

more equip refactored.

combat-2
MagicBot 8 months ago
parent
commit
68088a3399
  1. 24
      src/engine/objects/CharacterItemManager.java

24
src/engine/objects/CharacterItemManager.java

@ -50,7 +50,7 @@ public class CharacterItemManager {
private final HashSet<Item> inventory = new HashSet<>(); private final HashSet<Item> inventory = new HashSet<>();
private final HashSet<Item> bank = new HashSet<>(); private final HashSet<Item> bank = new HashSet<>();
private final HashSet<Item> vault = new HashSet<>(); private final HashSet<Item> vault = new HashSet<>();
private final HashSet<Integer> equipOrder = new HashSet<>(); private final HashSet<Enum.EquipSlotType> equipOrder = new HashSet<>();
public Item goldVault; public Item goldVault;
private Account account; private Account account;
private Item goldInventory; private Item goldInventory;
@ -187,7 +187,7 @@ public class CharacterItemManager {
case EQUIPPED: case EQUIPPED:
if (this.equipped.containsValue(i) == false) { if (this.equipped.containsValue(i) == false) {
this.equipped.put(i.equipSlot, i); this.equipped.put(i.equipSlot, i);
addEquipOrder(i.equipSlot.ordinal()); addEquipOrder(i.equipSlot);
} }
break; break;
case BANK: case BANK:
@ -877,11 +877,10 @@ public class CharacterItemManager {
return this.goldVault; return this.goldVault;
} }
public void addEquipOrder(int slot) { public void addEquipOrder(Enum.EquipSlotType slot) {
synchronized (this.equipOrder) { synchronized (this.equipOrder) {
Integer iSlot = slot; if (this.equipOrder.contains(slot))
if (this.equipOrder.contains(iSlot)) this.equipOrder.remove(slot);
this.equipOrder.remove(iSlot);
this.equipOrder.add(slot); this.equipOrder.add(slot);
} }
} }
@ -1314,7 +1313,7 @@ public class CharacterItemManager {
i.addToCache(); i.addToCache();
addEquipOrder(slot.ordinal()); addEquipOrder(slot);
//calculateWeights(); //calculateWeights();
} }
@ -1890,16 +1889,15 @@ public class CharacterItemManager {
ArrayList<Item> ret = new ArrayList<>(); ArrayList<Item> ret = new ArrayList<>();
synchronized (this.equipOrder) { synchronized (this.equipOrder) {
synchronized (this.equipped) { synchronized (this.equipped) {
for (int slot : this.equipOrder) { for (Enum.EquipSlotType slot : this.equipOrder) {
Enum.EquipSlotType slotType = Enum.EquipSlotType.values()[slot]; if (this.equipped.containsKey(slot))
if (this.equipped.containsKey(slotType)) ret.add(this.equipped.get(slot));
ret.add(this.equipped.get(slotType));
} }
if (ret.size() != this.equipped.size()) if (ret.size() != this.equipped.size())
//missed adding some items, figure out what. //missed adding some items, figure out what.
for (Enum.EquipSlotType slot : this.equipped.keySet()) { for (Enum.EquipSlotType slot : this.equipped.keySet()) {
if (!(this.equipOrder.contains(slot.ordinal()))) { if (!(this.equipOrder.contains(slot))) {
this.equipOrder.add(slot.ordinal()); this.equipOrder.add(slot);
ret.add(this.equipped.get(slot)); ret.add(this.equipped.get(slot));
} }
} }

Loading…
Cancel
Save