[12067] Use world state enum for adding/ remove a state in bg and various cleanups

Thanks to stfc for additional input

Signed-off-by: Schmoozerd <schmoozerd@scriptdev2.com>
This commit is contained in:
Shyax 2012-07-22 01:42:10 +02:00 committed by Schmoozerd
parent 3707b04330
commit 759d7f80db
28 changed files with 308 additions and 309 deletions

View file

@ -188,17 +188,17 @@ void BattleGroundWS::RespawnFlagAfterDrop(Team team)
ClearDroppedFlagGuid(team);
}
void BattleGroundWS::EventPlayerCapturedFlag(Player* Source)
void BattleGroundWS::EventPlayerCapturedFlag(Player* source)
{
if (GetStatus() != STATUS_IN_PROGRESS)
return;
m_LastCapturedFlagTeam = Source->GetTeam();
m_LastCapturedFlagTeam = source->GetTeam();
Team winner = TEAM_NONE;
Source->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT);
if (Source->GetTeam() == ALLIANCE)
source->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT);
if (source->GetTeam() == ALLIANCE)
{
if (!IsHordeFlagPickedup())
return;
@ -206,7 +206,7 @@ void BattleGroundWS::EventPlayerCapturedFlag(Player* Source)
// horde flag in base (but not respawned yet)
m_FlagState[BG_TEAM_HORDE] = BG_WS_FLAG_STATE_WAIT_RESPAWN;
// Drop Horde Flag from Player
Source->RemoveAurasDueToSpell(BG_WS_SPELL_WARSONG_FLAG);
source->RemoveAurasDueToSpell(BG_WS_SPELL_WARSONG_FLAG);
if (GetTeamScore(ALLIANCE) < BG_WS_MAX_TEAM_SCORE)
AddPoint(ALLIANCE, 1);
PlaySoundToAll(BG_WS_SOUND_FLAG_CAPTURED_ALLIANCE);
@ -220,28 +220,28 @@ void BattleGroundWS::EventPlayerCapturedFlag(Player* Source)
// alliance flag in base (but not respawned yet)
m_FlagState[BG_TEAM_ALLIANCE] = BG_WS_FLAG_STATE_WAIT_RESPAWN;
// Drop Alliance Flag from Player
Source->RemoveAurasDueToSpell(BG_WS_SPELL_SILVERWING_FLAG);
source->RemoveAurasDueToSpell(BG_WS_SPELL_SILVERWING_FLAG);
if (GetTeamScore(HORDE) < BG_WS_MAX_TEAM_SCORE)
AddPoint(HORDE, 1);
PlaySoundToAll(BG_WS_SOUND_FLAG_CAPTURED_HORDE);
RewardReputationToTeam(889, m_ReputationCapture, HORDE);
}
//for flag capture is reward 2 honorable kills
RewardHonorToTeam(GetBonusHonorFromKill(2), Source->GetTeam());
RewardHonorToTeam(GetBonusHonorFromKill(2), source->GetTeam());
// despawn flags
SpawnEvent(WS_EVENT_FLAG_A, 0, false);
SpawnEvent(WS_EVENT_FLAG_H, 0, false);
if (Source->GetTeam() == ALLIANCE)
SendMessageToAll(LANG_BG_WS_CAPTURED_HF, CHAT_MSG_BG_SYSTEM_ALLIANCE, Source);
if (source->GetTeam() == ALLIANCE)
SendMessageToAll(LANG_BG_WS_CAPTURED_HF, CHAT_MSG_BG_SYSTEM_ALLIANCE, source);
else
SendMessageToAll(LANG_BG_WS_CAPTURED_AF, CHAT_MSG_BG_SYSTEM_HORDE, Source);
SendMessageToAll(LANG_BG_WS_CAPTURED_AF, CHAT_MSG_BG_SYSTEM_HORDE, source);
UpdateFlagState(Source->GetTeam(), 1); // flag state none
UpdateTeamScore(Source->GetTeam());
UpdateFlagState(source->GetTeam(), 1); // flag state none
UpdateTeamScore(source->GetTeam());
// only flag capture should be updated
UpdatePlayerScore(Source, SCORE_FLAG_CAPTURES, 1); // +1 flag captures
UpdatePlayerScore(source, SCORE_FLAG_CAPTURES, 1); // +1 flag captures
if (GetTeamScore(ALLIANCE) == BG_WS_MAX_TEAM_SCORE)
winner = ALLIANCE;
@ -260,34 +260,34 @@ void BattleGroundWS::EventPlayerCapturedFlag(Player* Source)
}
else
{
m_FlagsTimer[GetOtherTeamIndex(GetTeamIndexByTeamId(Source->GetTeam()))] = BG_WS_FLAG_RESPAWN_TIME;
m_FlagsTimer[GetOtherTeamIndex(GetTeamIndexByTeamId(source->GetTeam()))] = BG_WS_FLAG_RESPAWN_TIME;
}
}
void BattleGroundWS::EventPlayerDroppedFlag(Player* Source)
void BattleGroundWS::EventPlayerDroppedFlag(Player* source)
{
if (GetStatus() != STATUS_IN_PROGRESS)
{
// if not running, do not cast things at the dropper player (prevent spawning the "dropped" flag), neither send unnecessary messages
// just take off the aura
if (Source->GetTeam() == ALLIANCE)
if (source->GetTeam() == ALLIANCE)
{
if (!IsHordeFlagPickedup())
return;
if (GetHordeFlagPickerGuid() == Source->GetObjectGuid())
if (GetHordeFlagPickerGuid() == source->GetObjectGuid())
{
ClearHordeFlagPicker();
Source->RemoveAurasDueToSpell(BG_WS_SPELL_WARSONG_FLAG);
source->RemoveAurasDueToSpell(BG_WS_SPELL_WARSONG_FLAG);
}
}
else
{
if (!IsAllianceFlagPickedup())
return;
if (GetAllianceFlagPickerGuid() == Source->GetObjectGuid())
if (GetAllianceFlagPickerGuid() == source->GetObjectGuid())
{
ClearAllianceFlagPicker();
Source->RemoveAurasDueToSpell(BG_WS_SPELL_SILVERWING_FLAG);
source->RemoveAurasDueToSpell(BG_WS_SPELL_SILVERWING_FLAG);
}
}
return;
@ -295,16 +295,16 @@ void BattleGroundWS::EventPlayerDroppedFlag(Player* Source)
bool set = false;
if (Source->GetTeam() == ALLIANCE)
if (source->GetTeam() == ALLIANCE)
{
if (!IsHordeFlagPickedup())
return;
if (GetHordeFlagPickerGuid() == Source->GetObjectGuid())
if (GetHordeFlagPickerGuid() == source->GetObjectGuid())
{
ClearHordeFlagPicker();
Source->RemoveAurasDueToSpell(BG_WS_SPELL_WARSONG_FLAG);
source->RemoveAurasDueToSpell(BG_WS_SPELL_WARSONG_FLAG);
m_FlagState[BG_TEAM_HORDE] = BG_WS_FLAG_STATE_ON_GROUND;
Source->CastSpell(Source, BG_WS_SPELL_WARSONG_FLAG_DROPPED, true);
source->CastSpell(source, BG_WS_SPELL_WARSONG_FLAG_DROPPED, true);
set = true;
}
}
@ -312,37 +312,37 @@ void BattleGroundWS::EventPlayerDroppedFlag(Player* Source)
{
if (!IsAllianceFlagPickedup())
return;
if (GetAllianceFlagPickerGuid() == Source->GetObjectGuid())
if (GetAllianceFlagPickerGuid() == source->GetObjectGuid())
{
ClearAllianceFlagPicker();
Source->RemoveAurasDueToSpell(BG_WS_SPELL_SILVERWING_FLAG);
source->RemoveAurasDueToSpell(BG_WS_SPELL_SILVERWING_FLAG);
m_FlagState[BG_TEAM_ALLIANCE] = BG_WS_FLAG_STATE_ON_GROUND;
Source->CastSpell(Source, BG_WS_SPELL_SILVERWING_FLAG_DROPPED, true);
source->CastSpell(source, BG_WS_SPELL_SILVERWING_FLAG_DROPPED, true);
set = true;
}
}
if (set)
{
Source->CastSpell(Source, SPELL_RECENTLY_DROPPED_FLAG, true);
UpdateFlagState(Source->GetTeam(), 1);
source->CastSpell(source, SPELL_RECENTLY_DROPPED_FLAG, true);
UpdateFlagState(source->GetTeam(), 1);
if (Source->GetTeam() == ALLIANCE)
if (source->GetTeam() == ALLIANCE)
{
SendMessageToAll(LANG_BG_WS_DROPPED_HF, CHAT_MSG_BG_SYSTEM_HORDE, Source);
SendMessageToAll(LANG_BG_WS_DROPPED_HF, CHAT_MSG_BG_SYSTEM_HORDE, source);
UpdateWorldState(BG_WS_FLAG_UNK_HORDE, uint32(-1));
}
else
{
SendMessageToAll(LANG_BG_WS_DROPPED_AF, CHAT_MSG_BG_SYSTEM_ALLIANCE, Source);
SendMessageToAll(LANG_BG_WS_DROPPED_AF, CHAT_MSG_BG_SYSTEM_ALLIANCE, source);
UpdateWorldState(BG_WS_FLAG_UNK_ALLIANCE, uint32(-1));
}
m_FlagsDropTimer[GetOtherTeamIndex(GetTeamIndexByTeamId(Source->GetTeam()))] = BG_WS_FLAG_DROP_TIME;
m_FlagsDropTimer[GetOtherTeamIndex(GetTeamIndexByTeamId(source->GetTeam()))] = BG_WS_FLAG_DROP_TIME;
}
}
void BattleGroundWS::EventPlayerClickedOnFlag(Player* Source, GameObject* target_obj)
void BattleGroundWS::EventPlayerClickedOnFlag(Player* source, GameObject* target_obj)
{
if (GetStatus() != STATUS_IN_PROGRESS)
return;
@ -353,48 +353,48 @@ void BattleGroundWS::EventPlayerClickedOnFlag(Player* Source, GameObject* target
uint8 event = (sBattleGroundMgr.GetGameObjectEventIndex(target_obj->GetGUIDLow())).event1;
//alliance flag picked up from base
if (Source->GetTeam() == HORDE && GetFlagState(ALLIANCE) == BG_WS_FLAG_STATE_ON_BASE
if (source->GetTeam() == HORDE && GetFlagState(ALLIANCE) == BG_WS_FLAG_STATE_ON_BASE
&& event == WS_EVENT_FLAG_A)
{
message_id = LANG_BG_WS_PICKEDUP_AF;
type = CHAT_MSG_BG_SYSTEM_HORDE;
PlaySoundToAll(BG_WS_SOUND_ALLIANCE_FLAG_PICKED_UP);
SpawnEvent(WS_EVENT_FLAG_A, 0, false);
SetAllianceFlagPicker(Source->GetObjectGuid());
SetAllianceFlagPicker(source->GetObjectGuid());
m_FlagState[BG_TEAM_ALLIANCE] = BG_WS_FLAG_STATE_ON_PLAYER;
//update world state to show correct flag carrier
UpdateFlagState(HORDE, BG_WS_FLAG_STATE_ON_PLAYER);
UpdateWorldState(BG_WS_FLAG_UNK_ALLIANCE, 1);
Source->CastSpell(Source, BG_WS_SPELL_SILVERWING_FLAG, true);
source->CastSpell(source, BG_WS_SPELL_SILVERWING_FLAG, true);
}
//horde flag picked up from base
if (Source->GetTeam() == ALLIANCE && GetFlagState(HORDE) == BG_WS_FLAG_STATE_ON_BASE
if (source->GetTeam() == ALLIANCE && GetFlagState(HORDE) == BG_WS_FLAG_STATE_ON_BASE
&& event == WS_EVENT_FLAG_H)
{
message_id = LANG_BG_WS_PICKEDUP_HF;
type = CHAT_MSG_BG_SYSTEM_ALLIANCE;
PlaySoundToAll(BG_WS_SOUND_HORDE_FLAG_PICKED_UP);
SpawnEvent(WS_EVENT_FLAG_H, 0, false);
SetHordeFlagPicker(Source->GetObjectGuid());
SetHordeFlagPicker(source->GetObjectGuid());
m_FlagState[BG_TEAM_HORDE] = BG_WS_FLAG_STATE_ON_PLAYER;
//update world state to show correct flag carrier
UpdateFlagState(ALLIANCE, BG_WS_FLAG_STATE_ON_PLAYER);
UpdateWorldState(BG_WS_FLAG_UNK_HORDE, 1);
Source->CastSpell(Source, BG_WS_SPELL_WARSONG_FLAG, true);
source->CastSpell(source, BG_WS_SPELL_WARSONG_FLAG, true);
}
//Alliance flag on ground(not in base) (returned or picked up again from ground!)
if (GetFlagState(ALLIANCE) == BG_WS_FLAG_STATE_ON_GROUND && Source->IsWithinDistInMap(target_obj, 10))
if (GetFlagState(ALLIANCE) == BG_WS_FLAG_STATE_ON_GROUND && source->IsWithinDistInMap(target_obj, 10))
{
if (Source->GetTeam() == ALLIANCE)
if (source->GetTeam() == ALLIANCE)
{
message_id = LANG_BG_WS_RETURNED_AF;
type = CHAT_MSG_BG_SYSTEM_ALLIANCE;
UpdateFlagState(HORDE, BG_WS_FLAG_STATE_WAIT_RESPAWN);
RespawnFlag(ALLIANCE, false);
PlaySoundToAll(BG_WS_SOUND_FLAG_RETURNED);
UpdatePlayerScore(Source, SCORE_FLAG_RETURNS, 1);
UpdatePlayerScore(source, SCORE_FLAG_RETURNS, 1);
}
else
{
@ -402,8 +402,8 @@ void BattleGroundWS::EventPlayerClickedOnFlag(Player* Source, GameObject* target
type = CHAT_MSG_BG_SYSTEM_HORDE;
PlaySoundToAll(BG_WS_SOUND_ALLIANCE_FLAG_PICKED_UP);
SpawnEvent(WS_EVENT_FLAG_A, 0, false);
SetAllianceFlagPicker(Source->GetObjectGuid());
Source->CastSpell(Source, BG_WS_SPELL_SILVERWING_FLAG, true);
SetAllianceFlagPicker(source->GetObjectGuid());
source->CastSpell(source, BG_WS_SPELL_SILVERWING_FLAG, true);
m_FlagState[BG_TEAM_ALLIANCE] = BG_WS_FLAG_STATE_ON_PLAYER;
UpdateFlagState(HORDE, BG_WS_FLAG_STATE_ON_PLAYER);
UpdateWorldState(BG_WS_FLAG_UNK_ALLIANCE, 1);
@ -413,16 +413,16 @@ void BattleGroundWS::EventPlayerClickedOnFlag(Player* Source, GameObject* target
}
//Horde flag on ground(not in base) (returned or picked up again)
if (GetFlagState(HORDE) == BG_WS_FLAG_STATE_ON_GROUND && Source->IsWithinDistInMap(target_obj, 10))
if (GetFlagState(HORDE) == BG_WS_FLAG_STATE_ON_GROUND && source->IsWithinDistInMap(target_obj, 10))
{
if (Source->GetTeam() == HORDE)
if (source->GetTeam() == HORDE)
{
message_id = LANG_BG_WS_RETURNED_HF;
type = CHAT_MSG_BG_SYSTEM_HORDE;
UpdateFlagState(ALLIANCE, BG_WS_FLAG_STATE_WAIT_RESPAWN);
RespawnFlag(HORDE, false);
PlaySoundToAll(BG_WS_SOUND_FLAG_RETURNED);
UpdatePlayerScore(Source, SCORE_FLAG_RETURNS, 1);
UpdatePlayerScore(source, SCORE_FLAG_RETURNS, 1);
}
else
{
@ -430,8 +430,8 @@ void BattleGroundWS::EventPlayerClickedOnFlag(Player* Source, GameObject* target
type = CHAT_MSG_BG_SYSTEM_ALLIANCE;
PlaySoundToAll(BG_WS_SOUND_HORDE_FLAG_PICKED_UP);
SpawnEvent(WS_EVENT_FLAG_H, 0, false);
SetHordeFlagPicker(Source->GetObjectGuid());
Source->CastSpell(Source, BG_WS_SPELL_WARSONG_FLAG, true);
SetHordeFlagPicker(source->GetObjectGuid());
source->CastSpell(source, BG_WS_SPELL_WARSONG_FLAG, true);
m_FlagState[BG_TEAM_HORDE] = BG_WS_FLAG_STATE_ON_PLAYER;
UpdateFlagState(ALLIANCE, BG_WS_FLAG_STATE_ON_PLAYER);
UpdateWorldState(BG_WS_FLAG_UNK_HORDE, 1);
@ -443,8 +443,8 @@ void BattleGroundWS::EventPlayerClickedOnFlag(Player* Source, GameObject* target
if (!message_id)
return;
SendMessageToAll(message_id, type, Source);
Source->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT);
SendMessageToAll(message_id, type, source);
source->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT);
}
void BattleGroundWS::RemovePlayer(Player* plr, ObjectGuid guid)
@ -490,7 +490,7 @@ void BattleGroundWS::UpdateTeamScore(Team team)
UpdateWorldState(BG_WS_FLAG_CAPTURES_HORDE, GetTeamScore(team));
}
void BattleGroundWS::HandleAreaTrigger(Player* Source, uint32 Trigger)
void BattleGroundWS::HandleAreaTrigger(Player* source, uint32 trigger)
{
// this is wrong way to implement these things. On official it done by gameobject spell cast.
if (GetStatus() != STATUS_IN_PROGRESS)
@ -498,7 +498,7 @@ void BattleGroundWS::HandleAreaTrigger(Player* Source, uint32 Trigger)
//uint32 SpellId = 0;
//uint64 buff_guid = 0;
switch (Trigger)
switch (trigger)
{
case 3686: // Alliance elixir of speed spawn. Trigger not working, because located inside other areatrigger, can be replaced by IsWithinDist(object, dist) in BattleGround::Update().
case 3687: // Horde elixir of speed spawn. Trigger not working, because located inside other areatrigger, can be replaced by IsWithinDist(object, dist) in BattleGround::Update().
@ -509,13 +509,13 @@ void BattleGroundWS::HandleAreaTrigger(Player* Source, uint32 Trigger)
break;
case 3646: // Alliance Flag spawn
if (m_FlagState[BG_TEAM_HORDE] && !m_FlagState[BG_TEAM_ALLIANCE])
if (GetHordeFlagPickerGuid() == Source->GetObjectGuid())
EventPlayerCapturedFlag(Source);
if (GetHordeFlagPickerGuid() == source->GetObjectGuid())
EventPlayerCapturedFlag(source);
break;
case 3647: // Horde Flag spawn
if (m_FlagState[BG_TEAM_ALLIANCE] && !m_FlagState[BG_TEAM_HORDE])
if (GetAllianceFlagPickerGuid() == Source->GetObjectGuid())
EventPlayerCapturedFlag(Source);
if (GetAllianceFlagPickerGuid() == source->GetObjectGuid())
EventPlayerCapturedFlag(source);
break;
case 3649: // unk1
case 3688: // unk2
@ -523,8 +523,8 @@ void BattleGroundWS::HandleAreaTrigger(Player* Source, uint32 Trigger)
case 4629: // unk4
break;
default:
sLog.outError("WARNING: Unhandled AreaTrigger in Battleground: %u", Trigger);
Source->GetSession()->SendAreaTriggerMessage("Warning: Unhandled AreaTrigger in Battleground: %u", Trigger);
sLog.outError("WARNING: Unhandled AreaTrigger in Battleground: %u", trigger);
source->GetSession()->SendAreaTriggerMessage("Warning: Unhandled AreaTrigger in Battleground: %u", trigger);
break;
}
}
@ -544,7 +544,7 @@ void BattleGroundWS::Reset()
m_ActiveEvents[WS_EVENT_FLAG_A] = BG_EVENT_NONE;
m_ActiveEvents[WS_EVENT_FLAG_H] = BG_EVENT_NONE;
for (uint32 i = 0; i < BG_TEAMS_COUNT; ++i)
for (uint8 i = 0; i < BG_TEAMS_COUNT; ++i)
{
m_DroppedFlagGuid[i].Clear();
m_FlagKeepers[i].Clear();
@ -584,10 +584,10 @@ void BattleGroundWS::HandleKillPlayer(Player* player, Player* killer)
BattleGround::HandleKillPlayer(player, killer);
}
void BattleGroundWS::UpdatePlayerScore(Player* Source, uint32 type, uint32 value)
void BattleGroundWS::UpdatePlayerScore(Player* source, uint32 type, uint32 value)
{
BattleGroundScoreMap::iterator itr = m_PlayerScores.find(Source->GetObjectGuid());
BattleGroundScoreMap::iterator itr = m_PlayerScores.find(source->GetObjectGuid());
if (itr == m_PlayerScores.end()) // player not found
return;
@ -600,7 +600,7 @@ void BattleGroundWS::UpdatePlayerScore(Player* Source, uint32 type, uint32 value
((BattleGroundWGScore*)itr->second)->FlagReturns += value;
break;
default:
BattleGround::UpdatePlayerScore(Source, type, value);
BattleGround::UpdatePlayerScore(source, type, value);
break;
}
}
@ -659,6 +659,6 @@ void BattleGroundWS::FillInitialWorldStates(WorldPacket& data, uint32& count)
else
FillInitialWorldState(data, count, BG_WS_FLAG_STATE_ALLIANCE, 1);
FillInitialWorldState(data, count, BG_WS_TIME_ENABLED, 1);
FillInitialWorldState(data, count, BG_WS_TIME_ENABLED, WORLD_STATE_ADD);
FillInitialWorldState(data, count, BG_WS_TIME_REMAINING, GetRemainingTimeInMinutes());
}