mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-02-01 02:14:32 +07:00
Moved AlternateListener to ItemData
This commit is contained in:
parent
0c48569120
commit
1666c528e7
@ -70,8 +70,6 @@ public class CharData {
|
||||
|
||||
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 @@ public class CharData {
|
||||
mercData.itemData.clear();
|
||||
golemItemData = null;
|
||||
|
||||
alternateListeners.clear();
|
||||
|
||||
skills.clear();
|
||||
chargedSkills.clear();
|
||||
skillListeners.clear();
|
||||
@ -431,26 +427,6 @@ public class CharData {
|
||||
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 class CharData {
|
||||
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 @@ public class CharData {
|
||||
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 @@ public class ItemData {
|
||||
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 class ItemData {
|
||||
public void clear() {
|
||||
cursor = INVALID_ITEM;
|
||||
alternate = D2S.PRIMARY;
|
||||
alternateListeners.clear();
|
||||
itemData.clear();
|
||||
equipped.clear();
|
||||
equipListeners.clear();
|
||||
@ -98,6 +101,26 @@ public class ItemData {
|
||||
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 @@ public class ItemData {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user