summaryrefslogtreecommitdiff
path: root/src/resources/inventory/complexinventory.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-01-08 20:27:29 +0300
committerAndrei Karas <akaras@inbox.ru>2016-01-08 20:27:29 +0300
commit5d0b4c09a67f279847337aa06bc3066c07f63114 (patch)
treeb2f8bbdb3252222c9bc50efa04a5689faa3b1760 /src/resources/inventory/complexinventory.cpp
parent4b014aa3f403ae02587f6a3d89180f75161d4b78 (diff)
downloadmanaplus-5d0b4c09a67f279847337aa06bc3066c07f63114.tar.gz
manaplus-5d0b4c09a67f279847337aa06bc3066c07f63114.tar.bz2
manaplus-5d0b4c09a67f279847337aa06bc3066c07f63114.tar.xz
manaplus-5d0b4c09a67f279847337aa06bc3066c07f63114.zip
Impliment craft inventory for moving items one by one.
Diffstat (limited to 'src/resources/inventory/complexinventory.cpp')
-rw-r--r--src/resources/inventory/complexinventory.cpp132
1 files changed, 132 insertions, 0 deletions
diff --git a/src/resources/inventory/complexinventory.cpp b/src/resources/inventory/complexinventory.cpp
index 15d40f499..06a8cf5c0 100644
--- a/src/resources/inventory/complexinventory.cpp
+++ b/src/resources/inventory/complexinventory.cpp
@@ -22,6 +22,12 @@
#include "resources/inventory/complexinventory.h"
+#include "logger.h"
+
+#include "being/playerinfo.h"
+
+#include "resources/item/complexitem.h"
+
#include "debug.h"
ComplexInventory::ComplexInventory(const InventoryTypeT type,
@@ -33,3 +39,129 @@ ComplexInventory::ComplexInventory(const InventoryTypeT type,
ComplexInventory::~ComplexInventory()
{
}
+
+bool ComplexInventory::addVirtualItem(const Item *const item,
+ int index,
+ const int amount)
+{
+ if (!item || PlayerInfo::isItemProtected(item->getId()))
+ return false;
+
+ if (index >= 0 && index < static_cast<int>(mSize))
+ {
+ ComplexItem *citem = nullptr;
+ if (mItems[index] != nullptr)
+ {
+ Item *const item2 = mItems[index];
+ if (item->getId() != item2->getId() ||
+ item->getColor() != item2->getColor())
+ { // not same id or color
+ return false;
+ }
+ citem = dynamic_cast<ComplexItem*>(mItems[index]);
+ if (!citem)
+ { // if in inventory not complex item, converting it to complex
+ citem = new ComplexItem(item2->getId(),
+ item2->getType(),
+ item2->getQuantity(),
+ item2->getRefine(),
+ item2->getColor(),
+ item2->getIdentified(),
+ item2->getDamaged(),
+ item2->getFavorite(),
+ Equipm_false,
+ Equipped_false);
+ citem->setTag(item2->getTag());
+ delete mItems[index];
+ mItems[index] = citem;
+ }
+ }
+ else
+ {
+ citem = new ComplexItem(item->getId(),
+ item->getType(),
+ 0,
+ item->getRefine(),
+ item->getColor(),
+ item->getIdentified(),
+ item->getDamaged(),
+ item->getFavorite(),
+ Equipm_false,
+ Equipped_false);
+ mItems[index] = citem;
+ }
+ citem->addChild(item, amount);
+ }
+ else
+ {
+ index = addItem(item->getId(),
+ item->getType(),
+ 1,
+ 1,
+ item->getColor(),
+ item->getIdentified(),
+ item->getDamaged(),
+ item->getFavorite(),
+ Equipm_false,
+ Equipped_false);
+ }
+ if (index == -1)
+ return false;
+
+ Item *const item2 = getItem(index);
+ if (item2)
+ item2->setTag(item->getInvIndex());
+ return true;
+}
+
+void ComplexInventory::setItem(const int index,
+ const int id,
+ const int type,
+ const int quantity,
+ const uint8_t refine,
+ const ItemColor color,
+ const Identified identified,
+ const Damaged damaged,
+ const Favorite favorite,
+ const Equipm equipment,
+ const Equipped equipped)
+{
+ if (index < 0 || index >= static_cast<int>(mSize))
+ {
+ logger->log("Warning: invalid inventory index: %d", index);
+ return;
+ }
+
+ Item *const item1 = mItems[index];
+ if (!item1 && id > 0)
+ {
+ ComplexItem *const item = new ComplexItem(id,
+ type,
+ quantity,
+ refine,
+ color,
+ identified,
+ damaged,
+ favorite,
+ equipment,
+ equipped);
+ item->setInvIndex(index);
+
+ Item *const item2 = new Item(id,
+ type,
+ quantity,
+ refine,
+ color,
+ identified,
+ damaged,
+ favorite,
+ equipment,
+ equipped);
+ item2->setInvIndex(index);
+ item->addChild(item2, quantity);
+
+ mItems[index] = item;
+ mUsed ++;
+ distributeSlotsChangedEvent();
+ }
+}