Rename and clean up MaplePlayerShopItem

This commit is contained in:
P0nk
2021-09-09 22:35:46 +02:00
parent f1ca5991c6
commit 667bc69eb1
8 changed files with 47 additions and 48 deletions

View File

@@ -66,7 +66,7 @@ public class HiredMerchant extends AbstractMapObject {
private String ownerName = "";
private String description = "";
private final Character[] visitors = new Character[3];
private final List<MaplePlayerShopItem> items = new LinkedList<>();
private final List<PlayerShopItem> items = new LinkedList<>();
private final List<Pair<String, Byte>> messages = new LinkedList<>();
private final List<SoldItem> sold = new LinkedList<>();
private final AtomicBoolean open = new AtomicBoolean();
@@ -216,7 +216,7 @@ public class HiredMerchant extends AbstractMapObject {
public void takeItemBack(int slot, Character chr) {
synchronized (items) {
MaplePlayerShopItem shopItem = items.get(slot);
PlayerShopItem shopItem = items.get(slot);
if (shopItem.isExist()) {
if (shopItem.getBundles() > 0) {
Item iitem = shopItem.getItem().copy();
@@ -249,7 +249,7 @@ public class HiredMerchant extends AbstractMapObject {
synchronized (items) {
int count = 0;
for (MaplePlayerShopItem mpsi : items) {
for (PlayerShopItem mpsi : items) {
if (mpsi.getItem().getItemId() == itemid) {
count += (mpsi.getBundles() * mpsi.getItem().getQuantity());
}
@@ -261,7 +261,7 @@ public class HiredMerchant extends AbstractMapObject {
public void buy(Client c, int item, short quantity) {
synchronized (items) {
MaplePlayerShopItem pItem = items.get(item);
PlayerShopItem pItem = items.get(item);
Item newItem = pItem.getItem().copy();
newItem.setQuantity((short) ((pItem.getItem().getQuantity() * quantity)));
@@ -408,9 +408,9 @@ public class HiredMerchant extends AbstractMapObject {
this.removeOwner(c.getPlayer());
try {
List<MaplePlayerShopItem> copyItems = getItems();
List<PlayerShopItem> copyItems = getItems();
if (check(c.getPlayer(), copyItems) && !timeout) {
for (MaplePlayerShopItem mpsi : copyItems) {
for (PlayerShopItem mpsi : copyItems) {
if (mpsi.isExist()) {
if (mpsi.getItem().getInventoryType().equals(InventoryType.EQUIP)) {
InventoryManipulator.addFromDrop(c, mpsi.getItem(), false);
@@ -512,14 +512,14 @@ public class HiredMerchant extends AbstractMapObject {
}
}
public List<MaplePlayerShopItem> getItems() {
public List<PlayerShopItem> getItems() {
synchronized (items) {
return Collections.unmodifiableList(items);
}
}
public boolean hasItem(int itemid) {
for (MaplePlayerShopItem mpsi : getItems()) {
for (PlayerShopItem mpsi : getItems()) {
if (mpsi.getItem().getItemId() == itemid && mpsi.isExist() && mpsi.getBundles() > 0) {
return true;
}
@@ -528,7 +528,7 @@ public class HiredMerchant extends AbstractMapObject {
return false;
}
public boolean addItem(MaplePlayerShopItem item) {
public boolean addItem(PlayerShopItem item) {
synchronized (items) {
if (items.size() >= 16) {
return false;
@@ -609,9 +609,9 @@ public class HiredMerchant extends AbstractMapObject {
broadcastToVisitorsThreadsafe(PacketCreator.hiredMerchantChat(message, slot));
}
public List<MaplePlayerShopItem> sendAvailableBundles(int itemid) {
List<MaplePlayerShopItem> list = new LinkedList<>();
List<MaplePlayerShopItem> all = new ArrayList<>();
public List<PlayerShopItem> sendAvailableBundles(int itemid) {
List<PlayerShopItem> list = new LinkedList<>();
List<PlayerShopItem> all = new ArrayList<>();
if (!open.get()) {
return list;
@@ -621,7 +621,7 @@ public class HiredMerchant extends AbstractMapObject {
all.addAll(items);
}
for (MaplePlayerShopItem mpsi : all) {
for (PlayerShopItem mpsi : all) {
if (mpsi.getItem().getItemId() == itemid && mpsi.getBundles() > 0 && mpsi.isExist()) {
list.add(mpsi);
}
@@ -633,7 +633,7 @@ public class HiredMerchant extends AbstractMapObject {
List<Pair<Item, InventoryType>> itemsWithType = new ArrayList<>();
List<Short> bundles = new ArrayList<>();
for (MaplePlayerShopItem pItems : getItems()) {
for (PlayerShopItem pItems : getItems()) {
Item newItem = pItems.getItem();
short newBundle = pItems.getBundles();
@@ -655,9 +655,9 @@ public class HiredMerchant extends AbstractMapObject {
FredrickProcessor.insertFredrickLog(this.ownerId);
}
private static boolean check(Character chr, List<MaplePlayerShopItem> items) {
private static boolean check(Character chr, List<PlayerShopItem> items) {
List<Pair<Item, InventoryType>> li = new ArrayList<>();
for (MaplePlayerShopItem item : items) {
for (PlayerShopItem item : items) {
Item it = item.getItem().copy();
it.setQuantity((short) (it.getQuantity() * item.getBundles()));

View File

@@ -49,7 +49,7 @@ public class PlayerShop extends AbstractMapObject {
private final int itemid;
private final Character[] visitors = new Character[3];
private final List<MaplePlayerShopItem> items = new ArrayList<>();
private final List<PlayerShopItem> items = new ArrayList<>();
private final List<SoldItem> sold = new LinkedList<>();
private String description;
private int boughtnumber = 0;
@@ -204,7 +204,7 @@ public class PlayerShop extends AbstractMapObject {
}
}
public boolean addItem(MaplePlayerShopItem item) {
public boolean addItem(PlayerShopItem item) {
synchronized (items) {
if (items.size() >= 16) {
return false;
@@ -225,7 +225,7 @@ public class PlayerShop extends AbstractMapObject {
public void takeItemBack(int slot, Character chr) {
synchronized (items) {
MaplePlayerShopItem shopItem = items.get(slot);
PlayerShopItem shopItem = items.get(slot);
if (shopItem.isExist()) {
if (shopItem.getBundles() > 0) {
Item iitem = shopItem.getItem().copy();
@@ -256,7 +256,7 @@ public class PlayerShop extends AbstractMapObject {
public boolean buy(Client c, int item, short quantity) {
synchronized (items) {
if (isVisitor(c.getPlayer())) {
MaplePlayerShopItem pItem = items.get(item);
PlayerShopItem pItem = items.get(item);
Item newItem = pItem.getItem().copy();
newItem.setQuantity((short) ((pItem.getItem().getQuantity() * quantity)));
@@ -473,14 +473,14 @@ public class PlayerShop extends AbstractMapObject {
}
}
public List<MaplePlayerShopItem> getItems() {
public List<PlayerShopItem> getItems() {
synchronized (items) {
return Collections.unmodifiableList(items);
}
}
public boolean hasItem(int itemid) {
for (MaplePlayerShopItem mpsi : getItems()) {
for (PlayerShopItem mpsi : getItems()) {
if (mpsi.getItem().getItemId() == itemid && mpsi.isExist() && mpsi.getBundles() > 0) {
return true;
}
@@ -552,15 +552,15 @@ public class PlayerShop extends AbstractMapObject {
}
}
public List<MaplePlayerShopItem> sendAvailableBundles(int itemid) {
List<MaplePlayerShopItem> list = new LinkedList<>();
List<MaplePlayerShopItem> all = new ArrayList<>();
public List<PlayerShopItem> sendAvailableBundles(int itemid) {
List<PlayerShopItem> list = new LinkedList<>();
List<PlayerShopItem> all = new ArrayList<>();
synchronized (items) {
all.addAll(items);
}
for (MaplePlayerShopItem mpsi : all) {
for (PlayerShopItem mpsi : all) {
if (mpsi.getItem().getItemId() == itemid && mpsi.getBundles() > 0 && mpsi.isExist()) {
list.add(mpsi);
}

View File

@@ -24,16 +24,15 @@ package server.maps;
import client.inventory.Item;
/**
*
* @author Matze
*/
public class MaplePlayerShopItem {
private Item item;
public class PlayerShopItem {
private final Item item;
private short bundles;
private int price;
private final int price;
private boolean doesExist;
public MaplePlayerShopItem(Item item, short bundles, int price) {
public PlayerShopItem(Item item, short bundles, int price) {
this.item = item;
this.bundles = bundles;
this.price = price;