mirror of
https://github.com/araxiaonline/mod-mythic-plus.git
synced 2026-06-13 03:02:24 -04:00
Added methods for saving group data to memory and the database
Also added some new commands
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
|
||||
#include "Chat.h"
|
||||
#include "MpDataStore.h"
|
||||
#include "MythicPlus.h"
|
||||
#include "MpLogger.h"
|
||||
#include "Player.h"
|
||||
#include "ScriptMgr.h"
|
||||
@@ -18,14 +20,16 @@ public:
|
||||
{
|
||||
static ChatCommandTable commandTableSet =
|
||||
{
|
||||
{"mythic", HandleSet, SEC_PLAYER, Console::No},
|
||||
{"", HandleSet, SEC_PLAYER, Console::No},
|
||||
{"mythic", HandleSetMythic, SEC_PLAYER, Console::No},
|
||||
{"3", HandleSetMythic, SEC_PLAYER, Console::No},
|
||||
};
|
||||
|
||||
static ChatCommandTable commandTableMain =
|
||||
{
|
||||
{"", HandleHelp, SEC_PLAYER, Console::No},
|
||||
{"status", HandleStatus, SEC_PLAYER, Console::Yes},
|
||||
{"set", commandTableSet}
|
||||
{"mythic",HandleSetMythic, SEC_PLAYER, Console::No},
|
||||
{"set", commandTableSet},
|
||||
};
|
||||
|
||||
static ChatCommandTable commandTable =
|
||||
@@ -44,29 +48,49 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleSet(ChatHandler* handler, const std::vector<std::string>& args)
|
||||
static bool HandleHelp(ChatHandler* handler, const std::vector<std::string>& /*args*/)
|
||||
{
|
||||
MpLogger::debug("HandleSet()");
|
||||
MpDataStore* mpds = MpDataStore::getInstance();
|
||||
const PlayerData* players = mpds->GetPlayerData();
|
||||
std::string helpText = "Mythic+ Commands:\n"
|
||||
" .mp status - show current global settings of Mythic+ mod\n"
|
||||
" .mp [mythic,legendary,ascendant] - Shortcode to set Mythic+ difficulty to level for your group. \n"
|
||||
" .mp set [mythic,legendary,ascendant] - Set Mythic+ difficulty to Mythic can also used (3,4,5)\n"
|
||||
" .mp [enable,disable] - enable or disable this mod\n"
|
||||
" .mp - Show this help message\n";
|
||||
handler->PSendSysMessage(helpText);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleSetMythic(ChatHandler* handler, const std::vector<std::string>& /*args*/)
|
||||
{
|
||||
Player* player = handler->GetSession()->GetPlayer();
|
||||
MpLogger::debug("HandleSet() player: {}", player->GetName());
|
||||
|
||||
mpds->SetPlayerDifficulty(player->GetGUID(), MP_DIFFICULTY_MYTHIC);
|
||||
if (!player->GetGroup()) {
|
||||
MpLogger::debug("HandleSetMythic() No Group for player: {}", player->GetName());
|
||||
handler->PSendSysMessage("You must be in a group to be able to set a Mythic+ difficulty.");
|
||||
return true;
|
||||
}
|
||||
|
||||
MpLogger::debug("HandleSetMythic() Set difficulty player: {}", player->GetName());
|
||||
|
||||
|
||||
|
||||
handler->SendSysMessage("Hello World from MythicPlus! ({})", args.size());
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleStatus(ChatHandler* handler)
|
||||
{
|
||||
MpLogger::debug("HandleStatus()");
|
||||
MpDataStore* mpds = MpDataStore::getInstance();
|
||||
const PlayerData* players = mpds->GetPlayerData();
|
||||
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");
|
||||
|
||||
|
||||
handler->SendSysMessage("Hello World from MythicPlus! ()");
|
||||
handler->PSendSysMessage(status);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
#include "MpDataStore.h"
|
||||
#include "MpLogger.h"
|
||||
#include "Player.h"
|
||||
|
||||
MpDataStore::MpDataStore() {
|
||||
// constructor
|
||||
@@ -10,14 +11,24 @@ MpDataStore::~MpDataStore() {
|
||||
// destructor
|
||||
}
|
||||
|
||||
void MpDataStore::AddGroupData(ObjectGuid guid, GroupData gd) {
|
||||
MpLogger::debug("AddGroupData for group {}", guid.GetCounter());
|
||||
groupData->insert({guid, gd});
|
||||
// Adds an entry for the group difficult to memory and updats database
|
||||
void MpDataStore::AddGroupData(Group *group, int8 difficulty) {
|
||||
ObjectGuid guid = group->GetGUID();
|
||||
|
||||
if (!guid) {
|
||||
MpLogger::error("AddGroupData called with invalid group GUID");
|
||||
return;
|
||||
}
|
||||
MpLogger::debug("Add Group difficulty for group {} to {}", guid.GetCounter());
|
||||
|
||||
CharacterDatabase.Execute("REPLACE INTO group_difficulty (guid, difficulty) VALUES ({},{}) ", guid.GetCounter(), difficulty);
|
||||
}
|
||||
|
||||
void MpDataStore::RemoveGroupData(ObjectGuid guid) {
|
||||
MpLogger::debug("RemoveGroupData for group {}", guid.GetCounter());
|
||||
groupData->erase(guid);
|
||||
void MpDataStore::RemoveGroupData(Group *group) {
|
||||
MpLogger::debug("RemoveGroupData for group {}", group->GetGUID().GetCounter());
|
||||
groupData->erase(group->GetGUID());
|
||||
|
||||
CharacterDatabase.Execute("DELETE FROM group_difficulty WHERE guid = {}) ", group->GetGUID().GetCounter());
|
||||
}
|
||||
|
||||
void MpDataStore::AddPlayerData(ObjectGuid guid, PlayerData pd) {
|
||||
@@ -25,15 +36,6 @@ void MpDataStore::AddPlayerData(ObjectGuid guid, PlayerData pd) {
|
||||
playerData->insert({guid, pd});
|
||||
}
|
||||
|
||||
const PlayerData* MpDataStore::GetPlayerData() {
|
||||
return playerData;
|
||||
}
|
||||
|
||||
void MpDataStore::SetPlayerDifficulty(ObjectGuid guid, uint8 difficulty) {
|
||||
MpLogger::debug("SetPlayerDifficulty for player {}", guid.GetCounter());
|
||||
playerData->at(guid).difficulty = difficulty;
|
||||
}
|
||||
|
||||
void MpDataStore::RemovePlayerData(ObjectGuid guid) {
|
||||
MpLogger::debug("RemovePlayerData for player {}", guid.GetCounter());
|
||||
playerData->erase(guid);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "Group.h"
|
||||
#include "MapMgr.h"
|
||||
#include "Player.h"
|
||||
|
||||
enum MpDifficulty {
|
||||
MP_DIFFICULTY_NORMAL = 0,
|
||||
@@ -52,13 +53,31 @@ public:
|
||||
MpDataStore(const MpDataStore&) = delete;
|
||||
MpDataStore& operator=(const MpDataStore&) = delete;
|
||||
|
||||
void AddGroupData(ObjectGuid guid, GroupData gd);
|
||||
void RemoveGroupData(ObjectGuid guid);
|
||||
const PlayerData* GetPlayerData(ObjectGuid guid) const {
|
||||
try {
|
||||
return &playerData->at(guid);
|
||||
} catch (const std::out_of_range& oor) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
const GroupData* GetGroupData(ObjectGuid guid) const {
|
||||
try {
|
||||
return &groupData->at(guid);
|
||||
} catch (const std::out_of_range& oor) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
const GroupData* GetGroupData(Player *player) const {
|
||||
return GetGroupData(player->GetGroup()->GetGUID());
|
||||
};
|
||||
|
||||
void AddGroupData(Group *group, int8 difficulty);
|
||||
void RemoveGroupData(Group *group);
|
||||
|
||||
void AddPlayerData(ObjectGuid guid, PlayerData pd);
|
||||
void RemovePlayerData(ObjectGuid guid);
|
||||
void SetPlayerDifficulty(ObjectGuid guid, uint8 difficulty);
|
||||
const PlayerData* GetPlayerData();
|
||||
void SetGroupDifficulty(ObjectGuid guid, uint8 difficulty);
|
||||
|
||||
void AddInstanceData(ObjectGuid guid, MapData md);
|
||||
void RemoveInstanceData(ObjectGuid guid);
|
||||
|
||||
@@ -12,27 +12,25 @@ public:
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void error(const char* fmt, Args&&... args) {
|
||||
static 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) {
|
||||
static 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) {
|
||||
static 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) {
|
||||
static void trace(const char* fmt, Args&&... args) {
|
||||
LOG_TRACE("module.MythicPlus", "[MythicPlus] " + std::string(fmt), std::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // MP_LOGGER_H
|
||||
|
||||
Reference in New Issue
Block a user