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

@@ -5545,7 +5545,7 @@ public class Character extends AbstractCharacterObject {
mps.setOpen(false);
getWorldServer().unregisterPlayerShop(mps);
for (MaplePlayerShopItem mpsi : mps.getItems()) {
for (PlayerShopItem mpsi : mps.getItems()) {
if (mpsi.getBundles() >= 2) {
Item iItem = mpsi.getItem().copy();
iItem.setQuantity((short) (mpsi.getBundles() * iItem.getQuantity()));

View File

@@ -599,7 +599,7 @@ public final class PlayerInteractionHandler extends AbstractPacketHandler {
sellItem.setQuantity(perBundle);
}
MaplePlayerShopItem shopItem = new MaplePlayerShopItem(sellItem, bundles, price);
PlayerShopItem shopItem = new PlayerShopItem(sellItem, bundles, price);
PlayerShop shop = chr.getPlayerShop();
HiredMerchant merchant = chr.getHiredMerchant();
if (shop != null && shop.isOwner(chr)) {

View File

@@ -396,7 +396,7 @@ public final class UseCashItemHandler extends AbstractPacketHandler {
c.getWorldServer().addOwlItemSearch(itemid);
}
player.setOwlSearch(itemid);
List<Pair<MaplePlayerShopItem, AbstractMapObject>> hmsAvailable = c.getWorldServer().getAvailableItemBundles(itemid);
List<Pair<PlayerShopItem, AbstractMapObject>> hmsAvailable = c.getWorldServer().getAvailableItemBundles(itemid);
if (!hmsAvailable.isEmpty()) {
remove(c, position, itemId);
}

View File

@@ -1813,21 +1813,21 @@ public class World {
}
}
public List<Pair<MaplePlayerShopItem, AbstractMapObject>> getAvailableItemBundles(int itemid) {
List<Pair<MaplePlayerShopItem, AbstractMapObject>> hmsAvailable = new ArrayList<>();
public List<Pair<PlayerShopItem, AbstractMapObject>> getAvailableItemBundles(int itemid) {
List<Pair<PlayerShopItem, AbstractMapObject>> hmsAvailable = new ArrayList<>();
for (HiredMerchant hm : getActiveMerchants()) {
List<MaplePlayerShopItem> itemBundles = hm.sendAvailableBundles(itemid);
List<PlayerShopItem> itemBundles = hm.sendAvailableBundles(itemid);
for(MaplePlayerShopItem mpsi : itemBundles) {
for(PlayerShopItem mpsi : itemBundles) {
hmsAvailable.add(new Pair<>(mpsi, hm));
}
}
for (PlayerShop ps : getActivePlayerShops()) {
List<MaplePlayerShopItem> itemBundles = ps.sendAvailableBundles(itemid);
List<PlayerShopItem> itemBundles = ps.sendAvailableBundles(itemid);
for(MaplePlayerShopItem mpsi : itemBundles) {
for(PlayerShopItem mpsi : itemBundles) {
hmsAvailable.add(new Pair<>(mpsi, ps));
}
}

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;

View File

@@ -3172,7 +3172,7 @@ public class PacketCreator {
final OutPacket p = OutPacket.create(SendOpcode.PLAYER_INTERACTION);
p.writeByte(PlayerInteractionHandler.Action.UPDATE_MERCHANT.getCode());
p.writeByte(shop.getItems().size());
for (MaplePlayerShopItem item : shop.getItems()) {
for (PlayerShopItem item : shop.getItems()) {
p.writeShort(item.getBundles());
p.writeShort(item.getItem().getQuantity());
p.writeInt(item.getPrice());
@@ -3231,10 +3231,10 @@ public class PacketCreator {
p.writeByte(0xFF);
p.writeString(shop.getDescription());
List<MaplePlayerShopItem> items = shop.getItems();
List<PlayerShopItem> items = shop.getItems();
p.writeByte(0x10); //TODO SLOTS, which is 16 for most stores...slotMax
p.writeByte(items.size());
for (MaplePlayerShopItem item : items) {
for (PlayerShopItem item : items) {
p.writeShort(item.getBundles());
p.writeShort(item.getItem().getQuantity());
p.writeInt(item.getPrice());
@@ -5004,7 +5004,7 @@ public class PacketCreator {
return p;
}
public static Packet owlOfMinerva(Client c, int itemId, List<Pair<MaplePlayerShopItem, AbstractMapObject>> hmsAvailable) {
public static Packet owlOfMinerva(Client c, int itemId, List<Pair<PlayerShopItem, AbstractMapObject>> hmsAvailable) {
byte itemType = ItemConstants.getInventoryType(itemId).getType();
OutPacket p = OutPacket.create(SendOpcode.SHOP_SCANNER_RESULT);
@@ -5012,8 +5012,8 @@ public class PacketCreator {
p.writeInt(0);
p.writeInt(itemId);
p.writeInt(hmsAvailable.size());
for (Pair<MaplePlayerShopItem, AbstractMapObject> hme : hmsAvailable) {
MaplePlayerShopItem item = hme.getLeft();
for (Pair<PlayerShopItem, AbstractMapObject> hme : hmsAvailable) {
PlayerShopItem item = hme.getLeft();
AbstractMapObject mo = hme.getRight();
if (mo instanceof PlayerShop ps) {
@@ -5131,7 +5131,7 @@ public class PacketCreator {
if (hm.getItems().isEmpty()) {
p.writeByte(0);//Hmm??
} else {
for (MaplePlayerShopItem item : hm.getItems()) {
for (PlayerShopItem item : hm.getItems()) {
p.writeShort(item.getBundles());
p.writeShort(item.getItem().getQuantity());
p.writeInt(item.getPrice());
@@ -5146,7 +5146,7 @@ public class PacketCreator {
p.writeByte(PlayerInteractionHandler.Action.UPDATE_MERCHANT.getCode());
p.writeInt(hm.isOwner(chr) ? chr.getMerchantMeso() : chr.getMeso());
p.writeByte(hm.getItems().size());
for (MaplePlayerShopItem item : hm.getItems()) {
for (PlayerShopItem item : hm.getItems()) {
p.writeShort(item.getBundles());
p.writeShort(item.getItem().getQuantity());
p.writeInt(item.getPrice());