示例#1
0
void EyeOfTheStorm::UpdateCPs()
{
	uint32 i;
	set< Object* >::iterator itr, itrend;
	Player* plr;
	GameObject* go;
	int32 delta = 0;
	uint32 playercounts[2];
	uint32 towers[2] = {0, 0};
	EOTSCaptureDisplayList::iterator eitr, eitr2, eitrend;
	EOTSCaptureDisplayList* disp;

	for(i = 0; i < EOTS_TOWER_COUNT; ++i)
	{
		/* loop players in range, add any that aren't in the set to the set */
		playercounts[0] = playercounts[1] = 0;
		go = m_CPStatusGO[i];
		disp = &m_CPDisplay[i];

		itr = go->GetInRangePlayerSetBegin();
		itrend = go->GetInRangePlayerSetEnd();

		for(; itr != itrend; ++itr)
		{
			plr = TO< Player* >(*itr);
			if(plr->isAlive() && !(plr->IsStealth()) && !(plr->m_invisible) && !(plr->SchoolImmunityList[0]) && plr->GetDistance2dSq(go) <= EOTS_CAPTURE_DISTANCE)
			{
				playercounts[plr->GetTeam()]++;

				if(disp->find(plr) == disp->end())
				{
					disp->insert(plr);
					plr->SendWorldStateUpdate(WORLDSTATE_EOTS_DISPLAYON, 1);
				}
			}
		}

		/* score diff calculation */
		//printf("EOTS: Playercounts = %u %u\n", playercounts[0], playercounts[1]);
		if(playercounts[0] != playercounts[1])
		{
			if(playercounts[0] > playercounts[1])
				delta = playercounts[0];
			else if(playercounts[1] > playercounts[0])
				delta = -(int32)playercounts[1];

			delta *= EOTS_CAPTURE_RATE;
			m_CPStatus[i] += delta;
			if(m_CPStatus[i] > 100)
				m_CPStatus[i] = 100;
			else if(m_CPStatus[i] < 0)
				m_CPStatus[i] = 0;

			// change the flag depending on cp status
			if(m_CPStatus[i] <= 30)
			{
				if(m_CPBanner[i] && m_CPBanner[i]->GetEntry() != EOTS_BANNER_HORDE)
				{
					RespawnCPFlag(i, EOTS_BANNER_HORDE);
					if(m_spiritGuides[i] != NULL)
					{
						RepopPlayersOfTeam(0, m_spiritGuides[i]);
						m_spiritGuides[i]->Despawn(0, 0);
						RemoveSpiritGuide(m_spiritGuides[i]);
						m_spiritGuides[i] = NULL;
					}
					m_spiritGuides[i] = SpawnSpiritGuide(EOTSGraveyardLocations[i][0], EOTSGraveyardLocations[i][1], EOTSGraveyardLocations[i][2], 0, 1);
					AddSpiritGuide(m_spiritGuides[i]);

					SetWorldState(m_iconsStates[i][0], 0);
					SetWorldState(m_iconsStates[i][1], 0);
					SetWorldState(m_iconsStates[i][2], 1);
					SendChatMessage(CHAT_MSG_BG_EVENT_HORDE, 0, "The Horde has taken the %s !", EOTSControlPointNames[i]);
					PlaySoundToAll(SOUND_HORDE_CAPTURE);
				}
			}
			else if(m_CPStatus[i] >= 70)
			{
				if(m_CPBanner[i] && m_CPBanner[i]->GetEntry() != EOTS_BANNER_ALLIANCE)
				{
					RespawnCPFlag(i, EOTS_BANNER_ALLIANCE);
					if(m_spiritGuides[i] != NULL)
					{
						RepopPlayersOfTeam(1, m_spiritGuides[i]);
						m_spiritGuides[i]->Despawn(0, 0);
						RemoveSpiritGuide(m_spiritGuides[i]);
						m_spiritGuides[i] = NULL;
					}

					m_spiritGuides[i] = SpawnSpiritGuide(EOTSGraveyardLocations[i][0], EOTSGraveyardLocations[i][1], EOTSGraveyardLocations[i][2], 0, 0);
					AddSpiritGuide(m_spiritGuides[i]);

					SetWorldState(m_iconsStates[i][0], 0);
					SetWorldState(m_iconsStates[i][1], 1);
					SetWorldState(m_iconsStates[i][2], 0);
					SendChatMessage(CHAT_MSG_BG_EVENT_ALLIANCE, 0, "The Alliance has taken the %s", EOTSControlPointNames[i]);
					PlaySoundToAll(SOUND_ALLIANCE_CAPTURE);
				}
			}
			else
			{
				if(m_CPBanner[i]->GetEntry() != EOTS_BANNER_NEUTRAL)
				{
					if(m_CPBanner[i]->GetEntry() == EOTS_BANNER_ALLIANCE)
					{
						SendChatMessage(CHAT_MSG_BG_EVENT_NEUTRAL, 0, "The Alliance has lost the control of the %s.", EOTSControlPointNames[i]);
					}
					else if(m_CPBanner[i]->GetEntry() == EOTS_BANNER_HORDE)
					{
						SendChatMessage(CHAT_MSG_BG_EVENT_NEUTRAL, 0, "The Horde has lost the control of the %s.", EOTSControlPointNames[i]);
					}
					RespawnCPFlag(i, EOTS_BANNER_NEUTRAL);
					if(m_spiritGuides[i] != NULL)
					{
						RepopPlayersOfTeam(-1, m_spiritGuides[i]);
						m_spiritGuides[i]->Despawn(0, 0);
						RemoveSpiritGuide(m_spiritGuides[i]);
						m_spiritGuides[i] = NULL;
					}
					SetWorldState(m_iconsStates[i][0], 1);
					SetWorldState(m_iconsStates[i][1], 0);
					SetWorldState(m_iconsStates[i][2], 0);
				}
			}
		}

		/* update the players with the new value */
		eitr = disp->begin();
		eitrend = disp->end();

		for(; eitr != eitrend;)
		{
			plr = *eitr;
			eitr2 = eitr;
			++eitr;

			if(plr->GetDistance2dSq(go) > EOTS_CAPTURE_DISTANCE)
			{
				disp->erase(eitr2);
				plr->SendWorldStateUpdate(WORLDSTATE_EOTS_DISPLAYON, 0);			// hide the cp bar
			}
			else
				plr->SendWorldStateUpdate(WORLDSTATE_EOTS_DISPLAYVALUE, m_CPStatus[i]);
		}
	}

	for(i = 0; i < EOTS_TOWER_COUNT; ++i)
	{
		if(m_CPBanner[i] && m_CPBanner[i]->GetEntry() == EOTS_BANNER_ALLIANCE)
			towers[0]++;
		else if(m_CPBanner[i] && m_CPBanner[i]->GetEntry() == EOTS_BANNER_HORDE)
			towers[1]++;
	}

	SetWorldState(WORLDSTATE_EOTS_ALLIANCE_BASES, towers[0]);
	SetWorldState(WORLDSTATE_EOTS_HORDE_BASES, towers[1]);
}
示例#2
0
void EyeOfTheStorm::UpdateCPs()
{
    uint32 plrcounts[2] = { 0, 0 };

    // details:
    //   loop through inrange players, for new ones, send the enable CP worldstate.
    //   the value of the map is a timestamp of the last update, to avoid cpu time wasted
    //   doing lookups of objects that have already been updated

    unordered_set<Player*  >::iterator itr;
    unordered_set<Player*  >::iterator itrend;
    map<uint32,uint32>::iterator it2, it3;
    uint32 timeptr = (uint32)UNIXTIME;
    bool in_range;
    bool is_valid;
    Player* plr;
    uint32 i;

    for(i = 0; i < EOTS_TOWER_COUNT; i++)
    {
        itr = m_CPStatusGO[i]->GetInRangePlayerSetBegin();
        itrend = m_CPStatusGO[i]->GetInRangePlayerSetEnd();
        plrcounts[0] = plrcounts[1] = 0;

        for(; itr != itrend; itr++)
        {
            if( !(*itr)->IsPvPFlagged() || (*itr)->InStealth() || (*itr)->m_invisible || (*itr)->SchoolImmunityList[0] || (*itr)->m_bgFlagIneligible )
                is_valid = false;
            else
                is_valid = true;

            in_range = ((*itr)->isAlive() && m_CPStatusGO[i]->GetDistanceSq((*itr)) <= EOTS_CAPTURE_DISTANCE) ? true : false;

            it2 = m_CPStored[i].find((*itr)->GetLowGUID());
            if( it2 == m_CPStored[i].end() )
            {
                // new player :)
                if( in_range )
                {
                    (*itr)->SendWorldStateUpdate(WORLDSTATE_EOTS_PVP_CAPTURE_BAR_DISPLAY, 1);
                    (*itr)->SendWorldStateUpdate(WORLDSTATE_EOTS_PVP_CAPTURE_BAR_VALUE, m_CPStatus[i]);
                    m_CPStored[i].insert(make_pair((*itr)->GetLowGUID(), timeptr));

                    if( is_valid )
                        plrcounts[(*itr)->GetTeam()]++;
                }
            }
            else
            {
                // oldie
                if( !in_range )
                {
                    (*itr)->SendWorldStateUpdate(WORLDSTATE_EOTS_PVP_CAPTURE_BAR_DISPLAY, 0);
                    m_CPStored[i].erase(it2);
                }
                else
                {
                    (*itr)->SendWorldStateUpdate(WORLDSTATE_EOTS_PVP_CAPTURE_BAR_VALUE, m_CPStatus[i]);
                    it2->second = timeptr;
                    if( is_valid )
                        plrcounts[(*itr)->GetTeam()]++;
                }
            }
        }

        // handle stuff for the last tick
        // change the flag depending on cp status
        if( m_CPStatus[i] < 50 )
        {
            if( ( m_CPBanner[i] && m_CPBanner[i]->GetEntry() != EOTS_BANNER_HORDE ) ||
              ( m_CPBanner2[i] && m_CPBanner2[i]->GetEntry() != EOTS_BANNER_HORDE ) ||
              ( m_CPBanner3[i] && m_CPBanner3[i]->GetEntry() != EOTS_BANNER_HORDE ) )
            {
                RespawnCPFlag(i, EOTS_BANNER_HORDE);
                if( m_spiritGuides[i] != NULL )
                {
                    RepopPlayersOfTeam( 0, m_spiritGuides[i] );
                    m_spiritGuides[i]->Despawn( 0, 0 );
                    RemoveSpiritGuide( m_spiritGuides[i] );
                    m_spiritGuides[i] = NULLCREATURE;
                }

                m_spiritGuides[i] = SpawnSpiritGuide( EOTSGraveyardLocations[i][0], EOTSGraveyardLocations[i][1], EOTSGraveyardLocations[i][2], 0, 1 );
                AddSpiritGuide( m_spiritGuides[i] );
                SendChatMessage(CHAT_MSG_BG_SYSTEM_HORDE, 0, "The Horde have captured the %s.", EOTSCPNames[i]);

                // set some world states
                m_mapMgr->GetStateManager().UpdateWorldState(EOTSNeturalDisplayFields[i], 0);
                m_mapMgr->GetStateManager().UpdateWorldState(EOTSHordeDisplayFields[i], 1);
                m_mapMgr->GetStateManager().UpdateWorldState(EOTSAllianceDisplayFields[i], 0);
                m_towerCount[1]++;
                m_mapMgr->GetStateManager().UpdateWorldState( WORLDSTATE_EOTS_HORDE_BASES, m_towerCount[1] );
            }
        }
        else if( m_CPStatus[i] > 50 )
        {
            if( ( m_CPBanner[i] && m_CPBanner[i]->GetEntry() != EOTS_BANNER_ALLIANCE ) ||
              ( m_CPBanner2[i] && m_CPBanner2[i]->GetEntry() != EOTS_BANNER_ALLIANCE ) ||
              ( m_CPBanner3[i] && m_CPBanner3[i]->GetEntry() != EOTS_BANNER_ALLIANCE ) )
            {
                RespawnCPFlag(i, EOTS_BANNER_ALLIANCE);
                if( m_spiritGuides[i] != NULL )
                {
                    RepopPlayersOfTeam( 1, m_spiritGuides[i] );
                    m_spiritGuides[i]->Despawn( 0, 0 );
                    RemoveSpiritGuide( m_spiritGuides[i] );
                    m_spiritGuides[i] = NULLCREATURE;
                }

                m_spiritGuides[i] = SpawnSpiritGuide( EOTSGraveyardLocations[i][0], EOTSGraveyardLocations[i][1], EOTSGraveyardLocations[i][2], 0, 0 );
                AddSpiritGuide( m_spiritGuides[i] );
                SendChatMessage(CHAT_MSG_BG_SYSTEM_ALLIANCE, 0, "The Alliance have captured the %s.", EOTSCPNames[i]);

                // set some world states
                m_mapMgr->GetStateManager().UpdateWorldState(EOTSNeturalDisplayFields[i], 0);
                m_mapMgr->GetStateManager().UpdateWorldState(EOTSHordeDisplayFields[i], 0);
                m_mapMgr->GetStateManager().UpdateWorldState(EOTSAllianceDisplayFields[i], 1);
                m_towerCount[0]++;
                m_mapMgr->GetStateManager().UpdateWorldState( WORLDSTATE_EOTS_ALLIANCE_BASES, m_towerCount[0] );
            }
        }
        else
        {
            if( ( m_CPBanner[i] && m_CPBanner[i]->GetEntry() != EOTS_BANNER_NEUTRAL ) ||
              ( m_CPBanner2[i] && m_CPBanner2[i]->GetEntry() != EOTS_BANNER_NEUTRAL ) ||
              ( m_CPBanner3[i] && m_CPBanner3[i]->GetEntry() != EOTS_BANNER_NEUTRAL ) )
            {
                // has to be below or equal to 50, or above/equal
                if( ( m_CPBanner[i]->GetEntry() == EOTS_BANNER_ALLIANCE && m_CPStatus[i] <= 50 ) ||
                    ( m_CPBanner[i]->GetEntry() == EOTS_BANNER_HORDE && m_CPStatus[i] >= 50 ) ||
                    ( m_CPBanner2[i]->GetEntry() == EOTS_BANNER_ALLIANCE && m_CPStatus[i] <= 50 ) ||
                    ( m_CPBanner2[i]->GetEntry() == EOTS_BANNER_HORDE && m_CPStatus[i] >= 50 ) ||
                    ( m_CPBanner3[i]->GetEntry() == EOTS_BANNER_ALLIANCE && m_CPStatus[i] <= 50 ) ||
                    ( m_CPBanner3[i]->GetEntry() == EOTS_BANNER_HORDE && m_CPStatus[i] >= 50 ) )
                {
                    if( m_CPBanner[i] && m_CPBanner[i]->GetEntry() == EOTS_BANNER_ALLIANCE )
                    {
                        SendChatMessage(CHAT_MSG_BG_SYSTEM_NEUTRAL, 0, "The Alliance have lost control of the %s.", EOTSCPNames[i]);
                        m_towerCount[0]--;
                        if( m_towerCount[0] < 0 )
                            m_towerCount[0] = 0;

                        m_mapMgr->GetStateManager().UpdateWorldState( WORLDSTATE_EOTS_ALLIANCE_BASES, m_towerCount[0] );
                    }
                    else
                    {
                        SendChatMessage(CHAT_MSG_BG_SYSTEM_NEUTRAL, 0, "The Horde have lost control of the %s.", EOTSCPNames[i]);
                        m_towerCount[1]--;
                        if( m_towerCount[1] < 0 )
                            m_towerCount[1] = 0;


                        m_mapMgr->GetStateManager().UpdateWorldState( WORLDSTATE_EOTS_HORDE_BASES, m_towerCount[1] );
                    }

                    RespawnCPFlag(i, EOTS_BANNER_NEUTRAL);
                    if( m_spiritGuides[i] != NULL )
                    {
                        RepopPlayersOfTeam( -1, m_spiritGuides[i] );
                        m_spiritGuides[i]->Despawn( 0, 0 );
                        RemoveSpiritGuide( m_spiritGuides[i] );
                        m_spiritGuides[i] = NULLCREATURE;
                    }

                    // set some world states
                    m_mapMgr->GetStateManager().UpdateWorldState(EOTSNeturalDisplayFields[i], 1);
                    m_mapMgr->GetStateManager().UpdateWorldState(EOTSHordeDisplayFields[i], 0);
                    m_mapMgr->GetStateManager().UpdateWorldState(EOTSAllianceDisplayFields[i], 0);
                }
            }
        }

        // send any out of range players the disable flag
        for(it2 = m_CPStored[i].begin(); it2 != m_CPStored[i].end(); )
        {
            it3 = it2;
            ++it2;

            if( it3->second != timeptr )
            {
                plr = m_mapMgr->GetPlayer(it3->first);

                // they WILL be out of range at this point. this is guaranteed. means they left the set rly quickly.
                if( plr != NULL )
                    plr->SendWorldStateUpdate(WORLDSTATE_EOTS_PVP_CAPTURE_BAR_DISPLAY, 0);

                m_CPStored[i].erase(it3);
            }
        }

        // work out current status for next tick
        int32 delta;
        if( plrcounts[0] > plrcounts[1] )
        {
            delta = plrcounts[0] - plrcounts[1];

            // cap it at 25 so the banner always gets removed.
            if( delta > 25 )
                delta = 25;

            m_CPStatus[i] += delta;
            if( m_CPStatus[i] < 0 )
                m_CPStatus[i] = 0;
        }
        else if( plrcounts[1] > plrcounts[0] )
        {
            delta = plrcounts[1] - plrcounts[0];

            // cap it at 25 so the banner always gets removed.
            if( delta > 25 )
                delta = 25;


            m_CPStatus[i] -= delta;
            if( m_CPStatus[i] > 100 )
                m_CPStatus[i] = 100;
        }
    }


}
示例#3
0
void EyeOfTheStorm::UpdateCPs()
{
	uint32 i;
	set<Player*>::iterator itr, itrend;
	Player * plr;
	GameObject * go;
	int32 delta;
	uint32 playercounts[2];
	uint32 towers[2] = {0,0};
	EOTSCaptureDisplayList::iterator eitr, eitr2, eitrend;
	EOTSCaptureDisplayList * disp;

	for(i = 0; i < EOTS_TOWER_COUNT; ++i)
	{
		/* loop players inrange, add any that arent in the set to the set */
		playercounts[0] = playercounts[1] = 0;
		go = m_CPStatusGO[i];
		disp = &m_CPDisplay[i];
		itr = go->GetInRangePlayerSetBegin();
		itrend = go->GetInRangePlayerSetEnd();

		for( ; itr != itrend; ++itr )
		{
			plr = *itr;
			if( (plr->GetDistance2dSq( go ) <= EOTS_CAPTURE_DISTANCE) && plr->isAlive() && !plr->IsStealth() )
			{
				playercounts[plr->GetTeam()]++;

				if( disp->find( plr ) == disp->end() )
				{
					disp->insert( plr );
					plr->SendWorldStateUpdate(EOTS_WORLDSTATE_DISPLAYON, 1);
				}
			}
		}

		/* score diff calculation */
		//printf("EOTS: Playercounts = %u %u\n", playercounts[0], playercounts[1]);
		if(playercounts[0] != playercounts[1])
		{
			if(playercounts[0] > playercounts[1])
				delta = playercounts[0];
			else if(playercounts[1] > playercounts[0])
				delta = -(int32)playercounts[1];

			delta *= EOTS_CAPTURE_RATE;
			m_CPStatus[i] += delta;
			if( m_CPStatus[i] > 100 )
				m_CPStatus[i] = 100;
			else if( m_CPStatus[i] < 0 )
				m_CPStatus[i] = 0;

			// change the flag depending on cp status
			if( m_CPStatus[i] == 0 )
			{
				if( m_CPBanner[i]->GetEntry() != EOTS_BANNER_HORDE )
				{
					SetWorldState( TowerWorldStates[i][0], 0);
					SetWorldState( TowerWorldStates[i][1], 1);

					RespawnCPFlag(i, EOTS_BANNER_HORDE);
					if( m_spiritGuides[i] != NULL )
					{
						RepopPlayersOfTeam( 0, m_spiritGuides[i] );
						m_spiritGuides[i]->Despawn( 0, 0 );
						RemoveSpiritGuide( m_spiritGuides[i] );
						m_spiritGuides[i] = NULL;
					}

					m_spiritGuides[i] = SpawnSpiritGuide( EOTSGraveyardLocations[i][0], EOTSGraveyardLocations[i][1], EOTSGraveyardLocations[i][2], 0, 1 );
					AddSpiritGuide( m_spiritGuides[i] );
				}
			}
			else if( m_CPStatus[i] == 100 )
			{
				if( m_CPBanner[i]->GetEntry() != EOTS_BANNER_ALLIANCE )
				{
					SetWorldState( TowerWorldStates[i][1], 0);
					SetWorldState( TowerWorldStates[i][0], 1);

					RespawnCPFlag(i, EOTS_BANNER_ALLIANCE);
					if( m_spiritGuides[i] != NULL )
					{
						RepopPlayersOfTeam( 1, m_spiritGuides[i] );
						m_spiritGuides[i]->Despawn( 0, 0 );
						RemoveSpiritGuide( m_spiritGuides[i] );
						m_spiritGuides[i] = NULL;
					}

					m_spiritGuides[i] = SpawnSpiritGuide( EOTSGraveyardLocations[i][0], EOTSGraveyardLocations[i][1], EOTSGraveyardLocations[i][2], 0, 0 );
					AddSpiritGuide( m_spiritGuides[i] );
				}
			}
			else
			{
				if( m_CPBanner[i]->GetEntry() != EOTS_BANNER_NEUTRAL )
				{

					for( uint32 j = 0; j < 2; ++j )
						SetWorldState( TowerWorldStates[i][j], 0);

					RespawnCPFlag(i, EOTS_BANNER_NEUTRAL);
					if( m_spiritGuides[i] != NULL )
					{
						RepopPlayersOfTeam( -1, m_spiritGuides[i] );
						m_spiritGuides[i]->Despawn( 0, 0 );
						RemoveSpiritGuide( m_spiritGuides[i] );
						m_spiritGuides[i] = NULL;
					}
				}
			}
		}

		/* update the players with the new value */
		eitr = disp->begin();
		eitrend = disp->end();

		for( ; eitr != eitrend; )
		{
			plr = *eitr;
			eitr2 = eitr;
			++eitr;

			if( plr->GetDistance2dSq( go ) > EOTS_CAPTURE_DISTANCE )
			{
				disp->erase( eitr2 );
				plr->SendWorldStateUpdate(EOTS_WORLDSTATE_DISPLAYON, 0);			// hide the cp bar
			}
			else
				plr->SendWorldStateUpdate(EOTS_WORLDSTATE_DISPLAYVALUE, m_CPStatus[i]);
		}
	}

	for(i = 0; i < EOTS_TOWER_COUNT; ++i)
	{
		if( m_CPStatus[i] == 100 )
			towers[0]++;
		else if( m_CPStatus[i] == 0 )
			towers[1]++;
	}

	SetWorldState( EOTS_WORLDSTATE_ALLIANCE_BASES, towers[0] );
	SetWorldState( EOTS_WORLDSTATE_HORDE_BASES, towers[1] );
}