diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-10-29 23:56:26 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-10-29 23:56:26 +0300 |
commit | 598de45a1e77e5f10c69694f607941336163673f (patch) | |
tree | ab0082f18939c41c402e90d99fbaa298aa21a3c9 /src/inventory.cpp | |
parent | b0cddefee60e56525fe4da0404f18af71c14acaf (diff) | |
download | manaverse-598de45a1e77e5f10c69694f607941336163673f.tar.gz manaverse-598de45a1e77e5f10c69694f607941336163673f.tar.bz2 manaverse-598de45a1e77e5f10c69694f607941336163673f.tar.xz manaverse-598de45a1e77e5f10c69694f607941336163673f.zip |
Dont allow add same item twice into npc inventory.
Diffstat (limited to 'src/inventory.cpp')
-rw-r--r-- | src/inventory.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/inventory.cpp b/src/inventory.cpp index c83ea5353..eecaacd6c 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -25,6 +25,8 @@ #include "item.h" #include "logger.h" +#include "being/playerinfo.h" + #include "net/inventoryhandler.h" #include "resources/iteminfo.h" @@ -347,3 +349,38 @@ void Inventory::resize(const unsigned int newSize) mItems = new Item*[static_cast<size_t>(mSize)]; std::fill_n(mItems, mSize, static_cast<Item*>(nullptr)); } + +int Inventory::findIndexByTag(const int tag) const +{ + for (unsigned i = 0; i < mSize; i++) + { + const Item *const item = mItems[i]; + if (item && item->mTag == tag) + return i; + } + + return -1; +} + +void Inventory::addVirtualItem(const Item *const item) +{ + if (item && !PlayerInfo::isItemProtected(item->getId())) + { + if (findIndexByTag(item->getInvIndex()) != -1) + return; + + const int index = addItem(item->getId(), + item->getType(), + 1, + 1, + item->getColor(), + item->getIdentified(), + item->getDamaged(), + item->getFavorite(), + Equipm_false, + Equipped_false); + Item *const item2 = getItem(index); + if (item2) + item2->setTag(item->getInvIndex()); + } +} |