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

Revision 2, 6.9 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

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