From 7d1a9018df51084ae4a212c966063e69a654c963 Mon Sep 17 00:00:00 2001 From: Ben Carter Date: Sat, 18 Jan 2025 11:29:21 -0500 Subject: [PATCH] Many changes to bring in the Advancement system for upgrading player stats via dice --- src/AdvancementMgr.cpp | 26 ++++++++++++++------------ src/AdvancementMgr.h | 7 ++++++- src/MpConstants.h | 3 ++- src/MpDataStore.h | 9 ++++++--- src/MpScheduler.h | 6 +++--- src/MpScriptAI.h | 6 +++--- src/MythicPlus_loader.cpp | 8 ++++---- 7 files changed, 38 insertions(+), 27 deletions(-) diff --git a/src/AdvancementMgr.cpp b/src/AdvancementMgr.cpp index f256d77..a4ecc7c 100644 --- a/src/AdvancementMgr.cpp +++ b/src/AdvancementMgr.cpp @@ -8,6 +8,7 @@ #include #include +#include /** * Table schema for upgrade ranks populated by go script: @@ -35,7 +36,7 @@ * This loads the ranks from the database and stores them into memory for access. This should only be * called on server start-up as it is static data that should only change no new builds. */ -int32 AdvancementMgr::LoadAdvencementRanks() { +int32 AdvancementMgr::LoadAdvancementRanks() { _advancementRanks.clear(); // @@ -127,6 +128,8 @@ int32 AdvancementMgr::LoadAdvencementRanks() { */ int32 AdvancementMgr::LoadPlayerAdvancements(Player* player) { + std::lock_guard lock(_playerAdvancementMutex); + constexpr std::string_view query = R"( SELECT guid, @@ -140,7 +143,7 @@ int32 AdvancementMgr::LoadPlayerAdvancements(Player* player) { QueryResult result = CharacterDatabase.Query(query, player->GetGUID().GetCounter()); - // If the player does not have any upgrades just return not a problem until they purchase one. + // If the player does not have any upgrades just return perfectly fine not a problem until they purchase one. if(!result) { return 0; } @@ -206,7 +209,7 @@ MpAdvancementRank* AdvancementMgr::GetAdvancementRank(uint32 rank, MpAdvancement } else { - MpLogger::error("Advancment Id {} and rank {} could not be found", rank, advancement); + MpLogger::error("Advancement Id {} and rank {} could not be found", rank, advancement); return nullptr; } } @@ -228,6 +231,8 @@ MpPlayerRank* AdvancementMgr::GetPlayerAdvancementRank(Player* player, MpAdvance bool AdvancementMgr::UpgradeAdvancement(Player* player, MpAdvancements advancement, uint32 diceCostLevel, uint32 itemEntry1, uint32 itemEntry2, uint32 itemEntry3) { + std::lock_guard lock(_playerAdvancementMutex); + // Validators to make sure inputs are correct to perform the upgrade if(!player) { MpLogger::error("Could not upgrade advancement for player, player was nullpointer"); @@ -238,7 +243,7 @@ bool AdvancementMgr::UpgradeAdvancement(Player* player, MpAdvancements advanceme return false; } if(itemEntry1 == 0) { - MpLogger::error("Material1 can not be 0 can not perform advancement upgrade for player {} Advancment {}", player->GetName(), advancement); + MpLogger::error("Material1 can not be 0 can not perform advancement upgrade for player {} Advancement {}", player->GetName(), advancement); return false; } @@ -286,20 +291,17 @@ bool AdvancementMgr::UpgradeAdvancement(Player* player, MpAdvancements advanceme return true; } -bool AdvancementMgr::ResetPlayerAdvancements(Player* player) +bool AdvancementMgr::ResetPlayerAdvancements(Player* /*player*/) { + std::lock_guard lock(_playerAdvancementMutex); + return true; } -/****************** - * - * Private Methods - * - ******************/ - void AdvancementMgr::_ResetPlayerAdvancement(Player* player, MpAdvancements advancement) { - + std::lock_guard lock(_playerAdvancementMutex); + return; } // Roll them stats DnD style. diff --git a/src/AdvancementMgr.h b/src/AdvancementMgr.h index 582bedf..2ca804f 100644 --- a/src/AdvancementMgr.h +++ b/src/AdvancementMgr.h @@ -7,8 +7,10 @@ #include #include #include +#include -enum MpAdvancements { +enum MpAdvancements +{ MP_ADV_STRENGTH = 0, MP_ADV_AGILITY = 1, MP_ADV_STAMINA = 2, @@ -72,6 +74,9 @@ struct MpPlayerRank class AdvancementMgr { +// Shared mutex for handling writes to shared player advancement data +std::mutex _playerAdvancementMutex; + // All advancement levels for each stat [rank][advancement_id] = AdvancementLevel std::map, MpAdvancementRank> _advancementRanks; diff --git a/src/MpConstants.h b/src/MpConstants.h index 37eae2b..944618f 100644 --- a/src/MpConstants.h +++ b/src/MpConstants.h @@ -2,7 +2,8 @@ #ifndef MP_CONSTANTS_H #define MP_CONSTANTS_H -namespace MpConstants { +namespace MpConstants +{ constexpr int ANCIENT_DICE = 911000; constexpr int DARK_SPIKE = 911001; } diff --git a/src/MpDataStore.h b/src/MpDataStore.h index 925cc0d..ed24b3e 100644 --- a/src/MpDataStore.h +++ b/src/MpDataStore.h @@ -15,7 +15,8 @@ #include #include -enum MpDifficulty { +enum MpDifficulty +{ MP_DIFFICULTY_NORMAL = 0, MP_DIFFICULTY_HEROIC = 1, MP_DIFFICULTY_EPIC = 2, @@ -26,7 +27,8 @@ enum MpDifficulty { class MpDataStore; -struct MpPlayerInstanceData { +struct MpPlayerInstanceData +{ uint32 deaths = 0; }; @@ -284,7 +286,8 @@ struct MpCreatureData /**@todo Add Affixes and Aura Spell methods */ }; -class MpDataStore { +class MpDataStore +{ private: MpDataStore() : _playerData(std::make_unique>()), diff --git a/src/MpScheduler.h b/src/MpScheduler.h index 987f8f4..a29d6b4 100644 --- a/src/MpScheduler.h +++ b/src/MpScheduler.h @@ -6,7 +6,8 @@ #include "TaskScheduler.h" #include -enum MP_SCHEDULE_GROUP { +enum MP_SCHEDULE_GROUP +{ MP_WORLD_TASK_GROUP = 100 }; @@ -25,8 +26,7 @@ enum MP_SCHEDULE_GROUP { class MpScheduler { public: - static MpScheduler* instance () - { + static MpScheduler* instance () { static MpScheduler instance; return &instance; } diff --git a/src/MpScriptAI.h b/src/MpScriptAI.h index ee1bb1b..6d8a413 100644 --- a/src/MpScriptAI.h +++ b/src/MpScriptAI.h @@ -1,6 +1,6 @@ #include "Creature.h" #include "CreatureAI.h" -#include "CreatureHooks.h" +// #include "CreatureHooks.h" #include "MpLogger.h" #include "MythicPlus.h" #include "ScriptMgr.h" @@ -27,12 +27,12 @@ public: } void JustDied(Unit* killer) override { - sCreatureHooks->JustDied(me->ToCreature(), killer); + // sCreatureHooks->JustDied(me->ToCreature(), killer); BaseAI::JustDied(killer); } void Reset() override { - sCreatureHooks->JustSpawned(me->ToCreature()); + // sCreatureHooks->JustSpawned(me->ToCreature()); BaseAI::Reset(); } diff --git a/src/MythicPlus_loader.cpp b/src/MythicPlus_loader.cpp index f160866..5525028 100755 --- a/src/MythicPlus_loader.cpp +++ b/src/MythicPlus_loader.cpp @@ -7,8 +7,7 @@ enum { }; // This adds schedulers for use across scripts scoped to MythicPlus -void Add_MP_Schedulers() -{ +void Add_MP_Schedulers() { MpLogger::debug("Add_MP_Schedulers()"); new MpScheduler_WorldScript(); } @@ -22,9 +21,9 @@ void Add_MP_GroupScripts(); void Add_MP_PlayerScripts(); void Add_MP_UnitScripts(); void Add_MP_WorldScripts(); +void Add_MP_PlayerMessageEvents(); -void Addmod_mythic_plusScripts() -{ +void Addmod_mythic_plusScripts() { Add_MP_AllCreatureScripts(); Add_MP_AllMapScripts(); Add_MP_CommandScripts(); @@ -34,6 +33,7 @@ void Addmod_mythic_plusScripts() Add_MP_UnitScripts(); Add_MP_WorldScripts(); Add_MP_Schedulers(); + Add_MP_PlayerMessageEvents(); // new Ragefire_Bazzalan_Mythic();