Add an option to remember item to remove when creating a group
--HG-- branch : item_group
This commit is contained in:
parent
f222d1736a
commit
65ae5b4ad1
3 changed files with 47 additions and 29 deletions
|
@ -228,7 +228,7 @@ NLMISC_COMMAND(moveGroup, "move group <name> to <dst>", "name dst")
|
|||
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())
|
||||
{
|
||||
|
@ -236,7 +236,10 @@ NLMISC_COMMAND(createGroup, "create group <name>", "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.";
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<std::string> getGroupNames(CDBCtrlSheet *pCS);
|
||||
|
|
Loading…
Reference in a new issue