diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/net/eathena/mail2recv.cpp | 42 | ||||
-rw-r--r-- | src/resources/inventory/inventory.cpp | 15 | ||||
-rw-r--r-- | src/resources/inventory/inventory.h | 2 |
3 files changed, 43 insertions, 16 deletions
diff --git a/src/net/eathena/mail2recv.cpp b/src/net/eathena/mail2recv.cpp index d3537a48a..b2e435bee 100644 --- a/src/net/eathena/mail2recv.cpp +++ b/src/net/eathena/mail2recv.cpp @@ -145,24 +145,34 @@ void Mail2Recv::processAddItemResult(Net::MessageIn &msg) delete options; return; } - const int slot = inventory->addItem(itemId, - itemType, - amount, - refine, - ItemColorManager::getColorFromCards(&cards[0]), - fromBool(identify, Identified), - damaged, - Favorite_false, - Equipm_false, - Equipped_false); - if (slot == -1) + + Item *const item = inventory->findItemByTag(index); + if (item == nullptr) { - delete options; - return; + const int slot = inventory->addItem(itemId, + itemType, + amount, + refine, + ItemColorManager::getColorFromCards(&cards[0]), + fromBool(identify, Identified), + damaged, + Favorite_false, + Equipm_false, + Equipped_false); + if (slot == -1) + { + delete options; + return; + } + inventory->setCards(slot, cards, maxCards); + inventory->setOptions(slot, options); + inventory->setTag(slot, index); } - inventory->setCards(slot, cards, maxCards); - inventory->setOptions(slot, options); - inventory->setTag(slot, index); + else + { + item->increaseQuantity(amount); + } + mailEditWindow->updateItems(); delete options; } diff --git a/src/resources/inventory/inventory.cpp b/src/resources/inventory/inventory.cpp index 7363bdd30..d256ea9ac 100644 --- a/src/resources/inventory/inventory.cpp +++ b/src/resources/inventory/inventory.cpp @@ -420,6 +420,21 @@ int Inventory::findIndexByTag(const int tag) const return -1; } +Item *Inventory::findItemByTag(const int tag) const +{ + for (unsigned i = 0; i < mSize; i++) + { + Item *const item = mItems[i]; + if (item != nullptr && + item->mTag == tag) + { + return item; + } + } + + return nullptr; +} + bool Inventory::addVirtualItem(const Item *const item, int index, const int amount) diff --git a/src/resources/inventory/inventory.h b/src/resources/inventory/inventory.h index a7b1e8e73..573a0f5c0 100644 --- a/src/resources/inventory/inventory.h +++ b/src/resources/inventory/inventory.h @@ -189,6 +189,8 @@ class Inventory notfinal int findIndexByTag(const int tag) const; + Item *findItemByTag(const int tag) const; + virtual bool addVirtualItem(const Item *const item, int index, const int amount); |