Skip to content
Permalink
Browse files

Moved AlternateListener to ItemData

  • Loading branch information
collinsmith committed Jan 12, 2020
1 parent 0c48569 commit 1666c528e70384d78de56bca4c2249ea0fc523b3
Showing with 38 additions and 38 deletions.
  1. +2 −38 core/src/com/riiablo/save/CharData.java
  2. +36 −0 core/src/com/riiablo/save/ItemData.java
@@ -70,8 +70,6 @@

private byte[] data; // TODO: replace this reference with D2S.serialize(CharData)

final Array<AlternateListener> alternateListeners = new Array<>(false, 16);

final IntIntMap skills = new IntIntMap();
final Array<Stat> chargedSkills = new Array<>(false, 16);
final Array<SkillListener> skillListeners = new Array<>(false, 16);
@@ -157,8 +155,6 @@ void softReset() {
mercData.itemData.clear();
golemItemData = null;

alternateListeners.clear();

skills.clear();
chargedSkills.clear();
skillListeners.clear();
@@ -431,26 +427,6 @@ public void swapBeltItem(int i) {
itemData.cursor = newCursor;
}

public int getAlternate() {
return itemData.alternate;
}

public void setAlternate(int alternate) {
if (itemData.alternate != alternate) {
itemData.alternate = alternate;
Item LH = itemData.getEquipped(BodyLoc.LARM);
Item RH = itemData.getEquipped(BodyLoc.RARM);
updateStats();
notifyAlternated(alternate, LH, RH);
}
}

public int alternate() {
int alt = getAlternate() > D2S.PRIMARY ? D2S.PRIMARY : D2S.SECONDARY;
setAlternate(alt);
return alt;
}

public static class MercData {
public int flags;
public int seed;
@@ -477,7 +453,8 @@ public String getName() {
public void clearListeners() {
itemData.equipListeners.clear();
mercData.itemData.equipListeners.clear();
alternateListeners.clear();
itemData.alternateListeners.clear();
mercData.itemData.alternateListeners.clear();
skillListeners.clear();
}

@@ -493,17 +470,4 @@ private void notifySkillChanged(IntIntMap skills, Array<Stat> chargedSkills) {
public interface SkillListener {
void onChanged(CharData client, IntIntMap skills, Array<Stat> chargedSkills);
}

public boolean addAlternateListener(AlternateListener l) {
alternateListeners.add(l);
return true;
}

private void notifyAlternated(int alternate, Item LH, Item RH) {
for (AlternateListener l : alternateListeners) l.onAlternated(this, alternate, LH, RH);
}

public interface AlternateListener {
void onAlternated(CharData charData, int alternate, Item LH, Item RH);
}
}
@@ -23,7 +23,9 @@
final Array<Item> itemData = new Array<>(Item.class);

int cursor = INVALID_ITEM;

int alternate = D2S.PRIMARY;
final Array<AlternateListener> alternateListeners = new Array<>(false, 16);

final EnumIntMap<BodyLoc> equipped = new EnumIntMap<>(BodyLoc.class, INVALID_ITEM);
final Array<EquipListener> equipListeners = new Array<>(false, 16);
@@ -38,6 +40,7 @@
public void clear() {
cursor = INVALID_ITEM;
alternate = D2S.PRIMARY;
alternateListeners.clear();
itemData.clear();
equipped.clear();
equipListeners.clear();
@@ -98,6 +101,26 @@ public boolean isActive(Item item) {
return item.bodyLoc == BodyLoc.getAlternate(item.bodyLoc, alternate);
}

public int getAlternate() {
return alternate;
}

public void setAlternate(int alternate) {
if (this.alternate != alternate) {
this.alternate = alternate;
Item LH = getEquipped(BodyLoc.LARM);
Item RH = getEquipped(BodyLoc.RARM);
updateStats();
notifyAlternated(alternate, LH, RH);
}
}

public int alternate() {
int alt = alternate > D2S.PRIMARY ? D2S.PRIMARY : D2S.SECONDARY;
setAlternate(alt);
return alt;
}

public int add(Item item) {
int i = itemData.size;
itemData.add(item);
@@ -228,4 +251,17 @@ private void notifyUnequip(BodyLoc bodyLoc, Item item) {
void onEquip(ItemData items, BodyLoc bodyLoc, Item item);
void onUnequip(ItemData items, BodyLoc bodyLoc, Item item);
}

public boolean addAlternateListener(AlternateListener l) {
alternateListeners.add(l);
return true;
}

private void notifyAlternated(int alternate, Item LH, Item RH) {
for (AlternateListener l : alternateListeners) l.onAlternated(this, alternate, LH, RH);
}

public interface AlternateListener {
void onAlternated(ItemData items, int alternate, Item LH, Item RH);
}
}

0 comments on commit 1666c52

Please sign in to comment.
You can’t perform that action at this time.