Scripts/Commands: Adjust .list respawns to use enum iteration. Add enum iteration capability to SpawnObjectTypes.

(cherry picked from commit b64834c3f5)
This commit is contained in:
Treeston
2019-07-17 22:58:49 +02:00
committed by Shauren
parent 39ef3e3e78
commit e270351a16
6 changed files with 85 additions and 46 deletions

View File

@@ -0,0 +1,2 @@
--
DELETE FROM `trinity_string` WHERE `entry` IN (5081,5082);

View File

@@ -64,7 +64,7 @@ TC_API_EXPORT EnumText EnumUtils<UnitFlags>::ToString(UnitFlags value)
case UNIT_FLAG_UNK_28: return { "UNIT_FLAG_UNK_28", "UNIT_FLAG_UNK_28", "" };
case UNIT_FLAG_UNK_29: return { "UNIT_FLAG_UNK_29", "UNIT_FLAG_UNK_29", "used in Feing Death spell" };
case UNIT_FLAG_SHEATHE: return { "UNIT_FLAG_SHEATHE", "UNIT_FLAG_SHEATHE", "" };
case UNIT_FLAG_IMMUNE: return { "UNIT_FLAG_IMMUNE", "UNIT_FLAG_IMMUNE", "is affected by a damage immunity aura" };
case UNIT_FLAG_IMMUNE: return { "UNIT_FLAG_IMMUNE", "UNIT_FLAG_IMMUNE", "Immune to damage" };
default: throw std::out_of_range("value");
}
}

View File

@@ -22,12 +22,13 @@
#include "Position.h"
#include <vector>
// EnumUtils: DESCRIBE THIS
enum SpawnObjectType
{
SPAWN_TYPE_CREATURE = 0,
SPAWN_TYPE_GAMEOBJECT = 1,
SPAWN_TYPE_CREATURE = 0, // TITLE Creature
SPAWN_TYPE_GAMEOBJECT = 1, // TITLE Gameobject
SPAWN_TYPE_MAX
SPAWN_TYPE_MAX // SKIP
};
enum SpawnObjectTypeMask

View File

@@ -0,0 +1,56 @@
/*
* Copyright (C) 2008-2019 TrinityCore <https://www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "SpawnData.h"
#include "Define.h"
#include "SmartEnum.h"
#include <stdexcept>
namespace Trinity
{
namespace Impl
{
/*******************************************************************\
|* data for enum 'SpawnObjectType' in 'SpawnData.h' auto-generated *|
\*******************************************************************/
template <>
TC_API_EXPORT EnumText EnumUtils<SpawnObjectType>::ToString(SpawnObjectType value)
{
switch (value)
{
case SPAWN_TYPE_CREATURE: return { "SPAWN_TYPE_CREATURE", "Creature", "" };
case SPAWN_TYPE_GAMEOBJECT: return { "SPAWN_TYPE_GAMEOBJECT", "Gameobject", "" };
default: throw std::out_of_range("value");
}
}
template <>
TC_API_EXPORT size_t EnumUtils<SpawnObjectType>::Count() { return 2; }
template <>
TC_API_EXPORT SpawnObjectType EnumUtils<SpawnObjectType>::FromIndex(size_t index)
{
switch (index)
{
case 0: return SPAWN_TYPE_CREATURE;
case 1: return SPAWN_TYPE_GAMEOBJECT;
default: throw std::out_of_range("index");
}
}
}
}

View File

@@ -1137,8 +1137,8 @@ enum TrinityStrings
LANG_LIST_RESPAWNS_ZONE = 5078,
LANG_LIST_RESPAWNS_LISTHEADER = 5079,
LANG_LIST_RESPAWNS_OVERDUE = 5080,
LANG_LIST_RESPAWNS_CREATURES = 5081,
LANG_LIST_RESPAWNS_GAMEOBJECTS = 5082,
// unused 5081
// unused 5082
LANG_OBJECTINFO_AITYPE = 5083,
LANG_NPCINFO_UNIT_FIELD_FLAGS_2 = 5084,
LANG_NPCINFO_UNIT_FIELD_FLAGS_3 = 5085,

View File

@@ -692,52 +692,32 @@ public:
if (*args)
range = atoi((char*)args);
std::vector<RespawnInfo*> respawns;
LocaleConstant locale = handler->GetSession()->GetSessionDbcLocale();
char const* stringOverdue = sObjectMgr->GetTrinityString(LANG_LIST_RESPAWNS_OVERDUE, locale);
char const* stringCreature = sObjectMgr->GetTrinityString(LANG_LIST_RESPAWNS_CREATURES, locale);
char const* stringGameobject = sObjectMgr->GetTrinityString(LANG_LIST_RESPAWNS_GAMEOBJECTS, locale);
uint32 zoneId = player->GetZoneId();
if (range)
handler->PSendSysMessage(LANG_LIST_RESPAWNS_RANGE, stringCreature, range);
else
handler->PSendSysMessage(LANG_LIST_RESPAWNS_ZONE, stringCreature, GetZoneName(zoneId, handler->GetSessionDbcLocale()), zoneId);
handler->PSendSysMessage(LANG_LIST_RESPAWNS_LISTHEADER);
map->GetRespawnInfo(respawns, SPAWN_TYPEMASK_CREATURE, range ? 0 : zoneId);
for (RespawnInfo* ri : respawns)
for (SpawnObjectType type : EnumUtils::Iterate<SpawnObjectType>())
{
CreatureData const* data = sObjectMgr->GetCreatureData(ri->spawnId);
if (!data)
continue;
if (range && !player->IsInDist(data->spawnPoint, range))
continue;
uint32 gridY = ri->gridId / MAX_NUMBER_OF_GRIDS;
uint32 gridX = ri->gridId % MAX_NUMBER_OF_GRIDS;
if (range)
handler->PSendSysMessage(LANG_LIST_RESPAWNS_RANGE, EnumUtils::ToTitle(type), range);
else
handler->PSendSysMessage(LANG_LIST_RESPAWNS_ZONE, EnumUtils::ToTitle(type), GetZoneName(zoneId, locale), zoneId);
handler->PSendSysMessage(LANG_LIST_RESPAWNS_LISTHEADER);
std::vector<RespawnInfo*> respawns;
map->GetRespawnInfo(respawns, SpawnObjectTypeMask(1 << type), range ? 0 : zoneId);
for (RespawnInfo* ri : respawns)
{
SpawnData const* data = sObjectMgr->GetSpawnData(ri->type, ri->spawnId);
if (!data)
continue;
if (range && !player->IsInDist(data->spawnPoint, range))
continue;
uint32 gridY = ri->gridId / MAX_NUMBER_OF_GRIDS;
uint32 gridX = ri->gridId % MAX_NUMBER_OF_GRIDS;
std::string respawnTime = ri->respawnTime > GameTime::GetGameTime() ? secsToTimeString(uint64(ri->respawnTime - GameTime::GetGameTime()), true) : stringOverdue;
handler->PSendSysMessage(UI64FMTD " | %u | [%02u,%02u] | %s (%u) | %s%s", ri->spawnId, ri->entry, gridX, gridY, GetZoneName(ri->zoneId, handler->GetSessionDbcLocale()), ri->zoneId, respawnTime.c_str(), map->IsSpawnGroupActive(data->spawnGroupData->groupId) ? "" : " (inactive)");
}
respawns.clear();
if (range)
handler->PSendSysMessage(LANG_LIST_RESPAWNS_RANGE, stringGameobject, range);
else
handler->PSendSysMessage(LANG_LIST_RESPAWNS_ZONE, stringGameobject, GetZoneName(zoneId, handler->GetSessionDbcLocale()), zoneId);
handler->PSendSysMessage(LANG_LIST_RESPAWNS_LISTHEADER);
map->GetRespawnInfo(respawns, SPAWN_TYPEMASK_GAMEOBJECT, range ? 0 : zoneId);
for (RespawnInfo* ri : respawns)
{
GameObjectData const* data = sObjectMgr->GetGameObjectData(ri->spawnId);
if (!data)
continue;
if (range && !player->IsInDist(data->spawnPoint, range))
continue;
uint32 gridY = ri->gridId / MAX_NUMBER_OF_GRIDS;
uint32 gridX = ri->gridId % MAX_NUMBER_OF_GRIDS;
std::string respawnTime = ri->respawnTime > GameTime::GetGameTime() ? secsToTimeString(uint64(ri->respawnTime - GameTime::GetGameTime()), true) : stringOverdue;
handler->PSendSysMessage(UI64FMTD " | %u | [% 02u, % 02u] | %s (%u) | %s%s", ri->spawnId, ri->entry, gridX, gridY, GetZoneName(ri->zoneId, handler->GetSessionDbcLocale()), ri->zoneId, respawnTime.c_str(), map->IsSpawnGroupActive(data->spawnGroupData->groupId) ? "" : " (inactive)");
std::string respawnTime = ri->respawnTime > GameTime::GetGameTime() ? secsToTimeString(uint64(ri->respawnTime - GameTime::GetGameTime()), true) : stringOverdue;
handler->PSendSysMessage(UI64FMTD " | %u | [%02u,%02u] | %s (%u) | %s%s", ri->spawnId, ri->entry, gridX, gridY, GetZoneName(ri->zoneId, locale), ri->zoneId, respawnTime.c_str(), map->IsSpawnGroupActive(data->spawnGroupData->groupId) ? "" : " (inactive)");
}
}
return true;
}