Building out data stores. Moved logging to standalone class.

This commit is contained in:
2024-08-05 22:19:46 -04:00
parent 0415c5ef41
commit 7446c676f2
12 changed files with 249 additions and 57 deletions

View File

@@ -1,6 +1,8 @@
#include "ScriptMgr.h"
#include "MythicPlus.h"
#include "MapMgr.h"
#include "MpDataStore.h"
#include "MpLogger.h"
#include "MythicPlus.h"
#include "ScriptMgr.h"
class MythicPlus_AllCreatureScript : public AllCreatureScript
{
@@ -17,8 +19,25 @@ public:
return;
}
mp->debug("OnCreatureAddWorld({}, {})", creature->GetName(), creature->GetLevel());
MpLogger::debug("OnCreatureAddWorld({}, {}) for instance {}",
creature->GetName(),
creature->GetLevel(),
creature->GetMap()->GetMapName()
);
MpDataStore* mpds = MpDataStore::getInstance();
mpds->AddInstanceCreatureData(
creature->GetGUID(),
{
creature,
const_cast<MapEntry*>(creature->GetMap()->GetEntry())
}
);
MpLogger::debug("Added creature {} to instance data for instance {}",
creature->GetName(),
creature->GetMap()->GetMapName()
);
}
void OnCreatureRemoveWorld(Creature* creature) override
@@ -28,15 +47,15 @@ public:
return;
}
// if (creature->GetMap()->IsDungeon() || creature->GetMap()->IsRaid())
// LOG_DEBUG("module.MythicPlus",
// "MythicPlus_AllCreatureScript::OnCreatureRemoveWorld(): {} ({})",
// creature->GetName(),
// creature->GetLevel()
// );
MpLogger::debug("AllCreatureScript::OnCreatureRemoveWorld({}, {})", creature->GetName(), creature->GetLevel());
// // remove the creature from the map's tracking list, if present
// sMythicPlus->RemoveCreatureFromMapData(creature);
MpDataStore* mpds = MpDataStore::getInstance();
mpds->RemoveInstanceCreatureData(creature->GetGUID());
MpLogger::debug("Removed creature {} from instance data for instance {}",
creature->GetName(),
creature->GetMap()->GetMapName()
);
}
void OnAllCreatureUpdate(Creature* creature, uint32 /*diff*/) override
@@ -59,12 +78,37 @@ public:
// }
}
bool UpdateCreature(Creature* creature)
{
MythicPlus* mp = MythicPlus::getInstance();
// make sure we have a creature and that it's assigned to a map
if (!creature || !creature->GetMap())
return false;
// if this isn't a dungeon or a battleground, make no changes
if (!mp->IsMapEligible(creature->GetMap()))
return false;
// if this is a pet or summon controlled by the player, make no changes
if ((creature->IsHunterPet() || creature->IsPet() || creature->IsSummon()) && creature->IsControlledByPlayer())
return false;
// if this is a non-relevant creature, skip
if (creature->IsCritter() || creature->IsTotem() || creature->IsTrigger())
return false;
if (creature->GetMap()->GetEntry()) {
}
return true;
}
};
void Add_MP_AllCreatureScripts()
{
static MythicPlus* mp = MythicPlus::getInstance();
mp->debug("Add_MP_AllCreatureScripts()");
MpLogger::debug("Add_MP_AllCreatureScripts()");
new MythicPlus_AllCreatureScript();
}

View File

@@ -1,9 +1,10 @@
#include "ScriptMgr.h"
#include "Log.h"
#include "Player.h"
#include "MythicPlus.h"
#include "Chat.h"
#include "Log.h"
#include "MapMgr.h"
#include "MpLogger.h"
#include "MythicPlus.h"
#include "Player.h"
#include "ScriptMgr.h"
class MythicPlus_AllMapScript : public AllMapScript
{
@@ -15,7 +16,7 @@ public:
void OnCreateMap(Map* map)
{
static MythicPlus* mp = MythicPlus::getInstance();
mp->debug("AllMapScript::OnCreateMap(): {}", map->GetMapName());
MpLogger::debug("AllMapScript::OnCreateMap(): {}", map->GetMapName());
if (!mp->IsMapEligible(map)) {
return;
@@ -27,7 +28,7 @@ public:
void OnPlayerEnterAll(Map* map, Player* player)
{
static MythicPlus* mp = MythicPlus::getInstance();
mp->debug("AllMapScript::OnPlayerEnterAll(): {}", map->GetMapName());
MpLogger::debug("AllMapScript::OnPlayerEnterAll(): {}", map->GetMapName());
if (!mp->IsMapEligible(map)) {
return;
@@ -38,7 +39,7 @@ public:
void OnPlayerLeaveAll(Map* map, Player* player)
{
static MythicPlus* mp = MythicPlus::getInstance();
mp->debug("AllMapScript::OnPlayerLeaveAll(): {}", map->GetMapName());
MpLogger::debug("AllMapScript::OnPlayerLeaveAll(): {}", map->GetMapName());
if (!mp->IsMapEligible(map)) {
return;
@@ -50,7 +51,6 @@ public:
void Add_MP_AllMapScripts()
{
static MythicPlus* mp = MythicPlus::getInstance();
mp->debug("Add_MP_AllMapScripts()");
MpLogger::debug("Add_MP_AllMapScripts()");
new MythicPlus_AllMapScript();
}

View File

@@ -1,4 +1,4 @@
#include "MythicPlus.h"
#include "MpLogger.h"
#include "ScriptMgr.h"
// make sure this is the new way to do this, i think it's the old busted shit
@@ -15,7 +15,5 @@ public:
void Add_MP_CommandScripts()
{
static MythicPlus* mp = MythicPlus::getInstance();
mp->debug("Add_MP_CommandScripts()");
MpLogger::debug("Add_MP_CommandScripts()");
}

View File

@@ -1,4 +1,4 @@
#include "MythicPlus.h"
#include "MpLogger.h"
#include "ScriptMgr.h"
class MythicPlus_GlobalScript : public GlobalScript
@@ -27,7 +27,6 @@ public:
void Add_MP_GlobalScripts()
{
static MythicPlus* mp = MythicPlus::getInstance();
mp->debug("Add_MP_GlobalScripts()");
MpLogger::debug("Add_MP_GlobalScripts()");
new MythicPlus_GlobalScript();
}

View File

@@ -1,6 +1,7 @@
#include "MpDataStore.h"
#include "MpLogger.h"
#include "ScriptMgr.h"
#include "MythicPlus.h"
// this handles updating custom group difficulties used in auto balancing mobs and
// scripts that enable buffs on mobs randomly
@@ -18,6 +19,9 @@ class MythicPlus_GroupScript : public GroupScript
return;
}
MpDataStore* mpds = MpDataStore::getInstance();
GroupData gd = { group, MP_DIFFICULTY_NORMAL };
mpds->AddGroupData(group->GetGUID(), gd);
}
void OnDisband(Group* group) override {
@@ -25,12 +29,13 @@ class MythicPlus_GroupScript : public GroupScript
return;
}
MpDataStore* mpds = MpDataStore::getInstance();
mpds->RemoveGroupData(group->GetGUID());
}
};
void Add_MP_GroupScripts()
{
static MythicPlus* mp = MythicPlus::getInstance();
mp->debug("Add_MP_GroupScripts()");
MpLogger::debug("Add_MP_GroupScripts()");
new MythicPlus_GroupScript();
}

51
src/MpDataStore.cpp Normal file
View File

@@ -0,0 +1,51 @@
#include "MpDataStore.h"
#include "MpLogger.h"
MpDataStore::MpDataStore() {
// constructor
}
MpDataStore::~MpDataStore() {
// destructor
}
void MpDataStore::AddGroupData(ObjectGuid guid, GroupData gd) {
MpLogger::debug("Adding group data for group %u", guid.GetCounter());
groupData[guid] = gd;
}
void MpDataStore::RemoveGroupData(ObjectGuid guid) {
MpLogger::debug("Removing group data for group %u", guid.GetCounter());
groupData.erase(guid);
}
void MpDataStore::AddPlayerData(ObjectGuid guid, PlayerData pd) {
MpLogger::debug("Adding player data for player %u", guid.GetCounter());
playerData[guid] = pd;
}
void MpDataStore::RemovePlayerData(ObjectGuid guid) {
MpLogger::debug("Removing player data for player %u", guid.GetCounter());
playerData.erase(guid);
}
void MpDataStore::AddInstanceData(ObjectGuid guid, MapData md) {
MpLogger::debug("Adding instance data for instance %u", guid.GetCounter());
instanceData[guid] = md;
}
void MpDataStore::RemoveInstanceData(ObjectGuid guid) {
MpLogger::debug("Removing instance data for instance %u", guid.GetCounter());
instanceData.erase(guid);
}
void MpDataStore::AddInstanceCreatureData(ObjectGuid guid, MapCreatureData mcd) {
MpLogger::debug("Adding instance creature data for creature %u", guid.GetCounter());
instanceCreatureData[guid] = mcd;
}
void MpDataStore::RemoveInstanceCreatureData(ObjectGuid guid) {
MpLogger::debug("Removing instance creature data for creature %u", guid.GetCounter());
instanceCreatureData.erase(guid);
}

66
src/MpDataStore.h Normal file
View File

@@ -0,0 +1,66 @@
#ifndef MYTHICPLUS_DATASTORE_H
#define MYTHICPLUS_DATASTORE_H
#include "Group.h"
#include "MapMgr.h"
enum MpDifficulty {
MP_DIFFICULTY_NORMAL = 0,
MP_DIFFICULTY_HEROIC = 1,
MP_DIFFICULTY_EPIC = 2,
MP_DIFFICULTY_HEROIC_25 = 3,
MP_DIFFICULTY_MYTHIC = 4,
MP_DIFFICULTY_LEGENDARY = 8,
MP_DIFFICULTY_ASCENDANT = 12
};
struct GroupData
{
Group* group;
uint8 difficulty;
};
struct PlayerData
{
Player* player;
};
struct MapData
{
Map* instance;
};
struct MapCreatureData
{
Creature* creature;
MapEntry* instance;
};
class MpDataStore {
private:
MpDataStore();
~MpDataStore();
std::map<ObjectGuid, GroupData> groupData;
std::map<ObjectGuid, PlayerData> playerData;
std::map<ObjectGuid, MapData> instanceData;
std::map<ObjectGuid, MapCreatureData> instanceCreatureData;
public:
void AddGroupData(ObjectGuid guid, GroupData gd);
void RemoveGroupData(ObjectGuid guid);
void AddPlayerData(ObjectGuid guid, PlayerData pd);
void RemovePlayerData(ObjectGuid guid);
void AddInstanceData(ObjectGuid guid, MapData md);
void RemoveInstanceData(ObjectGuid guid);
void AddInstanceCreatureData(ObjectGuid guid, MapCreatureData mcd);
void RemoveInstanceCreatureData(ObjectGuid guid);
static MpDataStore * getInstance() {
static MpDataStore instance;
return &instance;
}
};
#endif // MYTHICPLUS_DATASTORE_H

38
src/MpLogger.h Normal file
View File

@@ -0,0 +1,38 @@
#ifndef MP_LOGGER_H
#define MP_LOGGER_H
#include "Log.h"
class MpLogger
{
public:
template<typename... Args>
static void debug(const char* fmt, Args&&... args) {
LOG_DEBUG("module.MythicPlus", "[MythicPlus] " + std::string(fmt), std::forward<Args>(args)...);
}
template<typename... Args>
void error(const char* fmt, Args&&... args) {
LOG_ERROR("module.MythicPlus", "[MythicPlus] " + std::string(fmt), std::forward<Args>(args)...);
}
template<typename... Args>
void info(const char* fmt, Args&&... args) {
LOG_INFO("module.MythicPlus", "[MythicPlus] " + std::string(fmt), std::forward<Args>(args)...);
}
template<typename... Args>
void warn(const char* fmt, Args&&... args) {
LOG_WARN("module.MythicPlus", "[MythicPlus] " + std::string(fmt), std::forward<Args>(args)...);
}
template<typename... Args>
void trace(const char* fmt, Args&&... args) {
LOG_TRACE("module.MythicPlus", "[MythicPlus] " + std::string(fmt), std::forward<Args>(args)...);
}
};
#endif // MP_LOGGER_H

View File

@@ -8,22 +8,16 @@ class MythicPlus {
private:
MythicPlus();
~MythicPlus();
public:
public:
bool Enabled = true;
bool Enabled = true;
bool IsMapEligible(Map* map);
bool IsMapEligible(Map* map);
// create a variadic function called `debug` that takes a string and a variadic number of arguments
template<typename... Args>
void debug(const char* fmt, Args&&... args) {
LOG_DEBUG("module.MythicPlus", "[MythicPlus] " + std::string(fmt), std::forward<Args>(args)...);
}
static MythicPlus * getInstance() {
static MythicPlus instance;
return &instance;
}
static MythicPlus * getInstance() {
static MythicPlus instance;
return &instance;
}
};

View File

@@ -1,6 +1,6 @@
#include "ScriptMgr.h"
#include "MythicPlus.h"
#include "MpLogger.h"
#include "Player.h"
#include "ScriptMgr.h"
class MythicPlus_PlayerScript : public PlayerScript
{
@@ -52,7 +52,6 @@ public:
void Add_MP_PlayerScripts()
{
static MythicPlus* mp = MythicPlus::getInstance();
mp->debug("Add_MP_PlayerScripts()");
MpLogger::debug("Add_MP_PlayerScripts()");
new MythicPlus_PlayerScript();
}

View File

@@ -1,6 +1,6 @@
#include "ScriptMgr.h"
#include "MythicPlus.h"
#include "MpLogger.h"
#include "Player.h"
#include "ScriptMgr.h"
class MythicPlus_UnitScript : public UnitScript
{
@@ -16,7 +16,6 @@ public:
void Add_MP_UnitScripts()
{
static MythicPlus* mp = MythicPlus::getInstance();
mp->debug("Add_MP_UnitScripts()");
MpLogger::debug("Add_MP_UnitScripts()");
new MythicPlus_UnitScript();
}

View File

@@ -1,7 +1,7 @@
#include "ScriptMgr.h"
#include "MythicPlus.h"
#include "Config.h"
#include "MpLogger.h"
#include "Player.h"
#include "ScriptMgr.h"
class MythicPlus_WorldScript : public WorldScript
{
@@ -28,7 +28,6 @@ public:
void Add_MP_WorldScripts()
{
static MythicPlus* mp = MythicPlus::getInstance();
mp->debug("Add_MP_WorldScripts()");
MpLogger::debug("Add_MP_WorldScripts()");
new MythicPlus_WorldScript();
}