summaryrefslogtreecommitdiff
path: root/src/inventory.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-10-29 23:56:26 +0300
committerAndrei Karas <akaras@inbox.ru>2015-10-29 23:56:26 +0300
commit598de45a1e77e5f10c69694f607941336163673f (patch)
treeab0082f18939c41c402e90d99fbaa298aa21a3c9 /src/inventory.cpp
parentb0cddefee60e56525fe4da0404f18af71c14acaf (diff)
downloadplus-598de45a1e77e5f10c69694f607941336163673f.tar.gz
plus-598de45a1e77e5f10c69694f607941336163673f.tar.bz2
plus-598de45a1e77e5f10c69694f607941336163673f.tar.xz
plus-598de45a1e77e5f10c69694f607941336163673f.zip
Dont allow add same item twice into npc inventory.
Diffstat (limited to 'src/inventory.cpp')
-rw-r--r--src/inventory.cpp37
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());
+ }
+}