Refactored scripts and Creature data

This commit is contained in:
2024-11-29 15:25:38 -05:00
parent ccf222ec4f
commit fa6f3f3eab
14 changed files with 130 additions and 19 deletions

66
src/MpScheduler.h Normal file
View File

@@ -0,0 +1,66 @@
#ifndef MYTHICPLUS_SCHEDULER_H
#define MYTHICPLUS_SCHEDULER_H
#include "MpLogger.h"
#include "ScriptMgr.h"
#include "TaskScheduler.h"
#include <chrono>
enum MP_SCHEDULE_GROUP {
MP_WORLD_TASK_GROUP = 100
};
/**
* Global scheduler specifically for handling events fired inside of mythic
* scripts
*/
class MpScheduler
{
public:
static MpScheduler* instance ()
{
static MpScheduler instance;
return &instance;
}
MpScheduler(const MpScheduler&) = delete;
MpScheduler& operator=(const MpScheduler&) = delete;
TaskScheduler& GetWorldScheduler() {
return _worldScheduler;
}
void StartScheduler() {
MpLogger::info("Starting World Scheduler");
_worldScheduler.Schedule(1s, [&](TaskContext ctx) {
MpLogger::info("Insidie world scheduler");
return;
});
}
void ScheduleWorldTask(std::chrono::nanoseconds const& time, std::function<void (TaskContext)> task) {
_worldScheduler.Schedule(time, MP_WORLD_TASK_GROUP, task);
}
private:
MpScheduler() {}
~MpScheduler() {}
TaskScheduler _worldScheduler;
};
#define sMpScheduler MpScheduler::instance()
#endif // MYTHICPLUS_SCHEDULER_H
// Attach the world scheduler to listen to world events
class MpScheduler_WorldScript : public WorldScript
{
public:
MpScheduler_WorldScript() : WorldScript("MpScheduler_GlobalScript") { }
void OnUpdate(uint32 diff) override {
sMpScheduler->GetWorldScheduler().Update(diff);
}
};

View File

@@ -1,10 +1,19 @@
#include "Instances/Ragefire/boss_bazzalan.cpp"
#include "MpScheduler.h"
#include "MpLogger.h"
// Creature Overrides
enum {
RAGEFIRE_BAZZALAN = 11519
};
// This adds schedulers for use across scripts scoped to MythicPlus
void Add_MP_Schedulers()
{
MpLogger::debug("Add_MP_Schedulers()");
new MpScheduler_WorldScript();
sMpScheduler->StartScheduler();
}
void Addmod_mythic_plusScripts();
void Add_MP_AllCreatureScripts();
void Add_MP_AllMapScripts();
@@ -15,9 +24,6 @@ void Add_MP_PlayerScripts();
void Add_MP_UnitScripts();
void Add_MP_WorldScripts();
// Mythic custom encounters for mythic+ dungeons
void Addmod_mythic_plusScripts()
{
Add_MP_AllCreatureScripts();
@@ -28,6 +34,7 @@ void Addmod_mythic_plusScripts()
Add_MP_PlayerScripts();
Add_MP_UnitScripts();
Add_MP_WorldScripts();
Add_MP_Schedulers();
// new Ragefire_Bazzalan_Mythic();

View File

@@ -1,5 +1,6 @@
#include "MpLogger.h"
#include "MpDataStore.h"
#include "MpScheduler.h"
#include "MythicPlus.h"
#include "Player.h"
#include "Group.h"
@@ -9,9 +10,9 @@
class MythicPlus_PlayerScript : public PlayerScript
{
public:
MythicPlus_PlayerScript() : PlayerScript("MythicPlus_PlayerScript") { }
MythicPlus_PlayerScript() : PlayerScript("MythicPlus_PlayerScript") {}
void OnPlayerKilledByCreature(Creature* killer, Player* player)
void OnPlayerKilledByCreature(Creature* killer, Player* player) override
{
Map* map = player->GetMap();
if(!sMythicPlus->IsMapEligible(map)) {
@@ -52,8 +53,6 @@ public:
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();
@@ -61,19 +60,39 @@ public:
return;
}
// map->RemoveAllPlayers();
for(auto it = players.begin(); it != players.end(); ++it)
{
Player* player = it->GetSource();
player->GetSession()->SendNotification("Your group has died too many time to continue. %u", totalDeaths);
Group* group = player->GetGroup();
if(!group) {
MpLogger::warn("Player {} is not in a group.", player->GetName());
return;
}
map->RemoveAllPlayers();
map->ToInstanceMap()->Reset(0);
// map->RemoveAllPlayers();
MpLogger::info("Starting scheduled failure notification");
sMpScheduler->ScheduleWorldTask(1s, [](TaskContext ctx) {
MpLogger::info("<<<<<<<<<<< Player Death Scheduler fire >>>>>>>>>>>>>");
});
// sMpScheduler->GetWorldScheduler().Schedule(1s, [playerName = player->GetName()](TaskContext ctx) {
// MpLogger::info("<<<<<<<<<<< Player Death Scheduler fire {} >>>>>>>>>>>>>", playerName);
// return;
// });
// std::vector<Player*> players = GetGroupMembers(player);
// MpLogger::info("Failed mythic+ instance run notification fired. ");
// WorldPacket data;
// for(Player* player : players)
// {
// MpLogger::info("Seding notification of failure to player: {}", player->GetName());
// player->GetSession()->SendShowBank(player->GetGUID());
// // player->GetSession()->SendNotification("Your group has died too many time to continue.");
// // ChatHandler::BuildChatPacket(data, CHAT_MSG_RAID_BOSS_EMOTE, LANG_UNIVERSAL, nullptr, player, message);
// // player->GetSession()->SendPacket(&data);
// }
// map->ToInstanceMap()->Reset(0);
// );
}
}
void OnSave(Player* player) {
return;
}
@@ -122,6 +141,25 @@ public:
sMpDataStore->DBUpdatePlayerInstanceData(player->GetGUID(), data->difficulty, map->GetId(), map->GetInstanceId());
sMpDataStore->DBUpdateGroupData(group->GetGUID(), data->difficulty, map->GetId(), map->GetInstanceId(), 0);
}
std::vector<Player*> GetGroupMembers(Player* currentPlayer)
{
std::vector<Player*> groupPlayers;
Group* group = currentPlayer->GetGroup();
if (!group)
{
MpLogger::warn("Player is not in a group.");
return groupPlayers;
}
group->DoForAllMembers([&](Player* member) {
groupPlayers.push_back(member);
});
return groupPlayers;
}
};
void Add_MP_PlayerScripts()