From 3cf1e17c99028651a704f80488372b9da9b73b36 Mon Sep 17 00:00:00 2001 From: Ben Carter Date: Thu, 14 Nov 2024 00:07:36 -0500 Subject: [PATCH] Added more database storage of stats, timers, death and workign on final boss detection. --- src/MpDataStore.cpp | 88 ++++++++++++++++++++++++++++++++++++++------ src/MpDataStore.h | 13 ++++++- src/MythicPlus.cpp | 50 +++++++++++++++++++++++++ src/PlayerScript.cpp | 9 ++++- 4 files changed, 146 insertions(+), 14 deletions(-) diff --git a/src/MpDataStore.cpp b/src/MpDataStore.cpp index 93c2e1b..334ff87 100644 --- a/src/MpDataStore.cpp +++ b/src/MpDataStore.cpp @@ -126,6 +126,9 @@ void MpDataStore::RemoveGroupData(Group *group) { void MpDataStore::AddPlayerData(ObjectGuid guid, MpPlayerData pd) { MpLogger::debug("AddPlayerData for player {}", guid.GetCounter()); _playerData->emplace(guid, pd); + + // get the player + Player* player = ObjectAccessor::FindPlayer(guid); } void MpDataStore::UpdatePlayerData(ObjectGuid guid, MpPlayerData pd) { @@ -286,15 +289,78 @@ int32 MpDataStore::LoadScaleFactors() { return int32(_scaleFactors->size()); } -// Writes current player data about their current instance run -void MpDataStore::SavePlayerInstanceData(Player* player, MpPlayerData const* playerData) -{ - // CharacterDatabase.Execute("REPLACE INTO mp_character_instance (character_guid, difficulty, deaths, map_id, instance_id, group_id) VALUES ({},{},{},{},{},{}) ", - // player->GetGUID().GetCounter(), - // playerData->difficulty, - // playerData->deaths, - // playerData->mapId, - // playerData->instanceId, - // playerData->groupId - // ); +void MpDataStore::DBUpdatePlayerInstanceData(ObjectGuid playerGuid, MpDifficulty difficulty, uint32 mapId, uint32 instanceId, uint32 deaths) { + if (!playerGuid) { + MpLogger::error("DBAddPlayerData called with invalid playerData"); + return; + } + + CharacterDatabase.Execute("REPLACE INTO mp_player_instance_data (guid, mapId, instanceId, deaths) VALUES ({},{},{},{},{}) ", + playerGuid.GetCounter(), + difficulty, + mapId, + instanceId, + deaths + ); +} + +void MpDataStore::DBUpdatePlayerDeaths(ObjectGuid playerGuid, uint32 deaths) { + if (!playerGuid) { + MpLogger::error("DBUpdateDeaths called with invalid playerId"); + return; + } + + CharacterDatabase.Execute("UPDATE mp_player_instance_data SET deaths = {} WHERE guid = {}", + deaths, + playerGuid.GetCounter() + ); +} + +void MpDataStore::DBUpdateGroupData(ObjectGuid groupGuid, MpDifficulty difficulty, uint32 mapId, uint32 instanceId, uint32 deaths) { + if (!groupGuid) { + MpLogger::error("DBUpdateGroupData called with invalid groupGuid"); + return; + } + + CharacterDatabase.Execute("REPLACE INTO mp_group_data (guid, difficulty, mapId, instanceId, deaths) VALUES ({},{},{},{},{}) ", + groupGuid.GetCounter(), + difficulty, + mapId, + instanceId, + deaths + ); +} + +void MpDataStore::DBRemovePlayerData(ObjectGuid playerGuid) { + if (!playerGuid) { + MpLogger::error("DBRemovePlayerData called with invalid playerGuid"); + return; + } + + CharacterDatabase.Execute("DELETE FROM mp_player_instance_data WHERE guid = {} ", playerGuid.GetCounter()); +} + + +void MpDataStore::DBUpdateGroupTimerDeaths(ObjectGuid groupGuid, uint32 mapId, uint32 instanceId, uint32 timer, uint32 deaths) { + if (!groupGuid) { + MpLogger::error("DBUpdateGroupTimerDeaths called with invalid groupGuid"); + return; + } + + CharacterDatabase.Execute("REPLACE INTO mp_group_data (guid, mapId, instanceId, instanceTimer, deaths) VALUES ({},{},{},{},{}) ", + groupGuid.GetCounter(), + mapId, + instanceId, + timer, + deaths + ); +} + +void MpDataStore::DBRemoveGroupData(ObjectGuid groupGuid) { + if (!groupGuid) { + MpLogger::error("DBRemoveGroupData called with invalid groupGuid"); + return; + } + + CharacterDatabase.Execute("DELETE FROM mp_group_data WHERE guid = {} ", groupGuid.GetCounter()); } diff --git a/src/MpDataStore.h b/src/MpDataStore.h index d845e0c..253c6d9 100644 --- a/src/MpDataStore.h +++ b/src/MpDataStore.h @@ -38,7 +38,8 @@ struct MpPlayerData std::map,MpPlayerInstanceData> instanceData; MpPlayerData(Player* p, MpDifficulty diff, uint32_t groupId) - : player(p), difficulty(diff), groupId(groupId) {} + : player(p), difficulty(diff), groupId(groupId) { + } void AddDeath(uint32 mapId, uint32 instanceId) { auto key = std::make_pair(mapId, instanceId); @@ -77,9 +78,11 @@ struct MpGroupData Group* group; MpDifficulty difficulty; std::vector players; + MpDataStore* dataStore; MpGroupData() : group(nullptr), difficulty(MpDifficulty{}) { players.reserve(5); + dataStore = MpDataStore::instance(); } MpGroupData(Group* group, MpDifficulty difficulty) @@ -98,6 +101,8 @@ struct MpGroupData void ResetGroupDeaths(uint32 mapId, uint32 instanceId) { for (MpPlayerData* player : players) { player->ResetDeathCount(mapId, instanceId); + + } } @@ -374,6 +379,12 @@ public: int32 LoadScaleFactors(); // Database API calls + void DBUpdatePlayerInstanceData(ObjectGuid playerGuid, MpDifficulty difficulty, uint32 mapId = 0, uint32 instanceId = 0, uint32 deaths = 0); + void DBUpdatePlayerDeaths(ObjectGuid playerGuid, uint32 deaths); + void DBRemovePlayerData(ObjectGuid playerGuid); + void DBUpdateGroupData(ObjectGuid groupGuid, MpDifficulty difficulty, uint32 mapId, uint32 instanceId, uint32 deaths); + void DBUpdateGroupTimerDeaths(ObjectGuid groupGuid, uint32 mapId, uint32 instanceId, uint32 timer, uint32 deaths); + void DBRemoveGroupData(ObjectGuid groupGuid); void SavePlayerInstanceData(Player* player, MpPlayerData const* playerData); //SavePlayerDungeonStats(Group* group, MpGroupData const* groupData); diff --git a/src/MythicPlus.cpp b/src/MythicPlus.cpp index f673b2e..f98655b 100644 --- a/src/MythicPlus.cpp +++ b/src/MythicPlus.cpp @@ -476,6 +476,56 @@ int32 MythicPlus::ScaleHealSpell(SpellInfo const * spellInfo, uint32 heal, MpCre return int32(heal * scalingFactor * healMultiplier); } +static bool IsFinalBoss(Creature* creature) { + CreatureTemplate const* cInfo = creature->GetCreatureTemplate(); + std::array finalBosses = { + // --- WoW Classic --- + 11519, /* Bazzalan Ragefire */ + 639, /* Edwin VanCleef Deadmines */ + 3654, /* Mutanus the Devourer Wailing Caverns */ + 4275, /* Archmage Arugal Shadowfang Keep */ + 1716, /* Bazil Thredd Stockades */ + 4829, /* Aku'mai blackfathom Deeps */ + 7800, /* Mekgineer Thermaplugg Gnomeregan */ + 4421, /* Charlga Razorflank Razorfen Kraul */ + 4543, /* Bloodmage Thalnos Scarlet Monastery */ + 3975, /* Herod Scarlet Monastery */ + 3977, /* High Inquisitor Whitemane Scarlet Monastery */ + 7350, /* Amnennar the Coldbringer Razorfen Downs */ + 2748, /* Archaedas Uldaman */ + 7267, /* Chief Ukorz Sandscalp Zul'Farrak */ + 12201, /* Princess Theradras Maraudon */ + 5709, /* Shade of Eranikus Sunken Temple */ + 9019, /* Emperor Dagran Thaurissan Blackrock Depths */ + 9568, /* Overlord Wyrmthalak Lower Blackrock Spire */ + 10363, /* General Drakkisath Upper Blackrock Spire */ + 11492, /* alzzin the Wildshaper Dire Maul */ + 11496, /* Immol'thar Dire Maul */ + 11501, /* King Gordok Dire Maul */ + 1853, /* Darkmaster Gandling Scholomance */ + 10812, /* Grand Crusader Dathrohan Stratholme */ + 10440, /* Baron Rivendare Stratholme */ + + // --- The Burning Crusade --- + 18344, /* Nexus-Prince Shaffar - Mana-Tombs */ + 17942, /* Quagmirran - The Slave Pens */ + 17882, /* The Black Stalker - The Underbog */ + 17991, /* Rokmar the Crackler - The Slave Pens (Heroic) */ + 17977, /* Warp Splinter - The Botanica */ + 17881, /* Aeonus - The Black Morass */ + 18732, /* Grandmaster Vorpil - Shadow Labyrinth */ + 19221, /* Nethermancer Sepethrea - The Mechanar */ + 20885, /* Dalliah the Doomsayer - The Arcatraz */ + 17975, /* High Botanist Freywinn - The Botanica */ + 16808, /* Warchief Kargath Bladefist - The Shattered Halls */ + 18473, /* Talon King Ikiss - Sethekk Halls */ + 20912, /* Harbinger Skyriss - The Arcatraz */ + 22930, /* Akama - Black Temple */ + + // --- Wrath of the Lich King --- + + }; +} /** * Function is copied because was not accessible in core creature class diff --git a/src/PlayerScript.cpp b/src/PlayerScript.cpp index da67e2f..8d71947 100644 --- a/src/PlayerScript.cpp +++ b/src/PlayerScript.cpp @@ -44,7 +44,7 @@ public: MpPlayerData const * playerData = sMpDataStore->GetPlayerData(player->GetGUID()); if(playerData) { - sMpDataStore->SavePlayerInstanceData(player, playerData); + // sMpDataStore->SavePlayerInstanceData(player, playerData); } } @@ -88,7 +88,12 @@ public: .deaths = 0, }); - sMpDataStore->SavePlayerInstanceData(player,playerData); + sMpDataStore->DBUpdatePlayerInstanceData(player->GetGUID(), data->difficulty, map->GetId(), player->GetInstanceId(), 0); + + if(group->GetLeaderGUID() == player->GetGUID()) { + sMpDataStore->DBUpdateGroupData(group->GetGUID(), data->difficulty, map->GetId(), player->GetInstanceId(), 0); + } + } };