Changed MythicPlus and MpDataStore to pure singletons and updated current

calling scripts to not get the instance just call via defined macro
This commit is contained in:
2024-08-31 23:17:52 -04:00
parent 87d748cef6
commit 2c8b67ef07
6 changed files with 163 additions and 62 deletions

View File

@@ -12,10 +12,13 @@ public:
}
void Creature_SelectLevel(const CreatureTemplate* /*creatureTemplate*/, Creature* creature) override {
}
void OnCreatureAddWorld(Creature* creature) override
{
MythicPlus* mp = MythicPlus::getInstance();
if(!mp->IsMapEligible(creature->GetMap())) {
if(!sMythicPlus->IsMapEligible(creature->GetMap())) {
return;
}
@@ -25,8 +28,7 @@ public:
creature->GetMap()->GetMapName()
);
MpDataStore* mpds = MpDataStore::getInstance();
mpds->AddInstanceCreatureData(
sMpDataStore->AddInstanceCreatureData(
creature->GetGUID(),
{
creature,
@@ -42,15 +44,13 @@ public:
void OnCreatureRemoveWorld(Creature* creature) override
{
MythicPlus* mp = MythicPlus::getInstance();
if(!mp->IsMapEligible(creature->GetMap())) {
if(!sMythicPlus->IsMapEligible(creature->GetMap())) {
return;
}
MpLogger::debug("AllCreatureScript::OnCreatureRemoveWorld({}, {})", creature->GetName(), creature->GetLevel());
MpDataStore* mpds = MpDataStore::getInstance();
mpds->RemoveInstanceCreatureData(creature->GetGUID());
sMpDataStore->RemoveInstanceCreatureData(creature->GetGUID());
MpLogger::debug("Removed creature {} from instance data for instance {}",
creature->GetName(),
@@ -60,8 +60,6 @@ public:
void OnAllCreatureUpdate(Creature* creature, uint32 /*diff*/) override
{
MythicPlus* mp = MythicPlus::getInstance();
// If the config is out of date and the creature was reset, run modify against it
// if (ResetCreatureIfNeeded(creature))
// {
@@ -78,32 +76,30 @@ public:
// }
}
bool UpdateCreature(Creature* creature)
{
MythicPlus* mp = MythicPlus::getInstance();
bool UpdateCreature(Creature* creature)
{
// make sure we have a creature and that it's assigned to a map
if (!creature || !creature->GetMap())
return false;
// 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 (!sMythicPlus->IsMapEligible(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 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 this is a non-relevant creature, skip
if (creature->IsCritter() || creature->IsTotem() || creature->IsTrigger())
return false;
if (creature->GetMap()->GetEntry()) {
if (creature->GetMap()->GetEntry()) {
}
}
return true;
}
return true;
}
};

View File

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

View File

@@ -8,10 +8,9 @@ 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
MP_DIFFICULTY_MYTHIC = 3,
MP_DIFFICULTY_LEGENDARY = 4,
MP_DIFFICULTY_ASCENDANT = 5
};
struct GroupData
@@ -48,6 +47,11 @@ private:
std::map<ObjectGuid, MapCreatureData>* instanceCreatureData;
public:
// ensure we only ever have one instance of this class
MpDataStore(const MpDataStore&) = delete;
MpDataStore& operator=(const MpDataStore&) = delete;
void AddGroupData(ObjectGuid guid, GroupData gd);
void RemoveGroupData(ObjectGuid guid);
@@ -62,11 +66,12 @@ public:
void AddInstanceCreatureData(ObjectGuid guid, MapCreatureData mcd);
void RemoveInstanceCreatureData(ObjectGuid guid);
static MpDataStore* getInstance() {
static MpDataStore* instance() {
static MpDataStore instance;
return &instance;
}
};
#endif // MYTHICPLUS_DATASTORE_H
#define sMpDataStore MpDataStore::instance()
#endif // MpDataStore_DATASTORE_H

View File

@@ -1,24 +1,60 @@
#ifndef MYTHICPLUS_H
#define MYTHICPLUS_H
#include "MapMgr.h"
#include "Log.h"
#include "Define.h"
#include <map>
#include <string>
class MythicPlus {
private:
MythicPlus();
~MythicPlus();
class MythicPlus
{
public:
bool Enabled = true;
bool IsMapEligible(Map* map);
static MythicPlus * getInstance() {
// accessor for this singleton
static MythicPlus* instance()
{
static MythicPlus instance;
return &instance;
}
// ensure we only ever have one instance of this class
MythicPlus(const MythicPlus&) = delete;
MythicPlus& operator=(const MythicPlus&) = delete;
// Methods to clear and load settings
void ClearSettings();
// Check if a map is eligible for Mythic+ modifications
bool IsMapEligible(Map* map);
// Global Settings
bool Enabled;
bool Debug;
bool EnableItemRewards;
bool EnableDeathLimits;
// Difficulty Modifiers
std::map<std::string, float> mythicDungeonModifiers;
std::map<std::string, float> mythicBossModifiers;
std::map<std::string, float> legendaryDungeonModifiers;
std::map<std::string, float> legendaryBossModifiers;
// Death Allowances
uint32 mythicDeathAllowance;
uint32 legendaryDeathAllowance;
uint32 ascendantDeathAllowance;
// Itemization Offsets
uint32 mythicItemOffset;
uint32 legendaryItemOffset;
uint32 ascendantItemOffset;
private:
MythicPlus() { }
~MythicPlus() { }
};
#endif
#define sMythicPlus MythicPlus::instance()
#endif // MYTHICPLUS_H

View File

@@ -7,15 +7,28 @@ class MythicPlus_UnitScript : public UnitScript
public:
MythicPlus_UnitScript() : UnitScript("MythicPlus_UnitScript", true) { }
uint32 DealDamage(Unit* /*AttackerUnit*/, Unit* /*playerVictim*/, uint32 damage, DamageEffectType /*damagetype*/) override {
return damage;
}
void ModifyPeriodicDamageAurasTick(Unit* /*target */, Unit* /*attacker*/, uint32& /*damage*/, SpellInfo const* /*spellInfo*/) override {
}
void ModifySpellDamageTaken(Unit* /*target*/, Unit* /*attacker*/, int32& /*damage*/, SpellInfo const* /*spellInfo*/) override {
}
void ModifyMeleeDamage(Unit* /*target*/, Unit* /*attacker*/, uint32& /*damage*/) override {
}
void ModifyHealReceived(Unit* /*target*/, Unit* /*attacker*/, uint32& /*damage*/, SpellInfo const* /*spellInfo*/) override {
}
void OnAuraApply(Unit* unit, Aura* aura) override {
}
};
void Add_MP_UnitScripts()
{
MpLogger::debug("Add_MP_UnitScripts()");
new MythicPlus_UnitScript();
}

View File

@@ -1,4 +1,5 @@
#include "Config.h"
#include "MythicPlus.h"
#include "MpLogger.h"
#include "Player.h"
#include "ScriptMgr.h"
@@ -21,9 +22,61 @@ public:
void SetInitialWorldSettings()
{
// sMythicPlus->configValue = sConfigMgr->GetOption<float>("MythicPlus.ConfigValue", 1.0f, false);
// Clear existing data
sMythicPlus->mythicDungeonModifiers.clear();
sMythicPlus->mythicBossModifiers.clear();
// Global Settings
sMythicPlus->Enabled = sConfigMgr->GetOption<bool>("MythicPlus.Enabled", 1);
sMythicPlus->Debug = sConfigMgr->GetOption<bool>("MythicPlus.Debug", 0);
sMythicPlus->EnableItemRewards = sConfigMgr->GetOption<bool>("MythicPlus.EnableItemRewards", 1);
sMythicPlus->EnableDeathLimits = sConfigMgr->GetOption<bool>("MythicPlus.EnableDeathLimits", 1);
// Mythic Difficulty Modifiers
sMythicPlus->mythicDungeonModifiers = {
{"DungeonHealth", sConfigMgr->GetOption<float>("MythicPlus.Mythic.DungeonHealth", 1.25f)},
{"DungeonMelee", sConfigMgr->GetOption<float>("MythicPlus.Mythic.DungeonMelee", 1.25f)},
{"DungeonSpell", sConfigMgr->GetOption<float>("MythicPlus.Mythic.DungeonSpell", 1.15f)},
{"DungeonArmor", sConfigMgr->GetOption<float>("MythicPlus.Mythic.DungeonArmor", 1.25f)},
{"DungeonAvgLevel", sConfigMgr->GetOption<uint32>("MythicPlus.Mythic.DungeonAvgLevel", 83)}
};
sMythicPlus->mythicBossModifiers = {
{"DungeonBossHealth", sConfigMgr->GetOption<float>("MythicPlus.Mythic.DungeonBossHealth", 1.50f)},
{"DungeonBossMelee", sConfigMgr->GetOption<float>("MythicPlus.Mythic.DungeonBossMelee", 1.35f)},
{"DungeonBossSpell", sConfigMgr->GetOption<float>("MythicPlus.Mythic.DungeonBossSpell", 1.25f)},
{"DungeonBossArmor", sConfigMgr->GetOption<float>("MythicPlus.Mythic.DungeonBossArmor", 1.35f)},
{"DungeonBossLevel", sConfigMgr->GetOption<uint32>("MythicPlus.Mythic.DungeonBossLevel", 85)}
};
// Legendary Difficulty Modifiers
sMythicPlus->legendaryDungeonModifiers = {
{"DungeonHealth", sConfigMgr->GetOption<float>("MythicPlus.Legendary.DungeonHealth", 2.25f)},
{"DungeonMelee", sConfigMgr->GetOption<float>("MythicPlus.Legendary.DungeonMelee", 2.25f)},
{"DungeonSpell", sConfigMgr->GetOption<float>("MythicPlus.Legendary.DungeonSpell", 2.25f)},
{"DungeonArmor", sConfigMgr->GetOption<float>("MythicPlus.Legendary.DungeonArmor", 2.25f)},
{"DungeonAvgLevel", sConfigMgr->GetOption<uint32>("MythicPlus.Legendary.DungeonAvgLevel", 85)}
};
sMythicPlus->legendaryBossModifiers = {
{"DungeonBossHealth", sConfigMgr->GetOption<float>("MythicPlus.Legendary.DungeonBossHealth", 2.25f)},
{"DungeonBossMelee", sConfigMgr->GetOption<float>("MythicPlus.Legendary.DungeonBossMelee", 2.25f)},
{"DungeonBossSpell", sConfigMgr->GetOption<float>("MythicPlus.Legendary.DungeonBossSpell", 2.25f)},
{"DungeonBossArmor", sConfigMgr->GetOption<float>("MythicPlus.Legendary.DungeonBossArmor", 3.25f)},
{"DungeonBossLevel", sConfigMgr->GetOption<uint32>("MythicPlus.Legendary.DungeonBossLevel", 87)}
};
// Death Allowances
sMythicPlus->mythicDeathAllowance = sConfigMgr->GetOption<uint32>("MythicPlus.Mythic.DeathAllowance", 1000);
sMythicPlus->legendaryDeathAllowance = sConfigMgr->GetOption<uint32>("MythicPlus.Legendary.DeathAllowance", 30);
sMythicPlus->ascendantDeathAllowance = sConfigMgr->GetOption<uint32>("MythicPlus.Ascendant.DeathAllowance", 15);
// Itemization Offsets
sMythicPlus->mythicItemOffset = sConfigMgr->GetOption<uint32>("MythicPlus.Mythic.ItemOffset", 20000000);
sMythicPlus->legendaryItemOffset = sConfigMgr->GetOption<uint32>("MythicPlus.Legendary.ItemOffset", 21000000);
sMythicPlus->ascendantItemOffset = sConfigMgr->GetOption<uint32>("MythicPlus.Ascendant.ItemOffset", 22000000);
}
};
void Add_MP_WorldScripts()