diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-02-15 23:51:34 +0100 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-02-15 23:51:34 +0100 |
commit | f8ad53ea03253d3c792a7c0df9384d63aee12e85 (patch) | |
tree | 7feb8b83072ae97d6c704bcda981c23048472087 /src/game-server | |
parent | 35fa5a5a6621f50b7b45dcc83d5e4d6cf93597ad (diff) | |
download | manaserv-f8ad53ea03253d3c792a7c0df9384d63aee12e85.tar.gz manaserv-f8ad53ea03253d3c792a7c0df9384d63aee12e85.tar.bz2 manaserv-f8ad53ea03253d3c792a7c0df9384d63aee12e85.tar.xz manaserv-f8ad53ea03253d3c792a7c0df9384d63aee12e85.zip |
Fixed registering the players items to the buysell handler.
Now buy/sell lua functions can access the player inventory
again.
This is not using the delayed mode, so it won't be a problem.
Reviewed-by: Freeyorp.
Diffstat (limited to 'src/game-server')
-rw-r--r-- | src/game-server/buysell.cpp | 70 |
1 files changed, 46 insertions, 24 deletions
diff --git a/src/game-server/buysell.cpp b/src/game-server/buysell.cpp index b3abb3e2..c0a16bf7 100644 --- a/src/game-server/buysell.cpp +++ b/src/game-server/buysell.cpp @@ -66,38 +66,60 @@ bool BuySell::registerItem(int id, int amount, int cost) int BuySell::registerPlayerItems() { - return 0; // FIXME: STUB - /* - * Replaced with a no-op stub after the equipment slots become softcoded. - * I think this function is meant to fill the sell dialog with player - * items, but it's iterating through the inventory. - * The no-op here is to stop compilation errors while I work on other - * areas. FIXME - */ - /* + if (!mSell) + return 0; + int nbItemsToSell = 0; - if (mSell) + + // We parse the player inventory and add all item + // in a sell list. + const Possessions &charPoss = mChar->getPossessions(); + for (InventoryData::const_iterator it = charPoss.inventory.begin(), + it_end = charPoss.inventory.end(); it != it_end; ++it) { - for (int i = 0; i < EQUIPMENT_SLOTS; ++i) + unsigned int nb = it->second.amount; + if (!nb) + continue; + + int id = it->second.itemId; + int cost = -1; + if (itemManager->getItem(id)) + { + cost = itemManager->getItem(id)->getCost(); + } + else { - int id = Inventory(mChar).getItem(i); - int nb = Inventory(mChar).count(id); - if (nb > 0) + LOG_WARN("registerPlayersItems(): The character Id: " + << mChar->getPublicID() << " has unknown items (Id: " << id + << "). They have been ignored."); + continue; + } + + if (cost < 1) + continue; + + // We check if the item Id has been already + // added. If so, we cumulate the amounts. + bool itemAlreadyAdded = false; + for (TradedItems::iterator i = mItems.begin(), + i_end = mItems.end(); i != i_end; ++i) + { + if (i->itemId == id) { - int cost = -1; - if (ItemManager::getItem(id)) - cost = ItemManager::getItem(id)->getCost(); - if (cost > 0) - { - TradedItem it = { id, nb, cost }; - mItems.push_back(it); - nbItemsToSell++; - } + itemAlreadyAdded = true; + i->amount += nb; + break; } } + + if (!itemAlreadyAdded) + { + TradedItem itTrade = { id, nb, cost }; + mItems.push_back(itTrade); + nbItemsToSell++; + } } return nbItemsToSell; - */ } bool BuySell::start(Actor *actor) |