Skip to content

Commit

Permalink
Restore some func+code and fix build error
Browse files Browse the repository at this point in the history
  • Loading branch information
KamiliaBlow committed May 20, 2023
1 parent d504a6f commit ad715c3
Show file tree
Hide file tree
Showing 5 changed files with 593 additions and 102 deletions.
62 changes: 62 additions & 0 deletions src/common/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@
#include "Define.h"
#include <array>
#include <string>
#include <cstdlib>
#include <boost/any.hpp>
#include <mutex>
#include <unordered_map>
#include <map>
#include <regex>
#include <list>
#include "Errors.h"
#include "LockedQueue.h"
#include "StringFormat.h"

#define STRINGIZE(a) #a

Expand Down Expand Up @@ -121,4 +131,56 @@ struct LocalizedString

#define MAX_QUERY_LEN 32*1024

namespace ThisCore
{
class TC_GAME_API AnyData
{
public:
template<typename T>
void Set(std::string const& key, T value)
{
dataMap[key] = value;
}

template<typename T>
T GetValue(std::string const& key, T defaultValue = T()) const
{
auto itr = dataMap.find(key);
if (itr != dataMap.end())
return boost::any_cast<T>(itr->second);
return defaultValue;
}

bool Exist(std::string const& key) const
{
return dataMap.find(key) != dataMap.end();
}

void Remove(std::string const& key)
{
dataMap.erase(key);
}

uint32 Increment(std::string const& key, uint32 increment = 1)
{
uint32 currentValue = GetValue<uint32>(key, uint32(0));
Set(key, currentValue += increment);
return currentValue;
}

bool IncrementOrProcCounter(std::string const& key, uint32 maxVal, uint32 increment = 1)
{
uint32 newValue = Increment(key, increment);
if (newValue < maxVal)
return false;

Remove(key);
return true;
}

private:
std::unordered_map<std::string, boost::any> dataMap;
};
}

#endif
4 changes: 2 additions & 2 deletions src/server/game/Globals/ObjectMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9857,7 +9857,7 @@ uint32 ObjectMgr::LoadReferenceVendor(int32 vendor, int32 item, std::set<uint32>
vItem.PlayerConditionId = fields[7].GetUInt32();
vItem.IgnoreFiltering = fields[8].GetBool();

for (std::string_view token : Trinity::Tokenize(fields[5].GetStringView(), ' ', false))
for (std::string_view token : Trinity::Tokenize(fields[6].GetStringView(), ' ', false))
if (Optional<int32> bonusListID = Trinity::StringTo<int32>(token))
vItem.BonusListIDs.push_back(*bonusListID);

Expand Down Expand Up @@ -9915,7 +9915,7 @@ void ObjectMgr::LoadVendors()
vItem.PlayerConditionId = fields[8].GetUInt32();
vItem.IgnoreFiltering = fields[9].GetBool();

for (std::string_view token : Trinity::Tokenize(fields[6].GetStringView(), ' ', false))
for (std::string_view token : Trinity::Tokenize(fields[7].GetStringView(), ' ', false))
if (Optional<int32> bonusListID = Trinity::StringTo<int32>(token))
vItem.BonusListIDs.push_back(*bonusListID);

Expand Down
4 changes: 2 additions & 2 deletions src/server/game/RolePlay/RolePlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void Roleplay::LoadAllTables()
LoadCreatureTemplateExtras();
LoadCustomNpcs();

TC_LOG_INFO("server.loading", ">> Loaded Roleplay tables in %u ms", GetMSTimeDiffToNow(oldMSTime));
TC_LOG_INFO("server.loading", ">> Loaded Roleplay tables in {} ms", GetMSTimeDiffToNow(oldMSTime));
}

#pragma region CREATURE
Expand Down Expand Up @@ -704,7 +704,7 @@ void Roleplay::LoadCustomNpcs()
++count;
} while (result->NextRow());

TC_LOG_INFO("server.loading", ">> Loaded %u custom npcs in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
TC_LOG_INFO("server.loading", ">> Loaded {} custom npcs in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
}

void Roleplay::CreateCustomNpcFromPlayer(Player* player, std::string const& key)
Expand Down
103 changes: 6 additions & 97 deletions src/server/scripts/Commands/cs_npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ class npc_commandscript : public CommandScript
{ "follow", HandleNpcFollowCommand, rbac::RBAC_PERM_COMMAND_NPC_FOLLOW, Console::No },
{ "follow stop", HandleNpcUnFollowCommand, rbac::RBAC_PERM_COMMAND_NPC_FOLLOW, Console::No },
{ "evade", HandleNpcEvadeCommand, rbac::RBAC_PERM_COMMAND_NPC_EVADE, Console::No },
{ "go", HandleNpcGoCommand, rbac::RBAC_PERM_COMMAND_NPC_MOVE, Console::No },
{ "showloot", HandleNpcShowLootCommand, rbac::RBAC_PERM_COMMAND_NPC_SHOWLOOT, Console::No },
};
static ChatCommandTable commandTable =
Expand Down Expand Up @@ -1366,10 +1365,8 @@ class npc_commandscript : public CommandScript
return true;
}

static bool HandleNpcSetScaleCommand(ChatHandler* handler, const char* args)
static bool HandleNpcSetScaleCommand(ChatHandler* handler, float scale)
{
if (!*args)
return false;

Creature* creature = handler->getSelectedCreature();
if (!creature)
Expand All @@ -1379,8 +1376,6 @@ class npc_commandscript : public CommandScript
return false;
}

float scale = (float)atof((char*)args);

if (scale <= 0.0f)
{
scale = creature->GetCreatureTemplate()->scale;
Expand All @@ -1398,11 +1393,8 @@ class npc_commandscript : public CommandScript
}

// npc set aura
static bool HandleNpcSetAuraCommand(ChatHandler* handler, char const* args)
static bool HandleNpcSetAuraCommand(ChatHandler* handler, SpellInfo const* spellInfo)
{
if (!*args)
return false;


Creature* target = handler->getSelectedCreature();
ObjectGuid::LowType guidLow = UI64LIT(0);
Expand All @@ -1414,7 +1406,7 @@ class npc_commandscript : public CommandScript
return false;
}

uint32 spellId = handler->extractSpellIdFromLink((char*)args);
uint32 spellId = spellInfo->Id;

if (spellId == 172036 || spellId == 142873 || spellId == 163465 ||
spellId == 187998 || spellId == 190430 || spellId == 190429 ||
Expand Down Expand Up @@ -1469,12 +1461,8 @@ class npc_commandscript : public CommandScript

}

static bool HandleNpcSetMountCommand(ChatHandler* handler, char const* args)
static bool HandleNpcSetMountCommand(ChatHandler* handler, uint32 mount)
{
if (!*args)
return false;

uint32 mount = atoi((char*)args);

Creature* target = handler->getSelectedCreature();
ObjectGuid::LowType guidLow = UI64LIT(0);
Expand Down Expand Up @@ -1512,12 +1500,8 @@ class npc_commandscript : public CommandScript
}

// npc set animkit
static bool HandleNpcSetAnimKitCommand(ChatHandler* handler, char const* args)
static bool HandleNpcSetAnimKitCommand(ChatHandler* handler, uint16 animkit)
{
if (!*args)
return false;

uint16 animkit = atoi((char*)args);

Creature* target = handler->getSelectedCreature();
ObjectGuid::LowType guidLow = UI64LIT(0);
Expand Down Expand Up @@ -1552,84 +1536,9 @@ class npc_commandscript : public CommandScript
return true;
}

//move selected creature
static bool HandleNpcGoCommand(ChatHandler* handler, char const* args)
{

if (!*args)
return false;

char const* xs = strtok((char*)args, " ");
char const* ys = strtok(NULL, " ");
char const* zs = strtok(NULL, " ");
char const* speeds = strtok(NULL, " ");

if (!xs || !ys || !zs || !speeds)
return false;

float x = 0;
float y = 0;
float z = 0;
float speed = 0;

x = atof(xs);
y = atof(ys);
z = atof(zs);
speed = atof(speeds);

ObjectGuid::LowType lowguid = UI64LIT(0);

Creature* creature = handler->getSelectedCreature();

if (!creature)
{
// number or [name] Shift-click form |color|Hcreature:creature_guid|h[name]|h|r
char* cId = handler->extractKeyFromLink((char*)args, "Hcreature");
if (!cId)
return false;

lowguid = atoull(cId);

// Attempting creature load from DB data
CreatureData const* data = sObjectMgr->GetCreatureData(lowguid);
if (!data)
{
handler->PSendSysMessage(LANG_COMMAND_CREATGUIDNOTFOUND, std::to_string(lowguid).c_str());
handler->SetSentErrorMessage(true);
return false;
}

uint32 map_id = data->spawnPoint.m_mapId;

if (handler->GetSession()->GetPlayer()->GetMapId() != map_id)
{
handler->PSendSysMessage(LANG_COMMAND_CREATUREATSAMEMAP, std::to_string(lowguid).c_str());
handler->SetSentErrorMessage(true);
return false;
}
}
else
{
lowguid = creature->GetSpawnId();
}

if (creature)
{
Position pos{ x, y, z };
creature->AI()->EnterEvadeMode();
creature->MonsterMoveWithSpeed(x, y, z, speed);
}

return true;
}

// npc set anim
static bool HandleNpcSetAnimCommand(ChatHandler* handler, char const* args)
static bool HandleNpcSetAnimCommand(ChatHandler* handler, uint32 emote)
{
if (!*args)
return false;

uint32 emote = atoi((char*)args);

Creature* target = handler->getSelectedCreature();
ObjectGuid::LowType guidLow = UI64LIT(0);
Expand Down
Loading

0 comments on commit ad715c3

Please sign in to comment.