コード例 #1
0
ファイル: BattleGround.cpp プロジェクト: yunishaa/mangos-112
void BattleGround::Update(time_t diff)
{

    if(!GetPlayersSize() && !GetRemovedPlayersSize() && !GetReviveQueueSize())
        //BG is empty
        return;

    WorldPacket data;

    if(GetRemovedPlayersSize())
    {
        for(std::map<uint64, uint8>::iterator itr = m_RemovedPlayers.begin(); itr != m_RemovedPlayers.end(); ++itr)
        {
            Player *plr = objmgr.GetPlayer(itr->first);
            switch(itr->second)
            {
                //following code is handled by event:
                /*case 0:
                    sBattleGroundMgr.m_BattleGroundQueues[GetTypeID()].RemovePlayer(itr->first);
                    //RemovePlayerFromQueue(itr->first);
                    if(plr)
                    {
                        sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, this, plr->GetTeam(), plr->GetBattleGroundQueueIndex(m_TypeID), STATUS_NONE, 0, 0);
                        plr->GetSession()->SendPacket(&data);
                    }
                    break;*/
                case 1:                                     // currently in bg and was removed from bg
                    if(plr)
                        RemovePlayerAtLeave(itr->first, true, true);
                    else
                        RemovePlayerAtLeave(itr->first, false, false);
                    break;
                case 2:                                     // revive queue
                    RemovePlayerFromResurrectQueue(itr->first);
                    break;
                default:
                    sLog.outError("BattleGround: Unknown remove player case!");
            }
        }
        m_RemovedPlayers.clear();
    }

    // this code isn't efficient and its idea isn't implemented yet
    /* offline players are removed from battleground in worldsession::LogoutPlayer()
    // remove offline players from bg after ~5 minutes
    if(GetPlayersSize())
    {
        for(std::map<uint64, BattleGroundPlayer>::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
        {
            Player *plr = objmgr.GetPlayer(itr->first);
            itr->second.LastOnlineTime += diff;

            if(plr)
                itr->second.LastOnlineTime = 0;   // update last online time
            else
                if(itr->second.LastOnlineTime >= MAX_OFFLINE_TIME)                   // 5 minutes
                    m_RemovedPlayers[itr->first] = 1;       // add to remove list (BG)
        }
    }*/

    m_LastResurrectTime += diff;
    if (m_LastResurrectTime >= RESURRECTION_INTERVAL)
    {
        if(GetReviveQueueSize())
        {
            for(std::map<uint64, std::vector<uint64> >::iterator itr = m_ReviveQueue.begin(); itr != m_ReviveQueue.end(); ++itr)
            {
                Creature *sh = NULL;
                for(std::vector<uint64>::iterator itr2 = (itr->second).begin(); itr2 != (itr->second).end(); ++itr2)
                {
                    Player *plr = objmgr.GetPlayer(*itr2);
                    if(!plr)
                        continue;

                    if (!sh)
                    {
                        sh = ObjectAccessor::GetCreature(*plr, itr->first);
                        // only for visual effect
                        if (sh)
                            sh->CastSpell(sh, SPELL_SPIRIT_HEAL, true);   // Spirit Heal, effect 117
                    }

                    plr->CastSpell(plr, SPELL_RESURRECTION_VISUAL, true);   // Resurrection visual
                    m_ResurrectQueue.push_back(*itr2);
                }
                (itr->second).clear();
            }

            m_ReviveQueue.clear();
            m_LastResurrectTime = 0;
        }
        else
            // queue is clear and time passed, just update last resurrection time
            m_LastResurrectTime = 0;
    }
    else if (m_LastResurrectTime > 500)    // Resurrect players only half a second later, to see spirit heal effect on NPC
    {
        for(std::vector<uint64>::iterator itr = m_ResurrectQueue.begin(); itr != m_ResurrectQueue.end(); ++itr)
        {
            Player *plr = objmgr.GetPlayer(*itr);
            if(!plr)
                continue;
            plr->ResurrectPlayer(1.0f);
            plr->CastSpell(plr, SPELL_SPIRIT_HEAL_MANA, true);
            ObjectAccessor::Instance().ConvertCorpseForPlayer(*itr);
        }
        m_ResurrectQueue.clear();
    }

    if(GetStatus() == STATUS_WAIT_LEAVE)
    {
        // remove all players from battleground after 2 minutes
        m_EndTime += diff;
        if(m_EndTime >= TIME_TO_AUTOREMOVE)                 // 2 minutes
        {
            for(std::map<uint64, BattleGroundPlayer>::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
            {
                m_RemovedPlayers[itr->first] = 1;           // add to remove list (BG)
            }
            // do not change any battleground's private variables
        }
    }
}
コード例 #2
0
ファイル: OutdoorPvPHS.cpp プロジェクト: MrZomble/TrinityCore
bool OutdoorPvPHS::Update(uint32 diff)
{
    bool changed = OutdoorPvP::Update(diff);
    // Resurrection System
    m_LastResurrectTime += diff;
    if (m_LastResurrectTime >= HS_RESURRECTION_INTERVAL)
    {
        //sLog->outString("HillsbradMGR : Reviving...");
        if ( GetReviveQueueSize() )
        {
            sLog->outString("HillsbradMGR : Dead players in queue.");
            for (std::map<uint64, std::vector<uint64> >::iterator itr = m_ReviveQueue.begin(); itr != m_ReviveQueue.end(); ++itr)
            {
                Creature* sh = NULL;
                for (std::vector<uint64>::const_iterator itr2 = (itr->second).begin(); itr2 != (itr->second).end(); ++itr2)
                {
                    Player* plr = ObjectAccessor::FindPlayer(*itr2);
                    if (!plr)
                        continue;

                    if (!sh && plr->IsInWorld())
                    {
                        sh = plr->GetMap()->GetCreature(itr->first);
                        // only for visual effect
                        if (sh)
                            // Spirit Heal, effect 117
                            sh->CastSpell(sh, HS_SPELL_SPIRIT_HEAL, true);
                    }

                    // Resurrection visual
                    plr->CastSpell(plr, HS_SPELL_RESURRECTION_VISUAL, true);
                    m_ResurrectQueue.push_back(*itr2);
                }
                (itr->second).clear();
            }
            m_ReviveQueue.clear();
        }
        // Reset last resurrection time
        m_LastResurrectTime = 0;
    }
    else if (m_LastResurrectTime > 500) // Resurrect players only half a second later
    {
        if ( GetResurrectQueueSize() )
        {
            //sLog->outString("HillsbradMGR : Resurrecting...");
            for (std::vector<uint64>::const_iterator itr = m_ResurrectQueue.begin(); itr != m_ResurrectQueue.end(); ++itr)
            {
                Player* plr = ObjectAccessor::FindPlayer(*itr);
                if (!plr)
                    continue;
                plr->ResurrectPlayer(1.0f, false);
                plr->CastSpell(plr, 6962, true);
                plr->CastSpell(plr, HS_SPELL_SPIRIT_HEAL_MANA, true);
                sObjectAccessor->ConvertCorpseForPlayer(*itr);
            }
            m_ResurrectQueue.clear();
        }
    }
	
    // Arena Chest System.
    // Update the timer.
	
    //if( m_ChestGUID == 0 )
    //{ 
        if( m_ChestTimer < diff )
        {
            uint32 ffachest = 0;
            ffachest = urand(0, 9);
            if( uint32 guid = sObjectMgr->AddGOData(HSChestPoints[ffachest].entry, HSChestPoints[ffachest].map, HSChestPoints[ffachest].x, HSChestPoints[ffachest].y, HSChestPoints[ffachest].z, HSChestPoints[ffachest].o, 99999999999, 0, 0, 0, 0) )
			{
                //sLog->outString( "Hillsbrad : Spawned Chest(%u) at location %u.", guid,  ffachest);
                m_ChestGUID = guid;
                SendMessageToAll( "FFA chest has been spawned in the fields. Good luck!" );
				sLog->outString( "Hillsbrad : Spawned Chest(%u) at location %u.", m_ChestGUID,  ffachest);
            }
            m_ChestTimer = HS_FFA_CHEST_TIMER;
        }
        else
        {
            m_ChestTimer -= diff;
            // Announce when?
            if( m_ChestAnnounceTimer < diff )
            {
                uint32 ChestTimerSec = uint32( m_ChestTimer / IN_MILLISECONDS );
                if (
                    (ChestTimerSec < 3         && ChestTimerSec > 0) ||   
                    (ChestTimerSec < 30        && (ChestTimerSec % 5) == 0) ||         // < 30 sec; every 5 sec                      
                    (ChestTimerSec <=5*MINUTE  && (ChestTimerSec % MINUTE) == 0) ||    // < 5 min ; every 1 min
                    (ChestTimerSec <=30*MINUTE && (ChestTimerSec % (5*MINUTE)) == 0) ) // < 30 min; every 5 min
                {
                    std::string str = secsToTimeString( ChestTimerSec );
                    SendMessageToAll( "FFA chest will spawn in %s.", str.c_str() );
                }
                m_ChestAnnounceTimer = HS_FFA_CHEST_ANNOUNCE_TIMER;
            }
            else
                m_ChestAnnounceTimer -= diff;
        } 
    //} 
    // Chest debug. 
    if( m_ChestTimer < diff )
    {
        sLog->outString( "HillsbradMGR : Chest Guid (%u), Timer (%u), Announce Timer (%u).", m_ChestGUID, m_ChestTimer, m_ChestAnnounceTimer );
        m_ChestDebugTimer = 60000;
    }
    else
        m_ChestDebugTimer -= diff;
	/*
    // Player scale checker.
    if( m_TenacityTimer <= diff )
    {
        float ratio = 0;
        uint32 stack = 0;
        
        // Reset the stack count
        m_HordeBuff = 0;
        m_AllianceBuff = 0;
        
        if( m_HordeCount > 0 && m_AllianceCount > 0 )
        {
            if( m_AllianceCount > m_HordeCount )
                ratio = m_AllianceCount / m_HordeCount;
            else
                ratio = m_HordeCount / m_AllianceCount;
        }

        if( ratio >= 1.25f )
        { // Buff for lower team
            stack = ratio * ratio;
            if( stack > 20 )
                stack = 20;
            if( m_HordeCount < m_AllianceCount )
                m_HordeBuff = stack;
            else
                m_AllianceBuff = stack;
        }
        // Apply the buff to players.
        ApplyZoneBalanceBuff();
        m_TenacityTimer = HS_TENACITY_TIME;
    } else
        m_TenacityTimer -= diff; 
	*/
	ApplyZoneBalanceBuff();
    return changed;
}