From 3d53789e0fdfd72fd53125c1680d0ee7cbe55447 Mon Sep 17 00:00:00 2001 From: Guillaume Dupuy Date: Mon, 20 Mar 2017 20:38:51 +0100 Subject: [PATCH] Remember the slot (right/left hand) for item that can we weared in two similar slots --HG-- branch : item_group --- code/ryzom/client/src/item_group_manager.cpp | 39 +++++++++++++++----- code/ryzom/client/src/item_group_manager.h | 22 +++++------ 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/code/ryzom/client/src/item_group_manager.cpp b/code/ryzom/client/src/item_group_manager.cpp index f070ccf2e..b040d175c 100644 --- a/code/ryzom/client/src/item_group_manager.cpp +++ b/code/ryzom/client/src/item_group_manager.cpp @@ -35,9 +35,14 @@ CItemGroup::CItemGroup() { } - bool CItemGroup::contains(CDBCtrlSheet *other) { + SLOT_EQUIPMENT::TSlotEquipment slot = SLOT_EQUIPMENT::UNDEFINED; + return contains(other, slot); +} +bool CItemGroup::contains(CDBCtrlSheet *other, SLOT_EQUIPMENT::TSlotEquipment &slot) +{ + slot = SLOT_EQUIPMENT::UNDEFINED; for(int i=0;igetItemPrice() >= item.minPrice && other->getItemPrice() <= item.maxPrice)) ) { + slot = item.slot; return true; } } @@ -54,9 +60,9 @@ bool CItemGroup::contains(CDBCtrlSheet *other) return false; } -void CItemGroup::addItem(std::string sheetName, uint16 quality, uint32 weight, uint8 color) +void CItemGroup::addItem(std::string sheetName, uint16 quality, uint32 weight, uint8 color, SLOT_EQUIPMENT::TSlotEquipment slot) { - Items.push_back(CItem(sheetName, quality, weight, color)); + Items.push_back(CItem(sheetName, quality, weight, color, slot)); } void CItemGroup::addRemove(std::string slotName) @@ -85,6 +91,9 @@ void CItemGroup::writeTo(xmlNodePtr node) xmlSetProp (itemNode, (const xmlChar*)"color", (const xmlChar*)NLMISC::toString(item.color).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()); + // We need to save slot only if it's useful for clarity + if(item.slot == SLOT_EQUIPMENT::HANDL || item.slot == SLOT_EQUIPMENT::HANDR) + xmlSetProp(itemNode, (const xmlChar*)"slot", (const xmlChar*)SLOT_EQUIPMENT::toString(item.slot).c_str()); } for(int i=0;i::max()); + ptrName = (char*) xmlGetProp(curNode, (xmlChar*)"slot"); + std::string slot; + if (ptrName) NLMISC::fromString((const char*)ptrName, slot); + item.slot = SLOT_EQUIPMENT::stringToSlotEquipment(NLMISC::toUpper(slot)); //Old version of groups.xml could save unknown sheets, remove them for clarity if(item.sheetName != "unknown.unknown") Items.push_back(item); @@ -393,6 +406,14 @@ bool CItemGroupManager::equipGroup(std::string name, bool pullBefore) { CInventoryItem item = items[i]; ITEM_TYPE::TItemType itemType = item.pCS->asItemSheet()->ItemType; + // Special case for dagger (and all other items that can be equipped both right AND left hand, currently it's only dagger) + // We don't equip the one intended for left hand right away (it will be done in duals items later), let right hand be normally equipped + if(itemType == ITEM_TYPE::DAGGER && item.slot == SLOT_EQUIPMENT::HANDL) + { + duals.push_back(item); + continue; + } + // 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()) @@ -404,6 +425,7 @@ bool CItemGroupManager::equipGroup(std::string name, bool pullBefore) } possiblyDual[itemType] = true; } + maxEquipTime = std::max(maxEquipTime, item.pCS->asItemSheet()->EquipTime); CInventoryManager::getInstance()->autoEquip(item.indexInBag, true); } @@ -460,8 +482,8 @@ bool CItemGroupManager::createGroup(std::string name, bool removeUnequiped) if(!pCS) continue; if(pCS->isSheetValid()) { - NLMISC::CSheetId sheet(pCS->getSheetId()); - group.addItem(sheet.toString(), pCS->getQuality(), pCS->getItemWeight(), pCS->getItemColor()); + NLMISC::CSheetId sheet(pCS->getSheetId()); + group.addItem(sheet.toString(), pCS->getQuality(), pCS->getItemWeight(), pCS->getItemColor(), slot); } else if(removeUnequiped) { @@ -512,7 +534,6 @@ std::vector CItemGroupManager::getGroupNames(CDBCtrlSheet* pCS) CItemGroup group = _Groups[i]; if(group.contains(pCS)) out.push_back(group.name); - } return out; } @@ -564,10 +585,10 @@ std::vector CItemGroupManager::matchingItems(CItemGroup *group, for(uint i=0; i < MAX_BAGINV_ENTRIES; i++) { CDBCtrlSheet *pCS = pList->getSheet(i); - if(group->contains(pCS)) + SLOT_EQUIPMENT::TSlotEquipment slot; + if(group->contains(pCS, slot)) { - - out.push_back(CInventoryItem(pCS, inventory, i)); + out.push_back(CInventoryItem(pCS, inventory, i, slot)); } } diff --git a/code/ryzom/client/src/item_group_manager.h b/code/ryzom/client/src/item_group_manager.h index ee3378720..e4a3f5a47 100644 --- a/code/ryzom/client/src/item_group_manager.h +++ b/code/ryzom/client/src/item_group_manager.h @@ -28,7 +28,9 @@ public: CDBCtrlSheet* pCS; INVENTORIES::TInventory origin; uint32 indexInBag; - CInventoryItem(CDBCtrlSheet *pCS, INVENTORIES::TInventory origin, uint32 indexInBag) : pCS(pCS), origin(origin), indexInBag(indexInBag) {} + SLOT_EQUIPMENT::TSlotEquipment slot; // Used only for dagger (right/left hand slot) + CInventoryItem(CDBCtrlSheet *pCS, INVENTORIES::TInventory origin, uint32 indexInBag, SLOT_EQUIPMENT::TSlotEquipment slot = SLOT_EQUIPMENT::UNDEFINED) : + pCS(pCS), origin(origin), indexInBag(indexInBag), slot(slot) {} }; @@ -39,24 +41,22 @@ public: uint16 quality; uint32 weight; uint8 color; + SLOT_EQUIPMENT::TSlotEquipment slot; // Used only for dagger (right/left hand slot) uint32 minPrice; uint32 maxPrice; bool usePrice; - CItem() : sheetName(""), quality(0), color(0), weight(0), minPrice(0), maxPrice(std::numeric_limits::max()), usePrice(false) {} - CItem(std::string sheetName, uint16 quality, uint32 weight, uint8 color, uint32 minPrice, uint32 maxPrice, bool usePrice) : - sheetName(sheetName), quality(quality), weight(weight), color(color), minPrice(minPrice), maxPrice(maxPrice), usePrice(usePrice) {} - CItem(std::string sheetName, uint16 quality, uint32 weight, uint8 color) : - sheetName(sheetName), quality(quality), weight(weight), color(color), minPrice(0), maxPrice(std::numeric_limits::max()), usePrice(false) {} + CItem(std::string sheetName = "", uint16 quality = 0, uint32 weight = 0, uint8 color = 0, SLOT_EQUIPMENT::TSlotEquipment slot = SLOT_EQUIPMENT::UNDEFINED, uint32 minPrice = 0, uint32 maxPrice = std::numeric_limits::max(), bool usePrice = false) : + sheetName(sheetName), quality(quality), weight(weight), color(color), slot(slot), minPrice(minPrice), maxPrice(maxPrice), usePrice(usePrice) {} - - }; +}; public: CItemGroup(); - // 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); + // return true if any item in the group match the parameter ; slot is UNDEFINED unless the item has been found in the group + bool contains(CDBCtrlSheet *other); + bool contains(CDBCtrlSheet* other, SLOT_EQUIPMENT::TSlotEquipment &slot); + void addItem(std::string sheetName, uint16 quality, uint32 weight, uint8 color, SLOT_EQUIPMENT::TSlotEquipment slot); void addRemove(std::string slotName); void addRemove(SLOT_EQUIPMENT::TSlotEquipment slot); void writeTo(xmlNodePtr node);