Skip to content

Commit

Permalink
[Fix] market issue related to stash items and gold duplication (#359)
Browse files Browse the repository at this point in the history
There is an issue on the market that was making the item remove count 0 when accepting buy offer.

Issue reported by @Sparkz023
  • Loading branch information
marcosvf132 authored Apr 29, 2022
1 parent 03e8e09 commit 7082aff
Showing 1 changed file with 34 additions and 26 deletions.
60 changes: 34 additions & 26 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7783,37 +7783,45 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16
account.RegisterCoinsTransaction(account::COIN_REMOVE, amount,
"Sold on Market");
} else {
uint16_t stashminus = player->getStashItemCount(it.wareId);
amount = (amount - (amount > stashminus ? stashminus : amount));
std::forward_list<Item*> itemList = getMarketItemList(it.wareId, amount, depotLocker);
if (itemList.empty() && amount > 0) {
return;
}

if (stashminus > 0) {
player->withdrawItem(it.wareId, (amount > stashminus ? stashminus : amount));
uint16_t removeAmount = amount;
uint16_t stashCount = player->getStashItemCount(it.wareId);
if (stashCount > 0) {
if (removeAmount > stashCount && player->withdrawItem(it.wareId, stashCount)) {
removeAmount -= stashCount;
} else if (player->withdrawItem(it.wareId, removeAmount)) {
removeAmount = 0;
} else {
return;
}
}

if (it.stackable) {
uint16_t tmpAmount = amount;
for (Item* item : itemList) {
if (!item) {
continue;
}
uint16_t removeCount = std::min<uint16_t>(tmpAmount, item->getItemCount());
tmpAmount -= removeCount;
internalRemoveItem(item, removeCount);
if (removeAmount > 0) {
std::forward_list<Item*> itemList = getMarketItemList(it.wareId, removeAmount, depotLocker);
if (itemList.empty() && removeAmount > 0) {
return;
}

if (it.stackable) {
uint16_t tmpAmount = removeAmount;
for (Item* item : itemList) {
if (!item) {
continue;
}
uint16_t removeCount = std::min<uint16_t>(tmpAmount, item->getItemCount());
tmpAmount -= removeCount;
internalRemoveItem(item, removeCount);

if (tmpAmount == 0) {
break;
if (tmpAmount == 0) {
break;
}
}
}
} else {
for (Item* item : itemList) {
if (!item) {
continue;
} else {
for (Item* item : itemList) {
if (!item) {
continue;
}
internalRemoveItem(item);
}
internalRemoveItem(item);
}
}
}
Expand Down

0 comments on commit 7082aff

Please sign in to comment.