Rename and clean up MapleShop

This commit is contained in:
P0nk
2021-09-09 22:47:39 +02:00
parent e31894caae
commit 104444e83b
5 changed files with 42 additions and 42 deletions

View File

@@ -164,7 +164,7 @@ public class Character extends AbstractCharacterObject {
private Party party; private Party party;
private final Pet[] pets = new Pet[3]; private final Pet[] pets = new Pet[3];
private PlayerShop playerShop = null; private PlayerShop playerShop = null;
private MapleShop shop = null; private Shop shop = null;
private SkinColor skinColor = SkinColor.NORMAL; private SkinColor skinColor = SkinColor.NORMAL;
private MapleStorage storage = null; private MapleStorage storage = null;
private MapleTrade trade = null; private MapleTrade trade = null;
@@ -5792,7 +5792,7 @@ public class Character extends AbstractCharacterObject {
return search; return search;
} }
public MapleShop getShop() { public Shop getShop() {
return shop; return shop;
} }
@@ -9566,7 +9566,7 @@ public class Character extends AbstractCharacterObject {
InventoryManipulator.removeFromSlot(c, type, (byte) slot, quantity, false); InventoryManipulator.removeFromSlot(c, type, (byte) slot, quantity, false);
} }
public void setShop(MapleShop shop) { public void setShop(Shop shop) {
this.shop = shop; this.shop = shop;
} }

View File

@@ -38,8 +38,8 @@ import net.AbstractPacketHandler;
import net.packet.InPacket; import net.packet.InPacket;
import net.server.Server; import net.server.Server;
import server.ItemInformationProvider; import server.ItemInformationProvider;
import server.MapleShop;
import server.MapleShopFactory; import server.MapleShopFactory;
import server.Shop;
import server.TimerManager; import server.TimerManager;
import server.maps.*; import server.maps.*;
import tools.PacketCreator; import tools.PacketCreator;
@@ -494,7 +494,7 @@ public final class UseCashItemHandler extends AbstractPacketHandler {
} }
} else if (itemType == 545) { // MiuMiu's travel store } else if (itemType == 545) { // MiuMiu's travel store
if (player.getShop() == null) { if (player.getShop() == null) {
MapleShop shop = MapleShopFactory.getInstance().getShop(1338); Shop shop = MapleShopFactory.getInstance().getShop(1338);
if (shop != null) { if (shop != null) {
shop.sendShop(c); shop.sendShop(c);
remove(c, position, itemId); remove(c, position, itemId);

View File

@@ -373,7 +373,7 @@ public class NPCConversationManager extends AbstractPlayerInteraction {
} }
public void openShopNPC(int id) { public void openShopNPC(int id) {
MapleShop shop = MapleShopFactory.getInstance().getShop(id); Shop shop = MapleShopFactory.getInstance().getShop(id);
if (shop != null) { if (shop != null) {
shop.sendShop(c); shop.sendShop(c);

View File

@@ -36,11 +36,11 @@ public class MapleShopFactory {
return instance; return instance;
} }
private Map<Integer, MapleShop> shops = new HashMap<>(); private Map<Integer, Shop> shops = new HashMap<>();
private Map<Integer, MapleShop> npcShops = new HashMap<>(); private Map<Integer, Shop> npcShops = new HashMap<>();
private MapleShop loadShop(int id, boolean isShopId) { private Shop loadShop(int id, boolean isShopId) {
MapleShop ret = MapleShop.createFromDB(id, isShopId); Shop ret = Shop.createFromDB(id, isShopId);
if (ret != null) { if (ret != null) {
shops.put(ret.getId(), ret); shops.put(ret.getId(), ret);
npcShops.put(ret.getNpcId(), ret); npcShops.put(ret.getNpcId(), ret);
@@ -52,14 +52,14 @@ public class MapleShopFactory {
return ret; return ret;
} }
public MapleShop getShop(int shopId) { public Shop getShop(int shopId) {
if (shops.containsKey(shopId)) { if (shops.containsKey(shopId)) {
return shops.get(shopId); return shops.get(shopId);
} }
return loadShop(shopId, true); return loadShop(shopId, true);
} }
public MapleShop getShopForNPC(int npcId) { public Shop getShopForNPC(int npcId) {
if (npcShops.containsKey(npcId)) { if (npcShops.containsKey(npcId)) {
return npcShops.get(npcId); return npcShops.get(npcId);
} }

View File

@@ -40,16 +40,15 @@ import java.util.List;
import java.util.Set; import java.util.Set;
/** /**
*
* @author Matze * @author Matze
*/ */
public class MapleShop { public class Shop {
private static final Set<Integer> rechargeableItems = new LinkedHashSet<>(); private static final Set<Integer> rechargeableItems = new LinkedHashSet<>();
private int id; private final int id;
private int npcId; private final int npcId;
private List<MapleShopItem> items; private final List<MapleShopItem> items;
private int tokenvalue = 1000000000; private final int tokenvalue = 1000000000;
private int token = 4000313; private final int token = 4000313;
static { static {
for (int i = 2070000; i < 2070017; i++) { for (int i = 2070000; i < 2070017; i++) {
@@ -64,7 +63,7 @@ public class MapleShop {
} }
} }
private MapleShop(int id, int npcId) { private Shop(int id, int npcId) {
this.id = id; this.id = id;
this.npcId = npcId; this.npcId = npcId;
items = new ArrayList<>(); items = new ArrayList<>();
@@ -91,7 +90,7 @@ public class MapleShop {
} }
ItemInformationProvider ii = ItemInformationProvider.getInstance(); ItemInformationProvider ii = ItemInformationProvider.getInstance();
if (item.getPrice() > 0) { if (item.getPrice() > 0) {
int amount = (int)Math.min((float) item.getPrice() * quantity, Integer.MAX_VALUE); int amount = (int) Math.min((float) item.getPrice() * quantity, Integer.MAX_VALUE);
if (c.getPlayer().getMeso() >= amount) { if (c.getPlayer().getMeso() >= amount) {
if (InventoryManipulator.checkSpace(c, itemId, quantity, "")) { if (InventoryManipulator.checkSpace(c, itemId, quantity, "")) {
if (!ItemConstants.isRechargeable(itemId)) { //Pets can't be bought from shops if (!ItemConstants.isRechargeable(itemId)) { //Pets can't be bought from shops
@@ -104,14 +103,16 @@ public class MapleShop {
c.getPlayer().gainMeso(-item.getPrice(), false); c.getPlayer().gainMeso(-item.getPrice(), false);
} }
c.sendPacket(PacketCreator.shopTransaction((byte) 0)); c.sendPacket(PacketCreator.shopTransaction((byte) 0));
} else } else {
c.sendPacket(PacketCreator.shopTransaction((byte) 3)); c.sendPacket(PacketCreator.shopTransaction((byte) 3));
}
} else } else {
c.sendPacket(PacketCreator.shopTransaction((byte) 2)); c.sendPacket(PacketCreator.shopTransaction((byte) 2));
}
} else if (item.getPitch() > 0) { } else if (item.getPitch() > 0) {
int amount = (int)Math.min((float) item.getPitch() * quantity, Integer.MAX_VALUE); int amount = (int) Math.min((float) item.getPitch() * quantity, Integer.MAX_VALUE);
if (c.getPlayer().getInventory(InventoryType.ETC).countById(4310000) >= amount) { if (c.getPlayer().getInventory(InventoryType.ETC).countById(4310000) >= amount) {
if (InventoryManipulator.checkSpace(c, itemId, quantity, "")) { if (InventoryManipulator.checkSpace(c, itemId, quantity, "")) {
@@ -125,9 +126,10 @@ public class MapleShop {
InventoryManipulator.removeById(c, InventoryType.ETC, 4310000, amount, false, false); InventoryManipulator.removeById(c, InventoryType.ETC, 4310000, amount, false, false);
} }
c.sendPacket(PacketCreator.shopTransaction((byte) 0)); c.sendPacket(PacketCreator.shopTransaction((byte) 0));
} else } else {
c.sendPacket(PacketCreator.shopTransaction((byte) 3)); c.sendPacket(PacketCreator.shopTransaction((byte) 3));
} }
}
} else if (c.getPlayer().getInventory(InventoryType.CASH).countById(token) != 0) { } else if (c.getPlayer().getInventory(InventoryType.CASH).countById(token) != 0) {
int amount = c.getPlayer().getInventory(InventoryType.CASH).countById(token); int amount = c.getPlayer().getInventory(InventoryType.CASH).countById(token);
@@ -162,14 +164,12 @@ public class MapleShop {
short iQuant = item.getQuantity(); short iQuant = item.getQuantity();
if (iQuant == 0xFFFF) { if (iQuant == 0xFFFF) {
iQuant = 1; iQuant = 1;
} else if(iQuant < 0) { } else if (iQuant < 0) {
return false; return false;
} }
if (!ItemConstants.isRechargeable(item.getItemId())) { if (!ItemConstants.isRechargeable(item.getItemId())) {
if (iQuant == 0 || quantity > iQuant) { return iQuant != 0 && quantity <= iQuant;
return false;
}
} }
return true; return true;
@@ -194,7 +194,7 @@ public class MapleShop {
} }
Item item = c.getPlayer().getInventory(type).getItem(slot); Item item = c.getPlayer().getInventory(type).getItem(slot);
if(canSell(item, quantity)) { if (canSell(item, quantity)) {
quantity = getSellingQuantity(item, quantity); quantity = getSellingQuantity(item, quantity);
InventoryManipulator.removeFromSlot(c, type, (byte) slot, quantity, false); InventoryManipulator.removeFromSlot(c, type, (byte) slot, quantity, false);
@@ -236,8 +236,8 @@ public class MapleShop {
return items.get(slot); return items.get(slot);
} }
public static MapleShop createFromDB(int id, boolean isShopId) { public static Shop createFromDB(int id, boolean isShopId) {
MapleShop ret = null; Shop ret = null;
int shopId; int shopId;
try (Connection con = DatabaseConnection.getConnection()) { try (Connection con = DatabaseConnection.getConnection()) {
final String query; final String query;
@@ -253,7 +253,7 @@ public class MapleShop {
try (ResultSet rs = ps.executeQuery()) { try (ResultSet rs = ps.executeQuery()) {
if (rs.next()) { if (rs.next()) {
shopId = rs.getInt("shopid"); shopId = rs.getInt("shopid");
ret = new MapleShop(shopId, rs.getInt("npcid")); ret = new Shop(shopId, rs.getInt("npcid"));
} else { } else {
return null; return null;
} }