mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-07-08 14:57:30 +07:00
Moved pickup and store methods to ItemData
Added support for store listeners CharData store methods are now simple calls up to player ItemData reference
This commit is contained in:
@ -326,10 +326,7 @@ public class CharData implements ItemData.UpdateListener, Pool.Poolable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void itemToCursor(int i) {
|
public void itemToCursor(int i) {
|
||||||
assert itemData.cursor == ItemData.INVALID_ITEM;
|
itemData.pickup(i);
|
||||||
itemData.cursor = i;
|
|
||||||
Item item = itemData.getItem(i);
|
|
||||||
item.location = Location.CURSOR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void storeToCursor(int i) {
|
public void storeToCursor(int i) {
|
||||||
@ -337,13 +334,7 @@ public class CharData implements ItemData.UpdateListener, Pool.Poolable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void cursorToStore(StoreLoc storeLoc, int x, int y) {
|
public void cursorToStore(StoreLoc storeLoc, int x, int y) {
|
||||||
assert itemData.cursor != ItemData.INVALID_ITEM;
|
itemData.storeCursor(storeLoc, x, y);
|
||||||
Item item = itemData.getItem(itemData.cursor);
|
|
||||||
item.location = Location.STORED;
|
|
||||||
item.storeLoc = storeLoc;
|
|
||||||
item.gridX = (byte) x;
|
|
||||||
item.gridY = (byte) y;
|
|
||||||
itemData.cursor = ItemData.INVALID_ITEM;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void swapStoreItem(int i, StoreLoc storeLoc, int x, int y) {
|
public void swapStoreItem(int i, StoreLoc storeLoc, int x, int y) {
|
||||||
|
@ -27,6 +27,8 @@ public class ItemData {
|
|||||||
int alternate = D2S.PRIMARY;
|
int alternate = D2S.PRIMARY;
|
||||||
final Array<AlternateListener> alternateListeners = new Array<>(false, 16);
|
final Array<AlternateListener> alternateListeners = new Array<>(false, 16);
|
||||||
|
|
||||||
|
final Array<StoreListener> storeListeners = new Array<>(false, 16);
|
||||||
|
|
||||||
final EnumIntMap<BodyLoc> equipped = new EnumIntMap<>(BodyLoc.class, INVALID_ITEM);
|
final EnumIntMap<BodyLoc> equipped = new EnumIntMap<>(BodyLoc.class, INVALID_ITEM);
|
||||||
final Array<EquipListener> equipListeners = new Array<>(false, 16);
|
final Array<EquipListener> equipListeners = new Array<>(false, 16);
|
||||||
|
|
||||||
@ -165,6 +167,29 @@ public class ItemData {
|
|||||||
return getLocation(Location.STORED, storeLoc);
|
return getLocation(Location.STORED, storeLoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pickup(int i) {
|
||||||
|
assert cursor == INVALID_ITEM;
|
||||||
|
Item item = itemData.get(i);
|
||||||
|
if (item.location == Location.STORED) notifyStoreRemoved(item);
|
||||||
|
cursor = i;
|
||||||
|
item.location = Location.CURSOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
void storeCursor(StoreLoc storeLoc, int x, int y) {
|
||||||
|
assert cursor != ItemData.INVALID_ITEM;
|
||||||
|
store(storeLoc, cursor, x, y);
|
||||||
|
cursor = INVALID_ITEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
void store(StoreLoc storeLoc, int i, int x, int y) {
|
||||||
|
Item item = itemData.get(i);
|
||||||
|
item.location = Location.STORED;
|
||||||
|
item.storeLoc = storeLoc;
|
||||||
|
item.gridX = (byte) x;
|
||||||
|
item.gridY = (byte) y;
|
||||||
|
notifyStoreAdded(item);
|
||||||
|
}
|
||||||
|
|
||||||
void equip(BodyLoc bodyLoc, Item item) {
|
void equip(BodyLoc bodyLoc, Item item) {
|
||||||
assert !itemData.contains(item, true);
|
assert !itemData.contains(item, true);
|
||||||
equip(bodyLoc, add(item));
|
equip(bodyLoc, add(item));
|
||||||
@ -282,4 +307,22 @@ public class ItemData {
|
|||||||
public interface UpdateListener {
|
public interface UpdateListener {
|
||||||
void onUpdated(ItemData itemData);
|
void onUpdated(ItemData itemData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean addStoreListener(StoreListener l) {
|
||||||
|
storeListeners.add(l);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void notifyStoreAdded(Item item) {
|
||||||
|
for (StoreListener l : storeListeners) l.onAdded(this, item.storeLoc, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void notifyStoreRemoved(Item item) {
|
||||||
|
for (StoreListener l : storeListeners) l.onRemoved(this, item.storeLoc, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface StoreListener {
|
||||||
|
void onAdded(ItemData items, StoreLoc storeLoc, Item item);
|
||||||
|
void onRemoved(ItemData items, StoreLoc storeLoc, Item item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user