-
Notifications
You must be signed in to change notification settings - Fork 453
/
Spell.cpp
8911 lines (7825 loc) · 363 KB
/
Spell.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/>
* Copyright (C) 2009-2011 MaNGOSZero <https://github.com/mangos/zero>
* Copyright (C) 2011-2016 Nostalrius <https://nostalrius.org>
* Copyright (C) 2016-2017 Elysium Project <https://github.com/elysium-project>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "Spell.h"
#include "Log.h"
#include "Opcodes.h"
#include "WorldPacket.h"
#include "WorldSession.h"
#include "World.h"
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
#include "CellImpl.h"
#include "ObjectMgr.h"
#include "SpellMgr.h"
#include "Player.h"
#include "Pet.h"
#include "DynamicObject.h"
#include "Group.h"
#include "MapManager.h"
#include "ObjectAccessor.h"
#include "SharedDefines.h"
#include "LootMgr.h"
#include "VMapFactory.h"
#include "BattleGround.h"
#include "Util.h"
#include "PathFinder.h"
#include "CharacterDatabaseCache.h"
#include "ZoneScript.h"
using namespace Spells;
#define SPELL_CHANNEL_UPDATE_INTERVAL (1 * IN_MILLISECONDS)
extern pEffect SpellEffects[TOTAL_SPELL_EFFECTS];
SpellCastTargets::SpellCastTargets()
{
m_unitTarget = nullptr;
m_itemTarget = nullptr;
m_GOTarget = nullptr;
m_itemTargetEntry = 0;
m_srcX = m_srcY = m_srcZ = m_destX = m_destY = m_destZ = 0.0f;
m_targetMask = 0;
}
SpellCastTargets::~SpellCastTargets()
{
}
void SpellCastTargets::setUnitTarget(Unit* target)
{
if (!target)
return;
m_destX = target->GetPositionX();
m_destY = target->GetPositionY();
m_destZ = target->GetPositionZ();
m_unitTarget = target;
m_unitTargetGUID = target->GetObjectGuid();
m_targetMask |= TARGET_FLAG_UNIT;
}
void SpellCastTargets::setDestination(float x, float y, float z)
{
m_destX = x;
m_destY = y;
m_destZ = z;
m_targetMask |= TARGET_FLAG_DEST_LOCATION;
}
void SpellCastTargets::setSource(float x, float y, float z)
{
m_srcX = x;
m_srcY = y;
m_srcZ = z;
m_targetMask |= TARGET_FLAG_SOURCE_LOCATION;
}
void SpellCastTargets::setGOTarget(GameObject* target)
{
m_GOTarget = target;
m_GOTargetGUID = target->GetObjectGuid();
// m_targetMask |= TARGET_FLAG_OBJECT;
}
void SpellCastTargets::setItemTarget(Item* item)
{
if (!item)
return;
m_itemTarget = item;
m_itemTargetGUID = item->GetObjectGuid();
m_itemTargetEntry = item->GetEntry();
m_targetMask |= TARGET_FLAG_ITEM;
}
void SpellCastTargets::setTradeItemTarget(Player* caster)
{
m_itemTargetGUID = ObjectGuid(uint64(TRADE_SLOT_NONTRADED));
m_itemTargetEntry = 0;
m_targetMask |= TARGET_FLAG_TRADE_ITEM;
Update(caster);
}
void SpellCastTargets::setCorpseTarget(Corpse* corpse)
{
m_CorpseTargetGUID = corpse->GetObjectGuid();
}
void SpellCastTargets::Update(SpellCaster* pCaster)
{
m_GOTarget = m_GOTargetGUID ? pCaster->GetMap()->GetGameObject(m_GOTargetGUID) : nullptr;
m_unitTarget = m_unitTargetGUID ?
(m_unitTargetGUID == pCaster->GetObjectGuid() ? pCaster->ToUnit() : ObjectAccessor::GetUnit(*pCaster, m_unitTargetGUID)) :
nullptr;
m_itemTarget = nullptr;
if (Player* pPlayer = pCaster->ToPlayer())
{
if (m_targetMask & TARGET_FLAG_ITEM)
m_itemTarget = pPlayer->GetItemByGuid(m_itemTargetGUID);
else if (m_targetMask & TARGET_FLAG_TRADE_ITEM)
{
if (TradeData* pTrade = pPlayer->GetTradeData())
if (m_itemTargetGUID.GetRawValue() < TRADE_SLOT_COUNT)
m_itemTarget = pTrade->GetTraderData()->GetItem(TradeSlots(m_itemTargetGUID.GetRawValue()));
}
if (m_itemTarget)
m_itemTargetEntry = m_itemTarget->GetEntry();
}
}
void SpellCastTargets::read(ByteBuffer& data, Unit* caster)
{
data >> m_targetMask;
if (m_targetMask == TARGET_FLAG_SELF)
{
m_destX = caster->GetPositionX();
m_destY = caster->GetPositionY();
m_destZ = caster->GetPositionZ();
m_unitTarget = caster;
m_unitTargetGUID = caster->GetObjectGuid();
return;
}
// TARGET_FLAG_UNK2 is used for non-combat pets, maybe other?
if (m_targetMask & (TARGET_FLAG_UNIT | TARGET_FLAG_UNK2))
#if SUPPORTED_CLIENT_BUILD > CLIENT_BUILD_1_8_4
data >> m_unitTargetGUID.ReadAsPacked();
#else
data >> m_unitTargetGUID;
#endif
if (m_targetMask & (TARGET_FLAG_OBJECT | TARGET_FLAG_OBJECT_UNK))
#if SUPPORTED_CLIENT_BUILD > CLIENT_BUILD_1_8_4
data >> m_GOTargetGUID.ReadAsPacked();
#else
data >> m_GOTargetGUID;
#endif
if ((m_targetMask & (TARGET_FLAG_ITEM | TARGET_FLAG_TRADE_ITEM)) && caster->IsPlayer())
#if SUPPORTED_CLIENT_BUILD > CLIENT_BUILD_1_8_4
data >> m_itemTargetGUID.ReadAsPacked();
#else
data >> m_itemTargetGUID;
#endif
if (m_targetMask & TARGET_FLAG_SOURCE_LOCATION)
{
data >> m_srcX >> m_srcY >> m_srcZ;
if (!MaNGOS::IsValidMapCoord(m_srcX, m_srcY, m_srcZ))
throw ByteBufferException(false, data.rpos(), 0, data.size());
}
if (m_targetMask & TARGET_FLAG_DEST_LOCATION)
{
data >> m_destX >> m_destY >> m_destZ;
if (!MaNGOS::IsValidMapCoord(m_destX, m_destY, m_destZ))
throw ByteBufferException(false, data.rpos(), 0, data.size());
}
if (m_targetMask & TARGET_FLAG_STRING)
data >> m_strTarget;
if (m_targetMask & (TARGET_FLAG_CORPSE | TARGET_FLAG_PVP_CORPSE))
#if SUPPORTED_CLIENT_BUILD > CLIENT_BUILD_1_8_4
data >> m_CorpseTargetGUID.ReadAsPacked();
#else
data >> m_CorpseTargetGUID;
#endif
// find real units/GOs
Update(caster);
}
void SpellCastTargets::write(ByteBuffer& data) const
{
data << uint16(m_targetMask);
if (m_targetMask & (TARGET_FLAG_UNIT | TARGET_FLAG_PVP_CORPSE | TARGET_FLAG_OBJECT | TARGET_FLAG_CORPSE | TARGET_FLAG_UNK2))
{
if (m_targetMask & TARGET_FLAG_UNIT)
{
if (m_unitTarget)
#if SUPPORTED_CLIENT_BUILD > CLIENT_BUILD_1_8_4
data << m_unitTarget->GetPackGUID();
#else
data << m_unitTarget->GetGUID();
#endif
else
data << uint8(0);
}
else if (m_targetMask & (TARGET_FLAG_OBJECT | TARGET_FLAG_OBJECT_UNK))
{
if (m_GOTarget)
#if SUPPORTED_CLIENT_BUILD > CLIENT_BUILD_1_8_4
data << m_GOTarget->GetPackGUID();
#else
data << m_GOTarget->GetGUID();
#endif
else
data << uint8(0);
}
else if (m_targetMask & (TARGET_FLAG_CORPSE | TARGET_FLAG_PVP_CORPSE))
data << m_CorpseTargetGUID.WriteAsPacked();
else
data << uint8(0);
}
if (m_targetMask & (TARGET_FLAG_ITEM | TARGET_FLAG_TRADE_ITEM))
{
if (m_itemTarget)
#if SUPPORTED_CLIENT_BUILD > CLIENT_BUILD_1_8_4
data << m_itemTarget->GetPackGUID();
#else
data << m_itemTarget->GetGUID();
#endif
else
data << uint8(0);
}
if (m_targetMask & TARGET_FLAG_SOURCE_LOCATION)
data << m_srcX << m_srcY << m_srcZ;
if (m_targetMask & TARGET_FLAG_DEST_LOCATION)
data << m_destX << m_destY << m_destZ;
if (m_targetMask & TARGET_FLAG_STRING)
data << m_strTarget;
}
Spell::Spell(Unit* caster, SpellEntry const* info, bool triggered, ObjectGuid originalCasterGUID, SpellEntry const* triggeredBy, Unit* victim, SpellEntry const* triggeredByParent):
m_spellInfo(info), m_triggeredBySpellInfo(triggeredBy), m_triggeredByParentSpellInfo(triggeredByParent), m_caster(caster), m_casterUnit(caster), m_IsTriggeredSpell(triggered)
{
MANGOS_ASSERT(caster != nullptr && info != nullptr);
MANGOS_ASSERT(info == sSpellMgr.GetSpellEntry(info->Id) && "`info` must be pointer to a sSpellMgr element");
// Get data for type of attack
m_attackType = m_spellInfo->GetWeaponAttackType();
m_spellSchoolMask = info->GetSpellSchoolMask(); // Can be override for some spell (wand shoot for example)
// wand case
if (m_attackType == RANGED_ATTACK)
if (!!(caster->GetClassMask() & CLASSMASK_WAND_USERS) && caster->IsPlayer())
m_spellSchoolMask = GetSchoolMask(caster->GetWeaponDamageSchool(RANGED_ATTACK));
m_originalCasterGUID = originalCasterGUID ? originalCasterGUID : caster->GetObjectGuid();
UpdateOriginalCasterPointer();
for (uint8 i = 0; i < MAX_EFFECT_INDEX; ++i)
m_currentBasePoints[i] = m_spellInfo->CalculateSimpleValue(SpellEffectIndex(i));
m_TriggerSpells.clear();
m_preCastSpells.clear();
//Auto Shot & Shoot
m_autoRepeat = m_spellInfo->IsAutoRepeatRangedSpell();
m_channeled = info->IsChanneledSpell();
// determine reflection
m_canReflect = victim ? m_spellInfo->IsReflectableSpell(caster, victim) : m_spellInfo->IsReflectableSpell();
// Must initialize to an element in the list or bad things happen,
// begin changes so use end
m_channeledUpdateIterator = m_channeledHolders.end();
CleanupTargetList();
}
Spell::Spell(GameObject* caster, SpellEntry const* info, bool triggered, ObjectGuid originalCasterGUID, SpellEntry const* triggeredBy, Unit* victim, SpellEntry const* triggeredByParent):
m_spellInfo(info), m_triggeredBySpellInfo(triggeredBy), m_triggeredByParentSpellInfo(triggeredByParent), m_caster(caster), m_casterGo(caster), m_IsTriggeredSpell(triggered)
{
MANGOS_ASSERT(caster != nullptr && info != nullptr);
MANGOS_ASSERT(info == sSpellMgr.GetSpellEntry(info->Id) && "`info` must be pointer to a sSpellMgr element");
// Get data for type of attack
m_attackType = m_spellInfo->GetWeaponAttackType();
m_spellSchoolMask = info->GetSpellSchoolMask(); // Can be override for some spell (wand shoot for example)
m_originalCasterGUID = originalCasterGUID ? originalCasterGUID : caster->GetObjectGuid();
UpdateOriginalCasterPointer();
for (uint8 i = 0; i < MAX_EFFECT_INDEX; ++i)
m_currentBasePoints[i] = m_spellInfo->CalculateSimpleValue(SpellEffectIndex(i));
m_TriggerSpells.clear();
m_preCastSpells.clear();
//Auto Shot & Shoot
m_autoRepeat = m_spellInfo->IsAutoRepeatRangedSpell();
m_channeled = info->IsChanneledSpell();
// determine reflection
m_canReflect = victim ? m_spellInfo->IsReflectableSpell(caster, victim) : m_spellInfo->IsReflectableSpell();
// Must initialize to an element in the list or bad things happen,
// begin changes so use end
m_channeledUpdateIterator = m_channeledHolders.end();
CleanupTargetList();
}
Spell::~Spell()
{
m_destroyed = true;
}
template<typename T>
WorldObject* Spell::FindCorpseUsing()
{
if (!m_casterUnit)
return nullptr;
// non-standard target selection
SpellRangeEntry const* srange = sSpellRangeStore.LookupEntry(m_spellInfo->rangeIndex);
float max_range = GetSpellMaxRange(srange);
WorldObject* result = nullptr;
T u_check(m_casterUnit, max_range);
MaNGOS::WorldObjectSearcher<T> searcher(result, u_check);
Cell::VisitGridObjects(m_casterUnit, searcher, max_range);
if (!result)
Cell::VisitWorldObjects(m_casterUnit, searcher, max_range);
return result;
}
void Spell::FillTargetMap()
{
// TODO: ADD the correct target FILLS!!!!!!
for (uint8 i = 0; i < MAX_EFFECT_INDEX; ++i)
{
// not call for empty effect.
// Also some spells use not used effect targets for store targets for dummy effect in triggered spells
if (m_spellInfo->Effect[i] == SPELL_EFFECT_NONE)
continue;
// targets for TARGET_LOCATION_SCRIPT_NEAR_CASTER (A) and TARGET_UNIT_SCRIPT_NEAR_CASTER
// for TARGET_GAMEOBJECT_SCRIPT_NEAR_CASTER (A) all is checked in Spell::CheckCast and in Spell::CheckItem
// filled in Spell::CheckCast call
if (m_spellInfo->EffectImplicitTargetA[i] == TARGET_LOCATION_SCRIPT_NEAR_CASTER ||
m_spellInfo->EffectImplicitTargetA[i] == TARGET_UNIT_SCRIPT_NEAR_CASTER ||
m_spellInfo->EffectImplicitTargetA[i] == TARGET_GAMEOBJECT_SCRIPT_NEAR_CASTER ||
(m_spellInfo->EffectImplicitTargetB[i] == TARGET_UNIT_SCRIPT_NEAR_CASTER && m_spellInfo->EffectImplicitTargetA[i] != TARGET_UNIT_CASTER))
continue;
// TODO: find a way so this is not needed?
// for area auras always add caster as target (needed for totems for example)
if (m_casterUnit && IsAreaAuraEffect(m_spellInfo->Effect[i]))
AddUnitTarget(m_casterUnit, SpellEffectIndex(i));
#if SUPPORTED_CLIENT_BUILD <= CLIENT_BUILD_1_11_2
// Pre 1.12 most of the quest complete spells don't have correct target set.
if (m_casterUnit && m_spellInfo->Effect[i] == SPELL_EFFECT_QUEST_COMPLETE)
AddUnitTarget(m_casterUnit, SpellEffectIndex(i));
#endif
// If same target already filled, use it
// Example: AoE fear has effects speedup and modfear, with maxtargets = 1
// We dont want to apply speedup to the first, fear to the second.
if (m_spellInfo->MaxAffectedTargets > 1)
{
bool targetsCopied = false;
for (int j = 0; j < i; ++j)
{
// Check if same target, but handle i.e. AreaAuras different
if (m_spellInfo->EffectImplicitTargetA[i] == m_spellInfo->EffectImplicitTargetA[j] &&
m_spellInfo->EffectImplicitTargetB[i] == m_spellInfo->EffectImplicitTargetB[j] &&
m_spellInfo->Effect[j] != SPELL_EFFECT_NONE &&
!IsAreaAuraEffect(m_spellInfo->Effect[i]) &&
!IsAreaAuraEffect(m_spellInfo->Effect[j]))
{
targetsCopied = true;
// Copy targets from effect j to effect i
for (TargetList::iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
if (ihit->effectMask & (1 << j))
{
if (Unit* unit = m_caster->GetMap()->GetUnit(ihit->targetGUID))
AddUnitTarget(unit, SpellEffectIndex(i)); // Will not invalidate the iterator, since it updates the current Target.
else // Failed. Better do the computation once again.
{
for (ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
ihit->effectMask &= ~(1 << i);
targetsCopied = false;
break;
}
}
break;
}
}
if (targetsCopied)
continue;
}
UnitList tmpUnitMap;
// TargetA/TargetB dependent from each other, we not switch to full support this dependences
// but need it support in some know cases
switch (m_spellInfo->EffectImplicitTargetA[i])
{
case TARGET_NONE:
switch (m_spellInfo->EffectImplicitTargetB[i])
{
case TARGET_NONE:
SetTargetMap(SpellEffectIndex(i), TARGET_LOCATION_CASTER_DEST, tmpUnitMap);
break;
default:
SetTargetMap(SpellEffectIndex(i), m_spellInfo->EffectImplicitTargetB[i], tmpUnitMap);
break;
}
break;
case TARGET_UNIT_CASTER:
switch (m_spellInfo->EffectImplicitTargetB[i])
{
case TARGET_NONE:
// Arcane Missiles have strange targeting for auras
if (m_spellInfo->IsFitToFamily<SPELLFAMILY_MAGE, CF_MAGE_ARCANE_MISSILES_CHANNEL>())
{
if (Unit* pUnitTarget = m_caster->SelectMagnetTarget(m_targets.getUnitTarget(), this, SpellEffectIndex(i)))
{
if (m_caster->IsValidAttackTarget(pUnitTarget))
tmpUnitMap.push_back(pUnitTarget);
}
}
else
SetTargetMap(SpellEffectIndex(i), m_spellInfo->EffectImplicitTargetA[i], tmpUnitMap);
break;
case TARGET_LOCATION_CASTER_DEST:
SetTargetMap(SpellEffectIndex(i), m_spellInfo->EffectImplicitTargetA[i], tmpUnitMap);
break;
case TARGET_ENUM_UNITS_SCRIPT_AOE_AT_SRC_LOC: // use B case that not dependent from from A in fact
if ((m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION) == 0)
m_targets.setDestination(m_caster->GetPositionX(), m_caster->GetPositionY(), m_caster->GetPositionZ());
SetTargetMap(SpellEffectIndex(i), m_spellInfo->EffectImplicitTargetB[i], tmpUnitMap);
break;
default:
SetTargetMap(SpellEffectIndex(i), m_spellInfo->EffectImplicitTargetA[i], tmpUnitMap);
SetTargetMap(SpellEffectIndex(i), m_spellInfo->EffectImplicitTargetB[i], tmpUnitMap);
break;
}
break;
case TARGET_LOCATION_CASTER_DEST:
switch (m_spellInfo->EffectImplicitTargetB[i])
{
case TARGET_NONE:
case TARGET_LOCATION_CASTER_DEST:
SetTargetMap(SpellEffectIndex(i), m_spellInfo->EffectImplicitTargetA[i], tmpUnitMap);
break;
// dest point setup required
case TARGET_ENUM_UNITS_SCRIPT_AOE_AT_SRC_LOC:
case TARGET_ENUM_UNITS_SCRIPT_AOE_AT_DEST_LOC:
case TARGET_ENUM_UNITS_ENEMY_AOE_AT_SRC_LOC:
case TARGET_ENUM_UNITS_ENEMY_AOE_AT_DEST_LOC:
case TARGET_ENUM_UNITS_ENEMY_AOE_AT_DYNOBJ_LOC:
case TARGET_ENUM_UNITS_FRIEND_AOE_AT_DEST_LOC:
// triggered spells get dest point from default target set, ignore it
if (!(m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION) || m_IsTriggeredSpell)
if (SpellCaster* castObject = GetCastingObject())
m_targets.setDestination(castObject->GetPositionX(), castObject->GetPositionY(), castObject->GetPositionZ());
SetTargetMap(SpellEffectIndex(i), m_spellInfo->EffectImplicitTargetB[i], tmpUnitMap);
break;
// target pre-selection required
case TARGET_LOCATION_CASTER_HOME_BIND:
case TARGET_LOCATION_DATABASE:
case TARGET_LOCATION_CASTER_SRC:
case TARGET_LOCATION_SCRIPT_NEAR_CASTER:
case TARGET_LOCATION_CASTER_TARGET_POSITION:
case TARGET_LOCATION_UNIT_POSITION:
// need some target for processing
SetTargetMap(SpellEffectIndex(i), m_spellInfo->EffectImplicitTargetA[i], tmpUnitMap);
SetTargetMap(SpellEffectIndex(i), m_spellInfo->EffectImplicitTargetB[i], tmpUnitMap);
break;
default:
SetTargetMap(SpellEffectIndex(i), m_spellInfo->EffectImplicitTargetB[i], tmpUnitMap);
break;
}
break;
case TARGET_LOCATION_CASTER_SRC:
switch (m_spellInfo->EffectImplicitTargetB[i])
{
case TARGET_ENUM_UNITS_ENEMY_AOE_AT_SRC_LOC:
SetTargetMap(SpellEffectIndex(i), m_spellInfo->EffectImplicitTargetA[i], tmpUnitMap);
SetTargetMap(SpellEffectIndex(i), m_spellInfo->EffectImplicitTargetB[i], tmpUnitMap);
switch (m_spellInfo->Id)
{
case 5246:
// Exception: Intimidating Shout
// The AoE fear does not apply to spell main target (that is stunned by another aura)
for (UnitList::iterator itr = tmpUnitMap.begin(); itr != tmpUnitMap.end();)
{
if (*itr == m_targets.getUnitTarget())
itr = tmpUnitMap.erase(itr);
else
++itr;
}
break;
case 25676: // Drain Mana
case 25754:
case 26457:
case 26559:
// Avoid targeting players with no mana
for (UnitList::iterator itr = tmpUnitMap.begin(); itr != tmpUnitMap.end();)
{
if ((*itr)->GetPowerType() != POWER_MANA || (*itr)->GetPowerPercent(POWER_MANA) < 1.0f)
itr = tmpUnitMap.erase(itr);
else
++itr;
}
break;
case 27831:
// Shadow Bolt volley which should only target players with the Shadow Mark debuff
for (UnitList::iterator itr = tmpUnitMap.begin(); itr != tmpUnitMap.end();)
{
if (!(*itr)->HasAura(27825)) // Shadow Mark
itr = tmpUnitMap.erase(itr);
else
++itr;
}
break;
case 29484:
// Maexxna Web Spray should not hit players under Web Wrap or Petrification
for (UnitList::iterator itr = tmpUnitMap.begin(); itr != tmpUnitMap.end();)
{
if ((*itr)->HasAura(17624) || (*itr)->HasAura(28622))
itr = tmpUnitMap.erase(itr);
else
++itr;
}
break;
}
break;
case TARGET_LOCATION_UNIT_MINION_POSITION:
case TARGET_LOCATION_CASTER_FRONT_RIGHT:
case TARGET_LOCATION_CASTER_BACK_RIGHT:
case TARGET_LOCATION_CASTER_BACK_LEFT:
case TARGET_LOCATION_CASTER_FRONT_LEFT:
case TARGET_LOCATION_CASTER_FRONT:
case TARGET_LOCATION_CASTER_BACK:
case TARGET_LOCATION_CASTER_LEFT:
case TARGET_LOCATION_CASTER_RIGHT:
SetTargetMap(SpellEffectIndex(i), m_spellInfo->EffectImplicitTargetB[i], tmpUnitMap);
break;
case TARGET_NONE:
SetTargetMap(SpellEffectIndex(i), m_spellInfo->EffectImplicitTargetA[i], tmpUnitMap);
if (m_casterUnit)
tmpUnitMap.push_back(m_casterUnit);
else if (m_casterGo)
AddGOTarget(m_casterGo, SpellEffectIndex(i));
break;
default:
SetTargetMap(SpellEffectIndex(i), m_spellInfo->EffectImplicitTargetA[i], tmpUnitMap);
SetTargetMap(SpellEffectIndex(i), m_spellInfo->EffectImplicitTargetB[i], tmpUnitMap);
break;
}
break;
case TARGET_LOCATION_DATABASE:
switch (m_spellInfo->EffectImplicitTargetB[i])
{
case TARGET_NONE:
SetTargetMap(SpellEffectIndex(i), m_spellInfo->EffectImplicitTargetA[i], tmpUnitMap);
// need some target for processing
SetTargetMap(SpellEffectIndex(i), TARGET_LOCATION_CASTER_DEST, tmpUnitMap);
break;
case TARGET_ENUM_UNITS_SCRIPT_AOE_AT_SRC_LOC: // All 17/7 pairs used for dest teleportation, A processed in effect code
SetTargetMap(SpellEffectIndex(i), m_spellInfo->EffectImplicitTargetB[i], tmpUnitMap);
break;
default:
SetTargetMap(SpellEffectIndex(i), m_spellInfo->EffectImplicitTargetA[i], tmpUnitMap);
SetTargetMap(SpellEffectIndex(i), m_spellInfo->EffectImplicitTargetB[i], tmpUnitMap);
break;
}
break;
case TARGET_LOCATION_UNIT_POSITION:
switch (m_spellInfo->EffectImplicitTargetB[i])
{
case TARGET_NONE:
case TARGET_LOCATION_CASTER_DEST:
SetTargetMap(SpellEffectIndex(i), m_spellInfo->EffectImplicitTargetA[i], tmpUnitMap);
if (Unit* currentTarget = m_targets.getUnitTarget())
tmpUnitMap.push_back(currentTarget);
break;
default:
SetTargetMap(SpellEffectIndex(i), m_spellInfo->EffectImplicitTargetA[i], tmpUnitMap);
SetTargetMap(SpellEffectIndex(i), m_spellInfo->EffectImplicitTargetB[i], tmpUnitMap);
break;
}
break;
case TARGET_ENUM_UNITS_ENEMY_AOE_AT_SRC_LOC:
if ((m_targets.m_targetMask & TARGET_FLAG_SOURCE_LOCATION) && !(m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION))
m_targets.setDestination(m_targets.m_srcX, m_targets.m_srcY, m_targets.m_srcZ);
SetTargetMap(SpellEffectIndex(i), m_spellInfo->EffectImplicitTargetA[i], tmpUnitMap);
break;
default:
switch (m_spellInfo->EffectImplicitTargetB[i])
{
case TARGET_NONE:
case TARGET_LOCATION_CASTER_DEST:
SetTargetMap(SpellEffectIndex(i), m_spellInfo->EffectImplicitTargetA[i], tmpUnitMap);
break;
case TARGET_LOCATION_SCRIPT_NEAR_CASTER: // B case filled in CheckCast but we need fill unit list base at A case
SetTargetMap(SpellEffectIndex(i), m_spellInfo->EffectImplicitTargetA[i], tmpUnitMap);
break;
default:
SetTargetMap(SpellEffectIndex(i), m_spellInfo->EffectImplicitTargetA[i], tmpUnitMap);
SetTargetMap(SpellEffectIndex(i), m_spellInfo->EffectImplicitTargetB[i], tmpUnitMap);
break;
}
break;
}
for (UnitList::iterator itr = tmpUnitMap.begin(); itr != tmpUnitMap.end();)
{
if (!CheckTarget(*itr, SpellEffectIndex(i)))
{
itr = tmpUnitMap.erase(itr);
continue;
}
else
++itr;
}
for (const auto iunit : tmpUnitMap)
AddUnitTarget(iunit, SpellEffectIndex(i));
}
if (!m_UniqueTargetInfo.empty())
{
if (m_spellInfo->HasAttribute(SPELL_ATTR_EX2_FAIL_ON_ALL_TARGETS_IMMUNE))
{
bool allImmune = true;
for (auto& ihit : m_UniqueTargetInfo)
{
if (ihit.missCondition != SPELL_MISS_IMMUNE && ihit.missCondition != SPELL_MISS_IMMUNE2)
{
allImmune = false;
break;
}
}
if (allImmune)
{
SendCastResult(SPELL_FAILED_IMMUNE); // guessed error
finish(false);
}
}
if (m_spellInfo->HasAttribute(SPELL_ATTR_EX_REQUIRE_ALL_TARGETS))
{
for (auto& ihit : m_UniqueTargetInfo)
{
if (ihit.targetGUID == m_targets.getUnitTargetGuid() && ihit.missCondition != SPELL_MISS_NONE)
{
for (auto& ihit2 : m_UniqueTargetInfo)
ihit2.effectMask = 0;
return;
}
}
}
}
}
void Spell::prepareDataForTriggerSystem()
{
//==========================================================================================
// Now fill data for trigger system, need know:
// an spell trigger another or not ( m_canTrigger )
// Create base triggers flags for Attacker and Victim (m_procAttacker and m_procVictim)
//==========================================================================================
// Fill flag can spell trigger or not
// TODO: possible exist spell attribute for this
m_canTrigger = false;
m_procAttacker = PROC_FLAG_NONE;
m_procVictim = PROC_FLAG_NONE;
if (m_spellInfo->HasAttribute(SPELL_ATTR_EX3_SUPPRESS_CASTER_PROCS) &&
m_spellInfo->HasAttribute(SPELL_ATTR_EX3_SUPPRESS_TARGET_PROCS))
m_canTrigger = false; // Explicitly not allowed to trigger
else if (m_CastItem)
{
// Negative item effects do trigger procs.
// Confirmed with Vengeance: Fiery Plate Gauntlets, Storm Gauntlets, Dark Iron Bomb, Force Reactive Disk, Judgement Set 8 Piece Bonus
// Flash Bomb also needs to trigger procs to remove Fear Ward.
if (!m_spellInfo->IsPositiveSpell())
m_canTrigger = true;
else
m_canTrigger = false;
}
else if (m_originalCasterGUID.IsGameObject()) // Do not trigger anything if the spell is casted by using a game object (eg. Lightwell)
m_canTrigger = false;
else if (!m_IsTriggeredSpell)
m_canTrigger = true; // Normal cast - can trigger
else if (!m_triggeredByAuraSpell)
m_canTrigger = true; // Triggered from SPELL_EFFECT_TRIGGER_SPELL - can trigger
else if (m_spellInfo->HasAttribute(SPELL_ATTR_EX3_NOT_A_PROC))
m_canTrigger = true; // Spells with these special attributes can trigger even if triggeredByAuraSpell
if (!m_canTrigger) // Exceptions (some periodic triggers)
{
switch (m_spellInfo->SpellFamilyName)
{
case SPELLFAMILY_MAGE:
// Arcane Missiles / Blizzard triggers need do it
if (m_spellInfo->IsFitToFamilyMask(uint64(0x0000000000200080)))
m_canTrigger = true;
break;
case SPELLFAMILY_WARLOCK:
// For Hellfire Effect / Rain of Fire triggers need do it
if (m_spellInfo->IsFitToFamilyMask<CF_WARLOCK_RAIN_OF_FIRE, CF_WARLOCK_HELLFIRE>())
m_canTrigger = true;
break;
case SPELLFAMILY_HUNTER:
// Hunter Explosive Trap Effect/Immolation Trap Effect/Frost Trap Aura Effect
if (m_spellInfo->IsFitToFamilyMask<CF_HUNTER_FIRE_TRAP_EFFECTS, CF_HUNTER_FROST_TRAP_AURA>())
m_canTrigger = true;
break;
case SPELLFAMILY_PALADIN:
// Seal of Command (example Vengeance proc) | SPELLFAMILY_PALADIN override in spell_mod
if (m_spellInfo->Id == 20424)
m_canTrigger = true;
#if SUPPORTED_CLIENT_BUILD > CLIENT_BUILD_1_9_4
// Seal of Righteousness
else if (!m_spellInfo->SpellFamilyFlags && m_spellInfo->SpellIconID == 25)
m_canTrigger = true;
#endif
// Holy Shock
else if (m_spellInfo->IsFitToFamilyMask<CF_PALADIN_HOLY_SHOCK>())
m_canTrigger = true;
#if SUPPORTED_CLIENT_BUILD > CLIENT_BUILD_1_8_4
// Eye for an Eye triggered spell
else if (m_spellInfo->Id == 25997)
m_canTrigger = true;
#endif
break;
case SPELLFAMILY_PRIEST:
// Touch of Weakness / Devouring Plague
if (m_spellInfo->IsFitToFamilyMask<CF_PRIEST_TOUCH_OF_WEAKNESS, CF_PRIEST_DEVOURING_PLAGUE>())
m_canTrigger = true;
break;
default:
break;
}
}
// Get data for type of attack and fill base info for trigger
switch (m_spellInfo->DmgClass)
{
case SPELL_DAMAGE_CLASS_MELEE:
m_procAttacker = PROC_FLAG_DEAL_MELEE_ABILITY;
if (m_attackType == BASE_ATTACK)
m_procAttacker |= PROC_FLAG_MAIN_HAND_WEAPON_SWING;
else if (m_attackType == OFF_ATTACK)
m_procAttacker |= PROC_FLAG_OFF_HAND_WEAPON_SWING;
m_procVictim = PROC_FLAG_TAKE_MELEE_ABILITY;
if (m_spellInfo->IsNextMeleeSwingSpell())
{
m_procAttacker |= PROC_FLAG_DEAL_MELEE_SWING;
m_procVictim |= PROC_FLAG_TAKE_MELEE_SWING;
}
break;
case SPELL_DAMAGE_CLASS_RANGED:
// Auto attack
if (m_spellInfo->AttributesEx2 & SPELL_ATTR_EX2_AUTO_REPEAT)
{
m_procAttacker = PROC_FLAG_DEAL_RANGED_ATTACK;
m_procVictim = PROC_FLAG_TAKE_RANGED_ATTACK;
}
else // Ranged spell attack
{
// If blind or Expose Weakness, don't add proc flags for typical ranged abilities
// proc none
if (m_spellInfo->Id == 2094 || m_spellInfo->Id == 23577) {
m_procAttacker = PROC_FLAG_NONE;
m_procVictim = PROC_FLAG_NONE;
}
else {
m_procAttacker = PROC_FLAG_DEAL_RANGED_ABILITY;
m_procVictim = PROC_FLAG_TAKE_RANGED_ABILITY;
}
}
break;
default:
{
bool aoe = m_spellInfo->IsAreaOfEffectSpell();
bool positive = m_spellInfo->IsPositiveSpell();
// Some spells should be categorized as AoE
// Hellfire regularly triggers an AoE spell.
if (m_spellInfo->IsFitToFamily<SPELLFAMILY_WARLOCK, CF_WARLOCK_HELLFIRE>() && m_spellInfo->SpellIconID == 937)
aoe = true;
// Check for positive spell. 'Positive' spells include various things such as buffs, but
// they shouldn't proc with PROC_FLAG_DEAL_HELPFUL_SPELL. Note that some spells
// with SPELL_EFFECT_DISPEL are negative, such as Purge.
if (positive)
{
if (m_spellInfo->IsHealSpell())
{
m_procAttacker = PROC_FLAG_DEAL_HELPFUL_SPELL;
m_procVictim = PROC_FLAG_TAKE_HELPFUL_SPELL;
}
else
{
m_procAttacker = PROC_FLAG_DEAL_HELPFUL_ABILITY;
m_procVictim = PROC_FLAG_TAKE_HELPFUL_ABILITY;
}
}
// Wands auto attack
else if (m_spellInfo->AttributesEx2 & SPELL_ATTR_EX2_AUTO_REPEAT)
{
m_procAttacker = PROC_FLAG_DEAL_RANGED_ATTACK;
m_procVictim = PROC_FLAG_TAKE_RANGED_ATTACK;
}
else // Negative spell
{
if (m_spellInfo->HasAttribute(SPELL_ATTR_EX3_TREAT_AS_PERIODIC))
{
m_procAttacker = PROC_FLAG_DEAL_HARMFUL_PERIODIC;
m_procVictim = PROC_FLAG_TAKE_HARMFUL_PERIODIC;
}
else if (m_spellInfo->DmgClass == SPELL_DAMAGE_CLASS_MAGIC)
{
m_procAttacker = PROC_FLAG_DEAL_HARMFUL_SPELL;
m_procVictim = PROC_FLAG_TAKE_HARMFUL_SPELL;
}
else
{
m_procAttacker = PROC_FLAG_DEAL_HARMFUL_ABILITY;
m_procVictim = PROC_FLAG_TAKE_HARMFUL_ABILITY;
}
}
// Hunter trap spells - Entrapment
if (m_spellInfo->IsFitToFamily<SPELLFAMILY_HUNTER, CF_HUNTER_FIRE_TRAP_EFFECTS, CF_HUNTER_FREEZING_TRAP_EFFECT, CF_HUNTER_FROST_TRAP_AURA>())
m_procAttacker |= PROC_FLAG_ON_TRAP_ACTIVATION;
break;
}
}
// some negative spells have positive effects to another or same targets
// avoid triggering negative hit for only positive targets
m_negativeEffectMask = 0x0;
for (uint8 i = 0; i < MAX_EFFECT_INDEX; ++i)
{
if (!m_spellInfo->IsPositiveEffect(SpellEffectIndex(i)))
m_negativeEffectMask |= (1 << i);
// Self damage is a positive effect but should still trigger negative proc flags
if (m_spellInfo->Effect[i] == SPELL_EFFECT_SCHOOL_DAMAGE && m_spellInfo->EffectImplicitTargetA[i] == TARGET_UNIT_CASTER)
m_negativeEffectMask |= (1 << i);
}
}
void Spell::CleanupTargetList()
{
/*
m_UniqueTargetInfo.clear();
m_UniqueGOTargetInfo.clear();
*/
for (auto& itr : m_UniqueTargetInfo)
itr.deleted = true;
for (auto& itr : m_UniqueGOTargetInfo)
itr.deleted = true;
m_UniqueItemInfo.clear();
m_delayMoment = 0;
}
uint32 Spell::GetSpellBatchingEffectDelay(SpellCaster const* pTarget) const
{
// This tries to recreate the feeling of spell effect execution being done in batches,
// by syncing the delay of effects to the world timer so they happen simultaneously.
return ((sWorld.getConfig(CONFIG_UINT32_SPELL_EFFECT_DELAY) && pTarget != m_casterUnit) ?
(sWorld.getConfig(CONFIG_UINT32_SPELL_EFFECT_DELAY) - (WorldTimer::getMSTime() % sWorld.getConfig(CONFIG_UINT32_SPELL_EFFECT_DELAY))) : 0);
}
void Spell::AddUnitTarget(Unit* pTarget, SpellEffectIndex effIndex)
{
if (m_spellInfo->Effect[effIndex] == 0)
return;
if ((m_spellInfo->AttributesEx & SPELL_ATTR_EX_EXCLUDE_CASTER) && (m_spellInfo->EffectImplicitTargetA[effIndex] != TARGET_UNIT_CASTER) && (m_spellInfo->EffectImplicitTargetB[effIndex] != TARGET_UNIT_CASTER) && (pTarget->GetObjectGuid() == m_originalCasterGUID))
return;
// Check for effect immune skip if immuned
bool immuned = pTarget->IsImmuneToSpellEffect(m_spellInfo, effIndex, pTarget == m_caster);
ObjectGuid targetGUID = pTarget->GetObjectGuid();
// Lookup target in already in list
for (auto& ihit : m_UniqueTargetInfo)
{
if (ihit.deleted)
continue;
if (targetGUID == ihit.targetGUID) // Found in list
{
if (!immuned)
ihit.effectMask |= 1 << effIndex; // Add only effect mask if not immuned
return;
}
}
// This is new target calculate data for him
// Get spell hit result on target
TargetInfo targetInfo;
targetInfo.targetGUID = targetGUID; // Store target GUID
targetInfo.effectMask = immuned ? 0 : 1 << effIndex; // Store index of effect if not immuned
targetInfo.processed = false; // Effects not apply on target
targetInfo.deleted = false;
targetInfo.HitInfo = 0x0;
targetInfo.damage = 0;
// spell fly from visual cast object
SpellCaster* affectiveObject = GetAffectiveCasterObject();
if (affectiveObject && m_spellInfo->CanCrit())
targetInfo.isCrit = affectiveObject->IsSpellCrit(pTarget, m_spellInfo, m_spellSchoolMask, m_attackType, this);
else
targetInfo.isCrit = false;
// Calculate hit result
targetInfo.missCondition = m_caster->SpellHitResult(pTarget, m_spellInfo, effIndex, m_canReflect, this);
// Spell have speed - need calculate incoming time
if (m_spellInfo->speed > 0.0f && affectiveObject && pTarget != affectiveObject)
{
// calculate spell incoming interval
float dist = affectiveObject->GetDistance3dToCenter(pTarget);
if (dist < 5.0f)
dist = 5.0f;
targetInfo.timeDelay = (uint64) floor(dist / m_spellInfo->speed * 1000.0f);
// Calculate minimum incoming time
if (m_delayMoment == 0 || m_delayMoment > targetInfo.timeDelay)
m_delayMoment = targetInfo.timeDelay;
}
else if (m_delayed)
m_delayMoment = targetInfo.timeDelay = GetSpellBatchingEffectDelay(pTarget);
else
targetInfo.timeDelay = uint64(0);
// If target reflect spell back to caster
if (targetInfo.missCondition == SPELL_MISS_REFLECT)
{
// After patch 1.10, hunter trap effects are no longer reflected back.
// https://classic.wowhead.com/item=18634/gyrofreeze-ice-reflector#comments
#if SUPPORTED_CLIENT_BUILD > CLIENT_BUILD_1_9_4
if (!m_casterUnit || m_originalCasterGUID.IsGameObject())
#else
if (!m_casterUnit)