Skip to content

Commit

Permalink
Initial setup for Battleground SotA
Browse files Browse the repository at this point in the history
Please note that this is a development in progress.
The script is not yet functional.

(based on cmangos/mangos-wotlk@4f81063be)

Signed-off-by: Xfurry <xfurry.cmangos@outlook.com>
  • Loading branch information
xfurry committed Jan 2, 2018
1 parent 38627ba commit a8daff8
Show file tree
Hide file tree
Showing 3 changed files with 303 additions and 1 deletion.
167 changes: 166 additions & 1 deletion src/game/BattleGround/BattleGroundSA.cpp
Expand Up @@ -30,20 +30,185 @@ BattleGroundSA::BattleGroundSA()
m_StartMessageIds[BG_STARTING_EVENT_FOURTH] = LANG_BG_WS_HAS_BEGUN;
}

void BattleGroundSA::Update(uint32 diff)
{
BattleGround::Update(diff);

if (GetStatus() == STATUS_WAIT_JOIN)
{
if (m_boatStartTimer)
{
if (m_boatStartTimer <= diff)
{
// Set the boats in motion
for (GuidList::const_iterator itr = m_transportShipGuids[m_attackingTeamIdx].begin(); itr != m_transportShipGuids[m_attackingTeamIdx].end(); ++itr)
{
if (GameObject* pShip = GetBgMap()->GetGameObject(*itr))
{
pShip->SetRespawnTime(30);
pShip->Refresh();
pShip->SetUInt32Value(GAMEOBJECT_LEVEL, 0);
pShip->SetGoState(GO_STATE_READY);
}
}

// ToDo: stop the boats when they reach the destination. Should be handled by event id 22095 and 18829
m_boatStartTimer = 0;
}
else
m_boatStartTimer -= diff;
}
}
else if (GetStatus() == STATUS_IN_PROGRESS)
{
// battle timer
if (m_battleRoundTimer)
{
if (m_battleRoundTimer < diff)
{
// ToDo:
m_battleRoundTimer = 0;
}
else
{
// update timer - if BattlegroundMgr update timer interval needs to be lowered replace this line with the commented-out ones below
UpdateTimerWorldState();

/*if (m_zoneUpdateTimer < diff)
{
// update timer
UpdateTimerWorldState();
m_zoneUpdateTimer = BG_SA_TIMER_UPDATE_TIME;
}
else
m_zoneUpdateTimer -= diff;*/

m_battleRoundTimer -= diff;
}
}
}
}

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;

m_PlayerScores[plr->GetObjectGuid()] = sc;

// add phase aura
plr->CastSpell(plr, m_attackingTeamIdx == TEAM_INDEX_ALLIANCE ? BG_SA_SPELL_HORDE_CONTROL_PHASE_SHIFT : BG_SA_SPELL_ALLIANCE_CONTROL_PHASE_SHIFT, TRIGGERED_OLD_TRIGGERED);

// Teleport player to the correct location
if (GetTeamIndexByTeamId(plr->GetTeam()) == m_attackingTeamIdx)
{
// TODO: make this location more dyanmic, depending on the transport position
plr->CastSpell(plr, BG_SA_SPELL_TELEPORT_ATTACKERS, TRIGGERED_OLD_TRIGGERED);

// Note: the following code is temporary until spell effect 60178 is implemented
uint8 randLoc = (urand(0, 1));
plr->TeleportTo(plr->GetMapId(), strandTeleportLoc[randLoc][0], strandTeleportLoc[randLoc][1], strandTeleportLoc[randLoc][2], strandTeleportLoc[randLoc][3]);
}
else
plr->CastSpell(plr, BG_SA_SPELL_TELEPORT_DEFENDER, TRIGGERED_OLD_TRIGGERED);
}

void BattleGroundSA::StartingEventOpenDoors()
{
OpenDoorEvent(BG_EVENT_DOOR);

UpdateWorldState(BG_SA_STATE_ENABLE_TIMER, 1);
}

void BattleGroundSA::UpdatePlayerScore(Player* source, uint32 type, uint32 value)
{
BattleGroundScoreMap::iterator itr = m_PlayerScores.find(source->GetObjectGuid());
if (itr == m_PlayerScores.end()) // player not found...
if (itr == m_PlayerScores.end())
return;

BattleGround::UpdatePlayerScore(source, type, value);
}

void BattleGroundSA::HandleCreatureCreate(Creature* creature)
{
// ToDo handle vehicles
}

void BattleGroundSA::HandleGameObjectCreate(GameObject* go)
{
switch (go->GetEntry())
{
case BG_SA_GO_TRANSPORT_SHIP_HORDE_1:
case BG_SA_GO_TRANSPORT_SHIP_HORDE_2:
if (m_attackingTeamIdx == TEAM_INDEX_HORDE)
m_transportShipGuids[TEAM_INDEX_HORDE].push_back(go->GetObjectGuid());
break;
case BG_SA_GO_TRANSPORT_SHIP_ALLIANCE_1:
case BG_SA_GO_TRANSPORT_SHIP_ALLIANCE_2:
if (m_attackingTeamIdx == TEAM_INDEX_ALLIANCE)
m_transportShipGuids[TEAM_INDEX_ALLIANCE].push_back(go->GetObjectGuid());
break;
}
}

// Function used to update the timer
void BattleGroundSA::UpdateTimerWorldState()
{
// Calculate time
uint32 secondsLeft = m_battleRoundTimer;

UpdateWorldState(BG_SA_STATE_TIMER_SEC_FIRST_DIGIT, ((secondsLeft % 60000) % 10000) / 1000);
UpdateWorldState(BG_SA_STATE_TIMER_SEC_SECOND_DIGIT, (secondsLeft % 60000) / 10000);
UpdateWorldState(BG_SA_STATE_TIMER_MINUTES, secondsLeft / 60000);
}

void BattleGroundSA::FillInitialWorldStates(WorldPacket &data, uint32& count)
{
// fill attacker & defender states
FillInitialWorldState(data, count, BG_SA_STATE_ATTACKER_ALLIANCE, m_attackingTeamIdx == TEAM_INDEX_ALLIANCE);
FillInitialWorldState(data, count, BG_SA_STATE_ATTACKER_HORDE, m_attackingTeamIdx == TEAM_INDEX_HORDE);

FillInitialWorldState(data, count, BG_SA_STATE_DEFENSE_TOKEN_HORDE, m_attackingTeamIdx == TEAM_INDEX_ALLIANCE);
FillInitialWorldState(data, count, BG_SA_STATE_DEFENSE_TOKEN_ALLIANCE, m_attackingTeamIdx == TEAM_INDEX_HORDE);

FillInitialWorldState(data, count, BG_SA_STATE_RIGHT_ATTACK_TOKEN_ALLIANCE, m_attackingTeamIdx == TEAM_INDEX_ALLIANCE);
FillInitialWorldState(data, count, BG_SA_STATE_LEFT_ATTACK_TOKEN_ALLIANCE, m_attackingTeamIdx == TEAM_INDEX_ALLIANCE);
FillInitialWorldState(data, count, BG_SA_STATE_RIGHT_ATTACK_TOKEN_HORDE, m_attackingTeamIdx == TEAM_INDEX_HORDE);
FillInitialWorldState(data, count, BG_SA_STATE_LEFT_ATTACK_TOKEN_HORDE, m_attackingTeamIdx == TEAM_INDEX_HORDE);

// fill gates states
for (uint8 i = 0; i < BG_SA_MAX_GATES; ++i)
{
// special case for final gate: color depends on the defender (blue for alliance; red for horde)
if (i == BG_SA_MAX_GATES - 1 && m_attackingTeamIdx == TEAM_INDEX_ALLIANCE)
FillInitialWorldState(data, count, strandGates[i], m_gateStateValue[i] + 3);
else
FillInitialWorldState(data, count, strandGates[i], m_gateStateValue[i]);
}

// fill timer states - will be updated later in the script
FillInitialWorldState(data, count, BG_SA_STATE_ENABLE_TIMER, 0);
FillInitialWorldState(data, count, BG_SA_STATE_TIMER_MINUTES, 0);
FillInitialWorldState(data, count, BG_SA_STATE_TIMER_SEC_SECOND_DIGIT, 0);
FillInitialWorldState(data, count, BG_SA_STATE_TIMER_SEC_FIRST_DIGIT, 0);
FillInitialWorldState(data, count, BG_SA_STATE_BONUS_TIMER, 0);

// fill graveyard states
// ToDo:
}

void BattleGroundSA::Reset()
{
// call parent's class reset
BattleGround::Reset();

m_attackingTeamIdx = urand(0, 1) ? TEAM_INDEX_ALLIANCE : TEAM_INDEX_HORDE;

m_boatStartTimer = BG_SA_TIMER_BOAT_START;
m_battleRoundTimer = BG_SA_TIMER_ROUND_LENGTH;

// set initial gate state values
for (uint8 i = 0; i < BG_SA_MAX_GATES; ++i)
m_gateStateValue[i] = BG_SA_STATE_VALUE_GATE_INTACT;
}
129 changes: 129 additions & 0 deletions src/game/BattleGround/BattleGroundSA.h
Expand Up @@ -24,6 +24,116 @@ class BattleGround;
#define BG_SA_EVENT_START_BATTLE_1 23748 // Ally / Horde likely
#define BG_SA_EVENT_START_BATTLE_2 21702

enum
{
BG_SA_MAX_GATES = 6,

// world state values
BG_SA_STATE_VALUE_GATE_INTACT = 1,
BG_SA_STATE_VALUE_GATE_DAMAGED = 2,
BG_SA_STATE_VALUE_GATE_DESTROYED = 3,

// timers
BG_SA_TIMER_ROUND_LENGTH = 10 * MINUTE * IN_MILLISECONDS,
//BG_SA_TIMER_UPDATE_TIME = 1000,
BG_SA_TIMER_BOAT_START = 60000,

// world states
BG_SA_STATE_TIMER_MINUTES = 3559,
BG_SA_STATE_TIMER_SEC_SECOND_DIGIT = 3560, // tens
BG_SA_STATE_TIMER_SEC_FIRST_DIGIT = 3561, // units
BG_SA_STATE_ENABLE_TIMER = 3564,
BG_SA_STATE_BONUS_TIMER = 3571,

BG_SA_STATE_ATTACKER_ALLIANCE = 4352,
BG_SA_STATE_ATTACKER_HORDE = 4353,

BG_SA_STATE_PURPLE_GATE = 3614,
BG_SA_STATE_RED_GATE = 3617,
BG_SA_STATE_BLUE_GATE = 3620,
BG_SA_STATE_GREEN_GATE = 3623,
BG_SA_STATE_YELLOW_GATE = 3638,
BG_SA_STATE_ANCIENT_GATE = 3849,

BG_SA_STATE_GY_LEFT_ALLIANCE = 3635,
BG_SA_STATE_GY_RIGHT_ALLIANCE = 3636,
BG_SA_STATE_GY_CENTER_ALLIANCE = 3637,

BG_SA_STATE_GY_LEFT_HORDE = 3633,
BG_SA_STATE_GY_RIGHT_HORDE = 3632,
BG_SA_STATE_GY_CENTER_HORDE = 3634,

BG_SA_STATE_RIGHT_ATTACK_TOKEN_ALLIANCE = 3627,
BG_SA_STATE_LEFT_ATTACK_TOKEN_ALLIANCE = 3626,

BG_SA_STATE_RIGHT_ATTACK_TOKEN_HORDE = 3628,
BG_SA_STATE_LEFT_ATTACK_TOKEN_HORDE = 3629,

BG_SA_STATE_DEFENSE_TOKEN_HORDE = 3631,
BG_SA_STATE_DEFENSE_TOKEN_ALLIANCE = 3630,

// creatures
BG_SA_VEHICLE_DEMOLISHER = 28781,
BG_SA_VEHICLE_CANNON = 27894,

// gameobjects
// Main gates
BG_SA_GO_GATE_GREEN_EMERALD = 190722,
BG_SA_GO_GATE_MAUVE_AMETHYST = 190723,
BG_SA_GO_GATE_BLUE_SAPHIRE = 190724,
BG_SA_GO_GATE_RED_SUN = 190726,
BG_SA_GO_GATE_YELLOW_MOON = 190727,
BG_SA_GO_GATE_ANCIENT_SHRINE = 192549,

// Relics - main objective of the battleground (has same faction as the attackers)
BG_SA_GO_TITAN_RELIC_HORDE = 194082,
BG_SA_GO_TITAN_RELIC_ALLIANCE = 194083,

// Sigils - used for decoration purpose
BG_SA_GO_SIGIL_YELLOW_MOON = 192685,
BG_SA_GO_SIGIL_GREEN_MOON = 192687,
BG_SA_GO_SIGIL_BLUE_MOON = 192689,
BG_SA_GO_SIGIL_RED_MOON = 192690,
BG_SA_GO_SIGIL_PURPLE_MOON = 192691,

// various objects (have same faction as the defenders)
BG_SA_GO_DEFENDERS_PORTAL_ALLIANCE = 191575,
BG_SA_GO_DEFENDERS_PORTAL_HORDE = 190763,
BG_SA_GO_SEAFORIUM_BOMB_ALLIANCE = 190753,
BG_SA_GO_SEAFORIUM_BOMB_HORDE = 194086,

// graveyard flags
BG_SA_GO_GY_FLAG_ALLIANCE_1 = 191306,
BG_SA_GO_GY_FLAG_ALLIANCE_2 = 191308,
BG_SA_GO_GY_FLAG_ALLIANCE_3 = 191310,
BG_SA_GO_GY_FLAG_HORDE_1 = 191305,
BG_SA_GO_GY_FLAG_HORDE_2 = 191307,
BG_SA_GO_GY_FLAG_HORDE_3 = 191309,

// transport ships
BG_SA_GO_TRANSPORT_SHIP_HORDE_1 = 193183,
BG_SA_GO_TRANSPORT_SHIP_HORDE_2 = 193184,
BG_SA_GO_TRANSPORT_SHIP_ALLIANCE_1 = 193182,
BG_SA_GO_TRANSPORT_SHIP_ALLIANCE_2 = 193185,

// spells
BG_SA_SPELL_TELEPORT_DEFENDER = 52364,
BG_SA_SPELL_TELEPORT_ATTACKERS = 60178,
BG_SA_SPELL_END_OF_ROUND = 52459,
BG_SA_SPELL_REMOVE_SEAFORIUM = 59077,
BG_SA_SPELL_ALLIANCE_CONTROL_PHASE_SHIFT = 60027,
BG_SA_SPELL_HORDE_CONTROL_PHASE_SHIFT = 60028,
};

static const uint32 strandGates[BG_SA_MAX_GATES] = { BG_SA_STATE_PURPLE_GATE, BG_SA_STATE_RED_GATE, BG_SA_STATE_BLUE_GATE, BG_SA_STATE_GREEN_GATE, BG_SA_STATE_YELLOW_GATE, BG_SA_STATE_ANCIENT_GATE };

static const float strandTeleportLoc[3][4] =
{
{2682.936f, -830.368f, 19.0f, 2.895f}, // left side boat
{2577.003f, 980.261f, 19.0f, 0.807f}, // right side boat
{1209.7f, -65.16f, 70.1f, 0.0f} // defender position (not used; player teleported by spell)
};

class BattleGroundSAScore : public BattleGroundScore
{
public:
Expand All @@ -40,8 +150,27 @@ class BattleGroundSA : public BattleGround

/* inherited from BattlegroundClass */
virtual void AddPlayer(Player* plr) override;
virtual void StartingEventOpenDoors() override;
virtual void FillInitialWorldStates(WorldPacket &d, uint32& count) override;
virtual void Reset() override;

void HandleCreatureCreate(Creature* creature) override;
void HandleGameObjectCreate(GameObject* go) override;

/* Scorekeeping */
void UpdatePlayerScore(Player* source, uint32 type, uint32 value) override;

void Update(uint32 diff) override;

private:
void UpdateTimerWorldState();

PvpTeamIndex m_attackingTeamIdx;

uint32 m_gateStateValue[BG_SA_MAX_GATES];
uint32 m_battleRoundTimer;
uint32 m_boatStartTimer;

GuidList m_transportShipGuids[PVP_TEAM_COUNT];
};
#endif
8 changes: 8 additions & 0 deletions src/game/SpellEffects.cpp
Expand Up @@ -8999,6 +8999,14 @@ void Spell::EffectScriptEffect(SpellEffectEntry const* effect)
unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_STUN);
return;
}
case 54640: // Teleport
{
if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
return;

m_caster->CastSpell(unitTarget, m_spellInfo->CalculateSimpleValue(eff_idx), TRIGGERED_OLD_TRIGGERED, nullptr, nullptr, m_originalCasterGUID);
return;
}
case 55693: // Remove Collapsing Cave Aura
{
if (!unitTarget)
Expand Down

0 comments on commit a8daff8

Please sign in to comment.