Scripts/Commands: Convert argument parsing of most list commands to new system (#25303)
(cherry picked from commit 522a4cb1a66539a656c44342d7652c3065a90588)
This commit is contained in:
committed by
Shauren
parent
a915b42f89
commit
e9209c3131
@@ -41,6 +41,8 @@ EndScriptData */
|
|||||||
#include "WorldSession.h"
|
#include "WorldSession.h"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
using namespace Trinity::ChatCommands;
|
||||||
|
|
||||||
class list_commandscript : public CommandScript
|
class list_commandscript : public CommandScript
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -66,24 +68,8 @@ public:
|
|||||||
return commandTable;
|
return commandTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool HandleListCreatureCommand(ChatHandler* handler, char const* args)
|
static bool HandleListCreatureCommand(ChatHandler* handler, Variant<Hyperlink<creature_entry>, uint32> creatureId, Optional<uint32> countArg)
|
||||||
{
|
{
|
||||||
if (!*args)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
|
|
||||||
char* id = handler->extractKeyFromLink((char*)args, "Hcreature_entry");
|
|
||||||
if (!id)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
uint32 creatureId = atoul(id);
|
|
||||||
if (!creatureId)
|
|
||||||
{
|
|
||||||
handler->PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, creatureId);
|
|
||||||
handler->SetSentErrorMessage(true);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
CreatureTemplate const* cInfo = sObjectMgr->GetCreatureTemplate(creatureId);
|
CreatureTemplate const* cInfo = sObjectMgr->GetCreatureTemplate(creatureId);
|
||||||
if (!cInfo)
|
if (!cInfo)
|
||||||
{
|
{
|
||||||
@@ -92,8 +78,7 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* countStr = strtok(nullptr, " ");
|
uint32 count = countArg.value_or(10);
|
||||||
uint32 count = countStr ? atoul(countStr) : 10;
|
|
||||||
|
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
return false;
|
return false;
|
||||||
@@ -168,33 +153,10 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool HandleListItemCommand(ChatHandler* handler, char const* args)
|
static bool HandleListItemCommand(ChatHandler* handler, Hyperlink<item> item, Optional<uint32> countArg)
|
||||||
{
|
{
|
||||||
if (!*args)
|
uint32 itemId = item->Item->GetId();
|
||||||
return false;
|
uint32 count = countArg.value_or(10);
|
||||||
|
|
||||||
char const* id = handler->extractKeyFromLink((char*)args, "Hitem");
|
|
||||||
if (!id)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
uint32 itemId = atoul(id);
|
|
||||||
if (!itemId)
|
|
||||||
{
|
|
||||||
handler->PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, itemId);
|
|
||||||
handler->SetSentErrorMessage(true);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(itemId);
|
|
||||||
if (!itemTemplate)
|
|
||||||
{
|
|
||||||
handler->PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, itemId);
|
|
||||||
handler->SetSentErrorMessage(true);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* countStr = strtok(nullptr, " ");
|
|
||||||
uint32 count = countStr ? atoul(countStr) : 10;
|
|
||||||
|
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
return false;
|
return false;
|
||||||
@@ -386,24 +348,8 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool HandleListObjectCommand(ChatHandler* handler, char const* args)
|
static bool HandleListObjectCommand(ChatHandler* handler, Variant<Hyperlink<gameobject_entry>, uint32> gameObjectId, Optional<uint32> countArg)
|
||||||
{
|
{
|
||||||
if (!*args)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
|
|
||||||
char* id = handler->extractKeyFromLink((char*)args, "Hgameobject_entry");
|
|
||||||
if (!id)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
uint32 gameObjectId = atoul(id);
|
|
||||||
if (!gameObjectId)
|
|
||||||
{
|
|
||||||
handler->PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, gameObjectId);
|
|
||||||
handler->SetSentErrorMessage(true);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
GameObjectTemplate const* gInfo = sObjectMgr->GetGameObjectTemplate(gameObjectId);
|
GameObjectTemplate const* gInfo = sObjectMgr->GetGameObjectTemplate(gameObjectId);
|
||||||
if (!gInfo)
|
if (!gInfo)
|
||||||
{
|
{
|
||||||
@@ -412,8 +358,7 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* countStr = strtok(nullptr, " ");
|
uint32 count = countArg.value_or(10);
|
||||||
uint32 count = countStr ? atoul(countStr) : 10;
|
|
||||||
|
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
return false;
|
return false;
|
||||||
@@ -489,7 +434,7 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool HandleListAurasCommand(ChatHandler* handler, char const* /*args*/)
|
static bool HandleListAurasCommand(ChatHandler* handler)
|
||||||
{
|
{
|
||||||
Unit* unit = handler->getSelectedUnit();
|
Unit* unit = handler->getSelectedUnit();
|
||||||
if (!unit)
|
if (!unit)
|
||||||
@@ -504,10 +449,9 @@ public:
|
|||||||
|
|
||||||
Unit::AuraApplicationMap const& auras = unit->GetAppliedAuras();
|
Unit::AuraApplicationMap const& auras = unit->GetAppliedAuras();
|
||||||
handler->PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS, std::to_string(auras.size()).c_str());
|
handler->PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS, std::to_string(auras.size()).c_str());
|
||||||
for (Unit::AuraApplicationMap::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
|
for (auto const& [spellId, aurApp] : auras)
|
||||||
{
|
{
|
||||||
|
|
||||||
AuraApplication const* aurApp = itr->second;
|
|
||||||
Aura const* aura = aurApp->GetBase();
|
Aura const* aura = aurApp->GetBase();
|
||||||
char const* name = aura->GetSpellInfo()->SpellName->Str[handler->GetSessionDbcLocale()];
|
char const* name = aura->GetSpellInfo()->SpellName->Str[handler->GetSessionDbcLocale()];
|
||||||
bool talent = aura->GetSpellInfo()->HasAttribute(SPELL_ATTR0_CU_IS_TALENT);
|
bool talent = aura->GetSpellInfo()->HasAttribute(SPELL_ATTR0_CU_IS_TALENT);
|
||||||
@@ -530,8 +474,8 @@ public:
|
|||||||
|
|
||||||
handler->PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE, std::to_string(auraList.size()).c_str(), i);
|
handler->PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE, std::to_string(auraList.size()).c_str(), i);
|
||||||
|
|
||||||
for (Unit::AuraEffectList::const_iterator itr = auraList.begin(); itr != auraList.end(); ++itr)
|
for (AuraEffect const* effect : auraList)
|
||||||
handler->PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE, (*itr)->GetId(), (*itr)->GetEffIndex(), (*itr)->GetAmount());
|
handler->PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE, effect->GetId(), effect->GetEffIndex(), effect->GetAmount());
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -650,7 +594,7 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool HandleListSpawnPointsCommand(ChatHandler* handler, char const* /*args*/)
|
static bool HandleListSpawnPointsCommand(ChatHandler* handler)
|
||||||
{
|
{
|
||||||
Player const* player = handler->GetSession()->GetPlayer();
|
Player const* player = handler->GetSession()->GetPlayer();
|
||||||
Map const* map = player->GetMap();
|
Map const* map = player->GetMap();
|
||||||
@@ -688,13 +632,10 @@ public:
|
|||||||
return zoneEntry ? zoneEntry->AreaName[locale] : "<unknown zone>";
|
return zoneEntry ? zoneEntry->AreaName[locale] : "<unknown zone>";
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool HandleListRespawnsCommand(ChatHandler* handler, char const* args)
|
static bool HandleListRespawnsCommand(ChatHandler* handler, Optional<uint32> range)
|
||||||
{
|
{
|
||||||
Player const* player = handler->GetSession()->GetPlayer();
|
Player const* player = handler->GetSession()->GetPlayer();
|
||||||
Map* map = player->GetMap();
|
Map* map = player->GetMap();
|
||||||
uint32 range = 0;
|
|
||||||
if (*args)
|
|
||||||
range = atoi((char*)args);
|
|
||||||
|
|
||||||
LocaleConstant locale = handler->GetSession()->GetSessionDbcLocale();
|
LocaleConstant locale = handler->GetSession()->GetSessionDbcLocale();
|
||||||
char const* stringOverdue = sObjectMgr->GetTrinityString(LANG_LIST_RESPAWNS_OVERDUE, locale);
|
char const* stringOverdue = sObjectMgr->GetTrinityString(LANG_LIST_RESPAWNS_OVERDUE, locale);
|
||||||
@@ -704,7 +645,7 @@ public:
|
|||||||
for (SpawnObjectType type : EnumUtils::Iterate<SpawnObjectType>())
|
for (SpawnObjectType type : EnumUtils::Iterate<SpawnObjectType>())
|
||||||
{
|
{
|
||||||
if (range)
|
if (range)
|
||||||
handler->PSendSysMessage(LANG_LIST_RESPAWNS_RANGE, EnumUtils::ToTitle(type), range);
|
handler->PSendSysMessage(LANG_LIST_RESPAWNS_RANGE, EnumUtils::ToTitle(type), *range);
|
||||||
else
|
else
|
||||||
handler->PSendSysMessage(LANG_LIST_RESPAWNS_ZONE, EnumUtils::ToTitle(type), zoneName, zoneId);
|
handler->PSendSysMessage(LANG_LIST_RESPAWNS_ZONE, EnumUtils::ToTitle(type), zoneName, zoneId);
|
||||||
|
|
||||||
@@ -723,7 +664,7 @@ public:
|
|||||||
respawnZoneId = map->GetZoneId(PhasingHandler::GetEmptyPhaseShift(), edata->spawnPoint);
|
respawnZoneId = map->GetZoneId(PhasingHandler::GetEmptyPhaseShift(), edata->spawnPoint);
|
||||||
if (range)
|
if (range)
|
||||||
{
|
{
|
||||||
if (!player->IsInDist(edata->spawnPoint, range))
|
if (!player->IsInDist(edata->spawnPoint, *range))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -741,7 +682,7 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool HandleListScenesCommand(ChatHandler* handler, char const* /*args*/)
|
static bool HandleListScenesCommand(ChatHandler* handler)
|
||||||
{
|
{
|
||||||
Player* target = handler->getSelectedPlayer();
|
Player* target = handler->getSelectedPlayer();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user