More verbose message, bad command usage now print a synopsis

--HG--
branch : item_group
This commit is contained in:
Guillaume Dupuy 2017-03-20 17:16:19 +01:00
parent 65ae5b4ad1
commit 332a2b5a74
2 changed files with 54 additions and 12 deletions

View file

@ -217,23 +217,59 @@ NLMISC_COMMAND(listGroup, "list all available group", "")
NLMISC_COMMAND(equipGroup, "equip group <name>", "name") NLMISC_COMMAND(equipGroup, "equip group <name>", "name")
{ {
if(args.empty()) return false; CInterfaceManager *pIM = CInterfaceManager::getInstance();
return CItemGroupManager::getInstance()->equipGroup(args[0]);
if(args.empty())
{
pIM->displaySystemInfo(ucstring("equipGroup command usage :"));
pIM->displaySystemInfo(ucstring("/equipGroup group_name : Pull the items from the group group_name from available inventory and equip them."));
return false;
}
if(CItemGroupManager::getInstance()->equipGroup(args[0]))
{
pIM->displaySystemInfo(ucstring(toString("Group %s successfully equipped.", args[0].c_str())));
return true;
}
else
{
pIM->displaySystemInfo(ucstring(toString("Could not equip group %s because no group named like this was found.", args[0].c_str())));
return false;
}
} }
NLMISC_COMMAND(moveGroup, "move group <name> to <dst>", "name dst") NLMISC_COMMAND(moveGroup, "move group <name> to <dst>", "name dst")
{ {
if(args.empty() || args.size() < 2) return false; CInterfaceManager *pIM = CInterfaceManager::getInstance();
return CItemGroupManager::getInstance()->moveGroup(args[0], INVENTORIES::toInventory(args[1])); if(args.empty() || args.size() < 2)
{
pIM->displaySystemInfo(ucstring("moveGroup command usage :"));
pIM->displaySystemInfo(ucstring("/moveGroup group_name destination : move items from all available inventories to destination"));
pIM->displaySystemInfo(ucstring("destination can be either bag, player_room, guild, pet_animal1, pet_animal2, pet_animal3, pet_animal4"));
return false;
}
if(CItemGroupManager::getInstance()->moveGroup(args[0], INVENTORIES::toInventory(args[1])))
{
pIM->displaySystemInfo(ucstring(toString("Group %s successfully moved to %s.", args[0].c_str(), args[1].c_str())));
return true;
}
else
{
pIM->displaySystemInfo(ucstring(toString("Could not move group %s to %s because no group named like this was found, and/or it wasn't a valid inventory.",
args[0].c_str(), args[1].c_str())));
return true;
}
} }
NLMISC_COMMAND(createGroup, "create group <name> [true](create a <remove> for every unequiped item)", "name [removeUnequiped]") NLMISC_COMMAND(createGroup, "create group <name> [true](create a <remove> for every unequiped item)", "name [removeUnequiped]")
{ {
CInterfaceManager *pIM = CInterfaceManager::getInstance();
if(args.empty()) if(args.empty())
{ {
CInterfaceManager *pIM = CInterfaceManager::getInstance(); pIM->displaySystemInfo(ucstring("createGroup command usage :"));
pIM->displaySystemInfo(ucstring("Cannot create a group without name.")); pIM->displaySystemInfo(ucstring("/createGroup group_name : create a group named group_nam with all your equipped items"));
pIM->displaySystemInfo(ucstring("/createGroup group_name true : create a group named group_nam with all your equipped items, and create a remove command for every empty slot"));
return false; return false;
} }
bool removeUnequiped = false; bool removeUnequiped = false;
@ -241,29 +277,30 @@ NLMISC_COMMAND(createGroup, "create group <name> [true](create a <remove> for ev
removeUnequiped = !args[1].empty(); removeUnequiped = !args[1].empty();
if(!CItemGroupManager::getInstance()->createGroup(args[0], removeUnequiped)) if(!CItemGroupManager::getInstance()->createGroup(args[0], removeUnequiped))
{ {
CInterfaceManager *pIM = CInterfaceManager::getInstance(); std::string msg = toString("A group named %s already exist, cannot create one with the same name.", args[0].c_str());
std::string msg = "A group named " + args[0] + "already exist, cannot create one with the same name.";
pIM->displaySystemInfo(ucstring(msg)); pIM->displaySystemInfo(ucstring(msg));
return false; return false;
} }
pIM->displaySystemInfo(ucstring(toString("Group %s successfully created.", args[0].c_str())));
return true; return true;
} }
NLMISC_COMMAND(deleteGroup, "delete group <name>", "name") NLMISC_COMMAND(deleteGroup, "delete group <name>", "name")
{ {
CInterfaceManager *pIM = CInterfaceManager::getInstance();
if(args.empty()) if(args.empty())
{ {
CInterfaceManager *pIM = CInterfaceManager::getInstance(); pIM->displaySystemInfo(ucstring("deleteGroup command usage :"));
pIM->displaySystemInfo(ucstring("Cannot delete a group without name.")); pIM->displaySystemInfo(ucstring("/deleteGroup group_name : Remove the group named group_name if it exists."));
return false; return false;
} }
if(!CItemGroupManager::getInstance()->deleteGroup(args[0])) if(!CItemGroupManager::getInstance()->deleteGroup(args[0]))
{ {
CInterfaceManager *pIM = CInterfaceManager::getInstance(); std::string msg = toString("Cannot delete group %s : no group with this name found.", args[0].c_str());
std::string msg = "Cannot delete group " + args[0] + " : no group with this name found.";
pIM->displaySystemInfo(msg); pIM->displaySystemInfo(msg);
return false; return false;
} }
pIM->displaySystemInfo(ucstring(toString("Group %s successfully deleted.", args[0].c_str())));
return true; return true;
} }

View file

@ -323,6 +323,11 @@ bool CItemGroupManager::moveGroup(std::string name, INVENTORIES::TInventory dst)
nlinfo("group %s not found", name.c_str()); nlinfo("group %s not found", name.c_str());
return false; return false;
} }
if(dst == INVENTORIES::UNDEFINED)
{
nlinfo("Destination inventory not found");
return false;
}
CInventoryManager* pIM = CInventoryManager::getInstance(); CInventoryManager* pIM = CInventoryManager::getInstance();
std::string moveParams = "to=lists|nblist=1|listsheet0=" + toDbPath(dst); std::string moveParams = "to=lists|nblist=1|listsheet0=" + toDbPath(dst);