bool OPvPWintergrasp::Update(uint32 diff) { if(m_timer > diff) { m_timer -= diff; if(m_wartime) OutdoorPvP::Update(diff); // update capture points } else { if(m_wartime) { if(m_defender == TEAM_ALLIANCE) sWorld.SendZoneText(ZONE_WINTERGRASP, "Alliance has successfully defended the fortress!"); else sWorld.SendZoneText(ZONE_WINTERGRASP, "Horde has successfully defended the fortress!"); GiveReward(); EndBattle(); } else { sWorld.SendZoneText(ZONE_WINTERGRASP, "Battle begins!"); UpdateAllWorldObject(); StartBattle(); } } return false; }
void CArena::Enter() { CBBGame::Get()->RegisterRenderable(this); CBBGame::Get()->RegisterUpdateable(this); CMessageBroadcaster<CEvent>::Subscribe(this); StartBattle(); }
void cgBattleManager::SetCurBattle( int nBattleID ) { m_fBattleTime = 0.0f; m_fScrolledMiles = 0.0f; m_nCurBattleID = nBattleID; LoadBattle(); StartBattle(); }
void WintergraspScript::OnUpdate(uint32 p_time) { if(!m_Initialized) { m_Initialized = true; sLog.Notice("Wintergrasp", "Server is loading wintergrasp tiles, it might take some time.."); mgr->UpdateAllCells(true, ZONE_WINTERGRASP); sLog.Notice("Wintergrasp", "Finished loading tiles..."); } UpdateClockDigit(m_NextTime-UNIXTIME, m_started ? 0 : 1, 10); if(UNIXTIME >= m_NextTime) { if(m_started) { if(m_FinishTime > p_time) { m_FinishTime -= p_time; UpdateWarZones(); } else { EndBattle(); Herald((char*)format("The battle for Wintergrasp has ended! The Winner is, the %s!", ControllingTeam ? "Horde" : "Alliance").c_str()); } } else StartBattle(); } else { float timeInHours = float((m_NextTime-UNIXTIME)/60); if(timeInHours < 0.7) { float timeInMinutes = floor((timeInHours*60)); if(timeInMinutes == 30 && !ThirtyMinuteHerald) { ThirtyMinuteHerald = true; Herald("The battle for Wintergrasp begins in 30 minutes!"); } else if(timeInMinutes == 15 && !FifteenMinuteHerald) { FifteenMinuteHerald = true; Herald("The battle for Wintergrasp begins in 15 minutes!"); } } else { if(timeInHours == 1 && !FirstHourHerald) { FirstHourHerald = true; Herald("The battle for Wintergrasp begins in 1 hour!"); } } } }
bool OPvPWintergrasp::Update(uint32 diff) { if (m_timer > diff) { m_timer -= diff; if (m_wartime) OutdoorPvP::Update(diff); // update capture points UpdateClock(); } else { m_sendUpdate = false; if (m_wartime) { if (m_changeDefender) { m_changeDefender = false; m_defender = OTHER_TEAM(m_defender); if (m_defender == TEAM_ALLIANCE) sWorld.SendZoneText(ZONE_WINTERGRASP, "Alliance has taken over the fortress!"); else sWorld.SendZoneText(ZONE_WINTERGRASP, "Horde has taken over the fortress!"); } else { if (m_defender == TEAM_ALLIANCE) sWorld.SendZoneText(ZONE_WINTERGRASP, "Alliance has successfully defended the fortress!"); else sWorld.SendZoneText(ZONE_WINTERGRASP, "Horde has successfully defended the fortress!"); } EndBattle(); } else { sWorld.SendZoneText(ZONE_WINTERGRASP, "Battle begins!"); StartBattle(); } UpdateAllWorldObject(); UpdateClock(); SendInitWorldStatesTo(); m_sendUpdate = true; } return false; }
bool CArena::HandleMessage(CEvent e) { bool eaten = false; if (e.type == CEvent::KeyPressed) { if (e.key.code == CKeyboard::R) { StartBattle(); eaten = true; } } return eaten; }
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; }
//----------------------------------------------------------------------------- // Purpose: Start a Battle //----------------------------------------------------------------------------- void CDiscArena::StartBattleThink( void ) { StartBattle(); }
/** Battlefield update function */ void Battlefield::Update(uint32 diff) { // update battlefield timer to everyone SendBattlefieldTimerUpdate(); // global battlefield timer if (m_timer < diff) { if (m_status == BF_STATUS_COOLDOWN) StartBattle(m_zoneOwner); else if (m_status == BF_STATUS_IN_PROGRESS) EndBattle(m_zoneOwner); } else m_timer -= diff; // refresh battlefield players if (GetBattlefieldStatus() == BF_STATUS_IN_PROGRESS) { if (m_playersUpdateTimer < diff) { UpdateBattlefieldPlayers(); m_playersUpdateTimer = 5000; } else m_playersUpdateTimer -= diff; } // invite all players in zone to queue if (GetBattlefieldStatus() == BF_STATUS_COOLDOWN && m_timer <= m_startInviteDelay && !m_playersInvited) { m_playersInvited = true; for (auto& m_zonePlayer : m_zonePlayers) { if (!m_zonePlayer.first) continue; Player* player = sObjectMgr.GetPlayer(m_zonePlayer.first); if (!player) continue; InvitePlayerToQueue(player); } } // kick all the players marked to leave if (GetBattlefieldStatus() == BF_STATUS_IN_PROGRESS) { for (auto& m_invitedPlayer : m_invitedPlayers) { for (std::map<ObjectGuid, time_t>::iterator itr = m_invitedPlayer.begin(); itr != m_invitedPlayer.end();) { if (itr->second < time(nullptr)) { if (Player* player = sObjectMgr.GetPlayer(itr->first)) player->GetSession()->SendBattlefieldLeaveMessage(m_battleFieldId, BATTLEFIELD_LEAVE_REASON_EXITED); m_invitedPlayer.erase(itr++); } else ++itr; } } } // check the queued players if (m_queueUpdateTimer < diff) { m_queueUpdateTimer = 30000; for (auto& m_queuedPlayer : m_queuedPlayers) { for (std::set<ObjectGuid>::iterator itr = m_queuedPlayer.begin(); itr != m_queuedPlayer.end();) { if (!sObjectMgr.GetPlayer(*itr, true)) m_queuedPlayer.erase(itr++); else ++itr; } } } else m_queueUpdateTimer -= diff; }
bool Battlefield::Update(uint32 diff) { // When global timer is end if (m_Timer <= diff) { // Here end of battle by timer if (IsWarTime()) { EndBattle(true); } // Start of battle else { StartBattle(); } } else m_Timer -= diff; //Some times before battle start invite player to queue if (!m_StartGrouping && m_Timer <= m_StartGroupingTimer) { m_StartGrouping = true; InvitePlayerInZoneToQueue(); OnStartGrouping(); // for scripting } bool objective_changed = false; if (IsWarTime()) { if (m_uiKickAfkTimer <= diff) { m_uiKickAfkTimer = 1000; KickAfk(); } else m_uiKickAfkTimer -= diff; //Here kick player witch dont have accept invitation to join the war when time is end (time of windows) if (m_uiKickDontAcceptTimer <= diff) { for (int team = 0; team < 2; team++) for (PlayerTimerMap::iterator itr = m_InvitedPlayers[team].begin(); itr != m_InvitedPlayers[team].end(); itr++) if ((*itr).second <= time(NULL)) KickPlayerFromBf((*itr).first); InvitePlayerInZoneToWar(); for (int team = 0; team < 2; team++) for (PlayerTimerMap::iterator itr = m_PlayersWillBeKick[team].begin(); itr != m_PlayersWillBeKick[team].end(); itr++) if ((*itr).second <= time(NULL)) KickPlayerFromBf((*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_LastResurectTimer <= diff) { for (uint8 i = 0; i < m_GraveYardList.size(); i++) if (GetGraveYardById(i)) m_GraveYardList[i]->Resurrect(); m_LastResurectTimer = RESURRECTION_INTERVAL; } else m_LastResurectTimer -= diff; return objective_changed; }
void AutoHost::OnSaidBattle( const wxString& /*unused*/, const wxString& msg ) { // do nothing if autohost functionality is disabled if ( !m_enabled ) return; // protect against command spam time_t currentTime = time( NULL ); if ( ( currentTime - m_lastActionTime ) < 5 ) return; // check for autohost commands wxString command = msg.BeforeFirst( _T( ' ' ) ); wxString params = msg.AfterFirst( _T( ' ' ) ); if ( command == _T( "!start" ) ) { StartBattle(); } else if ( command == _T( "!balance" ) ) { unsigned int num = s2l( params ); m_battle.Autobalance( IBattle::balance_random, false, false, num ); m_battle.DoAction( _T( "is auto-balancing alliances ..." ) ); } else if ( command == _T( "!cbalance" ) ) { unsigned int num = s2l( params ); m_battle.Autobalance( IBattle::balance_random, true, false, num ); m_battle.DoAction( _T( "is auto-balancing alliances ..." ) ); } else if ( command == _T( "!help" ) ) { m_battle.DoAction( _T( "The following commands are available ( <> = mandatory value, {} = optional value ):" ) ); m_battle.DoAction( _T( "!addbox <topx> <topy> <bottomx> <bottomy> {allynumber}: adds a <allynumber> start restriction to the given coordinates, coordinates range from 0 to 200." ) ); m_battle.DoAction( _T( "!balance {number}: tries to put players into allyteams by how many start boxes there are, uses {number} allyteams if present." ) ); m_battle.DoAction( _T( "!cbalance {number}: see !balance but tries to put clanmates together first." ) ); m_battle.DoAction( _T( "!fixcolors: changes players duplicate colours so they are unique." ) ); m_battle.DoAction( _T( "!fixids {number}: tries to put players into control teams by number, if number is omitted it assignes as different controlteam per player." ) ); m_battle.DoAction( _T( "!cfixids {number}: see !fixids but tries to put clanmates together first." ) ); m_battle.DoAction( _T( "!help: this guide." ) ); m_battle.DoAction( _T( "!listprofiles: lists the available battle profiles." ) ); m_battle.DoAction( _T( "!loadprofile profilename: loads an available battle profile." ) ); m_battle.DoAction( _T( "!lock: prevents more people to join." ) ); m_battle.DoAction( _T( "!map <name>: switches to <name>." ) ); m_battle.DoAction( _T( "!removebox <allynumber>: deletes <allynumber> start restriction's box." ) ); m_battle.DoAction( _T( "!ring {name}: rings players that are not ready or {name} if specified." ) ); m_battle.DoAction( _T( "!set <optionname> <value>: sets battle option <optionname> to <value>" ) ); m_battle.DoAction( _T( "!spectunsynced: sets all players with unsynced status to be spectators." ) ); m_battle.DoAction( _T( "!start: starts the battle." ) ); m_battle.DoAction( _T( "!unlock: opens the battle again." ) ); } else if ( command == _T( "!ring" ) ) { if ( !params.IsEmpty() ) { wxString user = GetBestMatch( m_userlist, params ); try { User& u = m_battle.GetUser( user ); m_battle.RingPlayer( u ); m_battle.DoAction( _T( "is ringing " ) + user ); } catch ( ... ) { m_battle.DoAction( _T( "cannot ring " ) + user ); } } else { m_battle.RingNotReadyPlayers(); m_battle.DoAction( _T( "is ringing players not ready ..." ) ); } } else if ( command == _T( "!listprofiles" ) ) { wxArrayString profilelist = m_battle.GetPresetList(); unsigned int count = profilelist.GetCount(); if ( count == 0 ) { m_battle.DoAction( _T( "There are no presets available." ) ); } else { m_battle.DoAction( _T( "The following presets are available:" ) ); for ( unsigned int i = 0; i < count; i++ ) { m_battle.DoAction( profilelist[i] ); } } } else if ( command == _T( "!loadprofile" ) ) { wxString profilename = GetBestMatch( m_battle.GetPresetList(), params ); if ( !m_battle.LoadOptionsPreset( profilename ) ) m_battle.DoAction( _T( "Profile not found, use !listprofiles for a list of available profiles." ) ); else m_battle.DoAction( _T( "has loaded profile: " ) + profilename ); } else if ( command == _T( "!fixcolors" ) ) { m_battle.FixColours(); m_battle.DoAction( _T( "is fixing colors." ) ); } else if ( command == _T( "!lock" ) ) { m_battle.SetIsLocked( true ); m_battle.DoAction( _T( "has locked the battle." ) ); m_battle.SendHostInfo( IBattle::HI_Locked ); } else if ( command == _T( "!unlock" ) ) { m_battle.SetIsLocked( false ); m_battle.DoAction( _T( "has unlocked the battle." ) ); m_battle.SendHostInfo( IBattle::HI_Locked ); } else if ( command == _T( "!fixids" ) ) { unsigned int num = s2l( params ); m_battle.FixTeamIDs( IBattle::balance_divide, false, false, num ); m_battle.DoAction( _T( "is auto-balancing control teams ..." ) ); } else if ( command == _T( "!cfixids" ) ) { unsigned int num = s2l( params ); m_battle.FixTeamIDs( IBattle::balance_divide, true, true, num ); m_battle.DoAction( _T( "is auto-balancing control teams ..." ) ); } else if ( command == _T( "!spectunsynced" ) ) { m_battle.ForceUnsyncedToSpectate(); m_battle.DoAction( _T( "is forcing unsynced players to be spectators." ) ); } else if ( command == _T( "!map" ) ) { if ( params.IsEmpty() ) m_battle.DoAction( _T( "cannot switch to void mapname" ) ); else { wxString mapname = GetBestMatch( usync().GetMapList(), params ); try { UnitSyncMap map = usync().GetMap( mapname ); m_battle.SetLocalMap( map ); m_battle.DoAction( _T( "is switching to map " ) + mapname ); m_battle.SendHostInfo( IBattle::HI_Map ); } catch ( ... ) { m_battle.DoAction( _T( "cannot switch to map " ) + mapname ); } } } else if ( command == _T( "!set" ) ) { wxString key = params.BeforeFirst( _T( ' ' ) ); wxString value = params.AfterFirst( _T( ' ' ) ); bool exists = m_battle.CustomBattleOptions().keyExists( key ); if ( exists ) { bool result = m_battle.CustomBattleOptions().setSingleOption( key, value ); if ( result ) { OptionsWrapper::GameOption section = m_battle.CustomBattleOptions().GetSection( key ); m_battle.SendHostInfo( wxString::Format( _T( "%d_%s" ), section, key.c_str() ) ); m_battle.DoAction( _T( "has set option " ) + key + _T( " to value " ) + value ); } else m_battle.DoAction( _T( "cannot set option " ) + key + _T( " to value " ) + value + _T( ", reason: invalid value." ) ); } else { m_battle.DoAction( _T( "cannot find option entry " ) + key ); } } else if ( command == _T( "!addbox" ) ) { long allynumber; long topleftx; long toplefty; long bottomrightx; long bottomrighty; wxArrayString values = wxStringTokenize( params, _T( " " ) ); int numvalues = values.GetCount(); if ( numvalues > 4 || numvalues < 3 ) m_battle.DoAction( _T( "has recieved an invalid number of params for !addbox" ) ); else { bool valueok = values[0].ToLong( &topleftx ); valueok = valueok && values[1].ToLong( &toplefty ); valueok = valueok && values[2].ToLong( &bottomrightx ); valueok = valueok && values[3].ToLong( &bottomrighty ); if ( numvalues == 5 ) { valueok = valueok && values[4].ToLong( &allynumber ); valueok = valueok && ( allynumber > 0 ); } else { allynumber = m_battle.GetNextFreeRectIdx(); } valueok = valueok && ( topleftx >= 0 ) && ( topleftx <= 200 ); valueok = valueok && ( toplefty >= 0 ) && ( toplefty <= 200 ); valueok = valueok && ( bottomrightx >= 0 ) && ( bottomrightx <= 200 ); valueok = valueok && ( bottomrighty >= 0 ) && ( bottomrighty <= 200 ); if ( valueok ) { allynumber = allynumber - 1; BattleStartRect rect = m_battle.GetStartRect( allynumber ); if ( rect.IsOk() ) { m_battle.DoAction( _T( "cannot add a startbox for allyteam " ) + TowxString( allynumber ) + _T( " because one is already present." ) ); } else { m_battle.AddStartRect( allynumber, topleftx, toplefty, bottomrightx, bottomrighty ); m_battle.SendHostInfo( IBattle::HI_StartRects ); m_battle.DoAction( _T( "has added start box for allyteam " ) + TowxString( allynumber ) ); } } else { m_battle.DoAction( _T( "has recieved an invalid param for !addbox" ) ); } } } else if ( command == _T( "!removebox" ) ) { long boxnumber; bool numberok = params.ToLong( &boxnumber ); if ( numberok ) { boxnumber = boxnumber - 1; BattleStartRect rect = m_battle.GetStartRect( boxnumber ); if ( rect.IsOk() ) { m_battle.RemoveStartRect( boxnumber ); m_battle.SendHostInfo( IBattle::HI_StartRects ); m_battle.DoAction( _T( "has removed the start box for allyteam " ) + TowxString( boxnumber ) ); } else { m_battle.DoAction( _T( "cannot find start box " ) + params ); } } else { m_battle.DoAction( _T( "has recieved an invalid param to !removebox command" ) ); } } else return; m_lastActionTime = currentTime; }
// Update void _Server::Update(double FrameTime) { //if(std::abs(std::fmod(Time, 1.0)) >= 0.99) // std::cout << "Server: O=" << ObjectManager->Objects.size() << " B=" << BattleManager->Objects.size() << std::endl; // Update network Network->Update(FrameTime); // Get events _NetworkEvent NetworkEvent; while(Network->GetNetworkEvent(NetworkEvent)) { switch(NetworkEvent.Type) { case _NetworkEvent::CONNECT: HandleConnect(NetworkEvent); break; case _NetworkEvent::DISCONNECT: HandleDisconnect(NetworkEvent); break; case _NetworkEvent::PACKET: HandlePacket(*NetworkEvent.Data, NetworkEvent.Peer); delete NetworkEvent.Data; break; } } // Update objects ObjectManager->Update(FrameTime); // Spawn battles for(auto &BattleEvent : BattleEvents) StartBattle(BattleEvent); BattleEvents.clear(); // Update maps MapManager->Update(FrameTime); // Update battles BattleManager->Update(FrameTime); // Check if updates should be sent if(Network->NeedsUpdate()) { Network->ResetUpdateTimer(); if(Network->GetPeers().size() > 0) { // Send object updates for(auto &Map : MapManager->Objects) { Map->SendObjectUpdates(); } } } // Wait for peers to disconnect if(StartDisconnect) { Network->DisconnectAll(); StartDisconnect = false; StartShutdown = true; } else if(StartShutdown && Network->GetPeers().size() == 0) { Done = true; } TimeSteps++; Time += FrameTime; // Update scripting environment Scripting->InjectTime(Time); // Update clock Clock += FrameTime * MAP_CLOCK_SPEED; if(Clock >= MAP_DAY_LENGTH) Clock -= MAP_DAY_LENGTH; // Update autosave SaveTime += FrameTime; if(SaveTime >= DEFAULT_AUTOSAVE_PERIOD) { SaveTime = 0; // Save players for(auto &Object : ObjectManager->Objects) { Save->SavePlayer(Object); } } }