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

Revision 174, 7.3 kB (checked in by yumileroy, 17 years ago)

[svn] Implemented player on player and player on creature possession:
* Implemented packet and vision forwarding through possessed units
* Added new OnPossess? script call alerting scripts on when possession is applied/removed
* Moved fall damage and fall under map calculations into the Player class
* Added new PossessedAI that is applied only while possession on creature is active
* Implemented summon possessed spell effect
* Fixed Eyes of the Beast

Original author: gvcoman
Date: 2008-11-05 20:51:05-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        if (i_player.isPossessedByPlayer())
44            ((Player*)i_player.GetCharmer())->UpdateVisibilityOf(iter->getSource());
45    }
46}
47
48void
49VisibleChangesNotifier::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
60void
61VisibleNotifier::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
74void
75VisibleNotifier::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
98        #ifdef TRINITY_DEBUG
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
144void 
145Deliverer::Visit(PlayerMapType &m)
146{
147    for (PlayerMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
148    {
149        if (!i_dist || iter->getSource()->GetDistance(&i_source) <= i_dist)
150        {
151            // Send packet to possessor
152            if (iter->getSource()->isPossessedByPlayer())
153                SendPacket((Player*)iter->getSource()->GetCharmer());
154            VisitObject(iter->getSource());
155        }
156    }
157}
158
159void 
160Deliverer::Visit(CreatureMapType &m)
161{
162    for (CreatureMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
163    {
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        }
170    }
171}
172
173void
174Deliverer::SendPacket(Player* plr)
175{
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())
183    {
184        if (WorldSession* session = plr->GetSession())
185            session->SendPacket(i_message);
186        plr_list.insert(plr->GetGUID());
187    }
188}
189
190void
191MessageDeliverer::VisitObject(Player* plr)
192{
193    if (i_toSelf || plr != &i_source)
194        SendPacket(plr);
195}
196
197void
198MessageDistDeliverer::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())) )
202    {
203        SendPacket(plr);
204    }
205}
206
207template<class T> void
208ObjectUpdater::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
216template void ObjectUpdater::Visit<GameObject>(GameObjectMapType &);
217template void ObjectUpdater::Visit<DynamicObject>(DynamicObjectMapType &);
218
219bool 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}
Note: See TracBrowser for help on using the browser.