Core/Scripts: Add BGScripts and new hooks

* OnBattlegroudStart
* OnBattlegroudEndReward
* OnBattlegroudUpdate
* OnBattlegroudAddPlayer
This commit is contained in:
Kargatum
2018-06-18 02:00:20 +07:00
parent a1794c6193
commit 049386b936
3 changed files with 68 additions and 0 deletions
@@ -281,6 +281,8 @@ void Battleground::Update(uint32 diff)
m_ResetStatTimer += diff; m_ResetStatTimer += diff;
PostUpdateImpl(diff); PostUpdateImpl(diff);
sScriptMgr->OnBattlegroudUpdate(this, diff);
} }
inline void Battleground::_CheckSafePositions(uint32 diff) inline void Battleground::_CheckSafePositions(uint32 diff)
@@ -581,6 +583,8 @@ inline void Battleground::_ProcessJoin(uint32 diff)
// Announce BG starting // Announce BG starting
if (sWorld->getBoolConfig(CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_ENABLE)) if (sWorld->getBoolConfig(CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_ENABLE))
sWorld->SendWorldText(LANG_BG_STARTED_ANNOUNCE_WORLD, GetName(), std::min(GetMinLevel(), (uint32)80), std::min(GetMaxLevel(), (uint32)80)); sWorld->SendWorldText(LANG_BG_STARTED_ANNOUNCE_WORLD, GetName(), std::min(GetMinLevel(), (uint32)80), std::min(GetMaxLevel(), (uint32)80));
sScriptMgr->OnBattlegroudStart(this);
} }
} }
} }
@@ -974,6 +978,8 @@ void Battleground::EndBattleground(TeamId winnerTeamId)
uint32 loser_kills = player->GetRandomWinner() ? BG_REWARD_LOSER_HONOR_LAST : BG_REWARD_LOSER_HONOR_FIRST; uint32 loser_kills = player->GetRandomWinner() ? BG_REWARD_LOSER_HONOR_LAST : BG_REWARD_LOSER_HONOR_FIRST;
uint32 winner_arena = player->GetRandomWinner() ? BG_REWARD_WINNER_ARENA_LAST : BG_REWARD_WINNER_ARENA_FIRST; uint32 winner_arena = player->GetRandomWinner() ? BG_REWARD_WINNER_ARENA_LAST : BG_REWARD_WINNER_ARENA_FIRST;
sScriptMgr->OnBattlegroudEndReward(this, player, winnerTeamId);
// Reward winner team // Reward winner team
if (bgTeamId == winnerTeamId) if (bgTeamId == winnerTeamId)
{ {
@@ -1253,6 +1259,8 @@ void Battleground::AddPlayer(Player* player)
PlayerAddedToBGCheckIfBGIsRunning(player); PlayerAddedToBGCheckIfBGIsRunning(player);
AddOrSetPlayerToCorrectBgGroup(player, teamId); AddOrSetPlayerToCorrectBgGroup(player, teamId);
sScriptMgr->OnBattlegroudAddPlayer(this, player);
// Log // Log
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS) #if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDetail("BATTLEGROUND: Player %s joined the battle.", player->GetName().c_str()); sLog->outDetail("BATTLEGROUND: Player %s joined the battle.", player->GetName().c_str());
+30
View File
@@ -57,6 +57,7 @@ template class ScriptRegistry<UnitScript>;
template class ScriptRegistry<AllCreatureScript>; template class ScriptRegistry<AllCreatureScript>;
template class ScriptRegistry<AllMapScript>; template class ScriptRegistry<AllMapScript>;
template class ScriptRegistry<MovementHandlerScript>; template class ScriptRegistry<MovementHandlerScript>;
template class ScriptRegistry<BGScript>;
#include "ScriptMgrMacros.h" #include "ScriptMgrMacros.h"
@@ -207,6 +208,7 @@ void ScriptMgr::Unload()
SCR_CLEAR(GroupScript); SCR_CLEAR(GroupScript);
SCR_CLEAR(GlobalScript); SCR_CLEAR(GlobalScript);
SCR_CLEAR(ModuleScript); SCR_CLEAR(ModuleScript);
SCR_CLEAR(BGScript);
#undef SCR_CLEAR #undef SCR_CLEAR
} }
@@ -276,6 +278,7 @@ void ScriptMgr::CheckIfScriptsInDatabaseExist()
!ScriptRegistry<AchievementCriteriaScript>::GetScriptById(sid) && !ScriptRegistry<AchievementCriteriaScript>::GetScriptById(sid) &&
!ScriptRegistry<PlayerScript>::GetScriptById(sid) && !ScriptRegistry<PlayerScript>::GetScriptById(sid) &&
!ScriptRegistry<GuildScript>::GetScriptById(sid) && !ScriptRegistry<GuildScript>::GetScriptById(sid) &&
!ScriptRegistry<BGScript>::GetScriptById(sid) &&
!ScriptRegistry<GroupScript>::GetScriptById(sid)) !ScriptRegistry<GroupScript>::GetScriptById(sid))
sLog->outErrorDb("Script named '%s' is assigned in database, but has no code!", (*itr).c_str()); sLog->outErrorDb("Script named '%s' is assigned in database, but has no code!", (*itr).c_str());
} }
@@ -1960,6 +1963,27 @@ void ScriptMgr::OnAfterArenaRatingCalculation(Battleground *const bg, int32 &win
FOREACH_SCRIPT(FormulaScript)->OnAfterArenaRatingCalculation(bg, winnerMatchmakerChange, loserMatchmakerChange, winnerChange, loserChange); FOREACH_SCRIPT(FormulaScript)->OnAfterArenaRatingCalculation(bg, winnerMatchmakerChange, loserMatchmakerChange, winnerChange, loserChange);
} }
// BGScript
void ScriptMgr::OnBattlegroudStart(Battleground* bg)
{
FOREACH_SCRIPT(BGScript)->OnBattlegroudStart(bg);
}
void ScriptMgr::OnBattlegroudEndReward(Battleground* bg, Player* player, TeamId winnerTeamId)
{
FOREACH_SCRIPT(BGScript)->OnBattlegroudEndReward(bg, player, winnerTeamId);
}
void ScriptMgr::OnBattlegroudUpdate(Battleground* bg, uint32 diff)
{
FOREACH_SCRIPT(BGScript)->OnBattlegroudUpdate(bg, diff);
}
void ScriptMgr::OnBattlegroudAddPlayer(Battleground* bg, Player* player)
{
FOREACH_SCRIPT(BGScript)->OnBattlegroudAddPlayer(bg, player);
}
AllMapScript::AllMapScript(const char* name) AllMapScript::AllMapScript(const char* name)
: ScriptObject(name) : ScriptObject(name)
{ {
@@ -2135,6 +2159,12 @@ GlobalScript::GlobalScript(const char* name)
ScriptRegistry<GlobalScript>::AddScript(this); ScriptRegistry<GlobalScript>::AddScript(this);
} }
BGScript::BGScript(char const* name)
: ScriptObject(name)
{
ScriptRegistry<BGScript>::AddScript(this);
}
ModuleScript::ModuleScript(const char* name) ModuleScript::ModuleScript(const char* name)
: ScriptObject(name) : ScriptObject(name)
{ {
+30
View File
@@ -1037,6 +1037,29 @@ class GlobalScript : public ScriptObject
virtual void OnAfterUpdateEncounterState(Map* /*map*/, EncounterCreditType /*type*/, uint32 /*creditEntry*/, Unit* /*source*/, Difficulty /*difficulty_fixed*/, DungeonEncounterList const* /*encounters*/, uint32 /*dungeonCompleted*/, bool /*updated*/) { } virtual void OnAfterUpdateEncounterState(Map* /*map*/, EncounterCreditType /*type*/, uint32 /*creditEntry*/, Unit* /*source*/, Difficulty /*difficulty_fixed*/, DungeonEncounterList const* /*encounters*/, uint32 /*dungeonCompleted*/, bool /*updated*/) { }
}; };
class BGScript : public ScriptObject
{
protected:
BGScript(const char* name);
public:
bool IsDatabaseBound() const { return false; }
// Start Battlegroud
virtual void OnBattlegroudStart(Battleground* /*bg*/) { }
// End Battleground
virtual void OnBattlegroudEndReward(Battleground* /*bg*/, Player* /*player*/, TeamId /*winnerTeamId*/) { }
// Update Battlegroud
virtual void OnBattlegroudUpdate(Battleground* /*bg*/, uint32 /*diff*/) { }
// Add Player in Battlegroud
virtual void OnBattlegroudAddPlayer(Battleground* /*bg*/, Player* /*player*/) { }
};
// this class can be used to be extended by Modules // this class can be used to be extended by Modules
// creating their own custom hooks inside module itself // creating their own custom hooks inside module itself
class ModuleScript : public ScriptObject class ModuleScript : public ScriptObject
@@ -1356,6 +1379,13 @@ class ScriptMgr
//void OnPlayerEnterAll(Map* map, Player* player); //void OnPlayerEnterAll(Map* map, Player* player);
//void OnPlayerLeaveAll(Map* map, Player* player); //void OnPlayerLeaveAll(Map* map, Player* player);
public: /* BGScript */
void OnBattlegroudStart(Battleground* bg);
void OnBattlegroudEndReward(Battleground* bg, Player* player, TeamId winnerTeamId);
void OnBattlegroudUpdate(Battleground* bg, uint32 diff);
void OnBattlegroudAddPlayer(Battleground* bg, Player* player);
private: private:
uint32 _scriptCount; uint32 _scriptCount;