uint32 BattlefieldWG::GetData(uint32 data) const { switch (data) { // Used to determine when the phasing spells must be casted // See: SpellArea::IsFitToRequirements case AREA_THE_SUNKEN_RING: case AREA_THE_BROKEN_TEMPLATE: case AREA_WESTPARK_WORKSHOP: case AREA_EASTPARK_WORKSHOP: // Graveyards and Workshops are controlled by the same team. if (BfGraveyard const* graveyard = GetGraveyardById(GetSpiritGraveyardId(data))) return graveyard->GetControlTeamId(); } return Battlefield::GetData(data); }
bool Battlefield::Update(uint32 diff) { if (m_Timer <= diff) { // Battlefield ends on time if (IsWarTime()) EndBattle(true); else // Time to start a new battle! StartBattle(); } else m_Timer -= diff; // Invite players a few minutes before the battle's beginning if (!IsWarTime() && !m_StartGrouping && m_Timer <= m_StartGroupingTimer) { m_StartGrouping = true; InvitePlayersInZoneToQueue(); OnStartGrouping(); } bool objective_changed = false; if (IsWarTime()) { if (m_uiKickAfkPlayersTimer <= diff) { m_uiKickAfkPlayersTimer = 1000; KickAfkPlayers(); } else m_uiKickAfkPlayersTimer -= diff; // Kick players who chose not to accept invitation to the battle if (m_uiKickDontAcceptTimer <= diff) { time_t now = time(NULL); for (int team = 0; team < 2; team++) for (PlayerTimerMap::iterator itr = m_InvitedPlayers[team].begin(); itr != m_InvitedPlayers[team].end(); ++itr) if (itr->second <= now) KickPlayerFromBattlefield(itr->first); InvitePlayersInZoneToWar(); for (int team = 0; team < 2; team++) for (PlayerTimerMap::iterator itr = m_PlayersWillBeKick[team].begin(); itr != m_PlayersWillBeKick[team].end(); ++itr) if (itr->second <= now) KickPlayerFromBattlefield(itr->first); m_uiKickDontAcceptTimer = 1000; } else m_uiKickDontAcceptTimer -= diff; for (BfCapturePointMap::iterator itr = m_capturePoints.begin(); itr != m_capturePoints.end(); ++itr) if (itr->second->Update(diff)) objective_changed = true; } if (m_LastResurrectTimer <= diff) { for (uint8 i = 0; i < m_GraveyardList.size(); i++) if (GetGraveyardById(i)) m_GraveyardList[i]->Resurrect(); m_LastResurrectTimer = RESURRECTION_INTERVAL; } else m_LastResurrectTimer -= diff; return objective_changed; }
void BattlefieldWG::OnBattleEnd(bool endByTimer) { // Remove relic if (m_titansRelicGUID) if (GameObject* relic = GetGameObject(m_titansRelicGUID)) relic->RemoveFromWorld(); m_titansRelicGUID = 0; // Remove turret for (GuidSet::const_iterator itr = CanonList.begin(); itr != CanonList.end(); ++itr) { if (Creature* creature = GetCreature(*itr)) { if (!endByTimer) creature->setFaction(WintergraspFaction[GetDefenderTeam()]); HideNpc(creature); } } if (!endByTimer) // One player triggered the relic { // Change all npc in keep for (GuidSet::const_iterator itr = KeepCreature[GetAttackerTeam()].begin(); itr != KeepCreature[GetAttackerTeam()].end(); ++itr) if (Creature* creature = GetCreature(*itr)) HideNpc(creature); for (GuidSet::const_iterator itr = KeepCreature[GetDefenderTeam()].begin(); itr != KeepCreature[GetDefenderTeam()].end(); ++itr) if (Creature* creature = GetCreature(*itr)) ShowNpc(creature, true); // Change all npc out of keep for (GuidSet::const_iterator itr = OutsideCreature[GetDefenderTeam()].begin(); itr != OutsideCreature[GetDefenderTeam()].end(); ++itr) if (Creature* creature = GetCreature(*itr)) HideNpc(creature); for (GuidSet::const_iterator itr = OutsideCreature[GetAttackerTeam()].begin(); itr != OutsideCreature[GetAttackerTeam()].end(); ++itr) if (Creature* creature = GetCreature(*itr)) ShowNpc(creature, true); } // Update all graveyard, control is to defender when no wartime for (uint8 i = 0; i < BATTLEFIELD_WG_GY_HORDE; i++) if (BfGraveyard* graveyard = GetGraveyardById(i)) graveyard->GiveControlTo(GetDefenderTeam()); for (GuidSet::const_iterator itr = m_KeepGameObject[GetDefenderTeam()].begin(); itr != m_KeepGameObject[GetDefenderTeam()].end(); ++itr) if (GameObject* object = GetGameObject(*itr)) object->SetRespawnTime(RESPAWN_IMMEDIATELY); for (GuidSet::const_iterator itr = m_KeepGameObject[GetAttackerTeam()].begin(); itr != m_KeepGameObject[GetAttackerTeam()].end(); ++itr) if (GameObject* object = GetGameObject(*itr)) object->SetRespawnTime(RESPAWN_ONE_DAY); // Update portal defender faction for (GuidSet::const_iterator itr = DefenderPortalList.begin(); itr != DefenderPortalList.end(); ++itr) if (GameObject* portal = GetGameObject(*itr)) portal->SetFaction(WintergraspFaction[GetDefenderTeam()]); // Saving data for (GameObjectBuilding::const_iterator itr = BuildingsInZone.begin(); itr != BuildingsInZone.end(); ++itr) (*itr)->Save(); for (Workshop::const_iterator itr = WorkshopsList.begin(); itr != WorkshopsList.end(); ++itr) (*itr)->Save(); for (GuidSet::const_iterator itr = m_PlayersInWar[GetDefenderTeam()].begin(); itr != m_PlayersInWar[GetDefenderTeam()].end(); ++itr) { if (Player* player = sObjectAccessor->FindPlayer(*itr)) { player->CastSpell(player, SPELL_ESSENCE_OF_WINTERGRASP, true); player->CastSpell(player, SPELL_VICTORY_REWARD, true); // Send Wintergrasp victory achievement DoCompleteOrIncrementAchievement(ACHIEVEMENTS_WIN_WG, player); // Award achievement for succeeding in Wintergrasp in 10 minutes or less if (!endByTimer && GetTimer() <= 10000) DoCompleteOrIncrementAchievement(ACHIEVEMENTS_WIN_WG_TIMER_10, player); } } for (GuidSet::const_iterator itr = m_PlayersInWar[GetAttackerTeam()].begin(); itr != m_PlayersInWar[GetAttackerTeam()].end(); ++itr) if (Player* player = sObjectAccessor->FindPlayer(*itr)) player->CastSpell(player, SPELL_DEFEAT_REWARD, true); for (uint8 team = 0; team < 2; ++team) { for (GuidSet::const_iterator itr = m_PlayersInWar[team].begin(); itr != m_PlayersInWar[team].end(); ++itr) if (Player* player = sObjectAccessor->FindPlayer(*itr)) RemoveAurasFromPlayer(player); m_PlayersInWar[team].clear(); for (GuidSet::const_iterator itr = m_vehicles[team].begin(); itr != m_vehicles[team].end(); ++itr) if (Creature* creature = GetCreature(*itr)) if (creature->IsVehicle()) creature->DespawnOrUnsummon(); m_vehicles[team].clear(); } if (!endByTimer) { for (uint8 team = 0; team < 2; ++team) { for (GuidSet::const_iterator itr = m_players[team].begin(); itr != m_players[team].end(); ++itr) { if (Player* player = sObjectAccessor->FindPlayer(*itr)) { player->RemoveAurasDueToSpell(m_DefenderTeam == TEAM_ALLIANCE ? SPELL_HORDE_CONTROL_PHASE_SHIFT : SPELL_ALLIANCE_CONTROL_PHASE_SHIFT, player->GetGUID()); player->AddAura(m_DefenderTeam == TEAM_HORDE ? SPELL_HORDE_CONTROL_PHASE_SHIFT : SPELL_ALLIANCE_CONTROL_PHASE_SHIFT, player); } } } } if (!endByTimer) // win alli/horde SendWarningToAllInZone((GetDefenderTeam() == TEAM_ALLIANCE) ? BATTLEFIELD_WG_TEXT_WIN_KEEP : BATTLEFIELD_WG_TEXT_WIN_KEEP + 1); else // defend alli/horde SendWarningToAllInZone((GetDefenderTeam() == TEAM_ALLIANCE) ? BATTLEFIELD_WG_TEXT_DEFEND_KEEP : BATTLEFIELD_WG_TEXT_DEFEND_KEEP + 1); }
void BattlefieldTB::UpdateNPCsAndGameObjects() { for (ObjectGuid guid : BattleInactiveNPCs) if (Creature* creature = GetCreature(guid)) HideNpc(creature); for (ObjectGuid guid : BattleInactiveGOs) if (GameObject* gameobject = GetGameObject(guid)) gameobject->SetRespawnTime(RESPAWN_ONE_DAY); for (ObjectGuid guid : TemporaryNPCs) if (Creature* creature = GetCreature(guid)) creature->RemoveFromWorld(); TemporaryNPCs.clear(); for (ObjectGuid guid : TemporaryGOs) if (GameObject* gameobject = GetGameObject(guid)) gameobject->Delete(); TemporaryGOs.clear(); // Tol Barad gates - closed during warmup if (GameObject* gates = GetGameObject(TBGatesGUID)) gates->SetGoState(GetState() == BATTLEFIELD_WARMUP ? GO_STATE_READY : GO_STATE_ACTIVE); // Baradin Hold door - open when inactive if (GameObject* door = GetGameObject(TBDoorGUID)) door->SetGoState(GetState() == BATTLEFIELD_INACTIVE ? GO_STATE_ACTIVE : GO_STATE_READY); // Decide which cellblock and questgiver will be active. m_iCellblockRandom = GetState() == BATTLEFIELD_INACTIVE ? urand(CELLBLOCK_THE_HOLE, CELLBLOCK_CURSED_DEPTHS) : uint8(CELLBLOCK_NONE); // To The Hole gate if (GameObject* door = GetGameObject(m_gateToTheHoleGUID)) door->SetGoState(m_iCellblockRandom == CELLBLOCK_THE_HOLE ? GO_STATE_ACTIVE : GO_STATE_READY); // D-Block gate if (GameObject* door = GetGameObject(m_gateDBlockGUID)) door->SetGoState(m_iCellblockRandom == CELLBLOCK_D_BLOCK ? GO_STATE_ACTIVE : GO_STATE_READY); // Cursed Depths gate if (GameObject* door = GetGameObject(m_gateCursedDepthsGUID)) door->SetGoState(m_iCellblockRandom == CELLBLOCK_CURSED_DEPTHS ? GO_STATE_ACTIVE : GO_STATE_READY); if (GetState() == BATTLEFIELD_INACTIVE) { // Delete capture points for (BfCapturePointMap::iterator itr = m_capturePoints.begin(); itr != m_capturePoints.end(); ++itr) itr->second->DelCapturePoint(); m_capturePoints.clear(); // Create capture points for (uint8 i = 0; i < TB_BASE_COUNT; i++) { TolBaradCapturePoint* capturePoint = new TolBaradCapturePoint(this, GetDefenderTeam()); //Spawn flag pole if (GameObject* go = SpawnGameObject(TBCapturePoints[i].entryFlagPole[GetDefenderTeam()], TBCapturePoints[i].pos, QuaternionData())) { go->SetGoArtKit(GetDefenderTeam() == TEAM_ALLIANCE ? TB_GO_ARTKIT_FLAG_ALLIANCE : TB_GO_ARTKIT_FLAG_HORDE); capturePoint->SetCapturePointData(go); } AddCapturePoint(capturePoint); } for (ObjectGuid guid : BattleInactiveNPCs) if (Creature* creature = GetCreature(guid)) ShowNpc(creature, true); for (ObjectGuid guid : BattleInactiveGOs) if (GameObject* gameobject = GetGameObject(guid)) gameobject->SetRespawnTime(RESPAWN_IMMEDIATELY); for (uint8 i = 0; i < TB_QUEST_INFANTRY_MAX; i++) { uint32 entry = TB_QUEST_INFANTRY[GetDefenderTeam()][urand(0,3)]; if (Creature* creature = SpawnCreature(entry, TBQuestInfantrySpawnData[i])) TemporaryNPCs.insert(creature->GetGUID()); } for (uint8 i = 0; i < TB_GUARDS_MAX; i++) if (Creature* creature = SpawnCreature(GetDefenderTeam() == TEAM_ALLIANCE ? NPC_BARADIN_GUARD : NPC_HELLSCREAMS_SENTRY, GuardNPCSpawns[i])) TemporaryNPCs.insert(creature->GetGUID()); for (uint8 i = 0; i < TB_FACTION_NPC_MAX; i++) if (Creature* creature = SpawnCreature(GetDefenderTeam() == TEAM_ALLIANCE ? FactionNPCSpawns[i].entryAlliance : FactionNPCSpawns[i].entryHorde, FactionNPCSpawns[i].pos)) TemporaryNPCs.insert(creature->GetGUID()); if (Creature* creature = SpawnCreature(RandomQuestgivers[GetDefenderTeam()][m_iCellblockRandom], RandomQuestgiverPos)) TemporaryNPCs.insert(creature->GetGUID()); // Spawn portals for (uint8 i = 0; i < TB_PORTAL_MAX; i++) if (GameObject* go = SpawnGameObject(TBPortalEntry[GetDefenderTeam()], TBPortals[i], QuaternionData())) TemporaryGOs.insert(go->GetGUID()); // Update towers for (ObjectGuid guid : Towers) if (GameObject* go = GetGameObject(guid)) go->SetDestructibleState(GO_DESTRUCTIBLE_REBUILDING); } else if (GetState() == BATTLEFIELD_IN_PROGRESS) { for (uint8 i = 0; i < TB_ABANDONED_SIEGE_ENGINE_COUNT; i++) if (Creature* creature = SpawnCreature(NPC_ABANDONED_SIEGE_ENGINE, TBAbandonedSiegeEngineSpawnData[i])) TemporaryNPCs.insert(creature->GetGUID()); for (ObjectGuid guid : Towers) { if (GameObject* go = GetGameObject(guid)) { go->SetDestructibleState(GO_DESTRUCTIBLE_INTACT); go->ModifyHealth(go->GetGOValue()->Building.MaxHealth); } } } // Spawn banners for (uint8 i = 0; i < TB_BANNER_MAX; i++) if (GameObject* go = SpawnGameObject(TBBannerEntry[GetDefenderTeam()], TBBanners[i], QuaternionData())) TemporaryGOs.insert(go->GetGUID()); // Set graveyard controls for (uint8 i = 0; i < BATTLEFIELD_TB_GRAVEYARD_MAX; i++) if (BfGraveyard* graveyard = GetGraveyardById(i)) graveyard->GiveControlTo(!IsWarTime() || TBGraveyards[i].defenderControls ? GetDefenderTeam() : GetAttackerTeam()); };
void BattlefieldTB::OnBattleEnd(bool endbytimer) { if(!endbytimer) { //Change all npc in keep for(GuidSet::const_iterator itr = KeepCreature[GetAttackerTeam()].begin(); itr != KeepCreature[GetAttackerTeam()].end(); ++itr) { if (Unit* unit = ObjectAccessor::FindUnit((*itr))) if (Creature* creature = unit->ToCreature()) HideNpc(creature); } for(GuidSet::const_iterator itr = KeepCreature[GetDefenderTeam()].begin(); itr != KeepCreature[GetDefenderTeam()].end(); ++itr) { if (Unit* unit = ObjectAccessor::FindUnit((*itr))) if (Creature* creature = unit->ToCreature()) ShowNpc(creature,true); } // Hide creatures that should be visible only when battle is on. for(GuidSet::const_iterator itr = WarCreature[GetAttackerTeam()].begin(); itr != WarCreature[GetAttackerTeam()].end(); ++itr) { if (Unit* unit = ObjectAccessor::FindUnit((*itr))) if (Creature* creature = unit->ToCreature()) HideNpc(creature); } for(GuidSet::const_iterator itr = WarCreature[GetDefenderTeam()].begin(); itr != WarCreature[GetDefenderTeam()].end(); ++itr) { if (Unit* unit = ObjectAccessor::FindUnit((*itr))) if (Creature* creature = unit->ToCreature()) HideNpc(creature); } /*//Change all npc out of keep for(GuidSet::const_iterator itr = OutsideCreature[GetDefenderTeam()].begin(); itr != OutsideCreature[GetDefenderTeam()].end(); ++itr) { if (Unit* unit = sObjectAccessor->FindUnit((*itr))) if (Creature* creature = unit->ToCreature()) HideNpc(creature); } for(GuidSet::const_iterator itr = OutsideCreature[GetAttackerTeam()].begin(); itr != OutsideCreature[GetAttackerTeam()].end(); ++itr) { if (Unit* unit = sObjectAccessor->FindUnit((*itr))) if (Creature* creature = unit->ToCreature()) ShowNpc(creature,true); }*/ } for(TBGameObjectBuilding::const_iterator itr = BuildingsInZone.begin(); itr != BuildingsInZone.end(); ++itr) if ((*itr)) if (!endbytimer) (*itr)->Rebuild(); // Update all graveyard, control is to defender when no wartime for(uint8 i = 0; i<BATTLEFIELD_TB_GY_HORDE; i++) { if(GetGraveyardById(i)) { GetGraveyardById(i)->GiveControlTo(GetDefenderTeam()); } } for(TBGameObjectSet::const_iterator itr = m_KeepGameObject[GetDefenderTeam()].begin(); itr != m_KeepGameObject[GetDefenderTeam()].end(); ++itr) (*itr)->SetRespawnTime(RESPAWN_IMMEDIATELY); for(TBGameObjectSet::const_iterator itr = m_KeepGameObject[GetAttackerTeam()].begin(); itr != m_KeepGameObject[GetAttackerTeam()].end(); ++itr) (*itr)->SetRespawnTime(RESPAWN_ONE_DAY); //Saving data for(TBGameObjectBuilding::const_iterator itr = BuildingsInZone.begin(); itr != BuildingsInZone.end(); ++itr) (*itr)->Save(); for(TBWorkShop::const_iterator itr = WorkShopList.begin(); itr != WorkShopList.end(); ++itr) (*itr)->Save(); for(GuidSet::const_iterator itr = m_PlayersInWar[GetDefenderTeam()].begin(); itr != m_PlayersInWar[GetDefenderTeam()].end(); ++itr) { if (Player* player = sObjectAccessor->FindPlayer((*itr))) { if (player->GetTeamId() == TEAM_HORDE) { player->CastSpell(player, SPELL_TOL_BARAD_VICTORY_HORDE, true); player->CastSpell(player, SPELL_TOL_BARAD_QUEST_HORDE, true); } else { player->CastSpell(player, SPELL_TOL_BARAD_VICTORY_ALLIANCE, true); player->CastSpell(player, SPELL_TOL_BARAD_QUEST_ALLIANCE, true); } // Victory, TB TODO //DoCompleteOrIncrementAchievement(ACHIEVEMENTS_WIN_TB, player); // Ployez sous notre joug /*if (GetTimer() <= 10000 && !endbytimer) DoCompleteOrIncrementAchievement(ACHIEVEMENTS_WIN_TB_TIMER_10, player);*/ } } for(GuidSet::const_iterator itr = m_PlayersInWar[GetAttackerTeam()].begin(); itr != m_PlayersInWar[GetAttackerTeam()].end(); ++itr) { if (Player* player = sObjectAccessor->FindPlayer((*itr))) { player->CastSpell(player, SPELL_TOL_BARAD_DEFEAT, true); } } for(uint8 team = 0; team < 2; ++team) { for(GuidSet::const_iterator itr = m_PlayersInWar[team].begin(); itr != m_PlayersInWar[team].end(); ++itr) { if (Player* player = sObjectAccessor->FindPlayer((*itr))) { player->RemoveAura(SPELL_TOWER_BONUS); player->RemoveAurasDueToSpell(SPELL_VETERAN); player->RemoveAurasDueToSpell(SPELL_SPIRITUAL_IMMUNITY_TB); } } m_PlayersInWar[team].clear(); for(GuidSet::const_iterator itr = m_vehicles[team].begin(); itr != m_vehicles[team].end(); ++itr) { if (Unit* unit = ObjectAccessor::FindUnit((*itr))) if (Creature* creature = unit->ToCreature()) if (creature->IsVehicle()) creature->GetVehicleKit()->Dismiss(); } m_vehicles[team].clear(); } if(!endbytimer) { SendWarningToAllInZone(BATTLEFIELD_TB_TEXT_WIN_KEEP, sObjectMgr->GetTrinityStringForDBCLocale((GetDefenderTeam() == TEAM_ALLIANCE) ? BATTLEFIELD_TB_TEXT_ALLIANCE : BATTLEFIELD_TB_TEXT_HORDE)); } else { SendWarningToAllInZone(BATTLEFIELD_TB_TEXT_DEFEND_KEEP, sObjectMgr->GetTrinityStringForDBCLocale((GetDefenderTeam() == TEAM_ALLIANCE) ? BATTLEFIELD_TB_TEXT_ALLIANCE : BATTLEFIELD_TB_TEXT_HORDE)); } }