Add support for removing items before equipping an item group

--HG--
branch : item_group
This commit is contained in:
Guillaume Dupuy 2017-03-16 12:19:29 +01:00
parent a6f541aad2
commit 83dea32f41
2 changed files with 34 additions and 2 deletions

View file

@ -74,6 +74,11 @@ void CItemGroup::writeTo(xmlNodePtr node)
xmlSetProp (itemNode, (const xmlChar*)"minPrice", (const xmlChar*)NLMISC::toString(item.minPrice).c_str()); xmlSetProp (itemNode, (const xmlChar*)"minPrice", (const xmlChar*)NLMISC::toString(item.minPrice).c_str());
xmlSetProp (itemNode, (const xmlChar*)"maxPrice", (const xmlChar*)NLMISC::toString(item.maxPrice).c_str()); xmlSetProp (itemNode, (const xmlChar*)"maxPrice", (const xmlChar*)NLMISC::toString(item.maxPrice).c_str());
} }
for(int i=0;i<removeBeforeEquip.size();i++)
{
xmlNodePtr removeNode = xmlNewChild(groupNode, NULL, (const xmlChar*)"remove", NULL);
xmlSetProp(removeNode, (const xmlChar*)"slot", (const xmlChar*)removeBeforeEquip[i]);
}
} }
@ -107,6 +112,16 @@ void CItemGroup::readFrom(xmlNodePtr node)
if(item.sheetName != "unknown.unknown") if(item.sheetName != "unknown.unknown")
Items.push_back(item); Items.push_back(item);
} }
if (strcmp((char*)curNode->name, "remove") == 0)
{
std::string slot;
ptrName = (char*) xmlGetProp(curNode, (xmlChar*)"slot");
if (ptrName) NLMISC::fromString((const char*)ptrName, slot);
nlinfo("Got a slot %s", slot.c_str());
if(SLOTTYPE::stringToSlotType(slot) != SLOTTYPE::UNDEFINED)
removeBeforeEquip.push_back(SLOTTYPE::stringToSlotType(slot));
}
curNode = curNode->next; curNode = curNode->next;
} }
@ -320,6 +335,21 @@ bool CItemGroupManager::equipGroup(std::string name, bool pullBefore)
} }
if(pullBefore) moveGroup(name, INVENTORIES::TInventory::bag); if(pullBefore) moveGroup(name, INVENTORIES::TInventory::bag);
//Start by unequipping all slot that user wants to unequip
for(int i=0; i < group->removeBeforeEquip.size(); i++)
{
SLOTTYPE::TSlotType slot = group->removeBeforeEquip[i];
nlinfo("removing slot %d", slot);
std::string dbPath;
if(slot > SLOTTYPE::RIGHT_HAND)
dbPath = "LOCAL:INVENTORY:HAND:";
else
dbPath = "LOCAL:INVENTORY:EQUIP:";
//offset by 1 : TSlotType begins at 1 for actual items (because of UNDEFINED), whereas dbPath start at 0
dbPath += NLMISC::toString((uint8)slot - 1);
nlinfo("Removing path %s", dbPath.c_str());
CInventoryManager::getInstance()->unequip(dbPath);
}
uint32 maxEquipTime = 0; uint32 maxEquipTime = 0;

View file

@ -21,6 +21,7 @@
#include "interface_v3/inventory_manager.h" #include "interface_v3/inventory_manager.h"
#include "interface_v3/dbctrl_sheet.h" #include "interface_v3/dbctrl_sheet.h"
#include "game_share/inventories.h" #include "game_share/inventories.h"
#include "game_share/slot_types.h"
struct CInventoryItem { struct CInventoryItem {
public: public:
@ -61,6 +62,7 @@ public:
std::string name; std::string name;
std::vector<CItem> Items; std::vector<CItem> Items;
std::vector<SLOTTYPE::TSlotType> removeBeforeEquip;
}; };
class CItemGroupManager { class CItemGroupManager {