From 65ae5b4ad1a37b36ad3e10f5156b0d5f1c09b98b Mon Sep 17 00:00:00 2001 From: Guillaume Dupuy Date: Mon, 20 Mar 2017 16:31:37 +0100 Subject: [PATCH] Add an option to remember item to remove when creating a group --HG-- branch : item_group --- code/ryzom/client/src/commands.cpp | 7 ++- code/ryzom/client/src/item_group_manager.cpp | 65 ++++++++++++-------- code/ryzom/client/src/item_group_manager.h | 4 +- 3 files changed, 47 insertions(+), 29 deletions(-) diff --git a/code/ryzom/client/src/commands.cpp b/code/ryzom/client/src/commands.cpp index b05c5c71b..89b297f44 100644 --- a/code/ryzom/client/src/commands.cpp +++ b/code/ryzom/client/src/commands.cpp @@ -228,7 +228,7 @@ NLMISC_COMMAND(moveGroup, "move group to ", "name dst") return CItemGroupManager::getInstance()->moveGroup(args[0], INVENTORIES::toInventory(args[1])); } -NLMISC_COMMAND(createGroup, "create group ", "name") +NLMISC_COMMAND(createGroup, "create group [true](create a for every unequiped item)", "name [removeUnequiped]") { if(args.empty()) { @@ -236,7 +236,10 @@ NLMISC_COMMAND(createGroup, "create group ", "name") pIM->displaySystemInfo(ucstring("Cannot create a group without name.")); return false; } - if(!CItemGroupManager::getInstance()->createGroup(args[0])) + bool removeUnequiped = false; + if(args.size() > 1) + removeUnequiped = !args[1].empty(); + if(!CItemGroupManager::getInstance()->createGroup(args[0], removeUnequiped)) { CInterfaceManager *pIM = CInterfaceManager::getInstance(); std::string msg = "A group named " + args[0] + "already exist, cannot create one with the same name."; diff --git a/code/ryzom/client/src/item_group_manager.cpp b/code/ryzom/client/src/item_group_manager.cpp index 5b6d8e975..87c6aae51 100644 --- a/code/ryzom/client/src/item_group_manager.cpp +++ b/code/ryzom/client/src/item_group_manager.cpp @@ -59,6 +59,18 @@ void CItemGroup::addItem(std::string sheetName, uint16 quality, uint32 weight, u Items.push_back(CItem(sheetName, quality, weight, color)); } +void CItemGroup::addRemove(std::string slotName) +{ + SLOT_EQUIPMENT::TSlotEquipment slot = SLOT_EQUIPMENT::stringToSlotEquipment(NLMISC::toUpper(slotName)); + if(slot) + removeBeforeEquip.push_back(slot); +} + +void CItemGroup::addRemove(SLOT_EQUIPMENT::TSlotEquipment slot) +{ + removeBeforeEquip.push_back(slot); +} + void CItemGroup::writeTo(xmlNodePtr node) { xmlNodePtr groupNode = xmlNewChild (node, NULL, (const xmlChar*)"group", NULL ); @@ -117,9 +129,7 @@ void CItemGroup::readFrom(xmlNodePtr node) std::string slot; ptrName = (char*) xmlGetProp(curNode, (xmlChar*)"slot"); if (ptrName) NLMISC::fromString((const char*)ptrName, slot); - slot = NLMISC::toUpper(slot); - if(SLOT_EQUIPMENT::stringToSlotEquipment(slot) != SLOT_EQUIPMENT::UNDEFINED) - removeBeforeEquip.push_back(SLOT_EQUIPMENT::stringToSlotEquipment(slot)); + addRemove(slot); } curNode = curNode->next; @@ -352,11 +362,11 @@ bool CItemGroupManager::equipGroup(std::string name, bool pullBefore) { SLOT_EQUIPMENT::TSlotEquipment slot = group->removeBeforeEquip[i]; std::string dbPath; + // For hands equip, dbPath obviously starts at 0, we need to offset correctly if(slot == SLOT_EQUIPMENT::HANDL || slot == SLOT_EQUIPMENT::HANDR) - dbPath = "LOCAL:INVENTORY:HAND:"; + dbPath = "LOCAL:INVENTORY:HAND:" + NLMISC::toString((uint32)slot - SLOT_EQUIPMENT::HANDL); else - dbPath = "LOCAL:INVENTORY:EQUIP:"; - dbPath += NLMISC::toString((uint8)slot); + dbPath = "LOCAL:INVENTORY:EQUIP:" + NLMISC::toString((uint32)slot); CInventoryManager::getInstance()->unequip(dbPath); } @@ -375,17 +385,17 @@ bool CItemGroupManager::equipGroup(std::string name, bool pullBefore) for(int i=0; i < items.size(); i++) { CInventoryItem item = items[i]; - ITEM_TYPE::TItemType ItemType = item.pCS->asItemSheet()->ItemType; + ITEM_TYPE::TItemType itemType = item.pCS->asItemSheet()->ItemType; // If the item can be weared 2 times, don't automatically equip the second one // Or else it will simply replace the first. We'll deal with them later - if(possiblyDual.find(ItemType) != possiblyDual.end()) + if(possiblyDual.find(itemType) != possiblyDual.end()) { - if (possiblyDual[ItemType]) + if (possiblyDual[itemType]) { duals.push_back(item); continue; } - possiblyDual[ItemType] = true; + possiblyDual[itemType] = true; } maxEquipTime = std::max(maxEquipTime, item.pCS->asItemSheet()->EquipTime); CInventoryManager::getInstance()->autoEquip(item.indexInBag, true); @@ -394,9 +404,9 @@ bool CItemGroupManager::equipGroup(std::string name, bool pullBefore) for(int i=0;i < duals.size();i++) { CInventoryItem item = duals[i]; - ITEM_TYPE::TItemType ItemType = item.pCS->asItemSheet()->ItemType; + ITEM_TYPE::TItemType itemType = item.pCS->asItemSheet()->ItemType; std::string dstPath = string(LOCAL_INVENTORY); - switch(ItemType) + switch(itemType) { case ITEM_TYPE::ANKLET: dstPath += ":EQUIP:" + NLMISC::toString((int)SLOT_EQUIPMENT::ANKLER); break; @@ -407,10 +417,11 @@ bool CItemGroupManager::equipGroup(std::string name, bool pullBefore) case ITEM_TYPE::RING: dstPath += ":EQUIP:" + NLMISC::toString((int)SLOT_EQUIPMENT::FINGERR);;break; case ITEM_TYPE::DAGGER: - dstPath += "HAND:1"; break; + dstPath += ":HAND:1"; break; default: break; } + std::string srcPath = item.pCS->getSheet(); maxEquipTime = std::max(maxEquipTime, item.pCS->asItemSheet()->EquipTime); CInventoryManager::getInstance()->equip(srcPath, dstPath); @@ -424,30 +435,32 @@ bool CItemGroupManager::equipGroup(std::string name, bool pullBefore) } -bool CItemGroupManager::createGroup(std::string name) +bool CItemGroupManager::createGroup(std::string name, bool removeUnequiped) { if(findGroup(name)) return false; CItemGroup group = CItemGroup(); group.name = name; uint i; CDBCtrlSheet* pCS; - for (i = 0; i < MAX_HANDINV_ENTRIES; ++i) - { - pCS = CInventoryManager::getInstance()->getHandSheet(i); - if(!pCS) continue; - if(!pCS->isSheetValid()) continue; - NLMISC::CSheetId sheet(pCS->getSheetId()); - group.addItem(sheet.toString(), pCS->getQuality(), pCS->getItemWeight(), pCS->getItemColor()); - } - - for (i = 0; i < MAX_EQUIPINV_ENTRIES; ++i) { - pCS = CInventoryManager::getInstance()->getEquipSheet(i); + SLOT_EQUIPMENT::TSlotEquipment slot = (SLOT_EQUIPMENT::TSlotEquipment)i; + //Instead of doing two separate for, just be a bit tricky for hand equipment + if(slot == SLOT_EQUIPMENT::HANDR || slot == SLOT_EQUIPMENT::HANDL) + pCS = CInventoryManager::getInstance()->getHandSheet((uint32)(slot - SLOT_EQUIPMENT::HANDL)); + else + pCS = CInventoryManager::getInstance()->getEquipSheet(i); if(!pCS) continue; - if(!pCS->isSheetValid()) continue; + if(pCS->isSheetValid()) + { NLMISC::CSheetId sheet(pCS->getSheetId()); group.addItem(sheet.toString(), pCS->getQuality(), pCS->getItemWeight(), pCS->getItemColor()); + } + else if(removeUnequiped) + { + if(slot != SLOT_EQUIPMENT::UNDEFINED && slot != SLOT_EQUIPMENT::FACE) + group.addRemove(slot); + } } _Groups.push_back(group); diff --git a/code/ryzom/client/src/item_group_manager.h b/code/ryzom/client/src/item_group_manager.h index b1096a9f0..ee3378720 100644 --- a/code/ryzom/client/src/item_group_manager.h +++ b/code/ryzom/client/src/item_group_manager.h @@ -57,6 +57,8 @@ public: // return true if any item in the group match the parameter bool contains(CDBCtrlSheet* other); void addItem(std::string sheetName, uint16 quality, uint32 weight, uint8 color); + void addRemove(std::string slotName); + void addRemove(SLOT_EQUIPMENT::TSlotEquipment slot); void writeTo(xmlNodePtr node); void readFrom(xmlNodePtr node); @@ -83,7 +85,7 @@ public: //Return false if no group was found bool moveGroup(std::string name, INVENTORIES::TInventory dst); bool equipGroup(std::string name, bool pullBefore=true); - bool createGroup(std::string name); + bool createGroup(std::string name, bool removeUnequiped=false); bool deleteGroup(std::string name); void listGroup(); std::vector getGroupNames(CDBCtrlSheet *pCS);