mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-02-28 22:45:55 +00:00
feat(Core/Hooks) Adds hooks for BG and Arena systems. (#23543)
This commit is contained in:
@@ -104,6 +104,16 @@ void ScriptMgr::OnBattlegroundCreate(Battleground* bg)
|
||||
CALL_ENABLED_HOOKS(AllBattlegroundScript, ALLBATTLEGROUNDHOOK_ON_BATTLEGROUND_CREATE, script->OnBattlegroundCreate(bg));
|
||||
}
|
||||
|
||||
bool ScriptMgr::CanAddGroupToMatchingPool(BattlegroundQueue* queue, GroupQueueInfo* group, uint32 poolPlayerCount, Battleground* bg, BattlegroundBracketId bracketId)
|
||||
{
|
||||
CALL_ENABLED_BOOLEAN_HOOKS(AllBattlegroundScript, ALLBATTLEGROUNDHOOK_CAN_ADD_GROUP_TO_MATCHING_POOL, !script->CanAddGroupToMatchingPool(queue, group, poolPlayerCount, bg, bracketId));
|
||||
}
|
||||
|
||||
bool ScriptMgr::GetPlayerMatchmakingRating(ObjectGuid playerGuid, BattlegroundTypeId bgTypeId, float& outRating)
|
||||
{
|
||||
CALL_ENABLED_BOOLEAN_HOOKS_WITH_DEFAULT_FALSE(AllBattlegroundScript, ALLBATTLEGROUNDHOOK_GET_PLAYER_MATCHMAKING_RATING, script->GetPlayerMatchmakingRating(playerGuid, bgTypeId, outRating));
|
||||
}
|
||||
|
||||
AllBattlegroundScript::AllBattlegroundScript(char const* name, std::vector<uint16> enabledHooks) :
|
||||
ScriptObject(name, ALLBATTLEGROUNDHOOK_END)
|
||||
{
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#ifndef SCRIPT_OBJECT_ALL_BATTLEGROUND_SCRIPT_H_
|
||||
#define SCRIPT_OBJECT_ALL_BATTLEGROUND_SCRIPT_H_
|
||||
|
||||
#include "ObjectGuid.h"
|
||||
#include "ScriptObject.h"
|
||||
#include <vector>
|
||||
|
||||
@@ -40,6 +41,8 @@ enum AllBattlegroundHook
|
||||
ALLBATTLEGROUNDHOOK_ON_BATTLEGROUND_END,
|
||||
ALLBATTLEGROUNDHOOK_ON_BATTLEGROUND_DESTROY,
|
||||
ALLBATTLEGROUNDHOOK_ON_BATTLEGROUND_CREATE,
|
||||
ALLBATTLEGROUNDHOOK_CAN_ADD_GROUP_TO_MATCHING_POOL,
|
||||
ALLBATTLEGROUNDHOOK_GET_PLAYER_MATCHMAKING_RATING,
|
||||
ALLBATTLEGROUNDHOOK_END
|
||||
};
|
||||
|
||||
@@ -47,6 +50,9 @@ enum BattlegroundBracketId : uint8;
|
||||
enum BattlegroundTypeId : uint8;
|
||||
enum TeamId : uint8;
|
||||
|
||||
class BattlegroundQueue;
|
||||
struct GroupQueueInfo;
|
||||
|
||||
class AllBattlegroundScript : public ScriptObject
|
||||
{
|
||||
protected:
|
||||
@@ -132,6 +138,34 @@ public:
|
||||
* @param bg Contains information about the Battleground
|
||||
*/
|
||||
virtual void OnBattlegroundCreate(Battleground* /*bg*/) { }
|
||||
|
||||
/**
|
||||
* @brief This hook runs before adding a group to the battleground matching pool
|
||||
*
|
||||
* Allows modules to filter groups based on custom criteria (e.g., MMR matching).
|
||||
* Called during FillPlayersToBG before each group is added to the SelectionPool.
|
||||
*
|
||||
* @param queue The battleground queue
|
||||
* @param group The group being considered for addition
|
||||
* @param poolPlayerCount Current number of players already in the selection pool
|
||||
* @param bg The battleground instance
|
||||
* @param bracketId The bracket ID
|
||||
* @return True to allow adding this group, false to skip it
|
||||
*/
|
||||
[[nodiscard]] virtual bool CanAddGroupToMatchingPool(BattlegroundQueue* /*queue*/, GroupQueueInfo* /*group*/, uint32 /*poolPlayerCount*/, Battleground* /*bg*/, BattlegroundBracketId /*bracketId*/) { return true; }
|
||||
|
||||
/**
|
||||
* @brief This hook allows modules to provide matchmaking rating for a player
|
||||
*
|
||||
* Modules implementing MMR systems can use this hook to provide player ratings
|
||||
* for use in matchmaking algorithms.
|
||||
*
|
||||
* @param playerGuid The player's GUID
|
||||
* @param bgTypeId The battleground type
|
||||
* @param outRating Reference to store the rating value
|
||||
* @return True if rating was provided, false otherwise
|
||||
*/
|
||||
[[nodiscard]] virtual bool GetPlayerMatchmakingRating(ObjectGuid /*playerGuid*/, BattlegroundTypeId /*bgTypeId*/, float& /*outRating*/) { return false; }
|
||||
};
|
||||
|
||||
// Compatibility for old scripts
|
||||
|
||||
@@ -44,6 +44,16 @@ void ScriptMgr::OnArenaStart(Battleground* bg)
|
||||
CALL_ENABLED_HOOKS(ArenaScript, ARENAHOOK_ON_ARENA_START, script->OnArenaStart(bg));
|
||||
}
|
||||
|
||||
bool ScriptMgr::OnBeforeArenaTeamMemberUpdate(ArenaTeam* team, Player* player, bool won, uint32 opponentMatchmakerRating, int32 matchmakerChange)
|
||||
{
|
||||
CALL_ENABLED_BOOLEAN_HOOKS(ArenaScript, ARENAHOOK_ON_BEFORE_TEAM_MEMBER_UPDATE, !script->OnBeforeArenaTeamMemberUpdate(team, player, won, opponentMatchmakerRating, matchmakerChange));
|
||||
}
|
||||
|
||||
bool ScriptMgr::CanSaveArenaStatsForMember(ArenaTeam* team, ObjectGuid playerGuid)
|
||||
{
|
||||
CALL_ENABLED_BOOLEAN_HOOKS(ArenaScript, ARENAHOOK_CAN_SAVE_ARENA_STATS_FOR_MEMBER, !script->CanSaveArenaStatsForMember(team, playerGuid));
|
||||
}
|
||||
|
||||
ArenaScript::ArenaScript(const char* name, std::vector<uint16> enabledHooks)
|
||||
: ScriptObject(name, ARENAHOOK_END)
|
||||
{
|
||||
|
||||
@@ -29,6 +29,8 @@ enum ArenaHook
|
||||
ARENAHOOK_CAN_SAVE_TO_DB,
|
||||
ARENAHOOK_ON_BEFORE_CHECK_WIN_CONDITION,
|
||||
ARENAHOOK_ON_ARENA_START,
|
||||
ARENAHOOK_ON_BEFORE_TEAM_MEMBER_UPDATE,
|
||||
ARENAHOOK_CAN_SAVE_ARENA_STATS_FOR_MEMBER,
|
||||
ARENAHOOK_END
|
||||
};
|
||||
|
||||
@@ -51,6 +53,10 @@ public:
|
||||
[[nodiscard]] virtual bool CanSaveToDB(ArenaTeam* /*team*/) { return true; }
|
||||
|
||||
virtual void OnArenaStart(Battleground* /* bg */) { };
|
||||
|
||||
[[nodiscard]] virtual bool OnBeforeArenaTeamMemberUpdate(ArenaTeam* /*team*/, Player* /*player*/, bool /*won*/, uint32 /*opponentMatchmakerRating*/, int32 /*matchmakerChange*/) { return false; }
|
||||
|
||||
[[nodiscard]] virtual bool CanSaveArenaStatsForMember(ArenaTeam* /*team*/, ObjectGuid /*playerGuid*/) { return true; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -596,6 +596,8 @@ public: /* BGScript */
|
||||
void OnBattlegroundEnd(Battleground* bg, TeamId winnerTeamId);
|
||||
void OnBattlegroundDestroy(Battleground* bg);
|
||||
void OnBattlegroundCreate(Battleground* bg);
|
||||
bool CanAddGroupToMatchingPool(BattlegroundQueue* queue, GroupQueueInfo* group, uint32 poolPlayerCount, Battleground* bg, BattlegroundBracketId bracketId);
|
||||
bool GetPlayerMatchmakingRating(ObjectGuid playerGuid, BattlegroundTypeId bgTypeId, float& outRating);
|
||||
|
||||
public: /* Arena Team Script */
|
||||
void OnGetSlotByType(const uint32 type, uint8& slot);
|
||||
@@ -651,6 +653,8 @@ public: /* ArenaScript */
|
||||
bool CanSaveToDB(ArenaTeam* team);
|
||||
bool OnBeforeArenaCheckWinConditions(Battleground* const bg);
|
||||
void OnArenaStart(Battleground* const bg);
|
||||
bool OnBeforeArenaTeamMemberUpdate(ArenaTeam* team, Player* player, bool won, uint32 opponentMatchmakerRating, int32 matchmakerChange);
|
||||
bool CanSaveArenaStatsForMember(ArenaTeam* team, ObjectGuid playerGuid);
|
||||
|
||||
public: /* MiscScript */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user