Skip to content

Commit c08cc05

Browse files
authoredJun 25, 2017
Inventory: Fix wrong stack size behaviour and item loss (#6039)
Also fix itemFits and remove constness-nonsense
1 parent cad10ce commit c08cc05

File tree

4 files changed

+8
-13
lines changed

4 files changed

+8
-13
lines changed
 

‎src/database-postgresql.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ bool PlayerDatabasePostgreSQL::loadPlayer(RemotePlayer *player, PlayerSAO *sao)
584584
if (itemStr.length() > 0) {
585585
ItemStack stack;
586586
stack.deSerialize(itemStr);
587-
invList->addItem(pg_to_uint(results2, row2, 0), stack);
587+
invList->changeItem(pg_to_uint(results2, row2, 0), stack);
588588
}
589589
}
590590
PQclear(results2);

‎src/database-sqlite3.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ bool PlayerDatabaseSQLite3::loadPlayer(RemotePlayer *player, PlayerSAO *sao)
565565
if (itemStr.length() > 0) {
566566
ItemStack stack;
567567
stack.deSerialize(itemStr);
568-
invList->addItem(sqlite_to_uint(m_stmt_player_load_inventory_items, 0), stack);
568+
invList->changeItem(sqlite_to_uint(m_stmt_player_load_inventory_items, 0), stack);
569569
}
570570
}
571571
sqlite3_reset(m_stmt_player_load_inventory_items);

‎src/inventory.cpp

+4-8
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,8 @@ std::string ItemStack::getItemString() const
254254
}
255255

256256

257-
ItemStack ItemStack::addItem(const ItemStack &newitem_,
258-
IItemDefManager *itemdef)
257+
ItemStack ItemStack::addItem(ItemStack newitem, IItemDefManager *itemdef)
259258
{
260-
ItemStack newitem = newitem_;
261-
262259
// If the item is empty or the position invalid, bail out
263260
if(newitem.empty())
264261
{
@@ -267,7 +264,7 @@ ItemStack ItemStack::addItem(const ItemStack &newitem_,
267264
// If this is an empty item, it's an easy job.
268265
else if(empty())
269266
{
270-
const u16 stackMax = getStackMax(itemdef);
267+
const u16 stackMax = newitem.getStackMax(itemdef);
271268

272269
*this = newitem;
273270

@@ -303,11 +300,10 @@ ItemStack ItemStack::addItem(const ItemStack &newitem_,
303300
return newitem;
304301
}
305302

306-
bool ItemStack::itemFits(const ItemStack &newitem_,
303+
bool ItemStack::itemFits(ItemStack newitem,
307304
ItemStack *restitem,
308305
IItemDefManager *itemdef) const
309306
{
310-
ItemStack newitem = newitem_;
311307

312308
// If the item is empty or the position invalid, bail out
313309
if(newitem.empty())
@@ -317,7 +313,7 @@ bool ItemStack::itemFits(const ItemStack &newitem_,
317313
// If this is an empty item, it's an easy job.
318314
else if(empty())
319315
{
320-
const u16 stackMax = getStackMax(itemdef);
316+
const u16 stackMax = newitem.getStackMax(itemdef);
321317

322318
// If the item fits fully, delete it
323319
if (newitem.count <= stackMax) {

‎src/inventory.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,12 @@ struct ItemStack
143143
// If cannot be added at all, returns the item back.
144144
// If can be added partly, decremented item is returned back.
145145
// If can be added fully, empty item is returned.
146-
ItemStack addItem(const ItemStack &newitem,
147-
IItemDefManager *itemdef);
146+
ItemStack addItem(ItemStack newitem, IItemDefManager *itemdef);
148147

149148
// Checks whether newitem could be added.
150149
// If restitem is non-NULL, it receives the part of newitem that
151150
// would be left over after adding.
152-
bool itemFits(const ItemStack &newitem,
151+
bool itemFits(ItemStack newitem,
153152
ItemStack *restitem, // may be NULL
154153
IItemDefManager *itemdef) const;
155154

0 commit comments

Comments
 (0)
Please sign in to comment.