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 | #ifndef TRINITY_GRIDNOTIFIERS_H |
---|
22 | #define TRINITY_GRIDNOTIFIERS_H |
---|
23 | |
---|
24 | #include "ObjectGridLoader.h" |
---|
25 | #include "ByteBuffer.h" |
---|
26 | #include "UpdateData.h" |
---|
27 | #include <iostream> |
---|
28 | |
---|
29 | #include "Corpse.h" |
---|
30 | #include "Object.h" |
---|
31 | #include "DynamicObject.h" |
---|
32 | #include "GameObject.h" |
---|
33 | #include "Player.h" |
---|
34 | #include "Unit.h" |
---|
35 | |
---|
36 | class Player; |
---|
37 | //class Map; |
---|
38 | |
---|
39 | namespace Trinity |
---|
40 | { |
---|
41 | |
---|
42 | struct TRINITY_DLL_DECL PlayerNotifier |
---|
43 | { |
---|
44 | explicit PlayerNotifier(Player &pl) : i_player(pl) {} |
---|
45 | void Visit(PlayerMapType &); |
---|
46 | template<class SKIP> void Visit(GridRefManager<SKIP> &) {} |
---|
47 | Player &i_player; |
---|
48 | }; |
---|
49 | |
---|
50 | struct TRINITY_DLL_DECL VisibleNotifier |
---|
51 | { |
---|
52 | Player &i_player; |
---|
53 | UpdateData i_data; |
---|
54 | UpdateDataMapType i_data_updates; |
---|
55 | Player::ClientGUIDs i_clientGUIDs; |
---|
56 | std::set<WorldObject*> i_visibleNow; |
---|
57 | |
---|
58 | explicit VisibleNotifier(Player &player) : i_player(player),i_clientGUIDs(player.m_clientGUIDs) {} |
---|
59 | template<class T> void Visit(GridRefManager<T> &m); |
---|
60 | void Visit(PlayerMapType &); |
---|
61 | void Notify(void); |
---|
62 | }; |
---|
63 | |
---|
64 | struct TRINITY_DLL_DECL VisibleChangesNotifier |
---|
65 | { |
---|
66 | WorldObject &i_object; |
---|
67 | |
---|
68 | explicit VisibleChangesNotifier(WorldObject &object) : i_object(object) {} |
---|
69 | template<class T> void Visit(GridRefManager<T> &) {} |
---|
70 | void Visit(PlayerMapType &); |
---|
71 | }; |
---|
72 | |
---|
73 | struct TRINITY_DLL_DECL GridUpdater |
---|
74 | { |
---|
75 | GridType &i_grid; |
---|
76 | uint32 i_timeDiff; |
---|
77 | GridUpdater(GridType &grid, uint32 diff) : i_grid(grid), i_timeDiff(diff) {} |
---|
78 | |
---|
79 | template<class T> void updateObjects(GridRefManager<T> &m) |
---|
80 | { |
---|
81 | for(typename GridRefManager<T>::iterator iter = m.begin(); iter != m.end(); ++iter) |
---|
82 | iter->getSource()->Update(i_timeDiff); |
---|
83 | } |
---|
84 | |
---|
85 | void Visit(PlayerMapType &m) { updateObjects<Player>(m); } |
---|
86 | void Visit(CreatureMapType &m){ updateObjects<Creature>(m); } |
---|
87 | void Visit(GameObjectMapType &m) { updateObjects<GameObject>(m); } |
---|
88 | void Visit(DynamicObjectMapType &m) { updateObjects<DynamicObject>(m); } |
---|
89 | void Visit(CorpseMapType &m) { updateObjects<Corpse>(m); } |
---|
90 | }; |
---|
91 | |
---|
92 | struct TRINITY_DLL_DECL MessageDeliverer |
---|
93 | { |
---|
94 | Player &i_player; |
---|
95 | WorldPacket *i_message; |
---|
96 | bool i_toSelf; |
---|
97 | MessageDeliverer(Player &pl, WorldPacket *msg, bool to_self) : i_player(pl), i_message(msg), i_toSelf(to_self) {} |
---|
98 | void Visit(PlayerMapType &m); |
---|
99 | template<class SKIP> void Visit(GridRefManager<SKIP> &) {} |
---|
100 | }; |
---|
101 | |
---|
102 | struct TRINITY_DLL_DECL ObjectMessageDeliverer |
---|
103 | { |
---|
104 | WorldPacket *i_message; |
---|
105 | explicit ObjectMessageDeliverer(WorldPacket *msg) : i_message(msg) {} |
---|
106 | void Visit(PlayerMapType &m); |
---|
107 | template<class SKIP> void Visit(GridRefManager<SKIP> &) {} |
---|
108 | }; |
---|
109 | |
---|
110 | struct TRINITY_DLL_DECL MessageDistDeliverer |
---|
111 | { |
---|
112 | Player &i_player; |
---|
113 | WorldPacket *i_message; |
---|
114 | bool i_toSelf; |
---|
115 | bool i_ownTeamOnly; |
---|
116 | float i_dist; |
---|
117 | MessageDistDeliverer(Player &pl, WorldPacket *msg, float dist, bool to_self, bool ownTeamOnly) : i_player(pl), i_message(msg), i_dist(dist), i_toSelf(to_self), i_ownTeamOnly(ownTeamOnly) {} |
---|
118 | void Visit(PlayerMapType &m); |
---|
119 | template<class SKIP> void Visit(GridRefManager<SKIP> &) {} |
---|
120 | }; |
---|
121 | |
---|
122 | struct TRINITY_DLL_DECL ObjectMessageDistDeliverer |
---|
123 | { |
---|
124 | WorldObject &i_object; |
---|
125 | WorldPacket *i_message; |
---|
126 | float i_dist; |
---|
127 | ObjectMessageDistDeliverer(WorldObject &obj, WorldPacket *msg, float dist) : i_object(obj), i_message(msg), i_dist(dist) {} |
---|
128 | void Visit(PlayerMapType &m); |
---|
129 | template<class SKIP> void Visit(GridRefManager<SKIP> &) {} |
---|
130 | }; |
---|
131 | |
---|
132 | struct TRINITY_DLL_DECL ObjectUpdater |
---|
133 | { |
---|
134 | uint32 i_timeDiff; |
---|
135 | explicit ObjectUpdater(const uint32 &diff) : i_timeDiff(diff) {} |
---|
136 | template<class T> void Visit(GridRefManager<T> &m); |
---|
137 | void Visit(PlayerMapType &) {} |
---|
138 | void Visit(CorpseMapType &) {} |
---|
139 | void Visit(CreatureMapType &); |
---|
140 | }; |
---|
141 | |
---|
142 | template<class T> |
---|
143 | struct TRINITY_DLL_DECL ObjectAccessorNotifier |
---|
144 | { |
---|
145 | T *& i_object; |
---|
146 | |
---|
147 | uint64 i_id; |
---|
148 | ObjectAccessorNotifier(T * &obj, uint64 id) : i_object(obj), i_id(id) |
---|
149 | { |
---|
150 | i_object = NULL; |
---|
151 | } |
---|
152 | |
---|
153 | void Visit(GridRefManager<T> &m ) |
---|
154 | { |
---|
155 | if( i_object == NULL ) |
---|
156 | { |
---|
157 | GridRefManager<T> *iter = m.find(i_id); |
---|
158 | if( iter != m.end() ) |
---|
159 | { |
---|
160 | assert( iter->second != NULL ); |
---|
161 | i_object = iter->second; |
---|
162 | } |
---|
163 | } |
---|
164 | } |
---|
165 | |
---|
166 | template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {} |
---|
167 | }; |
---|
168 | |
---|
169 | struct TRINITY_DLL_DECL PlayerRelocationNotifier |
---|
170 | { |
---|
171 | Player &i_player; |
---|
172 | PlayerRelocationNotifier(Player &pl) : i_player(pl) {} |
---|
173 | template<class T> void Visit(GridRefManager<T> &) {} |
---|
174 | void Visit(PlayerMapType &); |
---|
175 | void Visit(CreatureMapType &); |
---|
176 | }; |
---|
177 | |
---|
178 | struct TRINITY_DLL_DECL CreatureRelocationNotifier |
---|
179 | { |
---|
180 | Creature &i_creature; |
---|
181 | CreatureRelocationNotifier(Creature &c) : i_creature(c) {} |
---|
182 | template<class T> void Visit(GridRefManager<T> &) {} |
---|
183 | #ifdef WIN32 |
---|
184 | template<> void Visit(PlayerMapType &); |
---|
185 | #endif |
---|
186 | }; |
---|
187 | |
---|
188 | struct TRINITY_DLL_DECL DynamicObjectUpdater |
---|
189 | { |
---|
190 | DynamicObject &i_dynobject; |
---|
191 | Unit* i_check; |
---|
192 | DynamicObjectUpdater(DynamicObject &dynobject, Unit* caster) : i_dynobject(dynobject) |
---|
193 | { |
---|
194 | i_check = caster; |
---|
195 | Unit* owner = i_check->GetOwner(); |
---|
196 | if(owner) |
---|
197 | i_check = owner; |
---|
198 | } |
---|
199 | |
---|
200 | template<class T> inline void Visit(GridRefManager<T> &) {} |
---|
201 | #ifdef WIN32 |
---|
202 | template<> inline void Visit<Player>(PlayerMapType &); |
---|
203 | template<> inline void Visit<Creature>(CreatureMapType &); |
---|
204 | #endif |
---|
205 | |
---|
206 | void VisitHelper(Unit* target); |
---|
207 | }; |
---|
208 | |
---|
209 | // SEARCHERS & LIST SEARCHERS & WORKERS |
---|
210 | |
---|
211 | // WorldObject searchers & workers |
---|
212 | |
---|
213 | template<class Check> |
---|
214 | struct TRINITY_DLL_DECL WorldObjectSearcher |
---|
215 | { |
---|
216 | WorldObject* &i_object; |
---|
217 | Check &i_check; |
---|
218 | |
---|
219 | WorldObjectSearcher(WorldObject* & result, Check& check) : i_object(result),i_check(check) {} |
---|
220 | |
---|
221 | void Visit(GameObjectMapType &m); |
---|
222 | void Visit(PlayerMapType &m); |
---|
223 | void Visit(CreatureMapType &m); |
---|
224 | void Visit(CorpseMapType &m); |
---|
225 | void Visit(DynamicObjectMapType &m); |
---|
226 | |
---|
227 | template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {} |
---|
228 | }; |
---|
229 | |
---|
230 | template<class Check> |
---|
231 | struct TRINITY_DLL_DECL WorldObjectListSearcher |
---|
232 | { |
---|
233 | std::list<WorldObject*> &i_objects; |
---|
234 | Check& i_check; |
---|
235 | |
---|
236 | WorldObjectListSearcher(std::list<WorldObject*> &objects, Check & check) : i_objects(objects),i_check(check) {} |
---|
237 | |
---|
238 | void Visit(PlayerMapType &m); |
---|
239 | void Visit(CreatureMapType &m); |
---|
240 | void Visit(CorpseMapType &m); |
---|
241 | void Visit(GameObjectMapType &m); |
---|
242 | void Visit(DynamicObjectMapType &m); |
---|
243 | |
---|
244 | template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {} |
---|
245 | }; |
---|
246 | |
---|
247 | template<class Do> |
---|
248 | struct TRINITY_DLL_DECL WorldObjectWorker |
---|
249 | { |
---|
250 | Do const& i_do; |
---|
251 | |
---|
252 | explicit WorldObjectWorker(Do const& _do) : i_do(_do) {} |
---|
253 | |
---|
254 | void Visit(GameObjectMapType &m) |
---|
255 | { |
---|
256 | for(GameObjectMapType::iterator itr=m.begin(); itr != m.end(); ++itr) |
---|
257 | i_do(itr->getSource()); |
---|
258 | } |
---|
259 | |
---|
260 | void Visit(PlayerMapType &m) |
---|
261 | { |
---|
262 | for(PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr) |
---|
263 | i_do(itr->getSource()); |
---|
264 | } |
---|
265 | void Visit(CreatureMapType &m) |
---|
266 | { |
---|
267 | for(CreatureMapType::iterator itr=m.begin(); itr != m.end(); ++itr) |
---|
268 | i_do(itr->getSource()); |
---|
269 | } |
---|
270 | |
---|
271 | void Visit(CorpseMapType &m) |
---|
272 | { |
---|
273 | for(CorpseMapType::iterator itr=m.begin(); itr != m.end(); ++itr) |
---|
274 | i_do(itr->getSource()); |
---|
275 | } |
---|
276 | |
---|
277 | void Visit(DynamicObjectMapType &m) |
---|
278 | { |
---|
279 | for(DynamicObjectMapType::iterator itr=m.begin(); itr != m.end(); ++itr) |
---|
280 | i_do(itr->getSource()); |
---|
281 | } |
---|
282 | |
---|
283 | template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {} |
---|
284 | }; |
---|
285 | |
---|
286 | // Gameobject searchers |
---|
287 | |
---|
288 | template<class Check> |
---|
289 | struct TRINITY_DLL_DECL GameObjectSearcher |
---|
290 | { |
---|
291 | GameObject* &i_object; |
---|
292 | Check &i_check; |
---|
293 | |
---|
294 | GameObjectSearcher(GameObject* & result, Check& check) : i_object(result),i_check(check) {} |
---|
295 | |
---|
296 | void Visit(GameObjectMapType &m); |
---|
297 | |
---|
298 | template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {} |
---|
299 | }; |
---|
300 | |
---|
301 | // Last accepted by Check GO if any (Check can change requirements at each call) |
---|
302 | template<class Check> |
---|
303 | struct TRINITY_DLL_DECL GameObjectLastSearcher |
---|
304 | { |
---|
305 | GameObject* &i_object; |
---|
306 | Check& i_check; |
---|
307 | |
---|
308 | GameObjectLastSearcher(GameObject* & result, Check& check) : i_object(result),i_check(check) {} |
---|
309 | |
---|
310 | void Visit(GameObjectMapType &m); |
---|
311 | |
---|
312 | template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {} |
---|
313 | }; |
---|
314 | |
---|
315 | template<class Check> |
---|
316 | struct TRINITY_DLL_DECL GameObjectListSearcher |
---|
317 | { |
---|
318 | std::list<GameObject*> &i_objects; |
---|
319 | Check& i_check; |
---|
320 | |
---|
321 | GameObjectListSearcher(std::list<GameObject*> &objects, Check & check) : i_objects(objects),i_check(check) {} |
---|
322 | |
---|
323 | void Visit(GameObjectMapType &m); |
---|
324 | |
---|
325 | template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {} |
---|
326 | }; |
---|
327 | |
---|
328 | // Unit searchers |
---|
329 | |
---|
330 | // First accepted by Check Unit if any |
---|
331 | template<class Check> |
---|
332 | struct TRINITY_DLL_DECL UnitSearcher |
---|
333 | { |
---|
334 | Unit* &i_object; |
---|
335 | Check & i_check; |
---|
336 | |
---|
337 | UnitSearcher(Unit* & result, Check & check) : i_object(result),i_check(check) {} |
---|
338 | |
---|
339 | void Visit(CreatureMapType &m); |
---|
340 | void Visit(PlayerMapType &m); |
---|
341 | |
---|
342 | template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {} |
---|
343 | }; |
---|
344 | |
---|
345 | // Last accepted by Check Unit if any (Check can change requirements at each call) |
---|
346 | template<class Check> |
---|
347 | struct TRINITY_DLL_DECL UnitLastSearcher |
---|
348 | { |
---|
349 | Unit* &i_object; |
---|
350 | Check & i_check; |
---|
351 | |
---|
352 | UnitLastSearcher(Unit* & result, Check & check) : i_object(result),i_check(check) {} |
---|
353 | |
---|
354 | void Visit(CreatureMapType &m); |
---|
355 | void Visit(PlayerMapType &m); |
---|
356 | |
---|
357 | template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {} |
---|
358 | }; |
---|
359 | |
---|
360 | // All accepted by Check units if any |
---|
361 | template<class Check> |
---|
362 | struct TRINITY_DLL_DECL UnitListSearcher |
---|
363 | { |
---|
364 | std::list<Unit*> &i_objects; |
---|
365 | Check& i_check; |
---|
366 | |
---|
367 | UnitListSearcher(std::list<Unit*> &objects, Check & check) : i_objects(objects),i_check(check) {} |
---|
368 | |
---|
369 | void Visit(PlayerMapType &m); |
---|
370 | void Visit(CreatureMapType &m); |
---|
371 | |
---|
372 | template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {} |
---|
373 | }; |
---|
374 | |
---|
375 | // Creature searchers |
---|
376 | |
---|
377 | template<class Check> |
---|
378 | struct TRINITY_DLL_DECL CreatureSearcher |
---|
379 | { |
---|
380 | Creature* &i_object; |
---|
381 | Check & i_check; |
---|
382 | |
---|
383 | CreatureSearcher(Creature* & result, Check & check) : i_object(result),i_check(check) {} |
---|
384 | |
---|
385 | void Visit(CreatureMapType &m); |
---|
386 | |
---|
387 | template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {} |
---|
388 | }; |
---|
389 | |
---|
390 | // Last accepted by Check Creature if any (Check can change requirements at each call) |
---|
391 | template<class Check> |
---|
392 | struct TRINITY_DLL_DECL CreatureLastSearcher |
---|
393 | { |
---|
394 | Creature* &i_object; |
---|
395 | Check & i_check; |
---|
396 | |
---|
397 | CreatureLastSearcher(Creature* & result, Check & check) : i_object(result),i_check(check) {} |
---|
398 | |
---|
399 | void Visit(CreatureMapType &m); |
---|
400 | |
---|
401 | template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {} |
---|
402 | }; |
---|
403 | |
---|
404 | template<class Check> |
---|
405 | struct TRINITY_DLL_DECL CreatureListSearcher |
---|
406 | { |
---|
407 | std::list<Creature*> &i_objects; |
---|
408 | Check& i_check; |
---|
409 | |
---|
410 | CreatureListSearcher(std::list<Creature*> &objects, Check & check) : i_objects(objects),i_check(check) {} |
---|
411 | |
---|
412 | void Visit(CreatureMapType &m); |
---|
413 | |
---|
414 | template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {} |
---|
415 | }; |
---|
416 | |
---|
417 | // Player searchers |
---|
418 | |
---|
419 | template<class Check> |
---|
420 | struct TRINITY_DLL_DECL PlayerSearcher |
---|
421 | { |
---|
422 | Player* &i_object; |
---|
423 | Check & i_check; |
---|
424 | |
---|
425 | PlayerSearcher(Player* & result, Check & check) : i_object(result),i_check(check) {} |
---|
426 | |
---|
427 | void Visit(PlayerMapType &m); |
---|
428 | |
---|
429 | template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {} |
---|
430 | }; |
---|
431 | |
---|
432 | template<class Do> |
---|
433 | struct TRINITY_DLL_DECL PlayerWorker |
---|
434 | { |
---|
435 | Do& i_do; |
---|
436 | |
---|
437 | explicit PlayerWorker(Do& _do) : i_do(_do) {} |
---|
438 | |
---|
439 | void Visit(PlayerMapType &m) |
---|
440 | { |
---|
441 | for(PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr) |
---|
442 | i_do(itr->getSource()); |
---|
443 | } |
---|
444 | |
---|
445 | template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {} |
---|
446 | }; |
---|
447 | |
---|
448 | // CHECKS && DO classes |
---|
449 | |
---|
450 | // WorldObject check classes |
---|
451 | class CannibalizeObjectCheck |
---|
452 | { |
---|
453 | public: |
---|
454 | CannibalizeObjectCheck(Unit* funit, float range) : i_funit(funit), i_range(range) {} |
---|
455 | bool operator()(Player* u) |
---|
456 | { |
---|
457 | if( i_funit->IsFriendlyTo(u) || u->isAlive() || u->isInFlight() ) |
---|
458 | return false; |
---|
459 | |
---|
460 | if(i_funit->IsWithinDistInMap(u, i_range) ) |
---|
461 | return true; |
---|
462 | |
---|
463 | return false; |
---|
464 | } |
---|
465 | bool operator()(Corpse* u); |
---|
466 | bool operator()(Creature* u) |
---|
467 | { |
---|
468 | if( i_funit->IsFriendlyTo(u) || u->isAlive() || u->isInFlight() || |
---|
469 | (u->GetCreatureTypeMask() & CREATURE_TYPEMASK_HUMANOID_OR_UNDEAD)==0) |
---|
470 | return false; |
---|
471 | |
---|
472 | if(i_funit->IsWithinDistInMap(u, i_range) ) |
---|
473 | return true; |
---|
474 | |
---|
475 | return false; |
---|
476 | } |
---|
477 | template<class NOT_INTERESTED> bool operator()(NOT_INTERESTED* u) { return false; } |
---|
478 | private: |
---|
479 | Unit* const i_funit; |
---|
480 | float i_range; |
---|
481 | }; |
---|
482 | |
---|
483 | // WorldObject do classes |
---|
484 | |
---|
485 | class RespawnDo |
---|
486 | { |
---|
487 | public: |
---|
488 | RespawnDo() {} |
---|
489 | void operator()(Creature* u) const { u->Respawn(); } |
---|
490 | void operator()(GameObject* u) const { u->Respawn(); } |
---|
491 | void operator()(WorldObject*) const {} |
---|
492 | void operator()(Corpse*) const {} |
---|
493 | }; |
---|
494 | |
---|
495 | // GameObject checks |
---|
496 | |
---|
497 | class GameObjectFocusCheck |
---|
498 | { |
---|
499 | public: |
---|
500 | GameObjectFocusCheck(Unit const* unit,uint32 focusId) : i_unit(unit), i_focusId(focusId) {} |
---|
501 | bool operator()(GameObject* go) const |
---|
502 | { |
---|
503 | if(go->GetGOInfo()->type != GAMEOBJECT_TYPE_SPELL_FOCUS) |
---|
504 | return false; |
---|
505 | |
---|
506 | if(go->GetGOInfo()->spellFocus.focusId != i_focusId) |
---|
507 | return false; |
---|
508 | |
---|
509 | float dist = go->GetGOInfo()->spellFocus.dist; |
---|
510 | |
---|
511 | return go->IsWithinDistInMap(i_unit, dist); |
---|
512 | } |
---|
513 | private: |
---|
514 | Unit const* i_unit; |
---|
515 | uint32 i_focusId; |
---|
516 | }; |
---|
517 | |
---|
518 | // Find the nearest Fishing hole and return true only if source object is in range of hole |
---|
519 | class NearestGameObjectFishingHole |
---|
520 | { |
---|
521 | public: |
---|
522 | NearestGameObjectFishingHole(WorldObject const& obj, float range) : i_obj(obj), i_range(range) {} |
---|
523 | bool operator()(GameObject* go) |
---|
524 | { |
---|
525 | if(go->GetGOInfo()->type == GAMEOBJECT_TYPE_FISHINGHOLE && go->isSpawned() && i_obj.IsWithinDistInMap(go, i_range) && i_obj.IsWithinDistInMap(go, go->GetGOInfo()->fishinghole.radius)) |
---|
526 | { |
---|
527 | i_range = i_obj.GetDistance(go); |
---|
528 | return true; |
---|
529 | } |
---|
530 | return false; |
---|
531 | } |
---|
532 | float GetLastRange() const { return i_range; } |
---|
533 | private: |
---|
534 | WorldObject const& i_obj; |
---|
535 | float i_range; |
---|
536 | |
---|
537 | // prevent clone |
---|
538 | NearestGameObjectFishingHole(NearestGameObjectFishingHole const&); |
---|
539 | }; |
---|
540 | |
---|
541 | // Success at unit in range, range update for next check (this can be use with GameobjectLastSearcher to find nearest GO) |
---|
542 | class NearestGameObjectEntryInObjectRangeCheck |
---|
543 | { |
---|
544 | public: |
---|
545 | NearestGameObjectEntryInObjectRangeCheck(WorldObject const& obj,uint32 entry, float range) : i_obj(obj), i_entry(entry), i_range(range) {} |
---|
546 | bool operator()(GameObject* go) |
---|
547 | { |
---|
548 | if(go->GetEntry() == i_entry && i_obj.IsWithinDistInMap(go, i_range)) |
---|
549 | { |
---|
550 | i_range = i_obj.GetDistance(go); // use found GO range as new range limit for next check |
---|
551 | return true; |
---|
552 | } |
---|
553 | return false; |
---|
554 | } |
---|
555 | float GetLastRange() const { return i_range; } |
---|
556 | private: |
---|
557 | WorldObject const& i_obj; |
---|
558 | uint32 i_entry; |
---|
559 | float i_range; |
---|
560 | |
---|
561 | // prevent clone this object |
---|
562 | NearestGameObjectEntryInObjectRangeCheck(NearestGameObjectEntryInObjectRangeCheck const&); |
---|
563 | }; |
---|
564 | |
---|
565 | class GameObjectWithDbGUIDCheck |
---|
566 | { |
---|
567 | public: |
---|
568 | GameObjectWithDbGUIDCheck(WorldObject const& obj,uint32 db_guid) : i_obj(obj), i_db_guid(db_guid) {} |
---|
569 | bool operator()(GameObject const* go) const |
---|
570 | { |
---|
571 | return go->GetDBTableGUIDLow() == i_db_guid; |
---|
572 | } |
---|
573 | private: |
---|
574 | WorldObject const& i_obj; |
---|
575 | uint32 i_db_guid; |
---|
576 | }; |
---|
577 | |
---|
578 | // Unit checks |
---|
579 | |
---|
580 | class AnyUnfriendlyUnitInObjectRangeCheck |
---|
581 | { |
---|
582 | public: |
---|
583 | AnyUnfriendlyUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range) : i_obj(obj), i_funit(funit), i_range(range) {} |
---|
584 | bool operator()(Unit* u) |
---|
585 | { |
---|
586 | if(u->isAlive() && i_obj->IsWithinDistInMap(u, i_range) && !i_funit->IsFriendlyTo(u)) |
---|
587 | return true; |
---|
588 | else |
---|
589 | return false; |
---|
590 | } |
---|
591 | private: |
---|
592 | WorldObject const* i_obj; |
---|
593 | Unit const* i_funit; |
---|
594 | float i_range; |
---|
595 | }; |
---|
596 | |
---|
597 | class AnyFriendlyUnitInObjectRangeCheck |
---|
598 | { |
---|
599 | public: |
---|
600 | AnyFriendlyUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range) : i_obj(obj), i_funit(funit), i_range(range) {} |
---|
601 | bool operator()(Unit* u) |
---|
602 | { |
---|
603 | if(u->isAlive() && i_obj->IsWithinDistInMap(u, i_range) && i_funit->IsFriendlyTo(u)) |
---|
604 | return true; |
---|
605 | else |
---|
606 | return false; |
---|
607 | } |
---|
608 | private: |
---|
609 | WorldObject const* i_obj; |
---|
610 | Unit const* i_funit; |
---|
611 | float i_range; |
---|
612 | }; |
---|
613 | |
---|
614 | class AnyUnitInObjectRangeCheck |
---|
615 | { |
---|
616 | public: |
---|
617 | AnyUnitInObjectRangeCheck(WorldObject const* obj, float range) : i_obj(obj), i_range(range) {} |
---|
618 | bool operator()(Unit* u) |
---|
619 | { |
---|
620 | if(u->isAlive() && i_obj->IsWithinDistInMap(u, i_range)) |
---|
621 | return true; |
---|
622 | |
---|
623 | return false; |
---|
624 | } |
---|
625 | private: |
---|
626 | WorldObject const* i_obj; |
---|
627 | float i_range; |
---|
628 | }; |
---|
629 | |
---|
630 | // Success at unit in range, range update for next check (this can be use with UnitLastSearcher to find nearest unit) |
---|
631 | class NearestAttackableUnitInObjectRangeCheck |
---|
632 | { |
---|
633 | public: |
---|
634 | NearestAttackableUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range) : i_obj(obj), i_funit(funit), i_range(range) {} |
---|
635 | bool operator()(Unit* u) |
---|
636 | { |
---|
637 | if( u->isTargetableForAttack() && i_obj->IsWithinDistInMap(u, i_range) && |
---|
638 | !i_funit->IsFriendlyTo(u) && u->isVisibleForOrDetect(i_funit,false) ) |
---|
639 | { |
---|
640 | i_range = i_obj->GetDistance(u); // use found unit range as new range limit for next check |
---|
641 | return true; |
---|
642 | } |
---|
643 | |
---|
644 | return false; |
---|
645 | } |
---|
646 | private: |
---|
647 | WorldObject const* i_obj; |
---|
648 | Unit const* i_funit; |
---|
649 | float i_range; |
---|
650 | |
---|
651 | // prevent clone this object |
---|
652 | NearestAttackableUnitInObjectRangeCheck(NearestAttackableUnitInObjectRangeCheck const&); |
---|
653 | }; |
---|
654 | |
---|
655 | class AnyAoETargetUnitInObjectRangeCheck |
---|
656 | { |
---|
657 | public: |
---|
658 | AnyAoETargetUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range) |
---|
659 | : i_obj(obj), i_funit(funit), i_range(range) |
---|
660 | { |
---|
661 | Unit const* check = i_funit; |
---|
662 | Unit const* owner = i_funit->GetOwner(); |
---|
663 | if(owner) |
---|
664 | check = owner; |
---|
665 | i_targetForPlayer = ( check->GetTypeId()==TYPEID_PLAYER ); |
---|
666 | } |
---|
667 | bool operator()(Unit* u) |
---|
668 | { |
---|
669 | // Check contains checks for: live, non-selectable, non-attackable flags, flight check and GM check, ignore totems |
---|
670 | if (!u->isTargetableForAttack()) |
---|
671 | return false; |
---|
672 | if(u->GetTypeId()==TYPEID_UNIT && ((Creature*)u)->isTotem()) |
---|
673 | return false; |
---|
674 | |
---|
675 | if(( i_targetForPlayer ? !i_funit->IsFriendlyTo(u) : i_funit->IsHostileTo(u) )&& i_obj->IsWithinDistInMap(u, i_range)) |
---|
676 | return true; |
---|
677 | |
---|
678 | return false; |
---|
679 | } |
---|
680 | private: |
---|
681 | bool i_targetForPlayer; |
---|
682 | WorldObject const* i_obj; |
---|
683 | Unit const* i_funit; |
---|
684 | float i_range; |
---|
685 | }; |
---|
686 | |
---|
687 | struct AnyDeadUnitCheck |
---|
688 | { |
---|
689 | bool operator()(Unit* u) { return !u->isAlive(); } |
---|
690 | }; |
---|
691 | |
---|
692 | struct AnyStealthedCheck |
---|
693 | { |
---|
694 | bool operator()(Unit* u) { return u->GetVisibility()==VISIBILITY_GROUP_STEALTH; } |
---|
695 | }; |
---|
696 | |
---|
697 | // Creature checks |
---|
698 | |
---|
699 | class InAttackDistanceFromAnyHostileCreatureCheck |
---|
700 | { |
---|
701 | public: |
---|
702 | explicit InAttackDistanceFromAnyHostileCreatureCheck(Unit* funit) : i_funit(funit) {} |
---|
703 | bool operator()(Creature* u) |
---|
704 | { |
---|
705 | if(u->isAlive() && u->IsHostileTo(i_funit) && i_funit->IsWithinDistInMap(u, u->GetAttackDistance(i_funit))) |
---|
706 | return true; |
---|
707 | |
---|
708 | return false; |
---|
709 | } |
---|
710 | private: |
---|
711 | Unit* const i_funit; |
---|
712 | }; |
---|
713 | |
---|
714 | class NearestAssistCreatureInCreatureRangeCheck |
---|
715 | { |
---|
716 | public: |
---|
717 | NearestAssistCreatureInCreatureRangeCheck(Creature* obj,Unit* enemy, float range) |
---|
718 | : i_obj(obj), i_enemy(enemy), i_range(range) {} |
---|
719 | |
---|
720 | bool operator()(Creature* u) |
---|
721 | { |
---|
722 | if(u->getFaction() == i_obj->getFaction() && !u->isInCombat() && !u->GetCharmerOrOwnerGUID() && u->IsHostileTo(i_enemy) && u->isAlive()&& i_obj->IsWithinDistInMap(u, i_range) && i_obj->IsWithinLOSInMap(u)) |
---|
723 | { |
---|
724 | i_range = i_obj->GetDistance(u); // use found unit range as new range limit for next check |
---|
725 | return true; |
---|
726 | } |
---|
727 | return false; |
---|
728 | } |
---|
729 | float GetLastRange() const { return i_range; } |
---|
730 | private: |
---|
731 | Creature* const i_obj; |
---|
732 | Unit* const i_enemy; |
---|
733 | float i_range; |
---|
734 | |
---|
735 | // prevent clone this object |
---|
736 | NearestAssistCreatureInCreatureRangeCheck(NearestAssistCreatureInCreatureRangeCheck const&); |
---|
737 | }; |
---|
738 | |
---|
739 | class AnyAssistCreatureInRangeCheck |
---|
740 | { |
---|
741 | public: |
---|
742 | AnyAssistCreatureInRangeCheck(Unit* funit, Unit* enemy, float range) |
---|
743 | : i_funit(funit), i_enemy(enemy), i_range(range) |
---|
744 | { |
---|
745 | } |
---|
746 | bool operator()(Creature* u) |
---|
747 | { |
---|
748 | if(u == i_funit) |
---|
749 | return false; |
---|
750 | |
---|
751 | // we don't need help from zombies :) |
---|
752 | if( !u->isAlive() ) |
---|
753 | return false; |
---|
754 | |
---|
755 | // skip fighting creature |
---|
756 | if( u->isInCombat() ) |
---|
757 | return false; |
---|
758 | |
---|
759 | // only from same creature faction |
---|
760 | if(u->getFaction() != i_funit->getFaction() ) |
---|
761 | return false; |
---|
762 | |
---|
763 | // only free creature |
---|
764 | if( u->GetCharmerOrOwnerGUID() ) |
---|
765 | return false; |
---|
766 | |
---|
767 | // too far |
---|
768 | if( !i_funit->IsWithinDistInMap(u, i_range) ) |
---|
769 | return false; |
---|
770 | |
---|
771 | // skip non hostile to caster enemy creatures |
---|
772 | if( !u->IsHostileTo(i_enemy) ) |
---|
773 | return false; |
---|
774 | |
---|
775 | // only if see assisted creature |
---|
776 | if(!u->IsWithinLOSInMap(i_funit) ) |
---|
777 | return false; |
---|
778 | |
---|
779 | return true; |
---|
780 | } |
---|
781 | private: |
---|
782 | Unit* const i_funit; |
---|
783 | Unit* const i_enemy; |
---|
784 | float i_range; |
---|
785 | }; |
---|
786 | |
---|
787 | // Success at unit in range, range update for next check (this can be use with CreatureLastSearcher to find nearest creature) |
---|
788 | class NearestCreatureEntryWithLiveStateInObjectRangeCheck |
---|
789 | { |
---|
790 | public: |
---|
791 | NearestCreatureEntryWithLiveStateInObjectRangeCheck(WorldObject const& obj,uint32 entry, bool alive, float range) |
---|
792 | : i_obj(obj), i_entry(entry), i_alive(alive), i_range(range) {} |
---|
793 | |
---|
794 | bool operator()(Creature* u) |
---|
795 | { |
---|
796 | if(u->GetEntry() == i_entry && u->isAlive()==i_alive && i_obj.IsWithinDistInMap(u, i_range)) |
---|
797 | { |
---|
798 | i_range = i_obj.GetDistance(u); // use found unit range as new range limit for next check |
---|
799 | return true; |
---|
800 | } |
---|
801 | return false; |
---|
802 | } |
---|
803 | float GetLastRange() const { return i_range; } |
---|
804 | private: |
---|
805 | WorldObject const& i_obj; |
---|
806 | uint32 i_entry; |
---|
807 | bool i_alive; |
---|
808 | float i_range; |
---|
809 | |
---|
810 | // prevent clone this object |
---|
811 | NearestCreatureEntryWithLiveStateInObjectRangeCheck(NearestCreatureEntryWithLiveStateInObjectRangeCheck const&); |
---|
812 | }; |
---|
813 | |
---|
814 | class AnyPlayerInObjectRangeCheck |
---|
815 | { |
---|
816 | public: |
---|
817 | AnyPlayerInObjectRangeCheck(WorldObject const* obj, float range) : i_obj(obj), i_range(range) {} |
---|
818 | bool operator()(Player* u) |
---|
819 | { |
---|
820 | if(u->isAlive() && i_obj->IsWithinDistInMap(u, i_range)) |
---|
821 | return true; |
---|
822 | |
---|
823 | return false; |
---|
824 | } |
---|
825 | private: |
---|
826 | WorldObject const* i_obj; |
---|
827 | float i_range; |
---|
828 | }; |
---|
829 | |
---|
830 | // Searchers used by ScriptedAI |
---|
831 | class MostHPMissingInRange |
---|
832 | { |
---|
833 | public: |
---|
834 | MostHPMissingInRange(Unit const* obj, float range, uint32 hp) : i_obj(obj), i_range(range), i_hp(hp) {} |
---|
835 | bool operator()(Unit* u) |
---|
836 | { |
---|
837 | if(u->isAlive() && u->isInCombat() && !i_obj->IsHostileTo(u) && i_obj->IsWithinDistInMap(u, i_range) && u->GetMaxHealth() - u->GetHealth() > i_hp) |
---|
838 | { |
---|
839 | i_hp = u->GetMaxHealth() - u->GetHealth(); |
---|
840 | return true; |
---|
841 | } |
---|
842 | return false; |
---|
843 | } |
---|
844 | private: |
---|
845 | Unit const* i_obj; |
---|
846 | float i_range; |
---|
847 | uint32 i_hp; |
---|
848 | }; |
---|
849 | |
---|
850 | class FriendlyCCedInRange |
---|
851 | { |
---|
852 | public: |
---|
853 | FriendlyCCedInRange(Unit const* obj, float range) : i_obj(obj), i_range(range) {} |
---|
854 | bool operator()(Unit* u) |
---|
855 | { |
---|
856 | if(u->isAlive() && u->isInCombat() && !i_obj->IsHostileTo(u) && i_obj->IsWithinDistInMap(u, i_range) && |
---|
857 | (u->isFeared() || u->isCharmed() || u->isFrozen() || u->hasUnitState(UNIT_STAT_STUNNED) || u->hasUnitState(UNIT_STAT_CONFUSED))) |
---|
858 | { |
---|
859 | return true; |
---|
860 | } |
---|
861 | return false; |
---|
862 | } |
---|
863 | private: |
---|
864 | Unit const* i_obj; |
---|
865 | float i_range; |
---|
866 | }; |
---|
867 | |
---|
868 | class FriendlyMissingBuffInRange |
---|
869 | { |
---|
870 | public: |
---|
871 | FriendlyMissingBuffInRange(Unit const* obj, float range, uint32 spellid) : i_obj(obj), i_range(range), i_spell(spellid) {} |
---|
872 | bool operator()(Unit* u) |
---|
873 | { |
---|
874 | if(u->isAlive() && u->isInCombat() && !i_obj->IsHostileTo(u) && i_obj->IsWithinDistInMap(u, i_range) && |
---|
875 | !(u->HasAura(i_spell, 0) || u->HasAura(i_spell, 1) || u->HasAura(i_spell, 2))) |
---|
876 | { |
---|
877 | return true; |
---|
878 | } |
---|
879 | return false; |
---|
880 | } |
---|
881 | private: |
---|
882 | Unit const* i_obj; |
---|
883 | float i_range; |
---|
884 | uint32 i_spell; |
---|
885 | }; |
---|
886 | |
---|
887 | class AllFriendlyCreaturesInGrid |
---|
888 | { |
---|
889 | public: |
---|
890 | AllFriendlyCreaturesInGrid(Unit const* obj) : pUnit(obj) {} |
---|
891 | bool operator() (Unit* u) |
---|
892 | { |
---|
893 | if(u->isAlive() && u->GetVisibility() == VISIBILITY_ON && u->IsFriendlyTo(pUnit)) |
---|
894 | return true; |
---|
895 | |
---|
896 | return false; |
---|
897 | } |
---|
898 | private: |
---|
899 | Unit const* pUnit; |
---|
900 | }; |
---|
901 | |
---|
902 | class AllGameObjectsWithEntryInGrid |
---|
903 | { |
---|
904 | public: |
---|
905 | AllGameObjectsWithEntryInGrid(uint32 ent) : entry(ent) {} |
---|
906 | bool operator() (GameObject* g) |
---|
907 | { |
---|
908 | if(g->GetEntry() == entry) |
---|
909 | return true; |
---|
910 | |
---|
911 | return false; |
---|
912 | } |
---|
913 | private: |
---|
914 | uint32 entry; |
---|
915 | }; |
---|
916 | |
---|
917 | class AllCreaturesOfEntryInRange |
---|
918 | { |
---|
919 | public: |
---|
920 | AllCreaturesOfEntryInRange(Unit const* obj, uint32 ent, float ran) : pUnit(obj), entry(ent), range(ran) {} |
---|
921 | bool operator() (Unit* u) |
---|
922 | { |
---|
923 | if(u->GetEntry() == entry && pUnit->IsWithinDistInMap(u, range)) |
---|
924 | return true; |
---|
925 | |
---|
926 | return false; |
---|
927 | } |
---|
928 | private: |
---|
929 | Unit const* pUnit; |
---|
930 | uint32 entry; |
---|
931 | float range; |
---|
932 | }; |
---|
933 | |
---|
934 | #ifndef WIN32 |
---|
935 | template<> void PlayerRelocationNotifier::Visit<Creature>(CreatureMapType &); |
---|
936 | template<> void PlayerRelocationNotifier::Visit<Player>(PlayerMapType &); |
---|
937 | template<> void CreatureRelocationNotifier::Visit<Player>(PlayerMapType &); |
---|
938 | template<> void CreatureRelocationNotifier::Visit<Creature>(CreatureMapType &); |
---|
939 | template<> inline void DynamicObjectUpdater::Visit<Creature>(CreatureMapType &); |
---|
940 | template<> inline void DynamicObjectUpdater::Visit<Player>(PlayerMapType &); |
---|
941 | #endif |
---|
942 | } |
---|
943 | #endif |
---|