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