From 5467ec2cfcc7290c932e72df573662b0c005d571 Mon Sep 17 00:00:00 2001 From: MobiusDevelopment <8391001+MobiusDevelopment@users.noreply.github.com> Date: Sun, 8 Jan 2023 22:00:59 +0000 Subject: [PATCH] WorldExchangeManager improvements. Contributed by Index. --- .../instancemanager/WorldExchangeManager.java | 36 +++++++++++-------- .../instancemanager/WorldExchangeManager.java | 36 +++++++++++-------- .../instancemanager/WorldExchangeManager.java | 36 +++++++++++-------- 3 files changed, 63 insertions(+), 45 deletions(-) diff --git a/L2J_Mobius_10.3_MasterClass/java/org/l2jmobius/gameserver/instancemanager/WorldExchangeManager.java b/L2J_Mobius_10.3_MasterClass/java/org/l2jmobius/gameserver/instancemanager/WorldExchangeManager.java index 0c4d9c33f6..3cc64eeddc 100644 --- a/L2J_Mobius_10.3_MasterClass/java/org/l2jmobius/gameserver/instancemanager/WorldExchangeManager.java +++ b/L2J_Mobius_10.3_MasterClass/java/org/l2jmobius/gameserver/instancemanager/WorldExchangeManager.java @@ -280,6 +280,16 @@ public class WorldExchangeManager implements IXmlReader } } + private long calculateFeeForRegister(Player player, int objectId, long amount, long priceForEach) + { + final Item itemToRemove = player.getInventory().getItemByObjectId(objectId); + if (itemToRemove.getId() == Inventory.ADENA_ID) + { + return priceForEach * 100L; + } + return Math.round(priceForEach * (itemToRemove.getId() == Inventory.ADENA_ID ? 1 : amount) * Config.WORLD_EXCHANGE_ADENA_FEE); + } + /** * Forwarded from client packet "ExWorldExchangeRegisterItem" for check ops and register item if it can in World Exchange system * @param player @@ -301,9 +311,16 @@ public class WorldExchangeManager implements IXmlReader player.sendPacket(WorldExchangeRegisterItem.FAIL); return; } + if (player.getInventory().getItemByObjectId(itemObjectId) == null) + { + player.sendPacket(new SystemMessage(SystemMessageId.THE_ITEM_THAT_YOU_SEARCHED_DOES_NOT_EXIST)); + player.sendPacket(WorldExchangeRegisterItem.FAIL); + return; + } - long totalPrice = priceForEach * amount; - long feePrice = Math.round(totalPrice * Config.WORLD_EXCHANGE_ADENA_FEE); + final Item item = player.getInventory().getItemByObjectId(itemObjectId); + long totalPrice = priceForEach * (item.getId() == Inventory.ADENA_ID ? 1 : amount); + long feePrice = calculateFeeForRegister(player, itemObjectId, amount, priceForEach); if ((Config.WORLD_EXCHANGE_MAX_ADENA_FEE != -1) && (feePrice > Config.WORLD_EXCHANGE_MAX_ADENA_FEE)) { feePrice = Config.WORLD_EXCHANGE_MAX_ADENA_FEE; @@ -315,15 +332,7 @@ public class WorldExchangeManager implements IXmlReader return; } - if (player.getInventory().getItemByObjectId(itemObjectId) == null) - { - player.sendPacket(new SystemMessage(SystemMessageId.THE_ITEM_THAT_YOU_SEARCHED_DOES_NOT_EXIST)); - player.sendPacket(WorldExchangeRegisterItem.FAIL); - return; - } - final long freeId = getNextId(); - final Item item = player.getInventory().getItemByObjectId(itemObjectId); final InventoryUpdate iu = new InventoryUpdate(); if (item.isStackable() && (player.getInventory().getInventoryItemCount(item.getId(), -1) > amount)) { @@ -536,11 +545,8 @@ public class WorldExchangeManager implements IXmlReader } player.sendPacket(new WorldExchangeSettleRecvResult(worldExchangeItem.getItemInstance().getObjectId(), worldExchangeItem.getItemInstance().getCount(), (byte) 1)); - long returnPrice = worldExchangeItem.getPrice() - Math.round(worldExchangeItem.getPrice() * Config.WORLD_EXCHANGE_LCOIN_TAX); - if ((Config.WORLD_EXCHANGE_MAX_LCOIN_TAX != -1) && (returnPrice > Config.WORLD_EXCHANGE_MAX_LCOIN_TAX)) - { - returnPrice = Config.WORLD_EXCHANGE_MAX_LCOIN_TAX; - } + final long fee = Math.round(((worldExchangeItem.getPrice() * Config.WORLD_EXCHANGE_LCOIN_TAX) * 100) / 100); + final long returnPrice = worldExchangeItem.getPrice() - Math.min(fee, (Config.WORLD_EXCHANGE_MAX_LCOIN_TAX != -1 ? Config.WORLD_EXCHANGE_MAX_LCOIN_TAX : Long.MAX_VALUE)); // floating-point accuracy workaround :D player.getInventory().addItem("World Exchange Took Money", Inventory.EINHASAD_COIN_ID, (returnPrice), player, null); worldExchangeItem.setStoreType(WorldExchangeItemStatusType.WORLD_EXCHANGE_NONE); Item item = worldExchangeItem.getItemInstance(); diff --git a/L2J_Mobius_Essence_6.2_Vanguard/java/org/l2jmobius/gameserver/instancemanager/WorldExchangeManager.java b/L2J_Mobius_Essence_6.2_Vanguard/java/org/l2jmobius/gameserver/instancemanager/WorldExchangeManager.java index 6ad11be85d..2df06cf8cc 100644 --- a/L2J_Mobius_Essence_6.2_Vanguard/java/org/l2jmobius/gameserver/instancemanager/WorldExchangeManager.java +++ b/L2J_Mobius_Essence_6.2_Vanguard/java/org/l2jmobius/gameserver/instancemanager/WorldExchangeManager.java @@ -285,6 +285,16 @@ public class WorldExchangeManager implements IXmlReader } } + private long calculateFeeForRegister(Player player, int objectId, long amount, long priceForEach) + { + final Item itemToRemove = player.getInventory().getItemByObjectId(objectId); + if (itemToRemove.getId() == Inventory.ADENA_ID) + { + return priceForEach * 100L; + } + return Math.round(priceForEach * (itemToRemove.getId() == Inventory.ADENA_ID ? 1 : amount) * Config.WORLD_EXCHANGE_ADENA_FEE); + } + /** * Forwarded from client packet "ExWorldExchangeRegisterItem" for check ops and register item if it can in World Exchange system * @param player @@ -306,9 +316,16 @@ public class WorldExchangeManager implements IXmlReader player.sendPacket(WorldExchangeRegisterItem.FAIL); return; } + if (player.getInventory().getItemByObjectId(itemObjectId) == null) + { + player.sendPacket(new SystemMessage(SystemMessageId.THE_ITEM_IS_NOT_FOUND)); + player.sendPacket(WorldExchangeRegisterItem.FAIL); + return; + } - long totalPrice = priceForEach * amount; - long feePrice = Math.round(totalPrice * Config.WORLD_EXCHANGE_ADENA_FEE); + final Item item = player.getInventory().getItemByObjectId(itemObjectId); + long totalPrice = priceForEach * (item.getId() == Inventory.ADENA_ID ? 1 : amount); + long feePrice = calculateFeeForRegister(player, itemObjectId, amount, priceForEach); if ((Config.WORLD_EXCHANGE_MAX_ADENA_FEE != -1) && (feePrice > Config.WORLD_EXCHANGE_MAX_ADENA_FEE)) { feePrice = Config.WORLD_EXCHANGE_MAX_ADENA_FEE; @@ -320,15 +337,7 @@ public class WorldExchangeManager implements IXmlReader return; } - if (player.getInventory().getItemByObjectId(itemObjectId) == null) - { - player.sendPacket(new SystemMessage(SystemMessageId.THE_ITEM_IS_NOT_FOUND)); - player.sendPacket(WorldExchangeRegisterItem.FAIL); - return; - } - final long freeId = getNextId(); - final Item item = player.getInventory().getItemByObjectId(itemObjectId); final InventoryUpdate iu = new InventoryUpdate(); if (item.isStackable() && (player.getInventory().getInventoryItemCount(item.getId(), -1) > amount)) { @@ -541,11 +550,8 @@ public class WorldExchangeManager implements IXmlReader } player.sendPacket(new WorldExchangeSettleRecvResult(worldExchangeItem.getItemInstance().getObjectId(), worldExchangeItem.getItemInstance().getCount(), (byte) 1)); - long returnPrice = worldExchangeItem.getPrice() - Math.round(worldExchangeItem.getPrice() * Config.WORLD_EXCHANGE_LCOIN_TAX); - if ((Config.WORLD_EXCHANGE_MAX_LCOIN_TAX != -1) && (returnPrice > Config.WORLD_EXCHANGE_MAX_LCOIN_TAX)) - { - returnPrice = Config.WORLD_EXCHANGE_MAX_LCOIN_TAX; - } + final long fee = Math.round(((worldExchangeItem.getPrice() * Config.WORLD_EXCHANGE_LCOIN_TAX) * 100) / 100); + final long returnPrice = worldExchangeItem.getPrice() - Math.min(fee, (Config.WORLD_EXCHANGE_MAX_LCOIN_TAX != -1 ? Config.WORLD_EXCHANGE_MAX_LCOIN_TAX : Long.MAX_VALUE)); // floating-point accuracy workaround :D player.getInventory().addItem("World Exchange Took Money", Inventory.LCOIN_ID, (returnPrice), player, null); worldExchangeItem.setStoreType(WorldExchangeItemStatusType.WORLD_EXCHANGE_NONE); Item item = worldExchangeItem.getItemInstance(); diff --git a/L2J_Mobius_Essence_6.3_Crusader/java/org/l2jmobius/gameserver/instancemanager/WorldExchangeManager.java b/L2J_Mobius_Essence_6.3_Crusader/java/org/l2jmobius/gameserver/instancemanager/WorldExchangeManager.java index 5c9c7653a9..1805846753 100644 --- a/L2J_Mobius_Essence_6.3_Crusader/java/org/l2jmobius/gameserver/instancemanager/WorldExchangeManager.java +++ b/L2J_Mobius_Essence_6.3_Crusader/java/org/l2jmobius/gameserver/instancemanager/WorldExchangeManager.java @@ -285,6 +285,16 @@ public class WorldExchangeManager implements IXmlReader } } + private long calculateFeeForRegister(Player player, int objectId, long amount, long priceForEach) + { + final Item itemToRemove = player.getInventory().getItemByObjectId(objectId); + if (itemToRemove.getId() == Inventory.ADENA_ID) + { + return priceForEach * 100L; + } + return Math.round(priceForEach * (itemToRemove.getId() == Inventory.ADENA_ID ? 1 : amount) * Config.WORLD_EXCHANGE_ADENA_FEE); + } + /** * Forwarded from client packet "ExWorldExchangeRegisterItem" for check ops and register item if it can in World Exchange system * @param player @@ -306,9 +316,16 @@ public class WorldExchangeManager implements IXmlReader player.sendPacket(WorldExchangeRegisterItem.FAIL); return; } + if (player.getInventory().getItemByObjectId(itemObjectId) == null) + { + player.sendPacket(new SystemMessage(SystemMessageId.THE_ITEM_IS_NOT_FOUND)); + player.sendPacket(WorldExchangeRegisterItem.FAIL); + return; + } - long totalPrice = priceForEach * amount; - long feePrice = Math.round(totalPrice * Config.WORLD_EXCHANGE_ADENA_FEE); + final Item item = player.getInventory().getItemByObjectId(itemObjectId); + long totalPrice = priceForEach * (item.getId() == Inventory.ADENA_ID ? 1 : amount); + long feePrice = calculateFeeForRegister(player, itemObjectId, amount, priceForEach); if ((Config.WORLD_EXCHANGE_MAX_ADENA_FEE != -1) && (feePrice > Config.WORLD_EXCHANGE_MAX_ADENA_FEE)) { feePrice = Config.WORLD_EXCHANGE_MAX_ADENA_FEE; @@ -320,15 +337,7 @@ public class WorldExchangeManager implements IXmlReader return; } - if (player.getInventory().getItemByObjectId(itemObjectId) == null) - { - player.sendPacket(new SystemMessage(SystemMessageId.THE_ITEM_IS_NOT_FOUND)); - player.sendPacket(WorldExchangeRegisterItem.FAIL); - return; - } - final long freeId = getNextId(); - final Item item = player.getInventory().getItemByObjectId(itemObjectId); final InventoryUpdate iu = new InventoryUpdate(); if (item.isStackable() && (player.getInventory().getInventoryItemCount(item.getId(), -1) > amount)) { @@ -541,11 +550,8 @@ public class WorldExchangeManager implements IXmlReader } player.sendPacket(new WorldExchangeSettleRecvResult(worldExchangeItem.getItemInstance().getObjectId(), worldExchangeItem.getItemInstance().getCount(), (byte) 1)); - long returnPrice = worldExchangeItem.getPrice() - Math.round(worldExchangeItem.getPrice() * Config.WORLD_EXCHANGE_LCOIN_TAX); - if ((Config.WORLD_EXCHANGE_MAX_LCOIN_TAX != -1) && (returnPrice > Config.WORLD_EXCHANGE_MAX_LCOIN_TAX)) - { - returnPrice = Config.WORLD_EXCHANGE_MAX_LCOIN_TAX; - } + final long fee = Math.round(((worldExchangeItem.getPrice() * Config.WORLD_EXCHANGE_LCOIN_TAX) * 100) / 100); + final long returnPrice = worldExchangeItem.getPrice() - Math.min(fee, (Config.WORLD_EXCHANGE_MAX_LCOIN_TAX != -1 ? Config.WORLD_EXCHANGE_MAX_LCOIN_TAX : Long.MAX_VALUE)); // floating-point accuracy workaround :D player.getInventory().addItem("World Exchange Took Money", Inventory.LCOIN_ID, (returnPrice), player, null); worldExchangeItem.setStoreType(WorldExchangeItemStatusType.WORLD_EXCHANGE_NONE); Item item = worldExchangeItem.getItemInstance();