uint32 GameEvent::Update() // return the next event delay in ms { uint32 nextEventDelay = max_ge_check_delay; // 1 day uint32 calcDelay; for (uint16 itr = 1; itr < mGameEvent.size(); ++itr) { //sLog.outErrorDb("Checking event %u",itr); if (CheckOneGameEvent(itr)) { //sLog.outDebug("GameEvent %u is active",itr->first); if (!IsActiveEvent(itr)) StartEvent(itr); } else { //sLog.outDebug("GameEvent %u is not active",itr->first); if (IsActiveEvent(itr)) StopEvent(itr); else { if (!isSystemInit) { int16 event_nid = (-1) * (itr); // spawn all negative ones for this event GameEventSpawn(event_nid); } } } calcDelay = NextCheck(itr); if (calcDelay < nextEventDelay) nextEventDelay = calcDelay; } sLog.outBasic("Next game event check in %u seconds.", nextEventDelay + 1); return (nextEventDelay + 1) * 1000; // Add 1 second to be sure event has started/stopped at next call }
void BattleGroundAV::HandleKillUnit(Creature* creature, Player* killer) { DEBUG_LOG("BattleGroundAV: HandleKillUnit %i", creature->GetEntry()); if (GetStatus() != STATUS_IN_PROGRESS) { return; } uint8 event1 = (sBattleGroundMgr.GetCreatureEventIndex(creature->GetGUIDLow())).event1; if (event1 == BG_EVENT_NONE) { return; } switch (event1) { case BG_AV_BOSS_A: CastSpellOnTeam(BG_AV_BOSS_KILL_QUEST_SPELL, HORDE); // this is a spell which finishes a quest where a player has to kill the boss RewardReputationToTeam(BG_AV_FACTION_H, m_RepBoss, HORDE); RewardHonorToTeam(GetBonusHonorFromKill(BG_AV_KILL_BOSS), HORDE); SendYellToAll(LANG_BG_AV_A_GENERAL_DEAD, LANG_UNIVERSAL, GetSingleCreatureGuid(BG_AV_HERALD, 0)); EndBattleGround(HORDE); break; case BG_AV_BOSS_H: CastSpellOnTeam(BG_AV_BOSS_KILL_QUEST_SPELL, ALLIANCE); // this is a spell which finishes a quest where a player has to kill the boss RewardReputationToTeam(BG_AV_FACTION_A, m_RepBoss, ALLIANCE); RewardHonorToTeam(GetBonusHonorFromKill(BG_AV_KILL_BOSS), ALLIANCE); SendYellToAll(LANG_BG_AV_H_GENERAL_DEAD, LANG_UNIVERSAL, GetSingleCreatureGuid(BG_AV_HERALD, 0)); EndBattleGround(ALLIANCE); break; case BG_AV_CAPTAIN_A: if (IsActiveEvent(BG_AV_NodeEventCaptainDead_A, 0)) { return; } RewardReputationToTeam(BG_AV_FACTION_H, m_RepCaptain, HORDE); RewardHonorToTeam(GetBonusHonorFromKill(BG_AV_KILL_CAPTAIN), HORDE); UpdateScore(BG_TEAM_ALLIANCE, (-1) * BG_AV_RES_CAPTAIN); // spawn destroyed aura SpawnEvent(BG_AV_NodeEventCaptainDead_A, 0, true); break; case BG_AV_CAPTAIN_H: if (IsActiveEvent(BG_AV_NodeEventCaptainDead_H, 0)) { return; } RewardReputationToTeam(BG_AV_FACTION_A, m_RepCaptain, ALLIANCE); RewardHonorToTeam(GetBonusHonorFromKill(BG_AV_KILL_CAPTAIN), ALLIANCE); UpdateScore(BG_TEAM_HORDE, (-1) * BG_AV_RES_CAPTAIN); // spawn destroyed aura SpawnEvent(BG_AV_NodeEventCaptainDead_H, 0, true); break; case BG_AV_MINE_BOSSES_NORTH: ChangeMineOwner(BG_AV_NORTH_MINE, GetAVTeamIndexByTeamId(killer->GetTeam())); break; case BG_AV_MINE_BOSSES_SOUTH: ChangeMineOwner(BG_AV_SOUTH_MINE, GetAVTeamIndexByTeamId(killer->GetTeam())); break; } }
// return the next event delay in ms uint32 GameEventMgr::Update(ActiveEvents const* activeAtShutdown /*= nullptr*/) { time_t currenttime = time(nullptr); uint32 nextEventDelay = max_ge_check_delay; // 1 day uint32 calcDelay; for (uint16 itr = 1; itr < mGameEvent.size(); ++itr) { if (mGameEvent[itr].occurence == 0) continue; // sLog.outErrorDb("Checking event %u",itr); if (CheckOneGameEvent(itr, currenttime)) { // DEBUG_LOG("GameEvent %u is active",itr->first); if (!IsActiveEvent(itr)) { if (mGameEvent[itr].linkedTo == 0 || IsActiveEvent(mGameEvent[itr].linkedTo)) { bool resume = activeAtShutdown && (activeAtShutdown->find(itr) != activeAtShutdown->end()); StartEvent(itr, false, resume); } } } else { // DEBUG_LOG("GameEvent %u is not active",itr->first); if (IsActiveEvent(itr)) { StopEvent(itr); if (mGameEvent[itr].linkedTo != 0) StopEvent(mGameEvent[itr].linkedTo); } else { if (!m_IsGameEventsInit) { int16 event_nid = (-1) * (itr); // spawn all negative ones for this event GameEventSpawn(event_nid); UpdateWorldStates(itr, false); } } } calcDelay = NextCheck(itr); if (calcDelay < nextEventDelay) nextEventDelay = calcDelay; } BASIC_LOG("Next game event check in %u seconds.", nextEventDelay + 1); return (nextEventDelay + 1) * IN_MILLISECONDS; // Add 1 second to be sure event has started/stopped at next call }
GameEventCreatureData const* GameEventMgr::GetCreatureUpdateDataForActiveEvent(uint32 lowguid) const { // only for active event, creature can be listed for many so search all uint32 event_id = 0; GameEventCreatureDataPerGuidBounds bounds = mGameEventCreatureDataPerGuid.equal_range(lowguid); for (GameEventCreatureDataPerGuidMap::const_iterator itr = bounds.first; itr != bounds.second; ++itr) { if (IsActiveEvent(itr->second)) { event_id = itr->second; break; } } if (!event_id) { return NULL; } for (GameEventCreatureDataList::const_iterator itr = mGameEventCreatureData[event_id].begin(); itr != mGameEventCreatureData[event_id].end(); ++itr) if (itr->first == lowguid) { return &itr->second; } return NULL; }
void BattleGroundAV::EndBattleGround(uint32 winner) { // calculate bonuskills for both teams: uint32 tower_survived[BG_TEAMS_COUNT] = {0, 0}; uint32 graves_owned[BG_TEAMS_COUNT] = {0, 0}; uint32 mines_owned[BG_TEAMS_COUNT] = {0, 0}; // towers all not destroyed: for(BG_AV_Nodes i = BG_AV_NODES_DUNBALDAR_SOUTH; i <= BG_AV_NODES_STONEHEART_BUNKER; ++i) if (m_Nodes[i].State == POINT_CONTROLLED) if (m_Nodes[i].TotalOwner == BG_TEAM_ALLIANCE) ++tower_survived[BG_TEAM_ALLIANCE]; for(BG_AV_Nodes i = BG_AV_NODES_ICEBLOOD_TOWER; i <= BG_AV_NODES_FROSTWOLF_WTOWER; ++i) if (m_Nodes[i].State == POINT_CONTROLLED) if (m_Nodes[i].TotalOwner == BG_TEAM_HORDE) ++tower_survived[BG_TEAM_HORDE]; // graves all controlled for(BG_AV_Nodes i = BG_AV_NODES_FIRSTAID_STATION; i < BG_AV_NODES_MAX; ++i) if (m_Nodes[i].State == POINT_CONTROLLED) ++graves_owned[m_Nodes[i].Owner]; for (uint32 i = 0; i < BG_AV_MAX_MINES; ++i) if (m_Mine_Owner[i] != BG_AV_NEUTRAL_TEAM) ++mines_owned[m_Mine_Owner[i]]; // now we have the values give the honor/reputation to the teams: uint32 team[BG_TEAMS_COUNT] = { ALLIANCE, HORDE }; uint32 faction[BG_TEAMS_COUNT] = { BG_AV_FACTION_A, BG_AV_FACTION_H }; for (uint32 i = 0; i < BG_TEAMS_COUNT; i++) { if (tower_survived[i]) { RewardReputationToTeam(BATTLEGROUND_AV, tower_survived[i] * m_RepSurviveTower, team[i]); RewardHonorToTeam(GetBonusHonorFromKill(tower_survived[i] * BG_AV_KILL_SURVIVING_TOWER), team[i]); RewardXpToTeam(0, 0.6, team[i]); } DEBUG_LOG("BattleGroundAV: EndbattleGround: bgteam: %u towers:%u honor:%u rep:%u", i, tower_survived[i], GetBonusHonorFromKill(tower_survived[i] * BG_AV_KILL_SURVIVING_TOWER), tower_survived[i] * BG_AV_REP_SURVIVING_TOWER); if (graves_owned[i]) RewardReputationToTeam(BATTLEGROUND_AV, graves_owned[i] * m_RepOwnedGrave, team[i]); if (mines_owned[i]) RewardReputationToTeam(BATTLEGROUND_AV, mines_owned[i] * m_RepOwnedMine, team[i]); // captain survived?: if (!IsActiveEvent(BG_AV_NodeEventCaptainDead_A + GetTeamIndexByTeamId(team[i]), 0)) { RewardReputationToTeam(BATTLEGROUND_AV, m_RepSurviveCaptain, team[i]); RewardHonorToTeam(GetBonusHonorFromKill(BG_AV_KILL_SURVIVING_CAPTAIN), team[i]); } } // both teams: if (m_HonorMapComplete) { RewardHonorToTeam(m_HonorMapComplete, ALLIANCE); RewardHonorToTeam(m_HonorMapComplete, HORDE); } BattleGround::EndBattleGround(winner); }
void BattleGround::OnObjectDBLoad(Creature* creature) { const BattleGroundEventIdx eventId = sBattleGroundMgr.GetCreatureEventIndex(creature->GetGUIDLow()); if (eventId.event1 == BG_EVENT_NONE) return; m_EventObjects[MAKE_PAIR32(eventId.event1, eventId.event2)].creatures.push_back(creature->GetObjectGuid()); if (!IsActiveEvent(eventId.event1, eventId.event2)) SpawnBGCreature(creature->GetObjectGuid(), RESPAWN_ONE_DAY); }
bool BattleGroundAV::hasAllTowers(int8 team) { // if the winner team captain is dead, no need to check further if ((IsActiveEvent((team == BG_TEAM_ALLIANCE) ? BG_AV_NodeEventCaptainDead_A : BG_AV_NodeEventCaptainDead_H, 0))) return false; // all winner towers/bunkers have to be owned by the winners, enemy ones must be destroyed (none in conflict) for (int i = BG_AV_NODES_DUNBALDAR_SOUTH; i <= BG_AV_NODES_FROSTWOLF_WTOWER; ++i) if (m_Nodes[i].Owner != team || m_Nodes[i].State != POINT_CONTROLLED) return false; return true; }
uint32 GameEventMgr::Update() // return the next event delay in ms { uint32 nextEventDelay = max_ge_check_delay; // 1 day uint32 calcDelay; for (uint16 itr = 1; itr < mGameEvent.size(); ++itr) { //sLog.outErrorDb("Checking event %u",itr); if (CheckOneGameEvent(itr)) { //DEBUG_LOG("GameEvent %u is active",itr->first); if (!IsActiveEvent(itr)) StartEvent(itr); } else { //DEBUG_LOG("GameEvent %u is not active",itr->first); if (IsActiveEvent(itr)) StopEvent(itr); else { if (!m_IsGameEventsInit) { int16 event_nid = (-1) * (itr); // spawn all negative ones for this event GameEventSpawn(event_nid); // disable any event specific quest (for cases where creature is spawned, but event not active). UpdateEventQuests(itr, false); UpdateWorldStates(itr, false); } } } calcDelay = NextCheck(itr); if (calcDelay < nextEventDelay) nextEventDelay = calcDelay; } BASIC_LOG("Next game event check in %u seconds.", nextEventDelay + 1); return (nextEventDelay + 1) * IN_MILLISECONDS; // Add 1 second to be sure event has started/stopped at next call }
void GameEventMgr::StopEvent(uint16 event_id, bool overwrite) { UnApplyEvent(event_id); if (overwrite) { mGameEvent[event_id].start = time(NULL) - mGameEvent[event_id].length * MINUTE; if (mGameEvent[event_id].end <= mGameEvent[event_id].start) { mGameEvent[event_id].end = mGameEvent[event_id].start + mGameEvent[event_id].length; } } #ifdef ENABLE_ELUNA if (!IsActiveEvent(event_id)) sEluna->OnGameEventStop(event_id); #endif }
void GameEventMgr::StartEvent(uint16 event_id, bool overwrite /*=false*/, bool resume /*=false*/) { ApplyNewEvent(event_id, resume); if (overwrite) { mGameEvent[event_id].start = time(NULL); if (mGameEvent[event_id].end <= mGameEvent[event_id].start) { mGameEvent[event_id].end = mGameEvent[event_id].start + mGameEvent[event_id].length; } } #ifdef ENABLE_ELUNA if (IsActiveEvent(event_id)) sEluna->OnGameEventStart(event_id); #endif }
void BattleGround::OpenDoorEvent(uint8 event1, uint8 event2 /*=0*/) { if (!IsDoor(event1, event2)) { sLog.outError("BattleGround:OpenDoorEvent this is no door event1:%u event2:%u", event1, event2); return; } if (!IsActiveEvent(event1, event2)) // maybe already despawned (eye) { sLog.outError("BattleGround:OpenDoorEvent this event isn't active event1:%u event2:%u", event1, event2); return; } GuidVector::const_iterator itr = m_EventObjects[MAKE_PAIR32(event1, event2)].gameobjects.begin(); for (; itr != m_EventObjects[MAKE_PAIR32(event1, event2)].gameobjects.end(); ++itr) DoorOpen(*itr); }
void BattleGround::OnObjectDBLoad(GameObject* obj) { const BattleGroundEventIdx eventId = sBattleGroundMgr.GetGameObjectEventIndex(obj->GetGUIDLow()); if (eventId.event1 == BG_EVENT_NONE) return; m_EventObjects[MAKE_PAIR32(eventId.event1, eventId.event2)].gameobjects.push_back(obj->GetObjectGuid()); if (!IsActiveEvent(eventId.event1, eventId.event2)) { SpawnBGObject(obj->GetObjectGuid(), RESPAWN_ONE_DAY); } else { // it's possible, that doors aren't spawned anymore (wsg) if (GetStatus() >= STATUS_IN_PROGRESS && IsDoor(eventId.event1, eventId.event2)) DoorOpen(obj->GetObjectGuid()); } }
void BattleGroundAV::EndBattleGround(Team winner) { // calculate bonuskills for both teams: uint32 tower_survived[PVP_TEAM_COUNT] = {0, 0}; uint32 graves_owned[PVP_TEAM_COUNT] = {0, 0}; uint32 mines_owned[PVP_TEAM_COUNT] = {0, 0}; for (uint32 i = 0; i < PVP_TEAM_COUNT; ++i) m_PerfectionAV[i] = false; // towers all not destroyed: for (BG_AV_Nodes i = BG_AV_NODES_DUNBALDAR_SOUTH; i <= BG_AV_NODES_STONEHEART_BUNKER; ++i) if (m_Nodes[i].State == POINT_CONTROLLED) if (m_Nodes[i].TotalOwner == TEAM_INDEX_ALLIANCE) ++tower_survived[TEAM_INDEX_ALLIANCE]; for(BG_AV_Nodes i = BG_AV_NODES_ICEBLOOD_TOWER; i <= BG_AV_NODES_FROSTWOLF_WTOWER; ++i) if (m_Nodes[i].State == POINT_CONTROLLED) if (m_Nodes[i].TotalOwner == TEAM_INDEX_HORDE) ++tower_survived[TEAM_INDEX_HORDE]; // graves all controlled for(BG_AV_Nodes i = BG_AV_NODES_FIRSTAID_STATION; i < BG_AV_NODES_MAX; ++i) if (m_Nodes[i].State == POINT_CONTROLLED && m_Nodes[i].Owner != TEAM_INDEX_NEUTRAL) ++graves_owned[m_Nodes[i].Owner]; for (uint32 i = 0; i < BG_AV_MAX_MINES; ++i) if (m_Mine_Owner[i] != TEAM_INDEX_NEUTRAL) ++mines_owned[m_Mine_Owner[i]]; // achievement Stormpike/Frostwolf Perfection if(winner == ALLIANCE) if(tower_survived[TEAM_INDEX_ALLIANCE]==4) if(tower_survived[TEAM_INDEX_HORDE]==0) if(!IsActiveEvent(BG_AV_NodeEventCaptainDead_A, 0)) if (IsActiveEvent(BG_AV_BOSS_A, 0)) m_PerfectionAV[TEAM_INDEX_ALLIANCE] = true; if(winner == HORDE) if(tower_survived[TEAM_INDEX_HORDE]==4) if(tower_survived[TEAM_INDEX_ALLIANCE]==0) if(!IsActiveEvent(BG_AV_NodeEventCaptainDead_H, 0)) if (IsActiveEvent(BG_AV_BOSS_H, 0)) m_PerfectionAV[TEAM_INDEX_HORDE] = true; // now we have the values give the honor/reputation to the teams: Team team[PVP_TEAM_COUNT] = { ALLIANCE, HORDE }; uint32 faction[PVP_TEAM_COUNT] = { BG_AV_FACTION_A, BG_AV_FACTION_H }; for (uint32 i = 0; i < PVP_TEAM_COUNT; i++) { if (tower_survived[i]) { RewardReputationToTeam(faction[i], tower_survived[i] * m_RepSurviveTower, team[i]); RewardHonorToTeam(GetBonusHonorFromKill(tower_survived[i] * BG_AV_KILL_SURVIVING_TOWER), team[i]); RewardXpToTeam(0, 0.6f, team[i]); } DEBUG_LOG("BattleGroundAV: EndbattleGround: bgteam: %u towers:%u honor:%u rep:%u", i, tower_survived[i], GetBonusHonorFromKill(tower_survived[i] * BG_AV_KILL_SURVIVING_TOWER), tower_survived[i] * BG_AV_REP_SURVIVING_TOWER); if (graves_owned[i]) RewardReputationToTeam(faction[i], graves_owned[i] * m_RepOwnedGrave, team[i]); if (mines_owned[i]) RewardReputationToTeam(faction[i], mines_owned[i] * m_RepOwnedMine, team[i]); // captain survived?: if (!IsActiveEvent(BG_AV_NodeEventCaptainDead_A + GetTeamIndex(team[i]), 0)) { RewardReputationToTeam(faction[i], m_RepSurviveCaptain, team[i]); RewardHonorToTeam(GetBonusHonorFromKill(BG_AV_KILL_SURVIVING_CAPTAIN), team[i]); } } // both teams: if (m_HonorMapComplete) { RewardHonorToTeam(m_HonorMapComplete, ALLIANCE); RewardHonorToTeam(m_HonorMapComplete, HORDE); } BattleGround::EndBattleGround(winner); }
void BattleGroundAV::Update(uint32 diff) { BattleGround::Update(diff); if (GetStatus() != STATUS_IN_PROGRESS) return; if (m_PlayerCheckTimer < diff) { BattleGroundAV::CheckPlayerSize(); m_PlayerCheckTimer = 1000; } else m_PlayerCheckTimer -= diff; // add points from mine owning, and look if the neutral team can reclaim the mine for(uint8 mine = 0; mine < BG_AV_MAX_MINES; mine++) { if (m_Mine_Owner[mine] != BG_AV_TEAM_NEUTRAL) { m_Mine_Timer[mine] -=diff; if (m_Mine_Timer[mine] <= 0) { m_Mine_Timer[mine] = BG_AV_MINE_TICK_TIMER; } if (m_Mine_Reclaim_Timer[mine] > diff) m_Mine_Reclaim_Timer[mine] -= diff; else ChangeMineOwner(mine, BG_AV_TEAM_NEUTRAL); } } // looks for all timers of the nodes and destroy the building (for graveyards the building wont get destroyed, it goes just to the other team for(BG_AV_Nodes i = BG_AV_NODES_FIRSTAID_STATION; i < BG_AV_NODES_MAX; ++i) { if (m_Nodes[i].State == POINT_ASSAULTED) { if (m_Nodes[i].Timer > diff) m_Nodes[i].Timer -= diff; else EventPlayerDestroyedPoint(i); } } for (uint8 i = 0; i < 2; i++) { //handle team captain buffs every 3 + random minutes until they are dead if (m_CaptainBuffTimer[i] != 0) { if (m_CaptainBuffTimer[i] <= diff) { if (i > 0) { if(!IsActiveEvent(BG_AV_NodeEventCaptainDead_H, 0)) { //text is missing / we cannot handle DoScriptText in core -> alterac valley/galvangar -> yell_buff CastSpellOnTeam(BG_AV_CAPTAIN_H_BUFF, HORDE); //PlaySoundToAll(); //probably wrong sound } } else { if(!IsActiveEvent(BG_AV_NodeEventCaptainDead_A, 0)) { //text is missing / we cannot handle DoScriptText in core -> alterac valley/balinda -> yell_buff CastSpellOnTeam(BG_AV_CAPTAIN_A_BUFF, ALLIANCE); //PlaySoundToAll(); //probably wrong sound } } m_CaptainBuffTimer[i] = (180000 + (urand(0,6) * 10000)); } else m_CaptainBuffTimer[i] -= diff; } //handle general warcry buff every 3 minutes + random if enough armor scraps are gathered if (m_GeneralBuffTimer[i] != 0) { if (m_GeneralBuffTimer[i] <= diff) { Team team[2] = {ALLIANCE, HORDE}; GossipIndex Channel; if (i > 0) { //text is missing / we cannot handle DoScriptText in core -> alterac valley/drekthar -> yell_random //PlaySoundToAll(); //probably wrong sound Channel = GOSSIP_CHANNEL2; } else { //text is missing / we cannot handle DoScriptText in core -> alterac valley/vanndar -> yell_random //PlaySoundToAll(); //probably wrong sound Channel = GOSSIP_CHANNEL1; } if (GetGossipStatus(Channel) == STATUS_ACTION1) CastSpellOnTeam(BG_AV_WARCRY_BUFF_1, team[i]); else if (GetGossipStatus(Channel) == STATUS_ACTION2) CastSpellOnTeam(BG_AV_WARCRY_BUFF_2, team[i]); else if (GetGossipStatus(Channel) == STATUS_ACTION3) CastSpellOnTeam(BG_AV_WARCRY_BUFF_3, team[i]); m_GeneralBuffTimer[i] = (180000 + (urand(0,6) * 10000)); } else m_GeneralBuffTimer[i] -= diff; } } }