-
Notifications
You must be signed in to change notification settings - Fork 403
/
botspellsai.cpp
3508 lines (3024 loc) · 108 KB
/
botspellsai.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
/* EQEMu: Everquest Server Emulator
Copyright (C) 2001-2016 EQEMu Development Team (http://eqemulator.org)
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; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY except by those people which sell it, which
are required to give you total support for your newly bought product;
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 "bot.h"
#include "../common/data_verification.h"
#include "../common/repositories/bot_spells_entries_repository.h"
#include "../common/repositories/npc_spells_repository.h"
bool Bot::AICastSpell(Mob* tar, uint8 iChance, uint32 iSpellTypes) {
// Bot AI
Raid* raid = entity_list.GetRaidByBotName(GetName());
if (!tar) {
return false;
}
if (!AI_HasSpells()) {
return false;
}
if (iChance < 100 && zone->random.Int(0, 100) > iChance) {
return false;
}
if (tar->GetAppearance() == eaDead && ((tar->IsClient() && !tar->CastToClient()->GetFeigned()) || tar->IsBot())) {
return false;
}
uint8 botClass = GetClass();
uint8 botLevel = GetLevel();
bool checked_los = false; //we do not check LOS until we are absolutely sure we need to, and we only do it once.
BotSpell botSpell;
botSpell.SpellId = 0;
botSpell.SpellIndex = 0;
botSpell.ManaCost = 0;
switch (iSpellTypes) {
case SpellType_Mez:
return BotCastMez(tar, botLevel, checked_los, botSpell, raid);
case SpellType_Heal:
return BotCastHeal(tar, botLevel, botClass, botSpell, raid);
case SpellType_Root:
return BotCastRoot(tar, botLevel, iSpellTypes, botSpell, checked_los);
case SpellType_Buff:
return BotCastBuff(tar, botLevel, botClass);
case SpellType_Escape:
return BotCastEscape(tar, botClass, botSpell, iSpellTypes);
case SpellType_Nuke:
return BotCastNuke(tar, botLevel, botClass, botSpell, checked_los);
case SpellType_Dispel:
return BotCastDispel(tar, botSpell, iSpellTypes, checked_los);
case SpellType_Pet:
return BotCastPet(tar, botClass, botSpell);
case SpellType_InCombatBuff:
return BotCastCombatBuff(tar, botLevel, botClass);
case SpellType_Lifetap:
return BotCastLifetap(tar, botLevel, botSpell, checked_los, iSpellTypes);
case SpellType_Snare:
return BotCastSnare(tar, botLevel, botSpell, checked_los, iSpellTypes);
case SpellType_DOT:
return BotCastDOT(tar, botLevel, botSpell, checked_los);
case SpellType_Slow:
return BotCastSlow(tar, botLevel, botClass, botSpell, checked_los, raid);
case SpellType_Debuff:
return BotCastDebuff(tar, botLevel, botSpell, checked_los);
case SpellType_Cure:
return BotCastCure(tar, botClass, botSpell, raid);
case SpellType_HateRedux:
return BotCastHateReduction(tar, botLevel, botSpell);
case SpellType_InCombatBuffSong:
return BotCastCombatSong(tar, botLevel);
case SpellType_OutOfCombatBuffSong:
return BotCastSong(tar, botLevel);
case SpellType_Resurrect:
case SpellType_PreCombatBuff:
case SpellType_PreCombatBuffSong:
default:
return false;
}
return false;
}
bool Bot::BotCastSong(Mob* tar, uint8 botLevel) {
bool casted_spell = false;
if (GetClass() != Class::Bard || tar != this || IsEngaged()) // Out-of-Combat songs can not be cast in combat
return casted_spell;
for (auto botSongList = GetPrioritizedBotSpellsBySpellType(this, SpellType_OutOfCombatBuffSong);
auto iter : botSongList) {
if (!iter.SpellId)
continue;
if (!CheckSpellRecastTimer(iter.SpellId))
continue;
if (!IsSpellUsableInThisZoneType(iter.SpellId, zone->GetZoneType()))
continue;
switch (spells[iter.SpellId].target_type) {
case ST_AEBard:
case ST_AECaster:
case ST_GroupTeleport:
case ST_Group:
case ST_Self:
break;
default:
continue;
}
if (tar->CanBuffStack(iter.SpellId, botLevel, true) < 0)
continue;
casted_spell = AIDoSpellCast(iter.SpellIndex, tar, iter.ManaCost);
if (casted_spell)
break;
}
return casted_spell;
}
bool Bot::BotCastCombatSong(Mob* tar, uint8 botLevel) {
bool casted_spell = false;
if (tar != this) { // In-Combat songs can be cast Out-of-Combat in preparation for battle
return casted_spell;
}
for (auto botSongList = GetPrioritizedBotSpellsBySpellType(this, SpellType_InCombatBuffSong);
auto iter : botSongList) {
if (!iter.SpellId)
continue;
if (!CheckSpellRecastTimer(iter.SpellId))
continue;
if (!IsSpellUsableInThisZoneType(iter.SpellId, zone->GetZoneType()))
continue;
switch (spells[iter.SpellId].target_type) {
case ST_AEBard:
case ST_AECaster:
case ST_GroupTeleport:
case ST_Group:
case ST_Self:
break;
default:
continue;
}
if (tar->CanBuffStack(iter.SpellId, botLevel, true) < 0)
continue;
casted_spell = AIDoSpellCast(iter.SpellIndex, tar, iter.ManaCost);
if (casted_spell)
break;
}
return casted_spell;
}
bool Bot::BotCastHateReduction(Mob* tar, uint8 botLevel, const BotSpell& botSpell) {
bool casted_spell = false;
if (GetClass() == Class::Bard) {
std::list<BotSpell_wPriority> botSongList = GetPrioritizedBotSpellsBySpellType(this, SpellType_HateRedux);
for (auto iter : botSongList) {
if (!iter.SpellId)
continue;
if (!CheckSpellRecastTimer(iter.SpellId))
continue;
if (!IsSpellUsableInThisZoneType(iter.SpellId, zone->GetZoneType()))
continue;
if (spells[iter.SpellId].target_type != ST_Target)
continue;
if (tar->CanBuffStack(iter.SpellId, botLevel, true) < 0)
continue;
if (IsValidSpellRange(iter.SpellId, tar)) {
casted_spell = AIDoSpellCast(iter.SpellIndex, tar, iter.ManaCost);
}
if (casted_spell) {
BotGroupSay(
this,
fmt::format(
"Attempting to reduce hate on {} with {}.",
tar->GetCleanName(),
spells[iter.SpellId].name
).c_str()
);
}
}
}
return casted_spell;
}
bool Bot::BotCastCure(Mob* tar, uint8 botClass, BotSpell& botSpell, Raid* raid) {
bool casted_spell = false;
if (
GetNeedsCured(tar) &&
(tar->DontCureMeBefore() < Timer::GetCurrentTime()) &&
GetNumberNeedingHealedInGroup(25, false, raid) <= 0 &&
GetNumberNeedingHealedInGroup(40, false, raid) <= 2
) {
botSpell = GetBestBotSpellForCure(this, tar);
if (!IsValidSpell(botSpell.SpellId)) {
return casted_spell;
}
uint32 TempDontCureMeBeforeTime = tar->DontCureMeBefore();
casted_spell = AIDoSpellCast(botSpell.SpellIndex, tar, botSpell.ManaCost, &TempDontCureMeBeforeTime);
if (casted_spell && botClass != Class::Bard) {
if (IsGroupSpell(botSpell.SpellId)) {
if (HasGroup()) {
Group const* group = GetGroup();
if (group) {
for (auto member : group->members) {
if (
member &&
!member->qglobal &&
TempDontCureMeBeforeTime != tar->DontCureMeBefore()
) {
member->SetDontCureMeBefore(Timer::GetCurrentTime() + 4000);
}
}
}
} else if (IsRaidGrouped()) {
uint32 r_group = raid->GetGroup(GetName());
if (r_group) {
std::vector<RaidMember> raid_group_members = raid->GetRaidGroupMembers(r_group);
for (auto& iter: raid_group_members) {
if (
iter.member &&
!iter.member->qglobal &&
TempDontCureMeBeforeTime != tar->DontCureMeBefore()
) {
iter.member->SetDontCureMeBefore(Timer::GetCurrentTime() + 4000);
}
}
}
}
} else if (TempDontCureMeBeforeTime != tar->DontCureMeBefore()) {
tar->SetDontCureMeBefore(Timer::GetCurrentTime() + 4000);
}
}
}
return casted_spell;
}
bool Bot::BotCastDebuff(Mob* tar, uint8 botLevel, BotSpell& botSpell, bool checked_los) {
bool casted_spell = false;
if ((tar->GetHPRatio() <= 99.0f) && (tar->GetHPRatio() > 20.0f))
{
if (!checked_los && (!CheckLosFN(tar) || !CheckWaterLoS(tar))) {
return casted_spell;
}
botSpell = GetBestBotSpellForResistDebuff(this, tar);
if (!IsValidSpell(botSpell.SpellId)) {
botSpell = GetDebuffBotSpell(this, tar);
}
if (!IsValidSpell(botSpell.SpellId)) {
return casted_spell;
}
if (!
(
!tar->IsImmuneToSpell(botSpell.SpellId, this) &&
(tar->CanBuffStack(botSpell.SpellId, botLevel, true) >= 0)
)
) {
return casted_spell;
}
if (IsValidSpellRange(botSpell.SpellId, tar)) {
casted_spell = AIDoSpellCast(botSpell.SpellIndex, tar, botSpell.ManaCost);
}
}
return casted_spell;
}
bool Bot::BotCastSlow(Mob* tar, uint8 botLevel, uint8 botClass, BotSpell& botSpell, const bool& checked_los, Raid* raid) {
bool casted_spell = false;
if (tar->GetHPRatio() <= 99.0f) {
if (!checked_los && (!CheckLosFN(tar) || !CheckWaterLoS(tar))) {
return casted_spell;
}
switch (botClass) {
case Class::Bard: {
// probably needs attackable check
for (
auto botSongList = GetPrioritizedBotSpellsBySpellType(this, SpellType_Slow);
auto iter : botSongList
) {
if (!iter.SpellId) {
continue;
}
if (!CheckSpellRecastTimer(iter.SpellId)) {
continue;
}
if (!IsSpellUsableInThisZoneType(iter.SpellId, zone->GetZoneType())) {
continue;
}
if (spells[iter.SpellId].target_type != ST_Target) {
continue;
}
if (tar->CanBuffStack(iter.SpellId, botLevel, true) < 0) {
continue;
}
if (IsValidSpellRange(iter.SpellId, tar)) {
casted_spell = AIDoSpellCast(iter.SpellIndex, tar, iter.ManaCost);
}
if (casted_spell) {
return casted_spell;
}
}
break;
}
case Class::Enchanter: {
botSpell = GetBestBotSpellForMagicBasedSlow(this);
break;
}
case Class::Shaman:
case Class::Beastlord: {
botSpell = GetBestBotSpellForDiseaseBasedSlow(this);
if (botSpell.SpellId == 0 || ((tar->GetMR() - 50) < (tar->GetDR() + spells[botSpell.SpellId].resist_difficulty)))
botSpell = GetBestBotSpellForMagicBasedSlow(this);
break;
}
}
if (!IsValidSpell(botSpell.SpellId)) {
return casted_spell;
}
if (!(!tar->IsImmuneToSpell(botSpell.SpellId, this) && tar->CanBuffStack(botSpell.SpellId, botLevel, true) >= 0)) {
return casted_spell;
}
if (IsValidSpellRange(botSpell.SpellId, tar)) {
casted_spell = AIDoSpellCast(botSpell.SpellIndex, tar, botSpell.ManaCost);
}
if (casted_spell && GetClass() != Class::Bard) {
if (raid) {
const auto msg = fmt::format("Attempting to slow {}.", tar->GetCleanName());
raid->RaidSay(msg.c_str(), GetCleanName(), Language::CommonTongue, Language::MaxValue);
} else {
BotGroupSay(
this,
fmt::format(
"Attempting to slow {} with {}.",
tar->GetCleanName(),
spells[botSpell.SpellId].name
).c_str()
);
}
}
}
return casted_spell;
}
bool Bot::BotCastDOT(Mob* tar, uint8 botLevel, const BotSpell& botSpell, const bool& checked_los) {
bool casted_spell = false;
if ((tar->GetHPRatio() <= 98.0f) && (tar->DontDotMeBefore() < Timer::GetCurrentTime()) && (tar->GetHPRatio() > 15.0f)) {
if (!checked_los && (!CheckLosFN(tar) || !CheckWaterLoS(tar))) {
return casted_spell;
}
if (GetClass() == Class::Bard) {
std::list<BotSpell_wPriority> dotList = GetPrioritizedBotSpellsBySpellType(this, SpellType_DOT);
const int maxDotSelect = 5;
int dotSelectCounter = 0;
for (const auto& s : dotList) {
if (!IsValidSpell(s.SpellId)) {
continue;
}
if (CheckSpellRecastTimer(s.SpellId))
{
if (!(!tar->IsImmuneToSpell(s.SpellId, this) && tar->CanBuffStack(s.SpellId, botLevel, true) >= 0)) {
continue;
}
uint32 TempDontDotMeBefore = tar->DontDotMeBefore();
casted_spell = AIDoSpellCast(s.SpellIndex, tar, s.ManaCost, &TempDontDotMeBefore);
if (TempDontDotMeBefore != tar->DontDotMeBefore()) {
tar->SetDontDotMeBefore(TempDontDotMeBefore);
}
}
dotSelectCounter++;
if ((dotSelectCounter == maxDotSelect) || casted_spell) {
break;
}
}
}
else {
std::list<BotSpell> dotList = GetBotSpellsBySpellType(this, SpellType_DOT);
const int maxDotSelect = 5;
int dotSelectCounter = 0;
for (const auto& s : dotList) {
if (!IsValidSpell(s.SpellId)) {
continue;
}
if (CheckSpellRecastTimer(s.SpellId)) {
if (!(!tar->IsImmuneToSpell(s.SpellId, this) &&
tar->CanBuffStack(s.SpellId, botLevel, true) >= 0)) {
continue;
}
uint32 TempDontDotMeBefore = tar->DontDotMeBefore();
if (IsValidSpellRange(s.SpellId, tar)) {
casted_spell = AIDoSpellCast(s.SpellIndex, tar, s.ManaCost, &TempDontDotMeBefore);
}
if (TempDontDotMeBefore != tar->DontDotMeBefore()) {
tar->SetDontDotMeBefore(TempDontDotMeBefore);
}
}
dotSelectCounter++;
if ((dotSelectCounter == maxDotSelect) || casted_spell) {
return casted_spell;
}
}
}
}
return casted_spell;
}
bool Bot::BotCastSnare(Mob* tar, uint8 botLevel, BotSpell& botSpell, const bool& checked_los, uint32 iSpellTypes) {
bool casted_spell = false;
if (tar->DontSnareMeBefore() < Timer::GetCurrentTime()) {
if (!checked_los && (!CheckLosFN(tar) || !CheckWaterLoS(tar))) {
return casted_spell;
}
botSpell = GetFirstBotSpellBySpellType(this, iSpellTypes);
if (!IsValidSpell(botSpell.SpellId)) {
return casted_spell;
}
if (!(!tar->IsImmuneToSpell(botSpell.SpellId, this) && tar->CanBuffStack(botSpell.SpellId, botLevel, true) >= 0)) {
return casted_spell;
}
uint32 TempDontSnareMeBefore = tar->DontSnareMeBefore();
if (IsValidSpellRange(botSpell.SpellId, tar)) {
casted_spell = AIDoSpellCast(botSpell.SpellIndex, tar, botSpell.ManaCost, &TempDontSnareMeBefore);
}
if (TempDontSnareMeBefore != tar->DontSnareMeBefore()) {
tar->SetDontSnareMeBefore(TempDontSnareMeBefore);
}
}
return casted_spell;
}
bool Bot::BotCastLifetap(Mob* tar, uint8 botLevel, BotSpell& botSpell, const bool& checked_los, uint32 iSpellTypes) {
bool casted_spell = false;
if (GetHPRatio() < 90.0f) {
if (!checked_los && (!CheckLosFN(tar) || !CheckWaterLoS(tar))) {
return casted_spell;
}
botSpell = GetFirstBotSpellBySpellType(this, iSpellTypes);
if (!IsValidSpell(botSpell.SpellId)) {
return casted_spell;
}
if (!(!tar->IsImmuneToSpell(botSpell.SpellId, this) && (tar->CanBuffStack(botSpell.SpellId, botLevel, true) >= 0))) {
return casted_spell;
}
if (IsValidSpellRange(botSpell.SpellId, tar)) {
casted_spell = AIDoSpellCast(botSpell.SpellIndex, tar, botSpell.ManaCost);
}
}
return casted_spell;
}
bool Bot::BotCastCombatBuff(Mob* tar, uint8 botLevel, uint8 botClass) {
bool casted_spell = false;
if (tar->DontBuffMeBefore() < Timer::GetCurrentTime()) {
std::list<BotSpell> buffSpellList = GetBotSpellsBySpellType(this, SpellType_InCombatBuff);
for (const auto& s : buffSpellList) {
if (!IsValidSpell(s.SpellId)) {
continue;
}
// no buffs with illusions.. use #bot command to cast illusions
if (IsEffectInSpell(s.SpellId, SE_Illusion) && tar != this) {
continue;
}
//no teleport spells use #bot command to cast teleports
if (IsEffectInSpell(s.SpellId, SE_Teleport) || IsEffectInSpell(s.SpellId, SE_Succor)) {
continue;
}
// can not cast buffs for your own pet only on another pet that isn't yours
if ((spells[s.SpellId].target_type == ST_Pet) && (tar != GetPet())) {
continue;
}
//Conversion Spells
if (
IsSelfConversionSpell(s.SpellId) &&
(
GetManaRatio() > 90.0f ||
GetHPRatio() < 50.0f ||
GetHPRatio() < (GetManaRatio() + 10.0f)
)
) {
break; //don't cast if low hp, lots of mana, or if mana is higher than hps
}
// Validate target
// TODO: Add ST_TargetsTarget support for Buffing.
if (
!(
(
spells[s.SpellId].target_type == ST_Target ||
spells[s.SpellId].target_type == ST_Pet ||
(tar == this && spells[s.SpellId].target_type != ST_TargetsTarget) ||
spells[s.SpellId].target_type == ST_Group ||
spells[s.SpellId].target_type == ST_GroupTeleport ||
(botClass == Class::Bard && spells[s.SpellId].target_type == ST_AEBard)
) &&
!tar->IsImmuneToSpell(s.SpellId, this) &&
tar->CanBuffStack(s.SpellId, botLevel, true) >= 0
)
) {
continue;
}
// Put the zone levitate and movement check here since bots are able to bypass the client casting check
if (
((IsEffectInSpell(s.SpellId, SE_Levitate) && !zone->CanLevitate()) ||
(IsEffectInSpell(s.SpellId, SE_MovementSpeed) && !zone->CanCastOutdoor())) &&
(botClass != Class::Bard || !IsSpellUsableInThisZoneType(s.SpellId, zone->GetZoneType()))
) {
continue;
}
if (!IsGroupSpell(s.SpellId)) {
//Only check archetype if spell is not a group spell
//Hybrids get all buffs
switch (tar->GetArchetype()) {
case Archetype::Caster:
//TODO: probably more caster specific spell effects in here
if (
(
IsEffectInSpell(s.SpellId, SE_AttackSpeed) ||
IsEffectInSpell(s.SpellId, SE_ATK) ||
IsEffectInSpell(s.SpellId, SE_STR) ||
IsEffectInSpell(s.SpellId, SE_ReverseDS) ||
IsEffectInSpell(s.SpellId, SE_DamageShield)
) &&
spells[s.SpellId].target_type != ST_Self
) {
continue;
}
break;
case Archetype::Melee:
if (
(
IsEffectInSpell(s.SpellId, SE_IncreaseSpellHaste) ||
IsEffectInSpell(s.SpellId, SE_ManaPool) ||
IsEffectInSpell(s.SpellId, SE_CastingLevel) ||
IsEffectInSpell(s.SpellId, SE_ManaRegen_v2) ||
IsEffectInSpell(s.SpellId, SE_CurrentMana)
) &&
spells[s.SpellId].target_type != ST_Self
) {
continue;
}
break;
default:
break;
}
}
// TODO: Add TriggerSpell Support for Exchanter Runes
if (botClass == Class::Enchanter && IsEffectInSpell(s.SpellId, SE_Rune)) {
float manaRatioToCast = 75.0f;
switch(GetBotStance()) {
case Stance::Efficient:
manaRatioToCast = 90.0f;
break;
case Stance::Balanced:
case Stance::Aggressive:
manaRatioToCast = 75.0f;
break;
case Stance::Reactive:
case Stance::Burn:
case Stance::AEBurn:
manaRatioToCast = 50.0f;
break;
default:
manaRatioToCast = 75.0f;
break;
}
//If we're at specified mana % or below, don't rune as enchanter
if (GetManaRatio() <= manaRatioToCast) {
break;
}
}
if (CheckSpellRecastTimer(s.SpellId)) {
uint32 TempDontBuffMeBefore = tar->DontBuffMeBefore();
casted_spell = AIDoSpellCast(s.SpellIndex, tar, s.ManaCost, &TempDontBuffMeBefore);
if (TempDontBuffMeBefore != tar->DontBuffMeBefore()) {
tar->SetDontBuffMeBefore(TempDontBuffMeBefore);
}
}
if (casted_spell) {
return casted_spell;
}
}
}
return casted_spell;
}
bool Bot::BotCastPet(Mob* tar, uint8 botClass, BotSpell& botSpell) {
bool casted_spell = false;
if (!IsPet() && !GetPetID() && !IsBotCharmer()) {
if (botClass == Class::Wizard) {
auto buffs_max = GetMaxBuffSlots();
auto my_buffs = GetBuffs();
int familiar_buff_slot = -1;
if (buffs_max && my_buffs) {
for (int index = 0; index < buffs_max; ++index) {
if (IsEffectInSpell(my_buffs[index].spellid, SE_Familiar)) {
MakePet(my_buffs[index].spellid, spells[my_buffs[index].spellid].teleport_zone);
familiar_buff_slot = index;
break;
}
}
}
if (GetPetID()) {
return casted_spell;
}
if (familiar_buff_slot >= 0) {
BuffFadeBySlot(familiar_buff_slot);
return casted_spell;
}
botSpell = GetFirstBotSpellBySpellType(this, SpellType_Pet);
}
else if (botClass == Class::Magician) {
botSpell = GetBestBotMagicianPetSpell(this);
}
else {
botSpell = GetFirstBotSpellBySpellType(this, SpellType_Pet);
}
if (!IsValidSpell(botSpell.SpellId)) {
return casted_spell;
}
casted_spell = AIDoSpellCast(botSpell.SpellIndex, tar, botSpell.ManaCost);
}
return casted_spell;
}
bool Bot::BotCastDispel(Mob* tar, BotSpell& botSpell, uint32 iSpellTypes, const bool& checked_los) {
bool casted_spell = false;
if (tar->GetHPRatio() > 95.0f) {
if (!checked_los && (!CheckLosFN(tar) || !CheckWaterLoS(tar))) {
return casted_spell;
}
botSpell = GetFirstBotSpellBySpellType(this, iSpellTypes);
if (!IsValidSpell(botSpell.SpellId)) {
return casted_spell;
}
// TODO: Check target to see if there is anything to dispel
if (tar->CountDispellableBuffs() > 0 && IsValidSpellRange(botSpell.SpellId, tar)) {
casted_spell = AIDoSpellCast(botSpell.SpellIndex, tar, botSpell.ManaCost);
}
}
return casted_spell;
}
bool Bot::BotCastNuke(Mob* tar, uint8 botLevel, uint8 botClass, BotSpell& botSpell, const bool& checked_los) {
bool casted_spell = false;
if ((tar->GetHPRatio() <= 95.0f) || ((botClass == Class::Bard) || (botClass == Class::Shaman) || (botClass == Class::Enchanter) || (botClass == Class::Paladin) || (botClass == Class::ShadowKnight) || (botClass == Class::Warrior)))
{
if (!checked_los && (!CheckLosFN(tar) || !CheckWaterLoS(tar))) {
return casted_spell;
}
if (botClass == Class::Cleric || botClass == Class::Enchanter)
{
float manaRatioToCast = 75.0f;
switch(GetBotStance()) {
case Stance::Efficient:
manaRatioToCast = 90.0f;
break;
case Stance::Balanced:
manaRatioToCast = 75.0f;
break;
case Stance::Reactive:
case Stance::Aggressive:
manaRatioToCast = 50.0f;
break;
case Stance::Burn:
case Stance::AEBurn:
manaRatioToCast = 25.0f;
break;
default:
manaRatioToCast = 50.0f;
break;
}
//If we're at specified mana % or below, don't nuke as cleric or enchanter
if (GetManaRatio() <= manaRatioToCast)
return casted_spell;
}
if (botClass == Class::Magician || botClass == Class::ShadowKnight || botClass == Class::Necromancer || botClass == Class::Paladin || botClass == Class::Ranger || botClass == Class::Druid || botClass == Class::Cleric) {
if (tar->GetBodyType() == BodyType::Undead || tar->GetBodyType() == BodyType::SummonedUndead || tar->GetBodyType() == BodyType::Vampire)
botSpell = GetBestBotSpellForNukeByTargetType(this, ST_Undead);
else if (tar->GetBodyType() == BodyType::Summoned || tar->GetBodyType() == BodyType::Summoned2 || tar->GetBodyType() == BodyType::Summoned3)
botSpell = GetBestBotSpellForNukeByTargetType(this, ST_Summoned);
}
if ((botClass == Class::Paladin || botClass == Class::Druid || botClass == Class::Cleric || botClass == Class::Enchanter || botClass == Class::Wizard) && !IsValidSpell(botSpell.SpellId)) {
uint8 stunChance = (tar->IsCasting() ? 30: 15);
if (botClass == Class::Paladin) {
stunChance = 50;
}
if (!tar->GetSpecialAbility(SpecialAbility::StunImmunity) && !tar->IsStunned() && (zone->random.Int(1, 100) <= stunChance)) {
botSpell = GetBestBotSpellForStunByTargetType(this, ST_Target);
}
}
if (botClass == Class::Wizard && botSpell.SpellId == 0) {
botSpell = GetBestBotWizardNukeSpellByTargetResists(this, tar);
}
if (!IsValidSpell(botSpell.SpellId)) {
botSpell = GetBestBotSpellForNukeByTargetType(this, ST_Target);
}
if (!IsValidSpell(botSpell.SpellId)) {
return casted_spell;
}
if (!(!tar->IsImmuneToSpell(botSpell.SpellId, this) && (tar->CanBuffStack(botSpell.SpellId, botLevel, true) >= 0))) {
return casted_spell;
}
if (IsFearSpell(botSpell.SpellId) && tar->GetSnaredAmount() == -1 && !tar->IsRooted()) {
return casted_spell;
}
if (IsValidSpellRange(botSpell.SpellId, tar)) {
casted_spell = AIDoSpellCast(botSpell.SpellIndex, tar, botSpell.ManaCost);
}
}
return casted_spell;
}
bool Bot::BotCastEscape(Mob*& tar, uint8 botClass, BotSpell& botSpell, uint32 iSpellTypes) {
bool casted_spell = false;
auto hpr = (uint8) GetHPRatio();
bool mayGetAggro = false;
if (hpr > 15 && ((botClass == Class::Wizard) || (botClass == Class::Enchanter) || (botClass == Class::Ranger))) {
mayGetAggro = HasOrMayGetAggro();
}
if (hpr <= 15 || mayGetAggro)
{
botSpell = GetFirstBotSpellBySpellType(this, iSpellTypes);
if (!IsValidSpell(botSpell.SpellId)) {
return casted_spell;
}
if (IsInvulnerabilitySpell(botSpell.SpellId)) {
tar = this; //target self for invul type spells
}
if (IsValidSpellRange(botSpell.SpellId, tar) || botClass == Class::Bard) {
casted_spell = AIDoSpellCast(botSpell.SpellIndex, tar, botSpell.ManaCost);
}
}
return casted_spell;
}
bool Bot::BotCastBuff(Mob* tar, uint8 botLevel, uint8 botClass) {
bool casted_spell = false;
if (tar->DontBuffMeBefore() < Timer::GetCurrentTime()) {
std::list<BotSpell> buffSpellList = GetBotSpellsBySpellType(this, SpellType_Buff);
for(const auto& s : buffSpellList) {
if (!IsValidSpell(s.SpellId)) {
continue;
}
// no buffs with illusions.. use #bot command to cast illusions
if (IsEffectInSpell(s.SpellId, SE_Illusion) && tar != this) {
continue;
}
//no teleport spells use #bot command to cast teleports
if (IsEffectInSpell(s.SpellId, SE_Teleport) || IsEffectInSpell(s.SpellId, SE_Succor)) {
continue;
}
// can not cast buffs for your own pet only on another pet that isn't yours
if ((spells[s.SpellId].target_type == ST_Pet) && (tar != GetPet())) {
continue;
}
// Validate target
// TODO: Add ST_TargetsTarget support for Buffing.
if (
!(
(
spells[s.SpellId].target_type == ST_Target ||
spells[s.SpellId].target_type == ST_Pet ||
(tar == this && spells[s.SpellId].target_type != ST_TargetsTarget) ||
spells[s.SpellId].target_type == ST_Group ||
spells[s.SpellId].target_type == ST_GroupTeleport ||
(botClass == Class::Bard && spells[s.SpellId].target_type == ST_AEBard)
) &&
!tar->IsImmuneToSpell(s.SpellId, this) &&
tar->CanBuffStack(s.SpellId, botLevel, true) >= 0
)
) {
continue;
}
// Put the zone levitate and movement check here since bots are able to bypass the client casting check
if (
(
(IsEffectInSpell(s.SpellId, SE_Levitate) && !zone->CanLevitate()) ||
(IsEffectInSpell(s.SpellId, SE_MovementSpeed) && !zone->CanCastOutdoor())
) &&
(botClass != Class::Bard || !IsSpellUsableInThisZoneType(s.SpellId, zone->GetZoneType()))
) {
continue;
}
switch (tar->GetArchetype())
{
case Archetype::Caster:
//TODO: probably more caster specific spell effects in here
if (IsEffectInSpell(s.SpellId, SE_AttackSpeed) || IsEffectInSpell(s.SpellId, SE_ATK) ||
IsEffectInSpell(s.SpellId, SE_STR) || IsEffectInSpell(s.SpellId, SE_ReverseDS))
{
continue;
}
break;
case Archetype::Melee:
if (IsEffectInSpell(s.SpellId, SE_IncreaseSpellHaste) || IsEffectInSpell(s.SpellId, SE_ManaPool) ||
IsEffectInSpell(s.SpellId, SE_CastingLevel) || IsEffectInSpell(s.SpellId, SE_ManaRegen_v2) ||
IsEffectInSpell(s.SpellId, SE_CurrentMana))
{
continue;
}
break;
default: //Hybrids get all buffs
break;
}
if (botClass == Class::Enchanter && IsEffectInSpell(s.SpellId, SE_Rune))
{
float manaRatioToCast = 75.0f;
switch (GetBotStance()) {
case Stance::Efficient:
manaRatioToCast = 90.0f;
break;
case Stance::Balanced:
case Stance::Aggressive:
manaRatioToCast = 75.0f;
break;
case Stance::Reactive:
case Stance::Burn:
case Stance::AEBurn:
manaRatioToCast = 50.0f;
break;
default:
manaRatioToCast = 75.0f;
break;
}
//If we're at specified mana % or below, don't rune as enchanter
if (GetManaRatio() <= manaRatioToCast) {
return casted_spell;
}
}
if (CheckSpellRecastTimer(s.SpellId))
{
uint32 TempDontBuffMeBefore = tar->DontBuffMeBefore();
casted_spell = AIDoSpellCast(s.SpellIndex, tar, s.ManaCost, &TempDontBuffMeBefore);
if (TempDontBuffMeBefore != tar->DontBuffMeBefore()) {
tar->SetDontBuffMeBefore(TempDontBuffMeBefore);
}
}
}
}
return casted_spell;
}
bool Bot::BotCastRoot(Mob* tar, uint8 botLevel, uint32 iSpellTypes, BotSpell& botSpell, const bool& checked_los) {
bool casted_spell = false;
if (!tar->IsRooted() && tar->DontRootMeBefore() < Timer::GetCurrentTime()) {
if (!checked_los && (!CheckLosFN(tar) || !CheckWaterLoS(tar))) {
return casted_spell;
}
// TODO: If there is a ranger in the group then don't allow root spells
botSpell = GetFirstBotSpellBySpellType(this, iSpellTypes);
if (!IsValidSpell(botSpell.SpellId)) {
return casted_spell;
}
if (tar->CanBuffStack(botSpell.SpellId, botLevel, true) == 0) {
return casted_spell;
}
uint32 TempDontRootMeBefore = tar->DontRootMeBefore();
if (IsValidSpellRange(botSpell.SpellId, tar)) {
casted_spell = AIDoSpellCast(botSpell.SpellIndex, tar, botSpell.ManaCost, &TempDontRootMeBefore);
}
if (TempDontRootMeBefore != tar->DontRootMeBefore()) {
tar->SetDontRootMeBefore(TempDontRootMeBefore);
}
}
return casted_spell;
}
bool Bot::BotCastHeal(Mob* tar, uint8 botLevel, uint8 botClass, BotSpell& botSpell, Raid* raid) {
bool casted_spell = false;
if (tar->DontHealMeBefore() < Timer::GetCurrentTime()) {
auto hpr = (uint8)tar->GetHPRatio();
bool hasAggro = false;
bool isPrimaryHealer = false;