/* * This file is part of the AzerothCore Project. See AUTHORS file for Copyright information * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ #ifndef ACORE_GRIDNOTIFIERSIMPL_H #define ACORE_GRIDNOTIFIERSIMPL_H #include "Corpse.h" #include "GridNotifiers.h" #include "Object.h" #include "Player.h" #include "WorldPacket.h" #include "WorldSession.h" template inline void Acore::VisibleNotifier::Visit(std::vector& m) { for (typename std::vector::iterator iter = m.begin(); iter != m.end(); ++iter) i_player.UpdateVisibilityOf((*iter), i_data, i_visibleNow); } template inline void Acore::VisibleNotifier::Visit(GridRefMgr& m) { // Xinef: Update gameobjects only if (i_gobjOnly) return; for (typename GridRefMgr::iterator iter = m.begin(); iter != m.end(); ++iter) i_player.UpdateVisibilityOf(iter->GetSource(), i_data, i_visibleNow); } // SEARCHERS & LIST SEARCHERS & WORKERS // WorldObject searchers & workers template void Acore::WorldObjectSearcher::Visit(GameObjectMapType& m) { if (!(i_mapTypeMask & GRID_MAP_TYPE_MASK_GAMEOBJECT)) return; // already found if (i_object) return; for (GameObjectMapType::iterator itr = m.begin(); itr != m.end(); ++itr) { if (!itr->GetSource()->InSamePhase(i_phaseMask)) continue; if (i_check(itr->GetSource())) { i_object = itr->GetSource(); return; } } } template void Acore::WorldObjectSearcher::Visit(PlayerMapType& m) { if (!(i_mapTypeMask & GRID_MAP_TYPE_MASK_PLAYER)) return; // already found if (i_object) return; for (PlayerMapType::iterator itr = m.begin(); itr != m.end(); ++itr) { if (!itr->GetSource()->InSamePhase(i_phaseMask)) continue; if (i_check(itr->GetSource())) { i_object = itr->GetSource(); return; } } } template void Acore::WorldObjectSearcher::Visit(CreatureMapType& m) { if (!(i_mapTypeMask & GRID_MAP_TYPE_MASK_CREATURE)) return; // already found if (i_object) return; for (CreatureMapType::iterator itr = m.begin(); itr != m.end(); ++itr) { if (!itr->GetSource()->InSamePhase(i_phaseMask)) continue; if (i_check(itr->GetSource())) { i_object = itr->GetSource(); return; } } } template void Acore::WorldObjectSearcher::Visit(CorpseMapType& m) { if (!(i_mapTypeMask & GRID_MAP_TYPE_MASK_CORPSE)) return; // already found if (i_object) return; for (CorpseMapType::iterator itr = m.begin(); itr != m.end(); ++itr) { if (!itr->GetSource()->InSamePhase(i_phaseMask)) continue; if (i_check(itr->GetSource())) { i_object = itr->GetSource(); return; } } } template void Acore::WorldObjectSearcher::Visit(DynamicObjectMapType& m) { if (!(i_mapTypeMask & GRID_MAP_TYPE_MASK_DYNAMICOBJECT)) return; // already found if (i_object) return; for (DynamicObjectMapType::iterator itr = m.begin(); itr != m.end(); ++itr) { if (!itr->GetSource()->InSamePhase(i_phaseMask)) continue; if (i_check(itr->GetSource())) { i_object = itr->GetSource(); return; } } } template void Acore::WorldObjectLastSearcher::Visit(GameObjectMapType& m) { if (!(i_mapTypeMask & GRID_MAP_TYPE_MASK_GAMEOBJECT)) return; for (GameObjectMapType::iterator itr = m.begin(); itr != m.end(); ++itr) { if (!itr->GetSource()->InSamePhase(i_phaseMask)) continue; if (i_check(itr->GetSource())) i_object = itr->GetSource(); } } template void Acore::WorldObjectLastSearcher::Visit(PlayerMapType& m) { if (!(i_mapTypeMask & GRID_MAP_TYPE_MASK_PLAYER)) return; for (PlayerMapType::iterator itr = m.begin(); itr != m.end(); ++itr) { if (!itr->GetSource()->InSamePhase(i_phaseMask)) continue; if (i_check(itr->GetSource())) i_object = itr->GetSource(); } } template void Acore::WorldObjectLastSearcher::Visit(CreatureMapType& m) { if (!(i_mapTypeMask & GRID_MAP_TYPE_MASK_CREATURE)) return; for (CreatureMapType::iterator itr = m.begin(); itr != m.end(); ++itr) { if (!itr->GetSource()->InSamePhase(i_phaseMask)) continue; if (i_check(itr->GetSource())) i_object = itr->GetSource(); } } template void Acore::WorldObjectLastSearcher::Visit(CorpseMapType& m) { if (!(i_mapTypeMask & GRID_MAP_TYPE_MASK_CORPSE)) return; for (CorpseMapType::iterator itr = m.begin(); itr != m.end(); ++itr) { if (!itr->GetSource()->InSamePhase(i_phaseMask)) continue; if (i_check(itr->GetSource())) i_object = itr->GetSource(); } } template void Acore::WorldObjectLastSearcher::Visit(DynamicObjectMapType& m) { if (!(i_mapTypeMask & GRID_MAP_TYPE_MASK_DYNAMICOBJECT)) return; for (DynamicObjectMapType::iterator itr = m.begin(); itr != m.end(); ++itr) { if (!itr->GetSource()->InSamePhase(i_phaseMask)) continue; if (i_check(itr->GetSource())) i_object = itr->GetSource(); } } template void Acore::WorldObjectListSearcher::Visit(PlayerMapType& m) { if (!(i_mapTypeMask & GRID_MAP_TYPE_MASK_PLAYER)) return; for (PlayerMapType::iterator itr = m.begin(); itr != m.end(); ++itr) if (i_check(itr->GetSource())) Insert(itr->GetSource()); } template void Acore::WorldObjectListSearcher::Visit(CreatureMapType& m) { if (!(i_mapTypeMask & GRID_MAP_TYPE_MASK_CREATURE)) return; for (CreatureMapType::iterator itr = m.begin(); itr != m.end(); ++itr) if (i_check(itr->GetSource())) Insert(itr->GetSource()); } template void Acore::WorldObjectListSearcher::Visit(CorpseMapType& m) { if (!(i_mapTypeMask & GRID_MAP_TYPE_MASK_CORPSE)) return; for (CorpseMapType::iterator itr = m.begin(); itr != m.end(); ++itr) if (i_check(itr->GetSource())) Insert(itr->GetSource()); } template void Acore::WorldObjectListSearcher::Visit(GameObjectMapType& m) { if (!(i_mapTypeMask & GRID_MAP_TYPE_MASK_GAMEOBJECT)) return; for (GameObjectMapType::iterator itr = m.begin(); itr != m.end(); ++itr) if (i_check(itr->GetSource())) Insert(itr->GetSource()); } template void Acore::WorldObjectListSearcher::Visit(DynamicObjectMapType& m) { if (!(i_mapTypeMask & GRID_MAP_TYPE_MASK_DYNAMICOBJECT)) return; for (DynamicObjectMapType::iterator itr = m.begin(); itr != m.end(); ++itr) if (i_check(itr->GetSource())) Insert(itr->GetSource()); } // Gameobject searchers template void Acore::GameObjectSearcher::Visit(GameObjectMapType& m) { // already found if (i_object) return; for (GameObjectMapType::iterator itr = m.begin(); itr != m.end(); ++itr) { if (!itr->GetSource()->InSamePhase(i_phaseMask)) continue; if (i_check(itr->GetSource())) { i_object = itr->GetSource(); return; } } } template void Acore::GameObjectLastSearcher::Visit(GameObjectMapType& m) { for (GameObjectMapType::iterator itr = m.begin(); itr != m.end(); ++itr) { if (!itr->GetSource()->InSamePhase(i_phaseMask)) continue; if (i_check(itr->GetSource())) i_object = itr->GetSource(); } } template void Acore::GameObjectListSearcher::Visit(GameObjectMapType& m) { for (GameObjectMapType::iterator itr = m.begin(); itr != m.end(); ++itr) if (itr->GetSource()->InSamePhase(i_phaseMask)) if (i_check(itr->GetSource())) Insert(itr->GetSource()); } // Unit searchers template void Acore::UnitSearcher::Visit(CreatureMapType& m) { // already found if (i_object) return; for (CreatureMapType::iterator itr = m.begin(); itr != m.end(); ++itr) { if (!itr->GetSource()->InSamePhase(i_phaseMask)) continue; if (i_check(itr->GetSource())) { i_object = itr->GetSource(); return; } } } template void Acore::UnitSearcher::Visit(PlayerMapType& m) { // already found if (i_object) return; for (PlayerMapType::iterator itr = m.begin(); itr != m.end(); ++itr) { if (!itr->GetSource()->InSamePhase(i_phaseMask)) continue; if (i_check(itr->GetSource())) { i_object = itr->GetSource(); return; } } } template void Acore::UnitLastSearcher::Visit(CreatureMapType& m) { for (CreatureMapType::iterator itr = m.begin(); itr != m.end(); ++itr) { if (!itr->GetSource()->InSamePhase(i_phaseMask)) continue; if (i_check(itr->GetSource())) i_object = itr->GetSource(); } } template void Acore::UnitLastSearcher::Visit(PlayerMapType& m) { for (PlayerMapType::iterator itr = m.begin(); itr != m.end(); ++itr) { if (!itr->GetSource()->InSamePhase(i_phaseMask)) continue; if (i_check(itr->GetSource())) i_object = itr->GetSource(); } } template void Acore::UnitListSearcher::Visit(PlayerMapType& m) { for (PlayerMapType::iterator itr = m.begin(); itr != m.end(); ++itr) if (itr->GetSource()->InSamePhase(i_phaseMask)) if (i_check(itr->GetSource())) Insert(itr->GetSource()); } template void Acore::UnitListSearcher::Visit(CreatureMapType& m) { for (CreatureMapType::iterator itr = m.begin(); itr != m.end(); ++itr) if (itr->GetSource()->InSamePhase(i_phaseMask)) if (i_check(itr->GetSource())) Insert(itr->GetSource()); } // Creature searchers template void Acore::CreatureSearcher::Visit(CreatureMapType& m) { // already found if (i_object) return; for (CreatureMapType::iterator itr = m.begin(); itr != m.end(); ++itr) { if (!itr->GetSource()->InSamePhase(i_phaseMask)) continue; if (i_check(itr->GetSource())) { i_object = itr->GetSource(); return; } } } template void Acore::CreatureLastSearcher::Visit(CreatureMapType& m) { for (CreatureMapType::iterator itr = m.begin(); itr != m.end(); ++itr) { if (!itr->GetSource()->InSamePhase(i_phaseMask)) continue; if (i_check(itr->GetSource())) i_object = itr->GetSource(); } } template void Acore::CreatureListSearcher::Visit(CreatureMapType& m) { for (CreatureMapType::iterator itr = m.begin(); itr != m.end(); ++itr) if (itr->GetSource()->InSamePhase(i_phaseMask)) if (i_check(itr->GetSource())) Insert(itr->GetSource()); } template void Acore::PlayerListSearcher::Visit(PlayerMapType& m) { for (PlayerMapType::iterator itr = m.begin(); itr != m.end(); ++itr) if (itr->GetSource()->InSamePhase(i_phaseMask)) if (i_check(itr->GetSource())) Insert(itr->GetSource()); } template void Acore::PlayerListSearcherWithSharedVision::Visit(PlayerMapType& m) { for (PlayerMapType::iterator itr = m.begin(); itr != m.end(); ++itr) if (itr->GetSource()->InSamePhase(i_phaseMask)) if (i_check(itr->GetSource(), true)) i_objects.push_back(itr->GetSource()); } template void Acore::PlayerListSearcherWithSharedVision::Visit(CreatureMapType& m) { for (CreatureMapType::iterator itr = m.begin(); itr != m.end(); ++itr) if (itr->GetSource()->InSamePhase(i_phaseMask) && itr->GetSource()->HasSharedVision()) for (SharedVisionList::const_iterator i = itr->GetSource()->GetSharedVisionList().begin(); i != itr->GetSource()->GetSharedVisionList().end(); ++i) if (i_check(*i, false)) i_objects.push_back(*i); } template void Acore::PlayerSearcher::Visit(PlayerMapType& m) { // already found if (i_object) return; for (PlayerMapType::iterator itr = m.begin(); itr != m.end(); ++itr) { if (!itr->GetSource()->InSamePhase(i_phaseMask)) continue; if (i_check(itr->GetSource())) { i_object = itr->GetSource(); return; } } } template void Acore::PlayerLastSearcher::Visit(PlayerMapType& m) { for (PlayerMapType::iterator itr = m.begin(); itr != m.end(); ++itr) { if (!itr->GetSource()->InSamePhase(i_phaseMask)) continue; if (i_check(itr->GetSource())) i_object = itr->GetSource(); } } template void Acore::LocalizedPacketDo::operator()(Player* p) { LocaleConstant loc_idx = p->GetSession()->GetSessionDbLocaleIndex(); uint32 cache_idx = loc_idx + 1; WorldPacket* data; // create if not cached yet if (i_data_cache.size() < cache_idx + 1 || !i_data_cache[cache_idx]) { if (i_data_cache.size() < cache_idx + 1) i_data_cache.resize(cache_idx + 1); data = new WorldPacket(); i_builder(*data, loc_idx); i_data_cache[cache_idx] = data; } else data = i_data_cache[cache_idx]; p->SendDirectMessage(data); } template void Acore::LocalizedPacketListDo::operator()(Player* p) { LocaleConstant loc_idx = p->GetSession()->GetSessionDbLocaleIndex(); uint32 cache_idx = loc_idx + 1; WorldPacketList* data_list; // create if not cached yet if (i_data_cache.size() < cache_idx + 1 || i_data_cache[cache_idx].empty()) { if (i_data_cache.size() < cache_idx + 1) i_data_cache.resize(cache_idx + 1); data_list = &i_data_cache[cache_idx]; i_builder(*data_list, loc_idx); } else data_list = &i_data_cache[cache_idx]; for (std::size_t i = 0; i < data_list->size(); ++i) p->SendDirectMessage((*data_list)[i]); } #endif // ACORE_GRIDNOTIFIERSIMPL_H