Ejemplo n.º 1
0
void Battlefield::EndBattle(bool endByTimer)
{
    if (!m_isActive)
        return;

    m_isActive = false;

    m_StartGrouping = false;

    if (!endByTimer)
        SetDefenderTeam(GetAttackerTeam());

    if (GetDefenderTeam() == TEAM_ALLIANCE)
        DoPlaySoundToAll(BF_ALLIANCE_WINS);
    else
        DoPlaySoundToAll(BF_HORDE_WINS);

    OnBattleEnd(endByTimer);

    // Reset battlefield timer
    m_Timer = m_NoWarBattleTime;
    SendInitWorldStatesToAll();
}
Ejemplo n.º 2
0
void Battlefield::StartBattle()
{
    if (m_isActive)
        return;

    for (int team = 0; team < BG_TEAMS_COUNT; team++)
    {
        m_PlayersInWar[team].clear();
        m_Groups[team].clear();
    }

    m_Timer = m_BattleTime;
    m_isActive = true;

    InvitePlayersInZoneToWar();
    InvitePlayersInQueueToWar();

    DoPlaySoundToAll(BF_START);

    OnBattleStart();
}
Ejemplo n.º 3
0
void BattlefieldTB::OnBattleStart()
{
    m_Data32[BATTLEFIELD_TB_DATA_CAPTURED] = 0;
    m_Data32[BATTLEFIELD_TB_DATA_DESTROYED] = 0;

    for (TbGameObjectBuilding::const_iterator itr = BuildingsInZone.begin(); itr != BuildingsInZone.end(); ++itr)
        if ((*itr))
            (*itr)->Rebuild();

    for (TbWorkShop::const_iterator itr = WorkShopList.begin(); itr != WorkShopList.end(); ++itr)
        if ((*itr))
            (*itr)->UpdateWorkshop();

    for (uint8 i = 0; i < BATTLEFIELD_TB_GY_MAX; i++)
    {
        BfGraveyardTB* graveyard = new BfGraveyardTB(this);

        if (i == BATTLEFIELD_TB_GY_BARADIN_HOLD)
            m_GraveyardList[i]->GiveControlTo(GetDefenderTeam());
        else
            m_GraveyardList[i]->GiveControlTo(GetAttackerTeam());

        m_GraveyardList[i] = graveyard;
    }

    for (GuidSet::const_iterator itr = npcAlliance.begin(); itr != npcAlliance.end(); ++itr)
        if (Unit* unit = sObjectAccessor->FindUnit((*itr)))
            if (Creature* creature = unit->ToCreature())
                HideNpc(creature);

    for (GuidSet::const_iterator itr = npcHorde.begin(); itr != npcHorde.end(); ++itr)
        if (Unit* unit = sObjectAccessor->FindUnit((*itr)))
            if (Creature* creature = unit->ToCreature())
                HideNpc(creature);

    for (GuidSet::const_iterator itr = npcOld.begin(); itr != npcOld.end(); ++itr)
        if (Unit* unit = sObjectAccessor->FindUnit((*itr)))
            if (Creature* creature = unit->ToCreature())
                HideNpc(creature);

    for (GameobjectSet::const_iterator itr = goDoors.begin(); itr != goDoors.end(); ++itr)
    {
        if (*itr)
        {
            (*itr)->ToGameObject()->SetLootState(GO_READY);
            (*itr)->ToGameObject()->UseDoorOrButton();
        }
    }

    for (GuidSet::const_iterator itr = Vehicles.begin(); itr != Vehicles.end(); ++itr)
    {
        if (Unit* unit = sObjectAccessor->FindUnit((*itr)))
        {
            if (Creature* creature = unit->ToCreature())
            {
                ShowNpc(creature, false);
                creature->setFaction(TolBaradFaction[GetAttackerTeam()]);
            }
        }
    }

    for (GuidSet::const_iterator itr = questgiversA.begin(); itr != questgiversA.end(); ++itr)
        if (Unit* unit = sObjectAccessor->FindUnit((*itr)))
            if (Creature* creature = unit->ToCreature())
                HideNpc(creature);

    for (GuidSet::const_iterator itr = questgiversH.begin(); itr != questgiversH.end(); ++itr)
        if (Unit* unit = sObjectAccessor->FindUnit((*itr)))
            if (Creature* creature = unit->ToCreature())
                HideNpc(creature);

    HashMapHolder<Player>::MapType const& plist = sObjectAccessor->GetPlayers();
    for (HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr)
    {
        if (Player* plr = itr->second)
        {
            plr->SendUpdateWorldState(WS_TB_BATTLE_TIMER_ENABLED, 1);
            plr->SendUpdateWorldState(WS_TB_BATTLE_TIMER, uint32(time(NULL) + GetTimer() / 1000));
            plr->SendUpdateWorldState(WS_TB_COUNTER_BUILDINGS, 0);
            plr->SendUpdateWorldState(WS_TB_COUNTER_BUILDINGS_ENABLED, 1);
            plr->SendUpdateWorldState(WS_TB_HORDE_DEFENCE, GetDefenderTeam() == TEAM_HORDE ? 1 : 0);
            plr->SendUpdateWorldState(WS_TB_ALLIANCE_DEFENCE, GetDefenderTeam() == TEAM_ALLIANCE ? 1 : 0);
            plr->SendUpdateWorldState(WS_TB_NEXT_BATTLE_TIMER_ENABLED, 0);
            plr->SendUpdateWorldState(WS_TB_KEEP_HORDE_DEFENCE, GetDefenderTeam() == TEAM_HORDE ? 1 : 0);
            plr->SendUpdateWorldState(WS_TB_KEEP_ALLIANCE_DEFENCE, GetDefenderTeam() == TEAM_ALLIANCE ? 1 : 0);
            plr->SendUpdateWorldState(WS_TB_ALLIANCE_ATTACK, GetDefenderTeam() == TEAM_HORDE ? 1 : 0);
            plr->SendUpdateWorldState(WS_TB_HORDE_ATTACK, GetDefenderTeam() == TEAM_ALLIANCE ? 1 : 0);

            switch (GetDefenderTeam())
            {
            case TEAM_ALLIANCE:
                for (int i = 0; i < MAX_CP_DIFF; i++)
                {
                    if (i == ALLIANCE_DEFENCE)
                        plr->SendUpdateWorldState(WS_TB_SOUTH_CAPTURE_POINT + i, 1);
                    else
                        plr->SendUpdateWorldState(WS_TB_SOUTH_CAPTURE_POINT + i, 0);
                }
                for (int i = 0; i < MAX_CP_DIFF; i++)
                {
                    if (i == ALLIANCE_DEFENCE)
                        plr->SendUpdateWorldState(WS_TB_EAST_CAPTURE_POINT + i, 1);
                    else
                        plr->SendUpdateWorldState(WS_TB_EAST_CAPTURE_POINT + i, 0);
                }
                for (int i = 0; i < MAX_CP_DIFF; i++)
                {
                    if (i == ALLIANCE_DEFENCE)
                        plr->SendUpdateWorldState(WS_TB_WEST_CAPTURE_POINT + i, 1);
                    else
                        plr->SendUpdateWorldState(WS_TB_WEST_CAPTURE_POINT + i, 0);
                }
                for (int i = 0; i < BUILDING_MAX_DIFF; i++)
                {
                    if (i == BUILDING_ALLIANCE_DEFENCE)
                        plr->SendUpdateWorldState(WS_TB_EAST_SPIRE + i, 1);
                    else
                        plr->SendUpdateWorldState(WS_TB_EAST_SPIRE + i, 0);
                }
                for (int i = 0; i < BUILDING_MAX_DIFF; i++)
                {
                    if (i == BUILDING_ALLIANCE_DEFENCE)
                        plr->SendUpdateWorldState(WS_TB_SOUTH_SPIRE + i, 1);
                    else
                        plr->SendUpdateWorldState(WS_TB_SOUTH_SPIRE + i, 0);
                }
                for (int i = 0; i < BUILDING_MAX_DIFF; i++)
                {
                    if (i == BUILDING_ALLIANCE_DEFENCE)
                        plr->SendUpdateWorldState(WS_TB_WEST_SPIRE + i, 1);
                    else
                        plr->SendUpdateWorldState(WS_TB_WEST_SPIRE + i, 0);
                }
                break;

            case TEAM_HORDE:
                for (int i = 0; i < MAX_CP_DIFF; i++)
                {
                    if (i == HORDE_DEFENCE)
                        plr->SendUpdateWorldState(WS_TB_SOUTH_CAPTURE_POINT + i, 1);
                    else
                        plr->SendUpdateWorldState(WS_TB_SOUTH_CAPTURE_POINT + i, 0);
                }
                for (int i = 0; i < MAX_CP_DIFF; i++)
                {
                    if (i == HORDE_DEFENCE)
                        plr->SendUpdateWorldState(WS_TB_EAST_CAPTURE_POINT + i, 1);
                    else
                        plr->SendUpdateWorldState(WS_TB_EAST_CAPTURE_POINT + i, 0);
                }
                for (int i = 0; i < MAX_CP_DIFF; i++)
                {
                    if (i == HORDE_DEFENCE)
                        plr->SendUpdateWorldState(WS_TB_WEST_CAPTURE_POINT + i, 1);
                    else
                        plr->SendUpdateWorldState(WS_TB_WEST_CAPTURE_POINT + i, 0);
                }
                for (int i = 0; i < BUILDING_MAX_DIFF; i++)
                {
                    if (i == BUILDING_HORDE_DEFENCE)
                        plr->SendUpdateWorldState(WS_TB_EAST_SPIRE + i, 1);
                    else
                        plr->SendUpdateWorldState(WS_TB_EAST_SPIRE + i, 0);
                }
                for (int i = 0; i < BUILDING_MAX_DIFF; i++)
                {
                    if (i == BUILDING_HORDE_DEFENCE)
                        plr->SendUpdateWorldState(WS_TB_SOUTH_SPIRE + i, 1);
                    else
                        plr->SendUpdateWorldState(WS_TB_SOUTH_SPIRE + i, 0);
                }
                for (int i = 0; i < BUILDING_MAX_DIFF; i++)
                {
                    if (i == BUILDING_HORDE_DEFENCE)
                        plr->SendUpdateWorldState(WS_TB_WEST_SPIRE + i, 1);
                    else
                        plr->SendUpdateWorldState(WS_TB_WEST_SPIRE + i, 0);
                }
                break;
            }
        }
    }

    for (uint8 team = 0; team < 2; ++team)
    {
        for (GuidSet::const_iterator itr = m_PlayersInWar[team].begin(); itr != m_PlayersInWar[team].end(); ++itr)
        {
            if (Player* plr = sObjectMgr->GetPlayerByLowGUID((*itr)))
            {
                if (plr->GetTeamId() == GetDefenderTeam())
                {
                    uint32 k = urand(0, 3);
                    plr->TeleportTo(BATTLEFIELD_TB_MAPID, TbDefencerStartPosition[k].m_positionX, TbDefencerStartPosition[k].m_positionY, TbDefencerStartPosition[k].m_positionZ, TbDefencerStartPosition[k].m_orientation);
                    plr->CastSpell(plr, SPELL_TB_TOL_BARAD_SLOW_FALL, true);
                }
                else
                    plr->TeleportTo(BATTLEFIELD_TB_MAPID, TbDefencerStartPosition[4].m_positionX, TbDefencerStartPosition[4].m_positionY, TbDefencerStartPosition[4].m_positionZ, TbDefencerStartPosition[4].m_orientation);
            }
        }
    }

    DoPlaySoundToAll(BATTLEFIELD_TB_START);
    SendWarningToAllInZone(BATTLEFIELD_TB_TEXT_START);
}