void UpdateTowerCount() { MapMgr* mgr = _gameobject->GetMapMgr(); mgr->GetWorldStatesHandler().SetWorldStateForZone(ZONE_TEROKKAR_FOREST, mgr->GetAreaID( _gameobject->GetPositionX(), _gameobject->GetPositionY() ),WORLDSTATE_TEROKKAR_ALLIANCE_TOWERS_CONTROLLED, TFg_allianceTowers); mgr->GetWorldStatesHandler().SetWorldStateForZone(ZONE_TEROKKAR_FOREST, mgr->GetAreaID( _gameobject->GetPositionX(), _gameobject->GetPositionY() ),WORLDSTATE_TEROKKAR_HORDE_TOWERS_CONTROLLED, TFg_hordeTowers); Player* plr = _gameobject->GetMapMgr()->GetInterface()->GetPlayerNearestCoords(_gameobject->GetPositionX(), _gameobject->GetPositionY(), _gameobject->GetPositionZ() - 34); if(TFg_superiorTeam == 0 && TFg_allianceTowers != 5) { plr->RemoveAura(BLESSING_OF_AUCHINDOUND); TFg_superiorTeam = -1; } if(TFg_superiorTeam == 1 && TFg_hordeTowers != 5) { plr->RemoveAura(BLESSING_OF_AUCHINDOUND); TFg_superiorTeam = -1; } if(TFg_allianceTowers == 5 && TFg_superiorTeam != 0) { TFg_superiorTeam = 0; plr->CastSpell(plr, BLESSING_OF_AUCHINDOUND, false); } if(TFg_hordeTowers == 5 && TFg_superiorTeam != 1) { TFg_superiorTeam = 1; plr->CastSpell(plr, BLESSING_OF_AUCHINDOUND, false); } }
void OnSpawn() { MapMgr* mgr = _gameobject->GetMapMgr(); Player* plr = _gameobject->GetMapMgr()->GetInterface()->GetPlayerNearestCoords(_gameobject->GetPositionX(), _gameobject->GetPositionY(), _gameobject->GetPositionZ()); m_bannerStatus = BANNER_STATUS_NEUTRAL; // preloaded data, do we have any? if(TFg_towerOwners[towerid] == 1) { m_bannerStatus = BANNER_STATUS_HORDE; Status = 0; // state update mgr->GetWorldStatesHandler().SetWorldStateForZone(ZONE_TEROKKAR_FOREST, mgr->GetAreaID( _gameobject->GetPositionX(), _gameobject->GetPositionY() ), g_hordeStateFields[towerid], 1); mgr->GetWorldStatesHandler().SetWorldStateForZone(ZONE_TEROKKAR_FOREST, mgr->GetAreaID( _gameobject->GetPositionX(), _gameobject->GetPositionY() ), g_neutralStateFields[towerid], 0); // countz TFg_hordeTowers++; UpdateTowerCount(); SetArtKit(); } else if(TFg_towerOwners[towerid] == 0) { m_bannerStatus = BANNER_STATUS_ALLIANCE; Status = 100; // state update mgr->GetWorldStatesHandler().SetWorldStateForZone(ZONE_TEROKKAR_FOREST, mgr->GetAreaID( _gameobject->GetPositionX(), _gameobject->GetPositionY() ), g_allianceStateFields[towerid], 1); mgr->GetWorldStatesHandler().SetWorldStateForZone(ZONE_TEROKKAR_FOREST, mgr->GetAreaID( _gameobject->GetPositionX(), _gameobject->GetPositionY() ), g_neutralStateFields[towerid], 0); // countz TFg_allianceTowers++; UpdateTowerCount(); SetArtKit(); } // start the event timer RegisterAIUpdateEvent(UPDATE_PERIOD); }
void AIUpdate() { 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 itr = _gameobject->GetInRangePlayerSetBegin(); itrend = _gameobject->GetInRangePlayerSetEnd(); map<uint32, uint32>::iterator it2, it3; uint32 timeptr = (uint32)UNIXTIME; bool in_range; bool is_valid; Player* plr; MapMgr* mgr = _gameobject->GetMapMgr(); for(; itr != itrend; ++itr) { plr = TO< Player* >(*itr); if(!plr->IsPvPFlagged() || !(plr->isAlive()) && !(plr->IsStealth()) && !(plr->m_invisible) && !(plr->SchoolImmunityList[0])) is_valid = false; else is_valid = true; in_range = (_gameobject->GetDistance2dSq((*itr)) <= BANNER_RANGE); it2 = StoredPlayers.find((*itr)->GetLowGUID()); if(it2 == StoredPlayers.end()) { // new player :) if(in_range) { plr->SendWorldStateUpdate(WORLDSTATE_TEROKKAR_PVP_CAPTURE_BAR_DISPLAY, 1); plr->SendWorldStateUpdate(WORLDSTATE_TEROKKAR_PVP_CAPTURE_BAR_VALUE, Status); StoredPlayers.insert(make_pair((*itr)->GetLowGUID(), timeptr)); if(is_valid) plrcounts[(*itr)->GetTeam()]++; } } else { // oldie if(!in_range) { plr->SendWorldStateUpdate(WORLDSTATE_TEROKKAR_PVP_CAPTURE_BAR_DISPLAY, 0); StoredPlayers.erase(it2); } else { plr->SendWorldStateUpdate(WORLDSTATE_TEROKKAR_PVP_CAPTURE_BAR_VALUE, Status); it2->second = timeptr; if(is_valid) plrcounts[(*itr)->GetTeam()]++; } } } // handle stuff for the last tick if(Status == 100 && m_bannerStatus != BANNER_STATUS_ALLIANCE) { m_bannerStatus = BANNER_STATUS_ALLIANCE; SetArtKit(); // send message to everyone in the zone, has been captured by the Alliance mgr->SendPvPCaptureMessage(ZONE_TEROKKAR_FOREST, ZONE_TEROKKAR_FOREST, "|cffffff00%s has been taken by the Alliance!|r", ControlPointName); // tower update TFg_allianceTowers++; UpdateTowerCount(); // state update mgr->GetWorldStatesHandler().SetWorldStateForZone(ZONE_TEROKKAR_FOREST, mgr->GetAreaID( _gameobject->GetPositionX(), _gameobject->GetPositionY() ), g_neutralStateFields[towerid], 0); mgr->GetWorldStatesHandler().SetWorldStateForZone(ZONE_TEROKKAR_FOREST, mgr->GetAreaID( _gameobject->GetPositionX(), _gameobject->GetPositionY() ), g_allianceStateFields[towerid], 1); // woot TFg_towerOwners[towerid] = 1; } else if(Status == 0 && m_bannerStatus != BANNER_STATUS_HORDE) { m_bannerStatus = BANNER_STATUS_HORDE; SetArtKit(); // send message to everyone in the zone, has been captured by the Horde mgr->SendPvPCaptureMessage(ZONE_TEROKKAR_FOREST, ZONE_TEROKKAR_FOREST, "|cffffff00%s has been taken by the Horde!|r", ControlPointName); // tower update TFg_hordeTowers++; UpdateTowerCount(); // state update mgr->GetWorldStatesHandler().SetWorldStateForZone(ZONE_TEROKKAR_FOREST, mgr->GetAreaID( _gameobject->GetPositionX(), _gameobject->GetPositionY() ), g_neutralStateFields[towerid], 0); mgr->GetWorldStatesHandler().SetWorldStateForZone(ZONE_TEROKKAR_FOREST, mgr->GetAreaID( _gameobject->GetPositionX(), _gameobject->GetPositionY() ), g_hordeStateFields[towerid], 1); // woot TFg_towerOwners[towerid] = 0; } else if(m_bannerStatus != BANNER_STATUS_NEUTRAL) { // if the difference for the faction is >50, change to neutral if(m_bannerStatus == BANNER_STATUS_ALLIANCE && Status <= 50) { // send message: The Alliance has lost control of point xxx m_bannerStatus = BANNER_STATUS_NEUTRAL; SetArtKit(); TFg_allianceTowers--; UpdateTowerCount(); mgr->SendPvPCaptureMessage(ZONE_TEROKKAR_FOREST, ZONE_TEROKKAR_FOREST, "|cffffff00The Alliance have lost control of %s!|r", ControlPointName); // state update mgr->GetWorldStatesHandler().SetWorldStateForZone(ZONE_TEROKKAR_FOREST, mgr->GetAreaID( _gameobject->GetPositionX(), _gameobject->GetPositionY() ), g_allianceStateFields[towerid], 0); mgr->GetWorldStatesHandler().SetWorldStateForZone(ZONE_TEROKKAR_FOREST, mgr->GetAreaID( _gameobject->GetPositionX(), _gameobject->GetPositionY() ), g_neutralStateFields[towerid], 1); // woot TFg_towerOwners[towerid] = -1; } else if(m_bannerStatus == BANNER_STATUS_HORDE && Status >= 50) { // send message: The Alliance has lost control of point xxx m_bannerStatus = BANNER_STATUS_NEUTRAL; SetArtKit(); TFg_hordeTowers--; UpdateTowerCount(); mgr->SendPvPCaptureMessage(ZONE_TEROKKAR_FOREST, ZONE_TEROKKAR_FOREST, "|cffffff00The Horde have lost control of %s!|r", ControlPointName); // state update mgr->GetWorldStatesHandler().SetWorldStateForZone(ZONE_TEROKKAR_FOREST, mgr->GetAreaID( _gameobject->GetPositionX(), _gameobject->GetPositionY() ), g_hordeStateFields[towerid], 0); mgr->GetWorldStatesHandler().SetWorldStateForZone(ZONE_TEROKKAR_FOREST, mgr->GetAreaID( _gameobject->GetPositionX(), _gameobject->GetPositionY() ), g_neutralStateFields[towerid], 1); // woot TFg_towerOwners[towerid] = -1; } } // send any out of range players the disable flag for(it2 = StoredPlayers.begin(); it2 != StoredPlayers.end();) { it3 = it2; ++it2; if(it3->second != timeptr) { plr = _gameobject->GetMapMgr()->GetPlayer(it3->first); // they WILL be out of range at this point. this is guaranteed. means they left the set rly quickly. if(plr) plr->SendWorldStateUpdate(WORLDSTATE_TEROKKAR_PVP_CAPTURE_BAR_DISPLAY, 0); StoredPlayers.erase(it3); } } // work out current status for next tick uint32 delta; if(plrcounts[0] > plrcounts[1]) { delta = plrcounts[0] - plrcounts[1]; delta *= CAPTURE_RATE; // cap it at 25 so the banner always gets removed. if(delta > 25) delta = 25; Status += delta; if(Status >= 100) Status = 100; } else if(plrcounts[1] > plrcounts[0]) { delta = plrcounts[1] - plrcounts[0]; delta *= CAPTURE_RATE; // cap it at 25 so the banner always gets removed. if(delta > 25) delta = 25; if(delta > Status) Status = 0; else Status -= delta; } }