Skip to content

Commit

Permalink
Fixed stuff related to shop trading (#202)
Browse files Browse the repository at this point in the history
> Refactored stuff to facilitate resolving an issue regarding sellnig item to a full shop
> Removed double value message in shop
  • Loading branch information
Gptaqbc authored and dginovker committed Nov 19, 2019
1 parent 820c6fa commit c0c6b40
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
2 changes: 2 additions & 0 deletions 2006Redone Server/src/redone/game/players/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ public Food getFood() {
return food;
}

public int TotalShopItems;

public void startCurrentTask(int ticksBetweenExecution, CycleEvent event) {
endCurrentTask();
currentTask = CycleEventHandler.getSingleton().addEvent(this, event, ticksBetweenExecution);
Expand Down
35 changes: 23 additions & 12 deletions 2006Redone Server/src/redone/game/shops/ShopAssistant.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,34 @@ public void updateshop(int i) {

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]);
}
Expand All @@ -98,7 +105,7 @@ public void resetShop(int ShopID) {
ShopHandler.ShopItems[ShopID][i]);
TotalCount++;
}
if (TotalCount > TotalItems) {
if (TotalCount > player.TotalShopItems) {
break;
}
}
Expand Down Expand Up @@ -328,11 +335,11 @@ public void sellToShopPrice(int removeId, int removeSlot) {
} 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) {
Expand All @@ -348,6 +355,10 @@ public boolean sellItem(int itemID, int fromSlot, int amount) {
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) {
Expand Down

0 comments on commit c0c6b40

Please sign in to comment.