feat(Core/Hooks): OnBattlegroundDesertion (#4619)

This commit is contained in:
Francesco Borzì 2021-02-21 22:12:25 +01:00 committed by GitHub
parent 8dbdffab92
commit a4115862de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 48 additions and 23 deletions

View File

@ -1061,14 +1061,18 @@ bool BGQueueRemoveEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/)
if (bgQueue.IsPlayerInvited(m_PlayerGuid, m_BgInstanceGUID, m_RemoveTime))
{
// track if player leaves the BG by not clicking enter button
if (bg && bg->isBattleground() && sWorld->getBoolConfig(CONFIG_BATTLEGROUND_TRACK_DESERTERS) &&
(bg->GetStatus() == STATUS_IN_PROGRESS || bg->GetStatus() == STATUS_WAIT_JOIN))
if (bg && bg->isBattleground() && (bg->GetStatus() == STATUS_IN_PROGRESS || bg->GetStatus() == STATUS_WAIT_JOIN))
{
if (sWorld->getBoolConfig(CONFIG_BATTLEGROUND_TRACK_DESERTERS))
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_DESERTER_TRACK);
stmt->setUInt32(0, player->GetGUIDLow());
stmt->setUInt8(1, BG_DESERTION_TYPE_NO_ENTER_BUTTON);
CharacterDatabase.Execute(stmt);
}
sScriptMgr->OnBattlegroundDesertion(player, BG_DESERTION_TYPE_NO_ENTER_BUTTON);
}
player->RemoveBattlegroundQueueId(m_BgQueueTypeId);
bgQueue.RemovePlayer(m_PlayerGuid, false, queueSlot);
}

View File

@ -22865,14 +22865,17 @@ void Player::LeaveBattleground(Battleground* bg)
return;
// Deserter tracker - leave BG
if (bg->isBattleground() && sWorld->getBoolConfig(CONFIG_BATTLEGROUND_TRACK_DESERTERS)
&& (bg->GetStatus() == STATUS_IN_PROGRESS || bg->GetStatus() == STATUS_WAIT_JOIN))
if (bg->isBattleground() && (bg->GetStatus() == STATUS_IN_PROGRESS || bg->GetStatus() == STATUS_WAIT_JOIN))
{
if (sWorld->getBoolConfig(CONFIG_BATTLEGROUND_TRACK_DESERTERS))
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_DESERTER_TRACK);
stmt->setUInt32(0, GetGUIDLow());
stmt->setUInt8(1, BG_DESERTION_TYPE_LEAVE_BG);
CharacterDatabase.Execute(stmt);
}
sScriptMgr->OnBattlegroundDesertion(this, BG_DESERTION_TYPE_LEAVE_BG);
}
// xinef: reset corpse reclaim time
m_deathExpireTime = time(nullptr);

View File

@ -471,14 +471,18 @@ void WorldSession::HandleBattleFieldPortOpcode(WorldPacket& recvData)
bgQueue.RemovePlayer(_player->GetGUID(), false, queueSlot);
_player->RemoveBattlegroundQueueId(bgQueueTypeId);
// track if player refuses to join the BG after being invited
if (bg->isBattleground() && sWorld->getBoolConfig(CONFIG_BATTLEGROUND_TRACK_DESERTERS) &&
(bg->GetStatus() == STATUS_IN_PROGRESS || bg->GetStatus() == STATUS_WAIT_JOIN))
if (bg->isBattleground() && (bg->GetStatus() == STATUS_IN_PROGRESS || bg->GetStatus() == STATUS_WAIT_JOIN))
{
if (sWorld->getBoolConfig(CONFIG_BATTLEGROUND_TRACK_DESERTERS))
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_DESERTER_TRACK);
stmt->setUInt32(0, _player->GetGUIDLow());
stmt->setUInt8(1, BG_DESERTION_TYPE_LEAVE_QUEUE);
CharacterDatabase.Execute(stmt);
}
sScriptMgr->OnBattlegroundDesertion(_player, BG_DESERTION_TYPE_LEAVE_QUEUE);
}
}
break;
default:

View File

@ -1339,6 +1339,11 @@ void ScriptMgr::OnPlayerCompleteQuest(Player* player, Quest const* quest)
FOREACH_SCRIPT(PlayerScript)->OnPlayerCompleteQuest(player, quest);
}
void ScriptMgr::OnBattlegroundDesertion(Player* player, BattlegroundDesertionType const desertionType)
{
FOREACH_SCRIPT(PlayerScript)->OnBattlegroundDesertion(player, desertionType);
}
void ScriptMgr::OnPlayerReleasedGhost(Player* player)
{
FOREACH_SCRIPT(PlayerScript)->OnPlayerReleasedGhost(player);

View File

@ -7,6 +7,7 @@
#ifndef SC_SCRIPTMGR_H
#define SC_SCRIPTMGR_H
#include "Battleground.h"
#include "Common.h"
#include "ObjectMgr.h"
#include "DBCStores.h"
@ -744,6 +745,9 @@ protected:
public:
virtual void OnPlayerReleasedGhost(Player* /*player*/) { }
// Called when a player does a desertion action (see BattlegroundDesertionType)
virtual void OnBattlegroundDesertion(Player* /*player*/, BattlegroundDesertionType const /*desertionType*/) { }
// Called when a player completes a quest
virtual void OnPlayerCompleteQuest(Player* /*player*/, Quest const* /*quest_id*/) { }
@ -1394,6 +1398,7 @@ public: /* PlayerScript */
void OnBeforeInitTalentForLevel(Player* player, uint8& level, uint32& talentPointsForLevel);
void OnFirstLogin(Player* player);
void OnPlayerCompleteQuest(Player* player, Quest const* quest);
void OnBattlegroundDesertion(Player* player, BattlegroundDesertionType const desertionType);
bool CanJoinInBattlegroundQueue(Player* player, uint64 BattlemasterGuid, BattlegroundTypeId BGTypeID, uint8 joinAsGroup, GroupJoinBattlegroundResult& err);
bool ShouldBeRewardedWithMoneyInsteadOfExp(Player* player);
void OnBeforeTempSummonInitStats(Player* player, TempSummon* tempSummon, uint32& duration);

View File

@ -513,13 +513,17 @@ void WorldSession::LogoutPlayer(bool save)
_player->RemoveBattlegroundQueueId(bgQueueTypeId);
sBattlegroundMgr->GetBattlegroundQueue(bgQueueTypeId).RemovePlayer(_player->GetGUID(), false, i);
// track if player logs out after invited to join BG
if (_player->IsInvitedForBattlegroundInstance() && sWorld->getBoolConfig(CONFIG_BATTLEGROUND_TRACK_DESERTERS))
if (_player->IsInvitedForBattlegroundInstance())
{
if (sWorld->getBoolConfig(CONFIG_BATTLEGROUND_TRACK_DESERTERS))
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_DESERTER_TRACK);
stmt->setUInt32(0, _player->GetGUIDLow());
stmt->setUInt8(1, BG_DESERTION_TYPE_INVITE_LOGOUT);
CharacterDatabase.Execute(stmt);
}
sScriptMgr->OnBattlegroundDesertion(_player, BG_DESERTION_TYPE_INVITE_LOGOUT);
}
}
///- If the player is in a guild, update the guild roster and broadcast a logout message to other guild members