feat(Core/Hooks): added collection of hooks to extends AC (#3047)

This collection of hooks comes from the Maelstrom project. It allows to release modules such as :
- 3v3-soloqueue
- 1v1 arena
- pvestats

and many others
This commit is contained in:
Kargatum
2021-04-13 18:26:39 +07:00
committed by GitHub
parent 911fbb377e
commit 2b3d46bd4f
46 changed files with 2053 additions and 278 deletions

View File

@@ -101,6 +101,9 @@ bool ArenaTeam::AddMember(uint64 playerGuid)
playerClass = playerData->playerClass;
}
if (!sScriptMgr->CanAddMember(this, playerGuid))
return false;
// Check if player is already in a similar arena team
if ((player && player->GetArenaTeamId(GetSlot())) || Player::GetArenaTeamIdFromStorage(GUID_LOPART(playerGuid), GetSlot()) != 0)
{
@@ -610,27 +613,24 @@ void ArenaTeam::MassInviteToEvent(WorldSession* session)
uint8 ArenaTeam::GetSlotByType(uint32 type)
{
uint8 slot = 0xFF;
switch (type)
auto const& itr = ArenaSlotByType.find(type);
if (itr == ArenaSlotByType.end())
{
case ARENA_TEAM_2v2:
slot = 0;
break;
case ARENA_TEAM_3v3:
slot = 1;
break;
case ARENA_TEAM_5v5:
slot = 2;
break;
default:
break;
sLog->outError("FATAL: Unknown arena team type %u for some arena team", type);
return slot;
}
//Get the changed slot type
slot = ArenaSlotByType.at(type);
// Get the changed slot type
sScriptMgr->OnGetSlotByType(type, slot);
if (slot != 0xFF)
{
return slot;
}
sLog->outError("FATAL: Unknown arena team type %u for some arena team", type);
return 0xFF;
}
@@ -868,12 +868,14 @@ void ArenaTeam::MemberWon(Player* player, uint32 againstMatchmakerRating, int32
{
// update personal rating
int32 mod = GetRatingMod(itr->PersonalRating, againstMatchmakerRating, true);
sScriptMgr->OnBeforeUpdatingPersonalRating(mod, GetType());
itr->ModifyPersonalRating(player, mod, GetType());
// update matchmaker rating (pussywizard: but don't allow it to go over team rating)
if (itr->MatchMakerRating < Stats.Rating)
{
mod = std::min(MatchmakerRatingChange, Stats.Rating - itr->MatchMakerRating);
sScriptMgr->OnBeforeUpdatingPersonalRating(mod, GetType());
itr->ModifyMatchmakerRating(mod, GetSlot());
}
@@ -922,6 +924,9 @@ void ArenaTeam::UpdateArenaPointsHelper(std::map<uint32, uint32>& playerPoints)
void ArenaTeam::SaveToDB()
{
if (!sScriptMgr->CanSaveToDB(this))
return;
// Save team and member stats to db
// Called after a match has ended or when calculating arena_points
@@ -997,3 +1002,83 @@ ArenaTeamMember* ArenaTeam::GetMember(uint64 guid)
return nullptr;
}
uint8 ArenaTeam::GetReqPlayersForType(uint32 type)
{
auto const& itr = ArenaReqPlayersForType.find(type);
if (itr == ArenaReqPlayersForType.end())
{
sLog->outError("FATAL: Unknown arena type %u!", type);
return 0xFF;
}
return ArenaReqPlayersForType.at(type);
}
void ArenaTeam::CreateTempArenaTeam(std::vector<Player*> playerList, uint8 type, std::string const& teamName)
{
auto playerCountInTeam = static_cast<uint32>(playerList.size());
ASSERT(playerCountInTeam == GetReqPlayersForType(type));
// Generate new arena team id
TeamId = sArenaTeamMgr->GenerateTempArenaTeamId();
// Assign member variables
CaptainGuid = playerList[0]->GetGUID();
Type = type;
TeamName = teamName;
BackgroundColor = 0;
EmblemStyle = 0;
EmblemColor = 0;
BorderStyle = 0;
BorderColor = 0;
Stats.WeekGames = 0;
Stats.SeasonGames = 0;
Stats.Rating = 0;
Stats.WeekWins = 0;
Stats.SeasonWins = 0;
for (auto const& _player : playerList)
{
ArenaTeam* team = sArenaTeamMgr->GetArenaTeamById(_player->GetArenaTeamId(GetSlotByType(type)));
if (!team)
continue;
ArenaTeamMember newMember;
for (auto const& itr : Members)
newMember = itr;
Stats.WeekGames += team->Stats.WeekGames;
Stats.SeasonGames += team->Stats.SeasonGames;
Stats.Rating += team->GetRating();
Stats.WeekWins += team->Stats.WeekWins;
Stats.SeasonWins += team->Stats.SeasonWins;
Members.push_back(newMember);
}
Stats.WeekGames /= playerCountInTeam;
Stats.SeasonGames /= playerCountInTeam;
Stats.Rating /= playerCountInTeam;
Stats.WeekWins /= playerCountInTeam;
Stats.SeasonWins /= playerCountInTeam;
}
// init/update unordered_map ArenaSlotByType
std::unordered_map<uint32, uint8> ArenaTeam::ArenaSlotByType =
{
{ ARENA_TEAM_2v2, ARENA_SLOT_2v2},
{ ARENA_TEAM_3v3, ARENA_SLOT_3v3},
{ ARENA_TEAM_5v5, ARENA_SLOT_5v5}
};
// init/update unordered_map ArenaReqPlayersForType
std::unordered_map<uint8, uint8> ArenaTeam::ArenaReqPlayersForType =
{
{ ARENA_TYPE_2v2, 4},
{ ARENA_TYPE_3v3, 6},
{ ARENA_TYPE_5v5, 10}
};