root/trunk/src/game/GridNotifiers.cpp @ 252

Revision 233, 8.5 kB (checked in by yumileroy, 17 years ago)

[svn] * Reimplemented packet/update forwarding in more generic way
* Implemented far sight spells (Far Sight, Eagle Eye, etc) at unlimited range and properly forward packets
* Implemented bind vision spells (Mind Vision, etc) to forward packets at unlimited distance
* Implemented Sentry Totem (both vision switching/forwarding and alerting)
* Other misc possession fixes
* Added .bindsight and .unbindsight commands

Please test out the above spells (including Mind Control) and report any issues on the forums.

Original author: gvcoman
Date: 2008-11-14 20:40:35-06:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * Copyright (C) 2008 Trinity <http://www.trinitycore.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
31using namespace Trinity;
32
33void
34Trinity::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        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());
47    }
48}
49
50void
51VisibleChangesNotifier::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
62void
63VisibleNotifier::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
76void
77VisibleNotifier::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
100        #ifdef TRINITY_DEBUG
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
146void 
147Deliverer::Visit(PlayerMapType &m)
148{
149    for (PlayerMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
150    {
151        if (!i_dist || iter->getSource()->GetDistance(&i_source) <= i_dist)
152        {
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
161            VisitObject(iter->getSource());
162        }
163    }
164}
165
166void 
167Deliverer::Visit(CreatureMapType &m)
168{
169    for (CreatureMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
170    {
171        if (!i_dist || iter->getSource()->GetDistance(&i_source) <= i_dist)
172        {
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            }
180        }
181    }
182}
183
184void
185Deliverer::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
200void
201Deliverer::SendPacket(Player* plr)
202{
203    if (!plr)
204        return;
205
206    // Don't send the packet to self if not supposed to
207    if (!i_toSelf && plr == &i_source)
208        return;
209
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())
215    {
216        if (WorldSession* session = plr->GetSession())
217            session->SendPacket(i_message);
218        plr_list.insert(plr->GetGUID());
219    }
220}
221
222void
223MessageDeliverer::VisitObject(Player* plr)
224{
225    SendPacket(plr);
226}
227
228void
229MessageDistDeliverer::VisitObject(Player* plr)
230{
231    if( !i_ownTeamOnly || (i_source.GetTypeId() == TYPEID_PLAYER && plr->GetTeam() == ((Player&)i_source).GetTeam()) )
232    {
233        SendPacket(plr);
234    }
235}
236
237template<class T> void
238ObjectUpdater::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
246template void ObjectUpdater::Visit<GameObject>(GameObjectMapType &);
247template void ObjectUpdater::Visit<DynamicObject>(DynamicObjectMapType &);
248
249bool 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}
Note: See TracBrowser for help on using the browser.