[2] | 1 | /* |
---|
[102] | 2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
| 3 | * |
---|
[44] | 4 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
---|
[2] | 5 | * |
---|
| 6 | * This program is free software; you can redistribute it and/or modify |
---|
| 7 | * it under the terms of the GNU General Public License as published by |
---|
| 8 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 9 | * (at your option) any later version. |
---|
| 10 | * |
---|
| 11 | * This program is distributed in the hope that it will be useful, |
---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
[221] | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
[2] | 14 | * GNU General Public License for more details. |
---|
| 15 | * |
---|
| 16 | * You should have received a copy of the GNU General Public License |
---|
| 17 | * along with this program; if not, write to the Free Software |
---|
[221] | 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
[2] | 19 | */ |
---|
| 20 | |
---|
| 21 | #include "GridNotifiers.h" |
---|
| 22 | #include "WorldPacket.h" |
---|
| 23 | #include "WorldSession.h" |
---|
| 24 | #include "UpdateData.h" |
---|
| 25 | #include "Item.h" |
---|
| 26 | #include "Map.h" |
---|
| 27 | #include "MapManager.h" |
---|
| 28 | #include "Transports.h" |
---|
| 29 | #include "ObjectAccessor.h" |
---|
| 30 | |
---|
[44] | 31 | using namespace Trinity; |
---|
[2] | 32 | |
---|
| 33 | void |
---|
[44] | 34 | Trinity::PlayerNotifier::Visit(PlayerMapType &m) |
---|
[2] | 35 | { |
---|
| 36 | for(PlayerMapType::iterator iter=m.begin(); iter != m.end(); ++iter) |
---|
| 37 | { |
---|
| 38 | if( iter->getSource() == &i_player ) |
---|
| 39 | continue; |
---|
| 40 | |
---|
| 41 | iter->getSource()->UpdateVisibilityOf(&i_player); |
---|
| 42 | i_player.UpdateVisibilityOf(iter->getSource()); |
---|
[233] | 43 | |
---|
| 44 | if (!i_player.GetSharedVisionList().empty()) |
---|
| 45 | for (SharedVisionList::const_iterator it = i_player.GetSharedVisionList().begin(); it != i_player.GetSharedVisionList().end(); ++it) |
---|
| 46 | (*it)->UpdateVisibilityOf(iter->getSource()); |
---|
[2] | 47 | } |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | void |
---|
| 51 | VisibleChangesNotifier::Visit(PlayerMapType &m) |
---|
| 52 | { |
---|
| 53 | for(PlayerMapType::iterator iter=m.begin(); iter != m.end(); ++iter) |
---|
| 54 | { |
---|
| 55 | if(iter->getSource() == &i_object) |
---|
| 56 | continue; |
---|
| 57 | |
---|
| 58 | iter->getSource()->UpdateVisibilityOf(&i_object); |
---|
| 59 | } |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | void |
---|
| 63 | VisibleNotifier::Visit(PlayerMapType &m) |
---|
| 64 | { |
---|
| 65 | for(PlayerMapType::iterator iter=m.begin(); iter != m.end(); ++iter) |
---|
| 66 | { |
---|
| 67 | if( iter->getSource() == &i_player ) |
---|
| 68 | continue; |
---|
| 69 | |
---|
| 70 | iter->getSource()->UpdateVisibilityOf(&i_player); |
---|
| 71 | i_player.UpdateVisibilityOf(iter->getSource(),i_data,i_data_updates,i_visibleNow); |
---|
| 72 | i_clientGUIDs.erase(iter->getSource()->GetGUID()); |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | void |
---|
| 77 | VisibleNotifier::Notify() |
---|
| 78 | { |
---|
| 79 | // at this moment i_clientGUIDs have guids that not iterate at grid level checks |
---|
| 80 | // but exist one case when this possible and object not out of range: transports |
---|
| 81 | if(Transport* transport = i_player.GetTransport()) |
---|
| 82 | { |
---|
| 83 | for(Transport::PlayerSet::const_iterator itr = transport->GetPassengers().begin();itr!=transport->GetPassengers().end();++itr) |
---|
| 84 | { |
---|
| 85 | if(i_clientGUIDs.find((*itr)->GetGUID())!=i_clientGUIDs.end()) |
---|
| 86 | { |
---|
| 87 | (*itr)->UpdateVisibilityOf(&i_player); |
---|
| 88 | i_player.UpdateVisibilityOf((*itr),i_data,i_data_updates,i_visibleNow); |
---|
| 89 | i_clientGUIDs.erase((*itr)->GetGUID()); |
---|
| 90 | } |
---|
| 91 | } |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | // generate outOfRange for not iterate objects |
---|
| 95 | i_data.AddOutOfRangeGUID(i_clientGUIDs); |
---|
| 96 | for(Player::ClientGUIDs::iterator itr = i_clientGUIDs.begin();itr!=i_clientGUIDs.end();++itr) |
---|
| 97 | { |
---|
| 98 | i_player.m_clientGUIDs.erase(*itr); |
---|
| 99 | |
---|
[44] | 100 | #ifdef TRINITY_DEBUG |
---|
[2] | 101 | if((sLog.getLogFilter() & LOG_FILTER_VISIBILITY_CHANGES)==0) |
---|
| 102 | sLog.outDebug("Object %u (Type: %u) is out of range (no in active cells set) now for player %u",GUID_LOPART(*itr),GuidHigh2TypeId(GUID_HIPART(*itr)),i_player.GetGUIDLow()); |
---|
| 103 | #endif |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | // send update to other players (except player updates that already sent using SendUpdateToPlayer) |
---|
| 107 | for(UpdateDataMapType::iterator iter = i_data_updates.begin(); iter != i_data_updates.end(); ++iter) |
---|
| 108 | { |
---|
| 109 | if(iter->first==&i_player) |
---|
| 110 | continue; |
---|
| 111 | |
---|
| 112 | WorldPacket packet; |
---|
| 113 | iter->second.BuildPacket(&packet); |
---|
| 114 | iter->first->GetSession()->SendPacket(&packet); |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | if( i_data.HasData() ) |
---|
| 118 | { |
---|
| 119 | // send create/outofrange packet to player (except player create updates that already sent using SendUpdateToPlayer) |
---|
| 120 | WorldPacket packet; |
---|
| 121 | i_data.BuildPacket(&packet); |
---|
| 122 | i_player.GetSession()->SendPacket(&packet); |
---|
| 123 | |
---|
| 124 | // send out of range to other players if need |
---|
| 125 | std::set<uint64> const& oor = i_data.GetOutOfRangeGUIDs(); |
---|
| 126 | for(std::set<uint64>::const_iterator iter = oor.begin(); iter != oor.end(); ++iter) |
---|
| 127 | { |
---|
| 128 | if(!IS_PLAYER_GUID(*iter)) |
---|
| 129 | continue; |
---|
| 130 | |
---|
| 131 | Player* plr = ObjectAccessor::GetPlayer(i_player,*iter); |
---|
| 132 | if(plr) |
---|
| 133 | plr->UpdateVisibilityOf(&i_player); |
---|
| 134 | } |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | // Now do operations that required done at object visibility change to visible |
---|
| 138 | |
---|
| 139 | // target aura duration for caster show only if target exist at caster client |
---|
| 140 | // send data at target visibility change (adding to client) |
---|
| 141 | for(std::set<WorldObject*>::const_iterator vItr = i_visibleNow.begin(); vItr != i_visibleNow.end(); ++vItr) |
---|
| 142 | if((*vItr)!=&i_player && (*vItr)->isType(TYPEMASK_UNIT)) |
---|
| 143 | i_player.SendAuraDurationsForTarget((Unit*)(*vItr)); |
---|
| 144 | } |
---|
| 145 | |
---|
[174] | 146 | void |
---|
| 147 | Deliverer::Visit(PlayerMapType &m) |
---|
[2] | 148 | { |
---|
[174] | 149 | for (PlayerMapType::iterator iter = m.begin(); iter != m.end(); ++iter) |
---|
[2] | 150 | { |
---|
[174] | 151 | if (!i_dist || iter->getSource()->GetDistance(&i_source) <= i_dist) |
---|
[2] | 152 | { |
---|
[233] | 153 | // Send packet to all who are sharing the player's vision |
---|
| 154 | if (!iter->getSource()->GetSharedVisionList().empty()) |
---|
| 155 | { |
---|
| 156 | SharedVisionList::const_iterator it = iter->getSource()->GetSharedVisionList().begin(); |
---|
| 157 | for ( ; it != iter->getSource()->GetSharedVisionList().end(); ++it) |
---|
| 158 | SendPacket(*it); |
---|
| 159 | } |
---|
| 160 | |
---|
[174] | 161 | VisitObject(iter->getSource()); |
---|
[2] | 162 | } |
---|
| 163 | } |
---|
| 164 | } |
---|
| 165 | |
---|
[174] | 166 | void |
---|
| 167 | Deliverer::Visit(CreatureMapType &m) |
---|
[2] | 168 | { |
---|
[174] | 169 | for (CreatureMapType::iterator iter = m.begin(); iter != m.end(); ++iter) |
---|
[2] | 170 | { |
---|
[174] | 171 | if (!i_dist || iter->getSource()->GetDistance(&i_source) <= i_dist) |
---|
| 172 | { |
---|
[233] | 173 | // Send packet to all who are sharing the creature's vision |
---|
| 174 | if (!iter->getSource()->GetSharedVisionList().empty()) |
---|
| 175 | { |
---|
| 176 | SharedVisionList::const_iterator it = iter->getSource()->GetSharedVisionList().begin(); |
---|
| 177 | for ( ; it != iter->getSource()->GetSharedVisionList().end(); ++it) |
---|
| 178 | SendPacket(*it); |
---|
| 179 | } |
---|
[174] | 180 | } |
---|
[2] | 181 | } |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | void |
---|
[233] | 185 | Deliverer::Visit(DynamicObjectMapType &m) |
---|
| 186 | { |
---|
| 187 | for (DynamicObjectMapType::iterator iter = m.begin(); iter != m.end(); ++iter) |
---|
| 188 | { |
---|
| 189 | if (IS_PLAYER_GUID(iter->getSource()->GetCasterGUID())) |
---|
| 190 | { |
---|
| 191 | // Send packet back to the caster if the caster has vision of dynamic object |
---|
| 192 | Player* caster = (Player*)iter->getSource()->GetCaster(); |
---|
| 193 | if (caster->GetUInt64Value(PLAYER_FARSIGHT) == iter->getSource()->GetGUID() && |
---|
| 194 | (!i_dist || iter->getSource()->GetDistance(&i_source) <= i_dist)) |
---|
| 195 | SendPacket(caster); |
---|
| 196 | } |
---|
| 197 | } |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | void |
---|
[174] | 201 | Deliverer::SendPacket(Player* plr) |
---|
[2] | 202 | { |
---|
[174] | 203 | if (!plr) |
---|
| 204 | return; |
---|
[233] | 205 | |
---|
| 206 | // Don't send the packet to self if not supposed to |
---|
| 207 | if (!i_toSelf && plr == &i_source) |
---|
| 208 | return; |
---|
| 209 | |
---|
[174] | 210 | // Don't send the packet to possesor if not supposed to |
---|
| 211 | if (!i_toPossessor && plr->isPossessing() && plr->GetCharmGUID() == i_source.GetGUID()) |
---|
| 212 | return; |
---|
| 213 | |
---|
| 214 | if (plr_list.find(plr->GetGUID()) == plr_list.end()) |
---|
[2] | 215 | { |
---|
[174] | 216 | if (WorldSession* session = plr->GetSession()) |
---|
| 217 | session->SendPacket(i_message); |
---|
| 218 | plr_list.insert(plr->GetGUID()); |
---|
[2] | 219 | } |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | void |
---|
[174] | 223 | MessageDeliverer::VisitObject(Player* plr) |
---|
[2] | 224 | { |
---|
[233] | 225 | SendPacket(plr); |
---|
[174] | 226 | } |
---|
| 227 | |
---|
| 228 | void |
---|
| 229 | MessageDistDeliverer::VisitObject(Player* plr) |
---|
| 230 | { |
---|
[233] | 231 | if( !i_ownTeamOnly || (i_source.GetTypeId() == TYPEID_PLAYER && plr->GetTeam() == ((Player&)i_source).GetTeam()) ) |
---|
[2] | 232 | { |
---|
[174] | 233 | SendPacket(plr); |
---|
[2] | 234 | } |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | template<class T> void |
---|
| 238 | ObjectUpdater::Visit(GridRefManager<T> &m) |
---|
| 239 | { |
---|
| 240 | for(typename GridRefManager<T>::iterator iter = m.begin(); iter != m.end(); ++iter) |
---|
| 241 | { |
---|
| 242 | iter->getSource()->Update(i_timeDiff); |
---|
| 243 | } |
---|
| 244 | } |
---|
| 245 | |
---|
| 246 | template void ObjectUpdater::Visit<GameObject>(GameObjectMapType &); |
---|
| 247 | template void ObjectUpdater::Visit<DynamicObject>(DynamicObjectMapType &); |
---|
| 248 | |
---|
| 249 | bool CannibalizeObjectCheck::operator()(Corpse* u) |
---|
| 250 | { |
---|
| 251 | // ignore bones |
---|
| 252 | if(u->GetType()==CORPSE_BONES) |
---|
| 253 | return false; |
---|
| 254 | |
---|
| 255 | Player* owner = ObjectAccessor::FindPlayer(u->GetOwnerGUID()); |
---|
| 256 | |
---|
| 257 | if( !owner || i_funit->IsFriendlyTo(owner)) |
---|
| 258 | return false; |
---|
| 259 | |
---|
| 260 | if(i_funit->IsWithinDistInMap(u, i_range) ) |
---|
| 261 | return true; |
---|
| 262 | |
---|
| 263 | return false; |
---|
| 264 | } |
---|