| 1 | /* |
|---|
| 2 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
|---|
| 3 | * |
|---|
| 4 | * Thanks to the original authors: MaNGOS <http://www.mangosproject.org/> |
|---|
| 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 |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 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 |
|---|
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 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 | |
|---|
| 31 | using namespace Trinity; |
|---|
| 32 | |
|---|
| 33 | void |
|---|
| 34 | Trinity::PlayerNotifier::Visit(PlayerMapType &m) |
|---|
| 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()); |
|---|
| 43 | } |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | void |
|---|
| 47 | VisibleChangesNotifier::Visit(PlayerMapType &m) |
|---|
| 48 | { |
|---|
| 49 | for(PlayerMapType::iterator iter=m.begin(); iter != m.end(); ++iter) |
|---|
| 50 | { |
|---|
| 51 | if(iter->getSource() == &i_object) |
|---|
| 52 | continue; |
|---|
| 53 | |
|---|
| 54 | iter->getSource()->UpdateVisibilityOf(&i_object); |
|---|
| 55 | } |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | void |
|---|
| 59 | VisibleNotifier::Visit(PlayerMapType &m) |
|---|
| 60 | { |
|---|
| 61 | for(PlayerMapType::iterator iter=m.begin(); iter != m.end(); ++iter) |
|---|
| 62 | { |
|---|
| 63 | if( iter->getSource() == &i_player ) |
|---|
| 64 | continue; |
|---|
| 65 | |
|---|
| 66 | iter->getSource()->UpdateVisibilityOf(&i_player); |
|---|
| 67 | i_player.UpdateVisibilityOf(iter->getSource(),i_data,i_data_updates,i_visibleNow); |
|---|
| 68 | i_clientGUIDs.erase(iter->getSource()->GetGUID()); |
|---|
| 69 | } |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | void |
|---|
| 73 | VisibleNotifier::Notify() |
|---|
| 74 | { |
|---|
| 75 | // at this moment i_clientGUIDs have guids that not iterate at grid level checks |
|---|
| 76 | // but exist one case when this possible and object not out of range: transports |
|---|
| 77 | if(Transport* transport = i_player.GetTransport()) |
|---|
| 78 | { |
|---|
| 79 | for(Transport::PlayerSet::const_iterator itr = transport->GetPassengers().begin();itr!=transport->GetPassengers().end();++itr) |
|---|
| 80 | { |
|---|
| 81 | if(i_clientGUIDs.find((*itr)->GetGUID())!=i_clientGUIDs.end()) |
|---|
| 82 | { |
|---|
| 83 | (*itr)->UpdateVisibilityOf(&i_player); |
|---|
| 84 | i_player.UpdateVisibilityOf((*itr),i_data,i_data_updates,i_visibleNow); |
|---|
| 85 | i_clientGUIDs.erase((*itr)->GetGUID()); |
|---|
| 86 | } |
|---|
| 87 | } |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | // generate outOfRange for not iterate objects |
|---|
| 91 | i_data.AddOutOfRangeGUID(i_clientGUIDs); |
|---|
| 92 | for(Player::ClientGUIDs::iterator itr = i_clientGUIDs.begin();itr!=i_clientGUIDs.end();++itr) |
|---|
| 93 | { |
|---|
| 94 | i_player.m_clientGUIDs.erase(*itr); |
|---|
| 95 | |
|---|
| 96 | #ifdef TRINITY_DEBUG |
|---|
| 97 | if((sLog.getLogFilter() & LOG_FILTER_VISIBILITY_CHANGES)==0) |
|---|
| 98 | 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()); |
|---|
| 99 | #endif |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | // send update to other players (except player updates that already sent using SendUpdateToPlayer) |
|---|
| 103 | for(UpdateDataMapType::iterator iter = i_data_updates.begin(); iter != i_data_updates.end(); ++iter) |
|---|
| 104 | { |
|---|
| 105 | if(iter->first==&i_player) |
|---|
| 106 | continue; |
|---|
| 107 | |
|---|
| 108 | WorldPacket packet; |
|---|
| 109 | iter->second.BuildPacket(&packet); |
|---|
| 110 | iter->first->GetSession()->SendPacket(&packet); |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | if( i_data.HasData() ) |
|---|
| 114 | { |
|---|
| 115 | // send create/outofrange packet to player (except player create updates that already sent using SendUpdateToPlayer) |
|---|
| 116 | WorldPacket packet; |
|---|
| 117 | i_data.BuildPacket(&packet); |
|---|
| 118 | i_player.GetSession()->SendPacket(&packet); |
|---|
| 119 | |
|---|
| 120 | // send out of range to other players if need |
|---|
| 121 | std::set<uint64> const& oor = i_data.GetOutOfRangeGUIDs(); |
|---|
| 122 | for(std::set<uint64>::const_iterator iter = oor.begin(); iter != oor.end(); ++iter) |
|---|
| 123 | { |
|---|
| 124 | if(!IS_PLAYER_GUID(*iter)) |
|---|
| 125 | continue; |
|---|
| 126 | |
|---|
| 127 | Player* plr = ObjectAccessor::GetPlayer(i_player,*iter); |
|---|
| 128 | if(plr) |
|---|
| 129 | plr->UpdateVisibilityOf(&i_player); |
|---|
| 130 | } |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | // Now do operations that required done at object visibility change to visible |
|---|
| 134 | |
|---|
| 135 | // target aura duration for caster show only if target exist at caster client |
|---|
| 136 | // send data at target visibility change (adding to client) |
|---|
| 137 | for(std::set<WorldObject*>::const_iterator vItr = i_visibleNow.begin(); vItr != i_visibleNow.end(); ++vItr) |
|---|
| 138 | if((*vItr)!=&i_player && (*vItr)->isType(TYPEMASK_UNIT)) |
|---|
| 139 | i_player.SendAuraDurationsForTarget((Unit*)(*vItr)); |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | void |
|---|
| 143 | MessageDeliverer::Visit(PlayerMapType &m) |
|---|
| 144 | { |
|---|
| 145 | for(PlayerMapType::iterator iter=m.begin(); iter != m.end(); ++iter) |
|---|
| 146 | { |
|---|
| 147 | if( i_toSelf || iter->getSource() != &i_player) |
|---|
| 148 | { |
|---|
| 149 | if(WorldSession* session = iter->getSource()->GetSession()) |
|---|
| 150 | session->SendPacket(i_message); |
|---|
| 151 | } |
|---|
| 152 | } |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | void |
|---|
| 156 | ObjectMessageDeliverer::Visit(PlayerMapType &m) |
|---|
| 157 | { |
|---|
| 158 | for(PlayerMapType::iterator iter=m.begin(); iter != m.end(); ++iter) |
|---|
| 159 | { |
|---|
| 160 | if(WorldSession* session = iter->getSource()->GetSession()) |
|---|
| 161 | session->SendPacket(i_message); |
|---|
| 162 | } |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | void |
|---|
| 166 | MessageDistDeliverer::Visit(PlayerMapType &m) |
|---|
| 167 | { |
|---|
| 168 | for(PlayerMapType::iterator iter=m.begin(); iter != m.end(); ++iter) |
|---|
| 169 | { |
|---|
| 170 | if( (i_toSelf || iter->getSource() != &i_player ) && |
|---|
| 171 | (!i_ownTeamOnly || iter->getSource()->GetTeam() == i_player.GetTeam() ) && |
|---|
| 172 | (!i_dist || iter->getSource()->GetDistance(&i_player) <= i_dist) ) |
|---|
| 173 | { |
|---|
| 174 | if(WorldSession* session = iter->getSource()->GetSession()) |
|---|
| 175 | session->SendPacket(i_message); |
|---|
| 176 | } |
|---|
| 177 | } |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | void |
|---|
| 181 | ObjectMessageDistDeliverer::Visit(PlayerMapType &m) |
|---|
| 182 | { |
|---|
| 183 | for(PlayerMapType::iterator iter=m.begin(); iter != m.end(); ++iter) |
|---|
| 184 | { |
|---|
| 185 | if( !i_dist || iter->getSource()->GetDistance(&i_object) <= i_dist ) |
|---|
| 186 | { |
|---|
| 187 | if(WorldSession* session = iter->getSource()->GetSession()) |
|---|
| 188 | session->SendPacket(i_message); |
|---|
| 189 | } |
|---|
| 190 | } |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | template<class T> void |
|---|
| 194 | ObjectUpdater::Visit(GridRefManager<T> &m) |
|---|
| 195 | { |
|---|
| 196 | for(typename GridRefManager<T>::iterator iter = m.begin(); iter != m.end(); ++iter) |
|---|
| 197 | { |
|---|
| 198 | iter->getSource()->Update(i_timeDiff); |
|---|
| 199 | } |
|---|
| 200 | } |
|---|
| 201 | |
|---|
| 202 | template void ObjectUpdater::Visit<GameObject>(GameObjectMapType &); |
|---|
| 203 | template void ObjectUpdater::Visit<DynamicObject>(DynamicObjectMapType &); |
|---|
| 204 | |
|---|
| 205 | bool CannibalizeObjectCheck::operator()(Corpse* u) |
|---|
| 206 | { |
|---|
| 207 | // ignore bones |
|---|
| 208 | if(u->GetType()==CORPSE_BONES) |
|---|
| 209 | return false; |
|---|
| 210 | |
|---|
| 211 | Player* owner = ObjectAccessor::FindPlayer(u->GetOwnerGUID()); |
|---|
| 212 | |
|---|
| 213 | if( !owner || i_funit->IsFriendlyTo(owner)) |
|---|
| 214 | return false; |
|---|
| 215 | |
|---|
| 216 | if(i_funit->IsWithinDistInMap(u, i_range) ) |
|---|
| 217 | return true; |
|---|
| 218 | |
|---|
| 219 | return false; |
|---|
| 220 | } |
|---|