Add an option to remember item to remove when creating a group

--HG--
branch : item_group
This commit is contained in:
Guillaume Dupuy 2017-03-20 16:31:37 +01:00
parent f222d1736a
commit 65ae5b4ad1
3 changed files with 47 additions and 29 deletions

View file

@ -228,7 +228,7 @@ NLMISC_COMMAND(moveGroup, "move group <name> to <dst>", "name dst")
return CItemGroupManager::getInstance()->moveGroup(args[0], INVENTORIES::toInventory(args[1])); return CItemGroupManager::getInstance()->moveGroup(args[0], INVENTORIES::toInventory(args[1]));
} }
NLMISC_COMMAND(createGroup, "create group <name>", "name") NLMISC_COMMAND(createGroup, "create group <name> [true](create a <remove> for every unequiped item)", "name [removeUnequiped]")
{ {
if(args.empty()) if(args.empty())
{ {
@ -236,7 +236,10 @@ NLMISC_COMMAND(createGroup, "create group <name>", "name")
pIM->displaySystemInfo(ucstring("Cannot create a group without name.")); pIM->displaySystemInfo(ucstring("Cannot create a group without name."));
return false; 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(); CInterfaceManager *pIM = CInterfaceManager::getInstance();
std::string msg = "A group named " + args[0] + "already exist, cannot create one with the same name."; std::string msg = "A group named " + args[0] + "already exist, cannot create one with the same name.";

View file

@ -59,6 +59,18 @@ void CItemGroup::addItem(std::string sheetName, uint16 quality, uint32 weight, u
Items.push_back(CItem(sheetName, quality, weight, color)); 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) void CItemGroup::writeTo(xmlNodePtr node)
{ {
xmlNodePtr groupNode = xmlNewChild (node, NULL, (const xmlChar*)"group", NULL ); xmlNodePtr groupNode = xmlNewChild (node, NULL, (const xmlChar*)"group", NULL );
@ -117,9 +129,7 @@ void CItemGroup::readFrom(xmlNodePtr node)
std::string slot; std::string slot;
ptrName = (char*) xmlGetProp(curNode, (xmlChar*)"slot"); ptrName = (char*) xmlGetProp(curNode, (xmlChar*)"slot");
if (ptrName) NLMISC::fromString((const char*)ptrName, slot); if (ptrName) NLMISC::fromString((const char*)ptrName, slot);
slot = NLMISC::toUpper(slot); addRemove(slot);
if(SLOT_EQUIPMENT::stringToSlotEquipment(slot) != SLOT_EQUIPMENT::UNDEFINED)
removeBeforeEquip.push_back(SLOT_EQUIPMENT::stringToSlotEquipment(slot));
} }
curNode = curNode->next; curNode = curNode->next;
@ -352,11 +362,11 @@ bool CItemGroupManager::equipGroup(std::string name, bool pullBefore)
{ {
SLOT_EQUIPMENT::TSlotEquipment slot = group->removeBeforeEquip[i]; SLOT_EQUIPMENT::TSlotEquipment slot = group->removeBeforeEquip[i];
std::string dbPath; 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) 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 else
dbPath = "LOCAL:INVENTORY:EQUIP:"; dbPath = "LOCAL:INVENTORY:EQUIP:" + NLMISC::toString((uint32)slot);
dbPath += NLMISC::toString((uint8)slot);
CInventoryManager::getInstance()->unequip(dbPath); CInventoryManager::getInstance()->unequip(dbPath);
} }
@ -375,17 +385,17 @@ bool CItemGroupManager::equipGroup(std::string name, bool pullBefore)
for(int i=0; i < items.size(); i++) for(int i=0; i < items.size(); i++)
{ {
CInventoryItem item = items[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 // 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 // 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); duals.push_back(item);
continue; continue;
} }
possiblyDual[ItemType] = true; possiblyDual[itemType] = true;
} }
maxEquipTime = std::max(maxEquipTime, item.pCS->asItemSheet()->EquipTime); maxEquipTime = std::max(maxEquipTime, item.pCS->asItemSheet()->EquipTime);
CInventoryManager::getInstance()->autoEquip(item.indexInBag, true); 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++) for(int i=0;i < duals.size();i++)
{ {
CInventoryItem item = duals[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); std::string dstPath = string(LOCAL_INVENTORY);
switch(ItemType) switch(itemType)
{ {
case ITEM_TYPE::ANKLET: case ITEM_TYPE::ANKLET:
dstPath += ":EQUIP:" + NLMISC::toString((int)SLOT_EQUIPMENT::ANKLER); break; 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: case ITEM_TYPE::RING:
dstPath += ":EQUIP:" + NLMISC::toString((int)SLOT_EQUIPMENT::FINGERR);;break; dstPath += ":EQUIP:" + NLMISC::toString((int)SLOT_EQUIPMENT::FINGERR);;break;
case ITEM_TYPE::DAGGER: case ITEM_TYPE::DAGGER:
dstPath += "HAND:1"; break; dstPath += ":HAND:1"; break;
default: default:
break; break;
} }
std::string srcPath = item.pCS->getSheet(); std::string srcPath = item.pCS->getSheet();
maxEquipTime = std::max(maxEquipTime, item.pCS->asItemSheet()->EquipTime); maxEquipTime = std::max(maxEquipTime, item.pCS->asItemSheet()->EquipTime);
CInventoryManager::getInstance()->equip(srcPath, dstPath); 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; if(findGroup(name)) return false;
CItemGroup group = CItemGroup(); CItemGroup group = CItemGroup();
group.name = name; group.name = name;
uint i; uint i;
CDBCtrlSheet* pCS; CDBCtrlSheet* pCS;
for (i = 0; i < MAX_HANDINV_ENTRIES; ++i) for (i = 0; i < MAX_EQUIPINV_ENTRIES; ++i)
{ {
pCS = CInventoryManager::getInstance()->getHandSheet(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) continue;
if(!pCS->isSheetValid()) continue; if(pCS->isSheetValid())
{
NLMISC::CSheetId sheet(pCS->getSheetId()); NLMISC::CSheetId sheet(pCS->getSheetId());
group.addItem(sheet.toString(), pCS->getQuality(), pCS->getItemWeight(), pCS->getItemColor()); group.addItem(sheet.toString(), pCS->getQuality(), pCS->getItemWeight(), pCS->getItemColor());
} }
else if(removeUnequiped)
for (i = 0; i < MAX_EQUIPINV_ENTRIES; ++i)
{ {
pCS = CInventoryManager::getInstance()->getEquipSheet(i); if(slot != SLOT_EQUIPMENT::UNDEFINED && slot != SLOT_EQUIPMENT::FACE)
if(!pCS) continue; group.addRemove(slot);
if(!pCS->isSheetValid()) continue; }
NLMISC::CSheetId sheet(pCS->getSheetId());
group.addItem(sheet.toString(), pCS->getQuality(), pCS->getItemWeight(), pCS->getItemColor());
} }
_Groups.push_back(group); _Groups.push_back(group);

View file

@ -57,6 +57,8 @@ public:
// return true if any item in the group match the parameter // return true if any item in the group match the parameter
bool contains(CDBCtrlSheet* other); bool contains(CDBCtrlSheet* other);
void addItem(std::string sheetName, uint16 quality, uint32 weight, uint8 color); 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 writeTo(xmlNodePtr node);
void readFrom(xmlNodePtr node); void readFrom(xmlNodePtr node);
@ -83,7 +85,7 @@ public:
//Return false if no group was found //Return false if no group was found
bool moveGroup(std::string name, INVENTORIES::TInventory dst); bool moveGroup(std::string name, INVENTORIES::TInventory dst);
bool equipGroup(std::string name, bool pullBefore=true); 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); bool deleteGroup(std::string name);
void listGroup(); void listGroup();
std::vector<std::string> getGroupNames(CDBCtrlSheet *pCS); std::vector<std::string> getGroupNames(CDBCtrlSheet *pCS);