diff --git a/src/PlayerScript.cpp b/src/PlayerScript.cpp deleted file mode 100644 index cd38b3b..0000000 --- a/src/PlayerScript.cpp +++ /dev/null @@ -1,131 +0,0 @@ -#include "MpLogger.h" -#include "MpDataStore.h" -#include "MythicPlus.h" -#include "Player.h" -#include "Group.h" -#include "ScriptMgr.h" -#include "Chat.h" - -class MythicPlus_PlayerScript : public PlayerScript -{ -public: - MythicPlus_PlayerScript() : PlayerScript("MythicPlus_PlayerScript") { } - - void OnPlayerKilledByCreature(Creature* killer, Player* player) - { - Map* map = player->GetMap(); - if(!sMythicPlus->IsMapEligible(map)) { - return; - } - - if (!player) { - return; - } - - Group* group = player->GetGroup(); - if(!group) { - MpLogger::warn("Missing group data for player {}", player->GetName()); - return; - } - - MpGroupData *data = sMpDataStore->GetGroupData(player->GetGroup()); - if (!data) { - MpLogger::warn("Missin group data for player {}", player->GetName()); - return; - } - - MpPlayerData *playerData = sMpDataStore->GetPlayerData(player->GetGUID()); - if (!playerData) { - MpLogger::warn("Missin player data for player {}", player->GetName()); - return; - } - - playerData->AddDeath(map->GetId(), map->GetInstanceId()); - - if(killer) { - sMpDataStore->DBAddPlayerDeath(player, killer, data->difficulty); - } else { - sMpDataStore->DBAddPlayerDeath(player); - } - - sMpDataStore->DBAddGroupDeath(group, player->GetMapId(), player->GetInstanceId(), data->difficulty); - - uint32 totalDeaths = data->GetDeaths(player->GetMapId(), player->GetInstanceId()); - if(totalDeaths > 1) { - // kick the group out of the instance - - Map* map = player->GetMap(); - Map::PlayerList players = map->GetPlayers(); - - if(!map || players.IsEmpty()) { - return; - } - - // map->RemoveAllPlayers(); - for(auto it = players.begin(); it != players.end(); ++it) - { - Player* player = it->GetSource(); - ChatHandler(player->GetSession()).PSendSysMessage("Your group has died too many time to continue. %u", totalDeaths); - } - map->RemoveAllPlayers(); - map->ToInstanceMap()->Reset(0); - } - - } - - void OnSave(Player* player) { - - } - - // When a player is bound to an instance need to make sure they are saved in the data soure to retrieve later. - void OnBindToInstance(Player* player, Difficulty /*difficulty*/, uint32 mapId, bool /*permanent*/) override - { - if(!player) { - return; - } - - Group* group = player->GetGroup(); - - // If they are not in a group do nothing. - if(!group) { - return; - } - - MpGroupData* data = sMpDataStore->GetGroupData(group); - - // If there is not any mythic+ data set for this group do nothing. - if(!data) { - return; - } - - Map* map = player->GetMap(); - if(!map) { - MpLogger::warn("Player {} is not in a map", player->GetName()); - return; - } - - // get the player data or set it up - MpPlayerData* playerData = sMpDataStore->GetPlayerData(player->GetGUID()); - if(!playerData) { - playerData = new MpPlayerData(player, data->difficulty, group->GetGUID().GetCounter()); - sMpDataStore->AddPlayerData(player->GetGUID(), playerData); - } - - // Add this players data to the group data - data->AddPlayerData(playerData); - - auto mapKey = sMpDataStore->GetInstanceDataKey(mapId, player->GetInstanceId()); - playerData->instanceData.emplace(mapKey, MpPlayerInstanceData{ - .deaths = 0, - }); - - sMpDataStore->DBUpdatePlayerInstanceData(player->GetGUID(), data->difficulty, map->GetId(), map->GetInstanceId()); - sMpDataStore->DBUpdateGroupData(group->GetGUID(), data->difficulty, map->GetId(), map->GetInstanceId(), 0); - } -}; - -void Add_MP_PlayerScripts() -{ - MpLogger::debug("Add_MP_PlayerScripts()"); - new MythicPlus_PlayerScript(); -} diff --git a/src/Scripts/CommandScript.cpp b/src/Scripts/CommandScript.cpp index 1b9e4a1..64f376c 100644 --- a/src/Scripts/CommandScript.cpp +++ b/src/Scripts/CommandScript.cpp @@ -1,5 +1,6 @@ #include "Chat.h" +#include "AdvancementMgr.h" #include "MpDataStore.h" #include "MythicPlus.h" #include "MpDataStore.h" @@ -38,7 +39,8 @@ public: {"mp", commandTableMain}, {"mythicplus", commandTableMain}, {"mp debug", HandleDebug, SEC_PLAYER, Console::No}, - {"mp reload", HandleReload, SEC_GAMEMASTER, Console::No} + {"mp reload", HandleReload, SEC_GAMEMASTER, Console::No}, + {"advancement", HandleAdvancement, SEC_PLAYER, Console::No} }; return commandTable; @@ -186,14 +188,11 @@ public: Map* map = player->GetMap(); uint32 mapId = player->GetMapId(); - std::string status = Acore::StringFormat( - "Mythic+ Status:\n" - " Mythic+ Enabled: %s\n" - " Mythic+ Item Rewards: %s\n" - " Mythic+ DeathLimits: %s\n", - sMythicPlus->Enabled ? "Yes" : "No", - sMythicPlus->EnableItemRewards ? "Yes" : "No", - sMythicPlus->EnableDeathLimits ? "Yes" : "No"); + std::string status = Acore::StringFormat("Mythic+ Status:\n Mythic+ Enabled: {}\n Mythic+ Item Rewards: {}\n Mythic+ DeathLimits: {}\n", + std::string((sMythicPlus->Enabled) ? "Yes" : "No"), + std::string((sMythicPlus->EnableItemRewards) ? "Yes" : "No"), + std::string((sMythicPlus->EnableDeathLimits) ? "Yes" : "No") + ); if (player->GetGroup()) { auto groupData = sMpDataStore->GetGroupData(player->GetGroup()->GetGUID()); @@ -204,10 +203,7 @@ public: scaleFactors = sMpDataStore->GetScaleFactor(mapId, groupData->difficulty); } - status += Acore::StringFormat( - " Group Difficulty: %u\n" - " Group Deaths: %u\n" - " Scale FactorStr %s\n", + status += Acore::StringFormat(" Group Difficulty: {}\n Group Deaths: {}\n Scale FactorStr {}\n", (groupData->difficulty) ? groupData->difficulty : 0, (groupData->GetDeaths(player->GetMapId(), player->GetInstanceId())), scaleFactors.ToString() @@ -317,7 +313,7 @@ public: if(groupData) { uint32 value = std::stoi(args[0]); sMpDataStore->SetDamageScaleFactor(player->GetMapId(), groupData->difficulty, value); - handler->PSendSysMessage(Acore::StringFormat("Melee scale factor set to: %u", value)); + handler->PSendSysMessage(Acore::StringFormat("Melee scale factor set to: {}", value)); return true; } } @@ -345,7 +341,7 @@ public: if(groupData) { uint32 value = std::stoi(args[0]); sMpDataStore->SetSpellScaleFactor(player->GetMapId(), groupData->difficulty, value); - handler->PSendSysMessage(Acore::StringFormat("Spell scale factor set to: %u", value)); + handler->PSendSysMessage(Acore::StringFormat("Spell scale factor set to: {}", value)); return true; } } @@ -373,7 +369,7 @@ public: if(groupData) { uint32 value = std::stoi(args[0]); sMpDataStore->SetHealthScaleFactor(player->GetMapId(), groupData->difficulty, value); - handler->PSendSysMessage(Acore::StringFormat("Health scale factor set to: %u", value)); + handler->PSendSysMessage(Acore::StringFormat("Health scale factor set to: {}", value)); return true; } } @@ -382,6 +378,29 @@ public: return true; } + static bool HandleAdvancement(ChatHandler* handler) + { + Player* player = handler->GetSession()->GetPlayer(); + std::string message = ""; + + for(int i =0; i < MpAdvancements::MP_ADV_MAX; i++) { + MpPlayerRank* playerRank = sAdvancementMgr->GetPlayerAdvancementRank(player, static_cast(i)); + if(!playerRank) { + continue; + } + + message += Acore::StringFormat("Your Advancement Bonuses: \n {}: {} bonus: {}", MpAdvancementsToString(static_cast(i)), playerRank->rank, playerRank->bonus); + } + + if(message.empty()) { + message = "You have no advancements."; + } + + handler->PSendSysMessage(message); + + return true; + } + }; void Add_MP_CommandScripts() diff --git a/src/Scripts/PlayerScript.cpp b/src/Scripts/PlayerScript.cpp index 18793a6..306b7b8 100644 --- a/src/Scripts/PlayerScript.cpp +++ b/src/Scripts/PlayerScript.cpp @@ -116,9 +116,10 @@ public: void OnLogin(Player* player) override { + MpLogger::info("Player {} logged in", player->GetName()); + // Load the player advancement data for the player when they login - int32 size = sAdvancementMgr->LoadPlayerAdvancements(player); - MpLogger::info("Loaded {} player advancements for player {}", size, player->GetName()); + sAdvancementMgr->LoadPlayerAdvancements(player); } // When a player is bound to an instance need to make sure they are saved in the data soure to retrieve later.