Files
TCPlayerbotCore/src/game/BattleGroundSA.cpp
T

682 lines
23 KiB
C++
Raw Normal View History

2009-01-05 14:53:33 -06:00
/*
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
2009-10-17 15:51:44 -07:00
2009-01-05 14:53:33 -06:00
#include "BattleGround.h"
#include "BattleGroundSA.h"
#include "Language.h"
2009-06-04 21:41:07 +02:00
#include "Player.h"
2010-02-14 19:13:14 -07:00
#include "GameObject.h"
#include "ObjectMgr.h"
#include "WorldPacket.h"
2009-10-17 15:51:44 -07:00
2009-01-05 14:53:33 -06:00
BattleGroundSA::BattleGroundSA()
{
2010-02-14 19:13:14 -07:00
m_StartMessageIds[BG_STARTING_EVENT_FIRST] = LANG_BG_SA_START_TWO_MINUTES;
m_StartMessageIds[BG_STARTING_EVENT_SECOND] = LANG_BG_SA_START_ONE_MINUTE;
m_StartMessageIds[BG_STARTING_EVENT_THIRD] = LANG_BG_SA_START_HALF_MINUTE;
m_StartMessageIds[BG_STARTING_EVENT_FOURTH] = LANG_BG_SA_HAS_BEGUN;
m_BgObjects.resize(BG_SA_MAXOBJ);
m_BgCreatures.resize(BG_SA_MAXNPC + BG_SA_MAX_GY);
TimerEnabled = false;
2009-01-05 14:53:33 -06:00
}
2009-10-17 15:51:44 -07:00
2009-01-05 14:53:33 -06:00
BattleGroundSA::~BattleGroundSA()
2010-02-14 19:13:14 -07:00
{
}
void BattleGroundSA::Reset()
{
TotalTime = 0;
2010-04-07 22:59:46 +02:00
attackers = ((urand(0,1)) ? TEAM_ALLIANCE : TEAM_HORDE);
2010-04-07 19:12:44 +02:00
for (uint8 i = 0; i <= 5; i++)
GateStatus[i] = BG_SA_GATE_OK;
ShipsStarted = false;
status = BG_SA_WARMUP;
2010-02-14 19:13:14 -07:00
}
bool BattleGroundSA::SetupBattleGround()
2009-01-05 14:53:33 -06:00
{
2010-04-07 18:09:10 +02:00
return ResetObjs();
2010-02-14 19:13:14 -07:00
}
bool BattleGroundSA::ResetObjs()
{
2010-03-07 14:16:55 +01:00
uint32 atF = BG_SA_Factions[attackers];
uint32 defF = BG_SA_Factions[attackers ? TEAM_ALLIANCE : TEAM_HORDE];
2010-02-14 19:13:14 -07:00
2010-04-07 19:12:44 +02:00
for (uint8 i = 0; i <BG_SA_MAXOBJ; i++)
2010-03-07 14:16:55 +01:00
DelObject(i);
2010-02-14 19:13:14 -07:00
2010-04-07 19:12:44 +02:00
for (uint8 i = 0; i < BG_SA_MAXNPC; i++)
2010-03-07 14:16:55 +01:00
DelCreature(i);
2010-04-07 18:09:10 +02:00
2010-04-07 19:12:44 +02:00
for (uint8 i = BG_SA_MAXNPC; i < BG_SA_MAXNPC + BG_SA_MAX_GY; i++)
2010-03-07 14:16:55 +01:00
DelCreature(i);
2010-02-14 19:13:14 -07:00
2010-04-07 19:12:44 +02:00
for (uint8 i = 0; i < 6; i++)
2010-03-07 14:16:55 +01:00
GateStatus[i] = BG_SA_GATE_OK;
2010-02-14 19:13:14 -07:00
2010-04-07 19:12:44 +02:00
for (uint8 i = 0; i < BG_SA_CENTRAL_FLAG; i++)
2010-02-14 19:13:14 -07:00
{
2010-04-07 19:14:10 +02:00
if (!AddObject(i,BG_SA_ObjEntries[i],
2010-04-07 17:24:07 +02:00
BG_SA_ObjSpawnlocs[i][0],BG_SA_ObjSpawnlocs[i][1],
BG_SA_ObjSpawnlocs[i][2],BG_SA_ObjSpawnlocs[i][3],
0,0,0,0,RESPAWN_ONE_DAY))
2010-03-07 14:16:55 +01:00
return false;
2010-02-14 19:13:14 -07:00
}
2010-03-07 14:16:55 +01:00
//Cannons and demolishers - NPCs are spawned
//By capturing GYs.
2010-04-07 19:12:44 +02:00
for (uint8 i = 0; i < BG_SA_NPC_SPARKLIGHT; i++)
2010-02-14 19:13:14 -07:00
{
2010-04-07 19:14:10 +02:00
if (!AddCreature(BG_SA_NpcEntries[i], i, (attackers == TEAM_ALLIANCE ? TEAM_HORDE : TEAM_ALLIANCE),
2010-04-07 17:24:07 +02:00
BG_SA_NpcSpawnlocs[i][0],BG_SA_NpcSpawnlocs[i][1],
BG_SA_NpcSpawnlocs[i][2],BG_SA_NpcSpawnlocs[i][3]))
2010-03-07 14:16:55 +01:00
return false;
2010-02-14 19:13:14 -07:00
}
OverrideGunFaction();
2010-04-07 18:09:10 +02:00
2010-04-07 19:12:44 +02:00
for (uint8 i = 0; i <= BG_SA_TITAN_RELIC; i++)
2010-02-14 19:13:14 -07:00
{
2010-03-07 14:16:55 +01:00
SpawnBGObject(i, RESPAWN_IMMEDIATELY);
GetBGObject(i)->SetUInt32Value(GAMEOBJECT_FACTION, defF);
2010-02-14 19:13:14 -07:00
}
2010-03-12 11:53:30 +01:00
GetBGObject(BG_SA_TITAN_RELIC)->SetUInt32Value(GAMEOBJECT_FACTION, atF);
GetBGObject(BG_SA_TITAN_RELIC)->Refresh();
2010-04-07 19:12:44 +02:00
for (uint8 i = 0; i <= 5; i++)
2010-03-07 14:16:55 +01:00
GateStatus[i] = BG_SA_GATE_OK;
2010-02-14 19:13:14 -07:00
2010-03-07 14:16:55 +01:00
// MAD props for Kiper for discovering those values - 4 hours of his work.
GetBGObject(BG_SA_BOAT_ONE)->UpdateRotationFields(1.0f, 0.0002f);
GetBGObject(BG_SA_BOAT_TWO)->UpdateRotationFields(1.0f, 0.00001f);
SpawnBGObject(BG_SA_BOAT_ONE, RESPAWN_IMMEDIATELY);
SpawnBGObject(BG_SA_BOAT_TWO, RESPAWN_IMMEDIATELY);
2010-02-14 19:13:14 -07:00
2010-03-07 14:16:55 +01:00
TotalTime = 0;
ShipsStarted = false;
2010-02-14 19:13:14 -07:00
2010-03-07 14:16:55 +01:00
//Graveyards!
2010-04-07 19:12:44 +02:00
for (uint8 i = 0;i < BG_SA_MAX_GY; i++)
2010-02-14 19:13:14 -07:00
{
2010-03-07 14:16:55 +01:00
WorldSafeLocsEntry const *sg = NULL;
sg = sWorldSafeLocsStore.LookupEntry(BG_SA_GYEntries[i]);
2010-02-14 19:13:14 -07:00
2010-04-07 19:14:10 +02:00
if (!sg)
2010-04-07 17:24:07 +02:00
{
2010-03-07 14:16:55 +01:00
sLog.outError("SOTA: Can't find GY entry %u",BG_SA_GYEntries[i]);
return false;
2010-04-07 18:09:10 +02:00
}
2010-02-14 19:13:14 -07:00
2010-04-07 19:14:10 +02:00
if (i == BG_SA_BEACH_GY)
2010-04-07 17:24:07 +02:00
{
2010-03-07 14:16:55 +01:00
GraveyardStatus[i] = attackers;
2010-04-07 22:59:46 +02:00
AddSpiritGuide(i + BG_SA_MAXNPC, sg->x, sg->y, sg->z, BG_SA_GYOrientation[i], ((attackers == TEAM_HORDE)? HORDE : ALLIANCE));
2010-04-07 17:24:07 +02:00
}
2010-03-07 14:16:55 +01:00
else
2010-04-07 17:24:07 +02:00
{
2010-04-07 22:59:46 +02:00
GraveyardStatus[i] = ((attackers == TEAM_HORDE)? TEAM_ALLIANCE : TEAM_HORDE);
if (!AddSpiritGuide(i + BG_SA_MAXNPC, sg->x, sg->y, sg->z, BG_SA_GYOrientation[i], ((attackers == TEAM_HORDE)? ALLIANCE : HORDE)))
2010-03-07 14:16:55 +01:00
sLog.outError("SOTA: couldn't spawn GY: %u",i);
2010-04-07 17:24:07 +02:00
}
2010-02-14 19:13:14 -07:00
}
2010-03-07 14:16:55 +01:00
//GY capture points
2010-04-07 19:12:44 +02:00
for (uint8 i = BG_SA_CENTRAL_FLAG; i < BG_SA_MAXOBJ; i++)
2010-02-14 19:13:14 -07:00
{
2010-04-07 18:09:10 +02:00
AddObject(i, BG_SA_ObjEntries[i] - (attackers == TEAM_ALLIANCE ? 1:0),
2010-03-07 14:16:55 +01:00
BG_SA_ObjSpawnlocs[i][0], BG_SA_ObjSpawnlocs[i][1],
BG_SA_ObjSpawnlocs[i][2], BG_SA_ObjSpawnlocs[i][3],
0,0,0,0,RESPAWN_ONE_DAY);
GetBGObject(i)->SetUInt32Value(GAMEOBJECT_FACTION, atF);
2010-02-14 19:13:14 -07:00
}
2010-03-07 14:16:55 +01:00
//Player may enter BEFORE we set up bG - lets update his worldstates anyway...
2010-04-07 22:59:46 +02:00
UpdateWorldState(BG_SA_RIGHT_GY_HORDE , GraveyardStatus[BG_SA_RIGHT_CAPTURABLE_GY] == TEAM_HORDE?1:0);
UpdateWorldState(BG_SA_LEFT_GY_HORDE , GraveyardStatus[BG_SA_LEFT_CAPTURABLE_GY] == TEAM_HORDE?1:0);
UpdateWorldState(BG_SA_CENTER_GY_HORDE , GraveyardStatus[BG_SA_CENTRAL_CAPTURABLE_GY] == TEAM_HORDE?1:0);
2010-04-07 18:09:10 +02:00
2010-04-07 22:59:46 +02:00
UpdateWorldState(BG_SA_RIGHT_GY_ALLIANCE , GraveyardStatus[BG_SA_RIGHT_CAPTURABLE_GY] == TEAM_ALLIANCE?1:0);
UpdateWorldState(BG_SA_LEFT_GY_ALLIANCE , GraveyardStatus[BG_SA_LEFT_CAPTURABLE_GY] == TEAM_ALLIANCE?1:0);
UpdateWorldState(BG_SA_CENTER_GY_ALLIANCE , GraveyardStatus[BG_SA_CENTRAL_CAPTURABLE_GY] == TEAM_ALLIANCE?1:0);
2010-04-07 18:09:10 +02:00
2010-04-07 19:14:10 +02:00
if (attackers == TEAM_ALLIANCE)
2010-02-14 19:13:14 -07:00
{
2010-03-07 14:16:55 +01:00
UpdateWorldState(BG_SA_ALLY_ATTACKS, 1);
UpdateWorldState(BG_SA_HORDE_ATTACKS, 0);
2010-04-07 18:09:10 +02:00
2010-03-07 14:16:55 +01:00
UpdateWorldState(BG_SA_RIGHT_ATT_TOKEN_ALL, 1);
UpdateWorldState(BG_SA_LEFT_ATT_TOKEN_ALL, 1);
UpdateWorldState(BG_SA_RIGHT_ATT_TOKEN_HRD, 0);
UpdateWorldState(BG_SA_LEFT_ATT_TOKEN_HRD, 0);
2010-04-07 18:09:10 +02:00
2010-03-07 14:16:55 +01:00
UpdateWorldState(BG_SA_HORDE_DEFENCE_TOKEN,1);
UpdateWorldState(BG_SA_ALLIANCE_DEFENCE_TOKEN,0);
2010-02-14 19:13:14 -07:00
}
2010-03-07 14:16:55 +01:00
else
2010-02-14 19:13:14 -07:00
{
2010-03-07 14:16:55 +01:00
UpdateWorldState(BG_SA_HORDE_ATTACKS, 1);
UpdateWorldState(BG_SA_ALLY_ATTACKS, 0);
2010-04-07 18:09:10 +02:00
2010-03-07 14:16:55 +01:00
UpdateWorldState(BG_SA_RIGHT_ATT_TOKEN_ALL, 0);
UpdateWorldState(BG_SA_LEFT_ATT_TOKEN_ALL, 0);
UpdateWorldState(BG_SA_RIGHT_ATT_TOKEN_HRD, 1);
UpdateWorldState(BG_SA_LEFT_ATT_TOKEN_HRD, 1);
2010-02-14 19:13:14 -07:00
2010-03-07 14:16:55 +01:00
UpdateWorldState(BG_SA_HORDE_DEFENCE_TOKEN,0);
UpdateWorldState(BG_SA_ALLIANCE_DEFENCE_TOKEN,1);
2010-02-14 19:13:14 -07:00
}
2010-03-07 14:16:55 +01:00
UpdateWorldState(BG_SA_PURPLE_GATEWS, 1);
UpdateWorldState(BG_SA_RED_GATEWS, 1);
UpdateWorldState(BG_SA_BLUE_GATEWS, 1);
UpdateWorldState(BG_SA_GREEN_GATEWS, 1);
UpdateWorldState(BG_SA_YELLOW_GATEWS, 1);
UpdateWorldState(BG_SA_ANCIENT_GATEWS, 1);
2010-04-07 18:09:10 +02:00
2010-03-07 14:16:55 +01:00
TeleportPlayers();
return true;
2010-02-14 19:13:14 -07:00
}
void BattleGroundSA::StartShips()
{
2010-04-07 19:14:10 +02:00
if (ShipsStarted)
2010-03-07 14:16:55 +01:00
return;
2010-02-14 19:13:14 -07:00
2010-03-07 14:16:55 +01:00
DoorOpen(BG_SA_BOAT_ONE);
DoorOpen(BG_SA_BOAT_TWO);
2010-04-07 19:12:44 +02:00
for (int i = BG_SA_BOAT_ONE; i <= BG_SA_BOAT_TWO; i++)
2010-02-14 19:13:14 -07:00
{
2010-04-07 22:59:46 +02:00
for (BattleGroundPlayerMap::const_iterator itr = GetPlayers().begin(); itr != GetPlayers().end();itr++)
2010-03-07 14:16:55 +01:00
{
2010-04-07 19:14:10 +02:00
if (Player* p = objmgr.GetPlayer(itr->first))
2010-03-07 14:16:55 +01:00
{
2010-04-07 19:14:10 +02:00
if (p->GetTeamId() != attackers)
2010-03-07 14:16:55 +01:00
continue;
2010-04-07 17:24:07 +02:00
UpdateData data;
WorldPacket pkt;
GetBGObject(i)->BuildValuesUpdateBlockForPlayer(&data, p);
data.BuildPacket(&pkt);
p->GetSession()->SendPacket(&pkt);
2010-03-07 14:16:55 +01:00
}
}
2010-02-14 19:13:14 -07:00
}
2010-03-07 14:16:55 +01:00
ShipsStarted = true;
2009-01-05 14:53:33 -06:00
}
2009-10-17 15:51:44 -07:00
2009-01-21 16:18:57 -06:00
void BattleGroundSA::Update(uint32 diff)
2009-01-05 14:53:33 -06:00
{
BattleGround::Update(diff);
2010-02-14 19:13:14 -07:00
TotalTime += diff;
2010-04-07 19:14:10 +02:00
if (status == BG_SA_WARMUP || status == BG_SA_SECOND_WARMUP)
2010-03-05 14:43:19 -03:00
{
2010-04-07 19:14:10 +02:00
if (TotalTime >= BG_SA_WARMUPLENGTH)
2010-03-05 14:43:19 -03:00
{
2010-04-07 17:24:07 +02:00
TotalTime = 0;
ToggleTimer();
status = (status == BG_SA_WARMUP) ? BG_SA_ROUND_ONE : BG_SA_ROUND_TWO;
2010-03-05 14:43:19 -03:00
}
2010-04-07 19:14:10 +02:00
if (TotalTime >= BG_SA_BOAT_START)
2010-03-05 14:43:19 -03:00
StartShips();
return;
}
2010-03-07 14:16:55 +01:00
else if (GetStatus() == STATUS_IN_PROGRESS)
2010-03-05 14:43:19 -03:00
{
2010-04-07 19:14:10 +02:00
if (status == BG_SA_ROUND_ONE)
2010-03-05 14:43:19 -03:00
{
2010-04-07 19:14:10 +02:00
if (TotalTime >= BG_SA_ROUNDLENGTH)
2010-03-07 14:16:55 +01:00
{
RoundScores[0].time = TotalTime;
TotalTime = 0;
status = BG_SA_SECOND_WARMUP;
attackers = (attackers == TEAM_ALLIANCE) ? TEAM_HORDE : TEAM_ALLIANCE;
RoundScores[0].winner = attackers;
status = BG_SA_SECOND_WARMUP;
ToggleTimer();
ResetObjs();
return;
}
2010-03-05 14:43:19 -03:00
}
2010-04-07 19:14:10 +02:00
else if (status == BG_SA_ROUND_TWO)
2010-03-05 14:43:19 -03:00
{
2010-04-07 19:14:10 +02:00
if (TotalTime >= BG_SA_ROUNDLENGTH)
2010-03-07 14:16:55 +01:00
{
2010-04-07 17:24:07 +02:00
RoundScores[1].time = TotalTime;
RoundScores[1].winner = (attackers == TEAM_ALLIANCE) ? TEAM_HORDE : TEAM_ALLIANCE;
2010-04-07 18:09:10 +02:00
2010-03-07 14:16:55 +01:00
if (RoundScores[0].time == RoundScores[1].time)
EndBattleGround(NULL);
2010-04-07 19:14:10 +02:00
else if (RoundScores[0].time < RoundScores[1].time)
2010-03-07 14:16:55 +01:00
EndBattleGround(RoundScores[0].winner == TEAM_ALLIANCE ? ALLIANCE : HORDE);
else
EndBattleGround(RoundScores[1].winner == TEAM_ALLIANCE ? ALLIANCE : HORDE);
return;
}
}
2010-04-07 19:14:10 +02:00
if (status == BG_SA_ROUND_ONE || status == BG_SA_ROUND_TWO)
2010-03-07 14:16:55 +01:00
SendTime();
2010-03-05 14:43:19 -03:00
}
2009-01-05 14:53:33 -06:00
}
2009-10-17 15:51:44 -07:00
void BattleGroundSA::StartingEventCloseDoors()
{
}
2009-10-17 15:51:44 -07:00
void BattleGroundSA::StartingEventOpenDoors()
{
}
2009-10-17 15:51:44 -07:00
2010-02-14 19:13:14 -07:00
void BattleGroundSA::FillInitialWorldStates(WorldPacket& data)
{
uint32 ally_attacks = uint32(attackers == TEAM_ALLIANCE ? 1 : 0);
uint32 horde_attacks = uint32(attackers == TEAM_HORDE ? 1 : 0);
data << uint32(BG_SA_ANCIENT_GATEWS) << uint32(GateStatus[BG_SA_ANCIENT_GATE]);
data << uint32(BG_SA_YELLOW_GATEWS) << uint32(GateStatus[BG_SA_YELLOW_GATE]);
data << uint32(BG_SA_GREEN_GATEWS) << uint32(GateStatus[BG_SA_GREEN_GATE]);
data << uint32(BG_SA_BLUE_GATEWS) << uint32(GateStatus[BG_SA_BLUE_GATE]);
data << uint32(BG_SA_RED_GATEWS) << uint32(GateStatus[BG_SA_RED_GATE]);
data << uint32(BG_SA_PURPLE_GATEWS) << uint32(GateStatus[BG_SA_PURPLE_GATE]);
data << uint32(BG_SA_BONUS_TIMER) << uint32(0);
data << uint32(BG_SA_HORDE_ATTACKS)<< horde_attacks;
data << uint32(BG_SA_ALLY_ATTACKS) << ally_attacks;
//Time will be sent on first update...
data << uint32(BG_SA_ENABLE_TIMER) << ((TimerEnabled) ? uint32(1) : uint32(0));
data << uint32(BG_SA_TIMER_MINS) << uint32(0);
data << uint32(BG_SA_TIMER_SEC_TENS) << uint32(0);
data << uint32(BG_SA_TIMER_SEC_DECS) << uint32(0);
2010-04-07 22:59:46 +02:00
data << uint32(BG_SA_RIGHT_GY_HORDE) << uint32(GraveyardStatus[BG_SA_RIGHT_CAPTURABLE_GY] == TEAM_HORDE?1:0);
data << uint32(BG_SA_LEFT_GY_HORDE) << uint32(GraveyardStatus[BG_SA_LEFT_CAPTURABLE_GY] == TEAM_HORDE?1:0);
data << uint32(BG_SA_CENTER_GY_HORDE) << uint32(GraveyardStatus[BG_SA_CENTRAL_CAPTURABLE_GY] == TEAM_HORDE?1:0);
2010-02-14 19:13:14 -07:00
2010-04-07 22:59:46 +02:00
data << uint32(BG_SA_RIGHT_GY_ALLIANCE) << uint32(GraveyardStatus[BG_SA_RIGHT_CAPTURABLE_GY] == TEAM_ALLIANCE?1:0);
data << uint32(BG_SA_LEFT_GY_ALLIANCE) << uint32(GraveyardStatus[BG_SA_LEFT_CAPTURABLE_GY] == TEAM_ALLIANCE?1:0);
data << uint32(BG_SA_CENTER_GY_ALLIANCE) << uint32(GraveyardStatus[BG_SA_CENTRAL_CAPTURABLE_GY] == TEAM_ALLIANCE?1:0);
2010-02-14 19:13:14 -07:00
data << uint32(BG_SA_HORDE_DEFENCE_TOKEN) << ally_attacks;
data << uint32(BG_SA_ALLIANCE_DEFENCE_TOKEN) << horde_attacks;
data << uint32(BG_SA_LEFT_ATT_TOKEN_HRD) << horde_attacks;
data << uint32(BG_SA_RIGHT_ATT_TOKEN_HRD) << horde_attacks;
data << uint32(BG_SA_RIGHT_ATT_TOKEN_ALL) << ally_attacks;
data << uint32(BG_SA_LEFT_ATT_TOKEN_ALL) << ally_attacks;
}
2009-01-05 14:53:33 -06:00
void BattleGroundSA::AddPlayer(Player *plr)
{
BattleGround::AddPlayer(plr);
//create score and add it to map, default values are set in constructor
BattleGroundSAScore* sc = new BattleGroundSAScore;
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if (!ShipsStarted)
2010-03-07 14:16:55 +01:00
{
2010-04-07 19:14:10 +02:00
if (plr->GetTeamId() == attackers)
2010-03-07 14:16:55 +01:00
{
plr->CastSpell(plr,12438,true);//Without this player falls before boat loads...
2010-04-07 18:09:10 +02:00
2010-04-07 19:14:10 +02:00
if (urand(0,1))
2010-03-07 14:16:55 +01:00
plr->TeleportTo(607, 2682.936f, -830.368f, 50.0f, 2.895f, 0);
else
plr->TeleportTo(607, 2577.003f, 980.261f, 50.0f, 0.807f, 0);
2010-04-07 18:09:10 +02:00
2010-03-07 14:16:55 +01:00
}
else
plr->TeleportTo(607, 1209.7f, -65.16f, 70.1f, 0.0f, 0);
}
2010-02-14 19:13:14 -07:00
else
2010-03-07 14:16:55 +01:00
{
2010-04-07 19:14:10 +02:00
if (plr->GetTeamId() == attackers)
2010-03-07 14:16:55 +01:00
plr->TeleportTo(607, 1600.381f, -106.263f, 8.8745f, 3.78f, 0);
else
plr->TeleportTo(607, 1209.7f, -65.16f, 70.1f, 0.0f, 0);
}
2010-02-14 19:13:14 -07:00
2009-01-05 14:53:33 -06:00
m_PlayerScores[plr->GetGUID()] = sc;
}
2009-10-17 15:51:44 -07:00
2009-01-05 14:53:33 -06:00
void BattleGroundSA::RemovePlayer(Player* /*plr*/,uint64 /*guid*/)
{
}
2009-10-17 15:51:44 -07:00
void BattleGroundSA::HandleAreaTrigger(Player * /*Source*/, uint32 /*Trigger*/)
2009-01-05 14:53:33 -06:00
{
// this is wrong way to implement these things. On official it done by gameobject spell cast.
if (GetStatus() != STATUS_IN_PROGRESS)
2009-01-05 14:53:33 -06:00
return;
}
2009-10-17 15:51:44 -07:00
2009-01-05 14:53:33 -06:00
void BattleGroundSA::UpdatePlayerScore(Player* Source, uint32 type, uint32 value)
{
BattleGroundScoreMap::iterator itr = m_PlayerScores.find(Source->GetGUID());
2010-04-07 19:14:10 +02:00
if (itr == m_PlayerScores.end()) // player not found...
2009-01-05 14:53:33 -06:00
return;
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if (type == SCORE_DESTROYED_DEMOLISHER)
2010-03-07 14:16:55 +01:00
((BattleGroundSAScore*)itr->second)->demolishers_destroyed += value;
2010-04-07 19:14:10 +02:00
else if (type == SCORE_DESTROYED_WALL)
2010-03-07 14:16:55 +01:00
((BattleGroundSAScore*)itr->second)->gates_destroyed += value;
2010-02-14 19:13:14 -07:00
else
2010-03-07 14:16:55 +01:00
BattleGround::UpdatePlayerScore(Source,type,value);
2010-02-14 19:13:14 -07:00
}
void BattleGroundSA::TeleportPlayers()
{
2010-03-07 14:16:55 +01:00
for (BattleGroundPlayerMap::const_iterator itr = GetPlayers().begin(); itr != GetPlayers().end(); ++itr)
2010-02-14 19:13:14 -07:00
{
2010-04-07 19:14:10 +02:00
if (Player *plr = objmgr.GetPlayer(itr->first))
2010-03-07 14:16:55 +01:00
{
// should remove spirit of redemption
2010-04-07 19:14:10 +02:00
if (plr->HasAuraType(SPELL_AURA_SPIRIT_OF_REDEMPTION))
2010-03-07 14:16:55 +01:00
plr->RemoveAurasByType(SPELL_AURA_MOD_SHAPESHIFT);
2010-02-14 19:13:14 -07:00
2010-03-07 14:16:55 +01:00
if (!plr->isAlive())
{
plr->ResurrectPlayer(1.0f);
plr->SpawnCorpseBones();
}
plr->SetHealth(plr->GetMaxHealth());
plr->SetPower(POWER_MANA, plr->GetMaxPower(POWER_MANA));
plr->CombatStopWithPets(true);
2010-04-07 19:14:10 +02:00
if (plr->GetTeamId() == attackers)
2010-03-07 14:16:55 +01:00
{
plr->CastSpell(plr,12438,true); //Without this player falls before boat loads...
2010-04-07 18:09:10 +02:00
2010-04-07 19:14:10 +02:00
if (urand(0,1))
2010-03-07 14:16:55 +01:00
plr->TeleportTo(607, 2682.936f, -830.368f, 50.0f, 2.895f, 0);
else
2010-04-07 18:09:10 +02:00
plr->TeleportTo(607, 2577.003f, 980.261f, 50.0f, 0.807f, 0);
2010-03-07 14:16:55 +01:00
}
else
plr->TeleportTo(607, 1209.7f, -65.16f, 70.1f, 0.0f, 0);
}
2010-02-14 19:13:14 -07:00
}
}
void BattleGroundSA::EventPlayerDamagedGO(Player* plr, GameObject* go, uint32 event)
{
2010-03-07 14:16:55 +01:00
switch(event)
2010-02-14 19:13:14 -07:00
{
2010-03-07 14:16:55 +01:00
case 19046: //Green gate destroyed
DestroyGate(BG_SA_GREEN_GATE,plr);
return;
case 19045: //blue gate
DestroyGate(BG_SA_BLUE_GATE,plr);
return;
case 19047: //red gate
DestroyGate(BG_SA_RED_GATE,plr);
return;
case 19048: //purple gate
DestroyGate(BG_SA_PURPLE_GATE,plr);
return;
case 19049: //yellow gate
DestroyGate(BG_SA_YELLOW_GATE,plr);
return;
case 19837: //ancient gate
DestroyGate(BG_SA_ANCIENT_GATE,plr);
return;
default:
return;
2010-02-14 19:13:14 -07:00
}
}
void BattleGroundSA::HandleKillUnit(Creature* unit, Player* killer)
{
2010-04-07 19:14:10 +02:00
if (!unit)
2010-03-07 14:16:55 +01:00
return;
2010-02-14 19:13:14 -07:00
2010-04-07 19:14:10 +02:00
if (unit->GetEntry() == 28781) //Demolisher
2010-03-07 14:16:55 +01:00
UpdatePlayerScore(killer, SCORE_DESTROYED_DEMOLISHER, 1);
2010-02-14 19:13:14 -07:00
}
/*
You may ask what the fuck does it do?
Prevents owner overwriting guns faction with own.
*/
void BattleGroundSA::OverrideGunFaction()
{
2010-04-07 19:14:10 +02:00
if (!m_BgCreatures[0])
2010-03-07 14:16:55 +01:00
return;
2010-04-07 18:09:10 +02:00
2010-04-07 19:12:44 +02:00
for (uint8 i = BG_SA_GUN_1; i <= BG_SA_GUN_10;i++)
2010-03-07 14:16:55 +01:00
{
2010-04-07 19:14:10 +02:00
if (Creature* gun = GetBGCreature(i))
2010-04-07 17:24:07 +02:00
gun->setFaction(BG_SA_Factions[attackers? TEAM_ALLIANCE : TEAM_HORDE]);
}
2010-04-07 18:09:10 +02:00
2010-04-07 19:12:44 +02:00
for (uint8 i = BG_SA_DEMOLISHER_1; i <= BG_SA_DEMOLISHER_4;i++)
2010-04-07 17:24:07 +02:00
{
2010-04-07 19:14:10 +02:00
if (Creature* dem = GetBGCreature(i))
2010-03-07 14:16:55 +01:00
dem->setFaction(BG_SA_Factions[attackers]);
2010-04-07 17:24:07 +02:00
}
2010-02-14 19:13:14 -07:00
}
void BattleGroundSA::DestroyGate(uint32 i, Player* pl)
{
2010-04-07 19:14:10 +02:00
if (!GateStatus[i])
2010-03-07 14:16:55 +01:00
return;
2010-02-14 19:13:14 -07:00
2010-04-07 19:14:10 +02:00
if (GameObject* g = GetBGObject(i))
2010-02-14 19:13:14 -07:00
{
2010-04-07 19:14:10 +02:00
if (g->GetGOValue()->building.health == 0)
2010-03-07 14:16:55 +01:00
{
GateStatus[i] = BG_SA_GATE_DESTROYED;
uint32 uws;
switch(i)
{
case 0:
uws = BG_SA_GREEN_GATEWS;
break;
case 1:
uws = BG_SA_YELLOW_GATEWS;
2010-04-07 17:24:07 +02:00
break;
case 2:
2010-03-07 14:16:55 +01:00
uws = BG_SA_BLUE_GATEWS;
2010-04-07 17:24:07 +02:00
break;
case 3:
uws = BG_SA_RED_GATEWS;
break;
case 4:
uws = BG_SA_PURPLE_GATEWS;
break;
case 5:
uws = BG_SA_ANCIENT_GATEWS;
break;
default:
ASSERT(false);
break;
}
2010-04-07 18:09:10 +02:00
2010-04-07 19:14:10 +02:00
if (i < 5)
2010-03-07 14:16:55 +01:00
DelObject(i+9);
UpdateWorldState(uws, GateStatus[i]);
UpdatePlayerScore(pl,SCORE_DESTROYED_WALL, 1);
}
2010-02-14 19:13:14 -07:00
}
}
WorldSafeLocsEntry const* BattleGroundSA::GetClosestGraveYard(Player* player)
{
2010-03-07 14:16:55 +01:00
uint32 safeloc = 0;
WorldSafeLocsEntry const* ret;
2010-04-08 11:49:34 +02:00
WorldSafeLocsEntry const* closest;
2010-03-07 14:16:55 +01:00
float dist, nearest;
float x,y,z;
2010-02-14 19:13:14 -07:00
2010-03-07 14:16:55 +01:00
player->GetPosition(x,y,z);
2010-02-14 19:13:14 -07:00
2010-04-07 19:14:10 +02:00
if (player->GetTeamId() == attackers)
2010-03-07 14:16:55 +01:00
safeloc = BG_SA_GYEntries[BG_SA_BEACH_GY];
else
safeloc = BG_SA_GYEntries[BG_SA_DEFENDER_LAST_GY];
2010-02-14 19:13:14 -07:00
2010-04-08 11:49:34 +02:00
closest = sWorldSafeLocsStore.LookupEntry(safeloc);
nearest = sqrt((closest->x - x)*(closest->x - x) + (closest->y - y)*(closest->y - y)+(closest->z - z)*(closest->z - z));
2010-02-14 19:13:14 -07:00
2010-04-07 19:12:44 +02:00
for (uint8 i = BG_SA_RIGHT_CAPTURABLE_GY; i < BG_SA_MAX_GY; i++)
2010-02-14 19:13:14 -07:00
{
2010-04-07 19:14:10 +02:00
if (GraveyardStatus[i] != player->GetTeamId())
2010-03-07 14:16:55 +01:00
continue;
2010-02-14 19:13:14 -07:00
2010-04-08 11:49:34 +02:00
ret = sWorldSafeLocsStore.LookupEntry(BG_SA_GYEntries[i]);
2010-03-07 14:16:55 +01:00
dist = sqrt((ret->x - x)*(ret->x - x) + (ret->y - y)*(ret->y - y)+(ret->z - z)*(ret->z - z));
2010-04-07 19:14:10 +02:00
if (dist < nearest)
2010-03-07 14:16:55 +01:00
{
2010-04-08 11:49:34 +02:00
closest = ret;
2010-03-07 14:16:55 +01:00
nearest = dist;
}
2010-02-14 19:13:14 -07:00
}
2010-04-08 11:49:34 +02:00
return closest;
2010-02-14 19:13:14 -07:00
}
void BattleGroundSA::SendTime()
{
2010-03-07 14:16:55 +01:00
uint32 end_of_round = (BG_SA_ROUNDLENGTH - TotalTime);
UpdateWorldState(BG_SA_TIMER_MINS, end_of_round/60000);
UpdateWorldState(BG_SA_TIMER_SEC_TENS, (end_of_round%60000)/10000);
UpdateWorldState(BG_SA_TIMER_SEC_DECS, ((end_of_round%60000)%10000)/1000);
2010-02-14 19:13:14 -07:00
}
void BattleGroundSA::EventPlayerClickedOnFlag(Player *Source, GameObject* target_obj)
{
2010-03-07 14:16:55 +01:00
switch(target_obj->GetEntry())
2010-02-14 19:13:14 -07:00
{
2010-03-07 14:16:55 +01:00
case 191307:
case 191308:
CaptureGraveyard(BG_SA_LEFT_CAPTURABLE_GY);
break;
case 191305:
case 191306:
CaptureGraveyard(BG_SA_RIGHT_CAPTURABLE_GY);
break;
case 191310:
case 191309:
CaptureGraveyard(BG_SA_CENTRAL_CAPTURABLE_GY);
break;
default:
return;
2010-02-14 19:13:14 -07:00
};
}
void BattleGroundSA::CaptureGraveyard(BG_SA_Graveyards i)
{
2010-03-07 14:16:55 +01:00
DelCreature(BG_SA_MAXNPC + i);
GraveyardStatus[i] = (GraveyardStatus[i] == TEAM_ALLIANCE? TEAM_HORDE : TEAM_ALLIANCE);
WorldSafeLocsEntry const *sg = NULL;
sg = sWorldSafeLocsStore.LookupEntry(BG_SA_GYEntries[i]);
2010-04-07 22:59:46 +02:00
AddSpiritGuide(i + BG_SA_MAXNPC, sg->x, sg->y, sg->z, BG_SA_GYOrientation[i], (GraveyardStatus[i] == TEAM_ALLIANCE? ALLIANCE : HORDE));
2010-03-07 14:16:55 +01:00
uint32 npc = 0;
switch(i)
2010-02-14 19:13:14 -07:00
{
2010-03-07 14:16:55 +01:00
case BG_SA_LEFT_CAPTURABLE_GY:
SpawnBGObject(BG_SA_LEFT_FLAG,RESPAWN_ONE_DAY);
npc = BG_SA_NPC_RIGSPARK;
2010-04-07 18:09:10 +02:00
AddCreature(BG_SA_NpcEntries[npc], npc, attackers,
2010-04-07 17:24:07 +02:00
BG_SA_NpcSpawnlocs[npc][0], BG_SA_NpcSpawnlocs[npc][1],
BG_SA_NpcSpawnlocs[npc][2], BG_SA_NpcSpawnlocs[npc][3]);
2010-03-07 14:16:55 +01:00
UpdateWorldState(BG_SA_LEFT_GY_ALLIANCE, (GraveyardStatus[i] == TEAM_ALLIANCE? 1:0));
UpdateWorldState(BG_SA_LEFT_GY_HORDE, (GraveyardStatus[i] == TEAM_ALLIANCE? 0:1));
break;
case BG_SA_RIGHT_CAPTURABLE_GY:
SpawnBGObject(BG_SA_RIGHT_FLAG, RESPAWN_ONE_DAY);
npc = BG_SA_NPC_SPARKLIGHT;
2010-04-07 18:09:10 +02:00
AddCreature(BG_SA_NpcEntries[npc], npc, attackers,
2010-04-07 17:24:07 +02:00
BG_SA_NpcSpawnlocs[npc][0], BG_SA_NpcSpawnlocs[npc][1],
BG_SA_NpcSpawnlocs[npc][2], BG_SA_NpcSpawnlocs[npc][3]);
2010-03-07 14:16:55 +01:00
UpdateWorldState(BG_SA_RIGHT_GY_ALLIANCE, (GraveyardStatus[i] == TEAM_ALLIANCE? 1:0));
UpdateWorldState(BG_SA_RIGHT_GY_HORDE, (GraveyardStatus[i] == TEAM_ALLIANCE? 0:1));
break;
case BG_SA_CENTRAL_CAPTURABLE_GY:
SpawnBGObject(BG_SA_CENTRAL_FLAG, RESPAWN_ONE_DAY);
UpdateWorldState(BG_SA_CENTER_GY_ALLIANCE, (GraveyardStatus[i] == TEAM_ALLIANCE? 1:0));
UpdateWorldState(BG_SA_CENTER_GY_HORDE, (GraveyardStatus[i] == TEAM_ALLIANCE? 0:1));
break;
default:
ASSERT(0);
break;
2010-02-14 19:13:14 -07:00
};
}
void BattleGroundSA::EventPlayerUsedGO(Player* Source, GameObject* object)
{
2010-04-07 19:14:10 +02:00
if (object->GetEntry() == BG_SA_ObjEntries[BG_SA_TITAN_RELIC])
2010-02-14 19:13:14 -07:00
{
2010-04-07 19:14:10 +02:00
if (Source->GetTeamId() == attackers)
2010-03-02 19:44:54 -06:00
{
2010-04-07 19:14:10 +02:00
if (status == BG_SA_ROUND_ONE)
2010-03-02 19:44:54 -06:00
{
RoundScores[0].winner = attackers;
RoundScores[0].time = TotalTime;
attackers = (attackers == TEAM_ALLIANCE) ? TEAM_HORDE : TEAM_ALLIANCE;
status = BG_SA_SECOND_WARMUP;
TotalTime = 0;
ToggleTimer();
ResetObjs();
}
2010-04-07 19:14:10 +02:00
else if (status == BG_SA_ROUND_TWO)
2010-03-02 19:44:54 -06:00
{
RoundScores[1].winner = attackers;
RoundScores[1].time = TotalTime;ToggleTimer();
2010-04-07 19:14:10 +02:00
if (RoundScores[0].time == RoundScores[1].time)
2010-03-02 19:44:54 -06:00
EndBattleGround(NULL);
2010-04-07 19:14:10 +02:00
else if (RoundScores[0].time < RoundScores[1].time)
2010-03-02 19:44:54 -06:00
EndBattleGround(RoundScores[0].winner == TEAM_ALLIANCE ? ALLIANCE : HORDE);
else
EndBattleGround(RoundScores[1].winner == TEAM_ALLIANCE ? ALLIANCE : HORDE);
2010-04-07 17:24:07 +02:00
}
}
2010-02-14 19:13:14 -07:00
}
}
void BattleGroundSA::ToggleTimer()
{
2010-03-07 14:16:55 +01:00
TimerEnabled = !TimerEnabled;
UpdateWorldState(BG_SA_ENABLE_TIMER, (TimerEnabled) ? 1 : 0);
2009-01-05 14:53:33 -06:00
}
2010-03-02 19:44:54 -06:00
void BattleGroundSA::EndBattleGround(uint32 winner)
{
//honor reward for winning
2010-03-02 19:44:54 -06:00
if (winner == ALLIANCE)
RewardHonorToTeam(GetBonusHonorFromKill(1), ALLIANCE);
2010-03-02 19:44:54 -06:00
else if (winner == HORDE)
RewardHonorToTeam(GetBonusHonorFromKill(1), HORDE);
2010-04-07 18:09:10 +02:00
2010-03-02 19:44:54 -06:00
//complete map_end rewards (even if no team wins)
RewardHonorToTeam(GetBonusHonorFromKill(2), ALLIANCE);
RewardHonorToTeam(GetBonusHonorFromKill(2), HORDE);
2010-03-02 19:44:54 -06:00
BattleGround::EndBattleGround(winner);
}
2010-03-07 14:16:55 +01:00