From c0c6b40387885ec9debec60726da34609645d615 Mon Sep 17 00:00:00 2001 From: Gptaqbc <56596815+Gptaqbc@users.noreply.github.com> Date: Tue, 19 Nov 2019 13:11:16 -0500 Subject: [PATCH] Fixed stuff related to shop trading (#202) > Refactored stuff to facilitate resolving an issue regarding sellnig item to a full shop > Removed double value message in shop --- .../src/redone/game/players/Client.java | 2 ++ .../src/redone/game/shops/ShopAssistant.java | 35 ++++++++++++------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/2006Redone Server/src/redone/game/players/Client.java b/2006Redone Server/src/redone/game/players/Client.java index 8cb12cad..4fc05104 100644 --- a/2006Redone Server/src/redone/game/players/Client.java +++ b/2006Redone Server/src/redone/game/players/Client.java @@ -391,6 +391,8 @@ public class Client extends Player { return food; } + public int TotalShopItems; + public void startCurrentTask(int ticksBetweenExecution, CycleEvent event) { endCurrentTask(); currentTask = CycleEventHandler.getSingleton().addEvent(this, event, ticksBetweenExecution); diff --git a/2006Redone Server/src/redone/game/shops/ShopAssistant.java b/2006Redone Server/src/redone/game/shops/ShopAssistant.java index 3434eac2..e46a6b10 100644 --- a/2006Redone Server/src/redone/game/shops/ShopAssistant.java +++ b/2006Redone Server/src/redone/game/shops/ShopAssistant.java @@ -66,27 +66,34 @@ public class ShopAssistant { public void resetShop(int ShopID) { synchronized (player) { - int TotalItems = 0; - for (int i = 0; i < ShopHandler.MaxShopItems; i++) { //adds items in store when items are sold until max value. - if (ShopHandler.ShopItems[ShopID][i] > 0) { - TotalItems++; + player.TotalShopItems = 0; + for (int i = 0; i < ShopHandler.MaxShopItems; i++) + { //adds items in store when items are sold until max value. + if (ShopHandler.ShopItems[ShopID][i] > 0) + { + player.TotalShopItems++; } } - if (TotalItems > ShopHandler.MaxShopItems) { - TotalItems = ShopHandler.MaxShopItems; //sets the stack of item sold to max value if the resulting amount is higher than max value. + if (player.TotalShopItems > 40){ + player.TotalShopItems = 40; //sets the number of stack of item sold to max possible value if the resulting amount is higher than max value. + //Items sold when shops are full will dissapears. Much more code would be needed if we want to restrict selling while still permitting selling items already in shops and such. } player.getOutStream().createFrameVarSizeWord(53); player.getOutStream().writeWord(3900); - player.getOutStream().writeWord(TotalItems); + player.getOutStream().writeWord(player.TotalShopItems); int TotalCount = 0; - for (int i = 0; i < ShopHandler.ShopItems.length; i++) { + for (int i = 0; i < ShopHandler.ShopItems.length; i++) + { if (ShopHandler.ShopItems[ShopID][i] > 0 - || i <= ShopHandler.ShopItemsStandard[ShopID]) { + || i <= ShopHandler.ShopItemsStandard[ShopID]) + { if (ShopHandler.ShopItemsN[ShopID][i] > 254) { player.getOutStream().writeByte(255); player.getOutStream().writeDWord_v2( ShopHandler.ShopItemsN[ShopID][i]); - } else { + } + else + { player.getOutStream().writeByte( ShopHandler.ShopItemsN[ShopID][i]); } @@ -98,7 +105,7 @@ public class ShopAssistant { ShopHandler.ShopItems[ShopID][i]); TotalCount++; } - if (TotalCount > TotalItems) { + if (TotalCount > player.TotalShopItems) { break; } } @@ -328,11 +335,11 @@ public class ShopAssistant { } else if (player.myShopId == CASTLE_SHOP) { player.getActionSender().sendMessage(ItemAssistant.getItemName(removeId) + ": shop will buy for " + getCastleItemValue(removeId) + " castle war tickets." + ShopAdd); } - player.getActionSender().sendMessage(ItemAssistant.getItemName(removeId) + ": shop will buy for " + ShopValue + " coins." + ShopAdd); } } public boolean sellItem(int itemID, int fromSlot, int amount) { + player.getItemAssistant(); for (int i : Constants.ITEM_SELLABLE) { if (i == itemID) { @@ -348,6 +355,10 @@ public class ShopAssistant { if(!player.isShopping) { return false; } + if (player.TotalShopItems >= 39) + { + player.getActionSender().sendMessage("If you sell more individuals items in this shop, they won't be displayed."); + } if (amount > 0 && itemID == (player.playerItems[fromSlot] - 1)) { if (ShopHandler.ShopSModifier[player.myShopId] > 1) {