Rename and clean up MapleShopItem

This commit is contained in:
P0nk
2021-09-09 22:49:02 +02:00
parent 43a80f0491
commit a4d3f17efb
3 changed files with 15 additions and 16 deletions

View File

@@ -46,7 +46,7 @@ public class Shop {
private static final Set<Integer> rechargeableItems = new LinkedHashSet<>(); private static final Set<Integer> rechargeableItems = new LinkedHashSet<>();
private final int id; private final int id;
private final int npcId; private final int npcId;
private final List<MapleShopItem> items; private final List<ShopItem> items;
private final int tokenvalue = 1000000000; private final int tokenvalue = 1000000000;
private final int token = 4000313; private final int token = 4000313;
@@ -69,7 +69,7 @@ public class Shop {
items = new ArrayList<>(); items = new ArrayList<>();
} }
private void addItem(MapleShopItem item) { private void addItem(ShopItem item) {
items.add(item); items.add(item);
} }
@@ -79,7 +79,7 @@ public class Shop {
} }
public void buy(Client c, short slot, int itemId, short quantity) { public void buy(Client c, short slot, int itemId, short quantity) {
MapleShopItem item = findBySlot(slot); ShopItem item = findBySlot(slot);
if (item != null) { if (item != null) {
if (item.getItemId() != itemId) { if (item.getItemId() != itemId) {
System.out.println("Wrong slot number in shop " + id); System.out.println("Wrong slot number in shop " + id);
@@ -232,7 +232,7 @@ public class Shop {
} }
} }
private MapleShopItem findBySlot(short slot) { private ShopItem findBySlot(short slot) {
return items.get(slot); return items.get(slot);
} }
@@ -267,17 +267,17 @@ public class Shop {
List<Integer> recharges = new ArrayList<>(rechargeableItems); List<Integer> recharges = new ArrayList<>(rechargeableItems);
while (rs.next()) { while (rs.next()) {
if (ItemConstants.isRechargeable(rs.getInt("itemid"))) { if (ItemConstants.isRechargeable(rs.getInt("itemid"))) {
MapleShopItem starItem = new MapleShopItem((short) 1, rs.getInt("itemid"), rs.getInt("price"), rs.getInt("pitch")); ShopItem starItem = new ShopItem((short) 1, rs.getInt("itemid"), rs.getInt("price"), rs.getInt("pitch"));
ret.addItem(starItem); ret.addItem(starItem);
if (rechargeableItems.contains(starItem.getItemId())) { if (rechargeableItems.contains(starItem.getItemId())) {
recharges.remove(Integer.valueOf(starItem.getItemId())); recharges.remove(Integer.valueOf(starItem.getItemId()));
} }
} else { } else {
ret.addItem(new MapleShopItem((short) 1000, rs.getInt("itemid"), rs.getInt("price"), rs.getInt("pitch"))); ret.addItem(new ShopItem((short) 1000, rs.getInt("itemid"), rs.getInt("price"), rs.getInt("pitch")));
} }
} }
for (Integer recharge : recharges) { for (Integer recharge : recharges) {
ret.addItem(new MapleShopItem((short) 1000, recharge, 0, 0)); ret.addItem(new ShopItem((short) 1000, recharge, 0, 0));
} }
} }
} }

View File

@@ -22,16 +22,15 @@
package server; package server;
/** /**
*
* @author Matze * @author Matze
*/ */
public class MapleShopItem { public class ShopItem {
private short buyable; private final short buyable;
private int itemId; private final int itemId;
private int price; private final int price;
private int pitch; private final int pitch;
public MapleShopItem(short buyable, int itemId, int price, int pitch) { public ShopItem(short buyable, int itemId, int price, int pitch) {
this.buyable = buyable; this.buyable = buyable;
this.itemId = itemId; this.itemId = itemId;
this.price = price; this.price = price;

View File

@@ -2357,12 +2357,12 @@ public class PacketCreator {
return (int) (Double.doubleToLongBits(d) >> 48); return (int) (Double.doubleToLongBits(d) >> 48);
} }
public static Packet getNPCShop(Client c, int sid, List<MapleShopItem> items) { public static Packet getNPCShop(Client c, int sid, List<ShopItem> items) {
ItemInformationProvider ii = ItemInformationProvider.getInstance(); ItemInformationProvider ii = ItemInformationProvider.getInstance();
final OutPacket p = OutPacket.create(SendOpcode.OPEN_NPC_SHOP); final OutPacket p = OutPacket.create(SendOpcode.OPEN_NPC_SHOP);
p.writeInt(sid); p.writeInt(sid);
p.writeShort(items.size()); // item count p.writeShort(items.size()); // item count
for (MapleShopItem item : items) { for (ShopItem item : items) {
p.writeInt(item.getItemId()); p.writeInt(item.getItemId());
p.writeInt(item.getPrice()); p.writeInt(item.getPrice());
p.writeInt(item.getPrice() == 0 ? item.getPitch() : 0); //Perfect Pitch p.writeInt(item.getPrice() == 0 ? item.getPitch() : 0); //Perfect Pitch