-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMQ2Relocate.cpp
More file actions
885 lines (762 loc) · 24.8 KB
/
MQ2Relocate.cpp
File metadata and controls
885 lines (762 loc) · 24.8 KB
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
/**
MQ2Relocate by Sic & ChatWithThisName
Purpose & Scope: Plugin to allow easier use of relocation items/aas, as well as specific logic to handle "converting" travel items like Wishing Lamp: and Zeuria Slide:
Usage:
/relocate help will give a list of available options
**/
#include <mq/Plugin.h>
PreSetup("MQ2Relocate");
PLUGIN_VERSION(2.0);
#define PLUGIN_MSG "\aw[\agRelocate\aw]\ao::\aw "
CAltAbilityData* AltAbility(const char* szAltName);
PlayerClient* MyTarget();
unsigned int MyTargetID();
void ReloCmd(const PlayerClient* pChar, const char* szLine);
void TransloCmd(const PlayerClient* pChar, const char* szLine);
bool StatusItemCheck(const char* szItemName);
void UseItem(const char* pItem);
bool HaveAlias(const std::string& aliasName);
bool UseClickyByItemName(const char* pItem);
bool IAmDead();
bool Invis(const PlayerClient* pSpawn);
bool IsClickyReadyByItemName(const char* pItem);
bool IsSpellBookOpen();
bool IsTargetPlayer();
bool ItemReady(const char* szItem);
bool ImDucking();
bool AltAbilityReady(const char*, const unsigned long TargetID = 0);
bool Casting();
bool CastingCheck();
bool DiscReady(const EQ_Spell* pSpell);
bool Moving(PlayerClient* pSpawn);
inline bool InGame();
int GroupSize();
char convertoption[MAX_STRING] = { 0 };
char reloClicky[128] = { 0 };
bool bAmConverting = false;
bool needsUsing = false;
bool bDebugging = true;
uint64_t GlobalLastTimeUsed = GetTickCount64();
int iPulse = 0;
int iPulseDelay = 75;
int GlobalSkillDelay = 600;
#pragma region ConvertibleItems
struct TeleportDestination {
const char* arg;
const char* fullName;
};
struct ConvertibleTeleportItem {
const char* itemPrefix;
const TeleportDestination* destinations;
int numDestinations;
};
constexpr TeleportDestination wishingLampDestinations[] = {
{ "air", "Wishing Lamp: Zephyr's Flight" },
{ "fire", "Wishing Lamp: Palace of Embers" },
{ "stone", "Wishing Lamp: The Stone Demesne" },
};
constexpr size_t iLampDestinations = std::size(wishingLampDestinations);
constexpr TeleportDestination zueriaSlideDestinations[] = {
{ "stonebrunt", "Zueria Slide: Stonebrunt" },
{ "dreadlands", "Zueria Slide: Dreadlands" },
{ "greatdivide", "Zueria Slide: Great Divide" },
{ "nek", "Zueria Slide: Nektulos" },
{ "nro", "Zueria Slide: North Ro" },
{ "skyfire", "Zueria Slide: Skyfire" },
};
constexpr size_t iZueriaSlideDestinations = std::size(zueriaSlideDestinations);
constexpr TeleportDestination aureateFigurineDestinations[] = {
{ "aureate", "Empowered Aureate Figurine" },
{ "hodstock", "Aureate Figurine" },
};
constexpr size_t iAureateFigurineDestinations = std::size(aureateFigurineDestinations);
constexpr ConvertibleTeleportItem convertibleItems[] = {
{ "Wishing Lamp", wishingLampDestinations, iLampDestinations },
{ "Zueria Slide", zueriaSlideDestinations, iZueriaSlideDestinations },
{ "Aureate Figurine", aureateFigurineDestinations, iAureateFigurineDestinations },
};
constexpr size_t iNumConvertibleItems = std::size(convertibleItems);
bool HandleConvertibleTeleport(const char* arg)
{
for (const auto& item : convertibleItems) {
// Check if this arg matches any destination for this item
for (int j = 0; j < item.numDestinations; j++) {
if (ci_equals(arg, item.destinations[j].arg)) {
// Check if we have the base item
if (!FindItemByName(item.itemPrefix)) {
WriteChatf(PLUGIN_MSG "\arYou do not appear to have a %s.", item.itemPrefix);
// return true because it is a valid option, we just dont have it.
return true;
}
// Check if we already have the converted destination
const char* fullName = item.destinations[j].fullName;
if (FindItemByName(fullName, true)) {
UseClickyByItemName(fullName);
}
else {
// if we did find the item prefix, but didn't find the full itemw
// we need to check if it is in the keyring, because we can't convert in the keyring
if (const auto baseItem = FindItemByName(item.itemPrefix)) {
if (baseItem->GetItemLocation().IsKeyRingLocation()) {
WriteChatf(PLUGIN_MSG "\ar%s is in your \ag\"\ayTeleport Item Keyring\ag\"\ar, but can only be converted from regular inventory slots.", item.itemPrefix);
// return true because it is a valid option, we just can't convert it.
return true;
}
}
// Need to convert
bAmConverting = true;
sprintf_s(convertoption, MAX_STRING, fullName);
sprintf_s(reloClicky, 128, item.itemPrefix);
}
return true;
}
}
}
return false;
}
#pragma endregion ConvertibleItems
#pragma region AATeleport
struct AATeleport {
const char* aaName;
int altActID;
const char* message;
};
static constexpr AATeleport aaByName[] = {
{ "Gate", 1217, "\agRelocating with: \ayGate AA\aw." },
{ "Origin", 331, "\agRelocating with: \ayOrigin AA\aw." },
{ "Throne of Heroes", 511, "\agRelocating to \agGuild Lobby\aw with: \ayThrone of Heroes AA\aw." },
{ "Harmonic Dissonance", 574, "\agRelocating to \agTheater of Blood\aw with: \ayHarmonic Dissonance AA\aw." },
{ "Teleport", 9704, "\agTeleporting surrounding allies with: \ayTeleport AA\aw."},
};
constexpr size_t iNumAATeleports = std::size(aaByName);
bool ActivateAAByName(const char* name)
{
for (const auto& i : aaByName) {
if (ci_equals(i.aaName, name)) {
if (AltAbility(i.aaName) && AltAbility(i.aaName)->CurrentRank > 0) {
if (AltAbilityReady(i.aaName)) {
DoCommandf("/alt act %d", i.altActID);
WriteChatf(PLUGIN_MSG "%s", i.message);
return true;
}
else {
WriteChatf(PLUGIN_MSG "%s \arisn't ready right now\aw.", i.aaName);
return false;
}
}
else {
WriteChatf(PLUGIN_MSG "\arI don't have the \ay%s \arAA\aw!", i.aaName);
return false;
}
}
}
return false;
}
#pragma endregion AATeleport
#pragma region EvacAA
struct EvacAA {
const char* name;
int altActID;
const char* message;
};
static constexpr EvacAA evacAAs[] = {
{ "Stealthy Getaway", 789, "\agSelf Evac with: \ayStealthy Getaway AA\aw." },
{ "Abscond", 490, "\agSelf Evac with: \ayAbscond AA\aw." },
{ "Egress", 8602, "\agSelf Evac with: \ayEgress AA\aw." },
{ "Levant", 2899, "\agSelf Evac with: \ayLevant AA\aw." },
{ "Exodus", 43, "\agGroup Evac with: \ayExodus AA\aw." },
};
constexpr size_t iNumEvacAAs = std::size(evacAAs);
#pragma endregion EvacAA
#pragma region SimpleTeleportItems
struct SimpleItemTeleport {
const char* arg;
const char* itemName;
};
constexpr SimpleItemTeleport simpleItems[] = {
{ "anchor1", "Primary Anchor Transport Device" },
{ "anchor2", "Secondary Anchor Transport Device" },
{ "brell", "Mark of Brell" },
{ "bronze", "Harbinger's Staff" },
{ "crystal", "Froststone Crystal Resonator" },
{ "laurion", "Laurion Inn Lute" },
{ "nro2", "Northern Desert Outlook Device" },
{ "shadowhaven", "Lost Turnip Sign" },
{ "skyshrine", "Skyshrine Crystal" },
{ "umbral", "Umbral Plains Mushroom" },
{ "loio", "Broken Spear of Ill Omen" },
{ "scarredgrove", "Tunare's Lily" },
{ "ruinedrelic", "Tsikut's Crystallized Magic" },
};
constexpr size_t iSimpleTeleportItems = std::size(simpleItems);
bool HandleSimpleItemTeleport(const char* arg)
{
for (const auto& item : simpleItems) {
if (ci_equals(item.arg, arg)) {
if (!FindItemByName(item.itemName)) {
WriteChatf(PLUGIN_MSG "\arYou do not appear to have a %s.", item.itemName);
return false;
}
if (IsClickyReadyByItemName(item.itemName)) {
sprintf_s(reloClicky, item.itemName);
if (UseClickyByItemName(reloClicky)) {
return true;
}
}
WriteChatf(PLUGIN_MSG "\ar%s is not ready.", item.itemName);
return false;
}
}
return false;
}
#pragma endregion SimpleTeleportItems
#pragma region Gate
constexpr const char* gateItems[] = {
"Philter of Major Translocation",
"Gate Potion"
"Bulwark of Many Portals",
};
constexpr size_t iNumGateItems = std::size(gateItems);
constexpr const char* gateClasses[] = {
"CLR", "DRU", "SHM", "NEC", "WIZ", "MAG", "ENC"
};
bool AmIAGateClass()
{
const char* playerCode = pLocalPlayer->GetClassThreeLetterCode();
if (!playerCode) {
return false;
}
return std::any_of(std::begin(gateClasses), std::end(gateClasses),
[playerCode](const std::string_view gateClass) {
return ci_equals(gateClass, playerCode);
});
}
#pragma endregion Gate
#pragma region PoKItems
struct PokItem {
const char* itemName;
bool bNeedQuintessence;
};
static constexpr PokItem pokItems[] = {
{ "Drunkard's Stein", false },
{ "Brick of Knowledge", false },
{ "The Binden Concerrentia", true },
{ "The Fabled Binden Concerrentia", true },
};
constexpr size_t iNumPokItems = std::size(pokItems);
#pragma endregion PoKItems
#pragma region Anchors
struct AnchorDevice {
const char* name;
int anchorItemID;
};
static constexpr AnchorDevice anchors[] = {
{ "Primary Anchor Transport Device", 52584 },
{ "Secondary Anchor Transport Device", 52585 }
};
constexpr size_t iNumAnchors = std::size(anchors);
#pragma endregion Anchors
void Help()
{
WriteChatf(PLUGIN_MSG "Welcome to MQ2Relocate!");
WriteChatf(PLUGIN_MSG "By \agSic\aw & \aoChatWithThisName\aw Exclusively for \arRedGuides\aw.");
WriteChatf(PLUGIN_MSG "Valid \aoRelocate\ax options are:\aw");
WriteChatf(PLUGIN_MSG "/relocate \agair\aw, \agfire\aw, and \agstone\aw for \ayZephyr's Lamp\aw.");
WriteChatf(PLUGIN_MSG "/relocate \agaureate\aw to use your \ayEmpowered Aureate Figurine\aw.");
WriteChatf(PLUGIN_MSG "/relocate \aghodstock\aw to use your \ayAureate Figurine\aw.");
WriteChatf(PLUGIN_MSG "/relocate \agstonebrunt\aw, \agdreadlands\aw, \aggreatdivide\aw, \agnek\aw, \agnro\aw, and \agskyfire\aw for \ayZueria Slide\aw.");
WriteChatf(PLUGIN_MSG "/relocate \agpok\aw for \ayPlane of Knowledge\aw.");
WriteChatf(PLUGIN_MSG "/relocate \aggate\aw to use your \ayGate AA\aw or \ayTranslocation Potion\aw.");
WriteChatf(PLUGIN_MSG "/relocate \agorigin\aw to use your \ayOrigin AA\aw.");
WriteChatf(PLUGIN_MSG "/relocate \agbrell\aw to use your \ayMark of Brell\aw.");
WriteChatf(PLUGIN_MSG "/relocate \agbronze\aw to use your \ayHarbinger's Staff\aw.");
WriteChatf(PLUGIN_MSG "/relocate \aganchor\aw to use your \ayPrimary \awor \aySecondary Anchor\aw.");
WriteChatf(PLUGIN_MSG "/relocate \aganchor1\aw to use your \ayPrimary Anchor\aw.");
WriteChatf(PLUGIN_MSG "/relocate \aganchor2\aw to use your \aySecondary Anchor\aw.");
WriteChatf(PLUGIN_MSG "/relocate \agfellow\aw or \agfellowship\aw to use your \ayFellowship Insignia\aw.");
WriteChatf(PLUGIN_MSG "/relocate \aglobby\aw to use your \ay Throne of Heroes AA\aw.");
WriteChatf(PLUGIN_MSG "/relocate \agloio\aw to use your \ay Broken Spear of Ill Omen\aw.");
WriteChatf(PLUGIN_MSG "/relocate \agblood\aw to use your \ay Theatre of Blood AA\aw.");
WriteChatf(PLUGIN_MSG "/relocate \agcrystal\aw to use your \ayFroststone Crystal Resonator\aw.");
WriteChatf(PLUGIN_MSG "/relocate \aglaurion\aw to use your \ayLaurion Inn Lute\aw.");
WriteChatf(PLUGIN_MSG "/relocate \agnro2\aw to use your \ayNorthern Desert Outlook Device\aw.");
WriteChatf(PLUGIN_MSG "/relocate \agumbral\aw to use your \ayUmbral Plains Mushroom\aw.");
WriteChatf(PLUGIN_MSG "/relocate \agruinedrelic\aw to use your \ayTsikut's Crystallized Magic\aw.");
WriteChatf(PLUGIN_MSG "/relocate \agshadowhaven\aw to use your \ayLost Turnip Sign\aw.");
WriteChatf(PLUGIN_MSG "/relocate \agscarredgrove\aw to use your \ayTunare's Lily\aw.");
WriteChatf(PLUGIN_MSG "/relocate \agskyshrine\aw to use your \aySkyshrine Crystal\aw.");
WriteChatf(PLUGIN_MSG "/relocate \agevac\aw to use your \ay Group Evac AA\aw (if you are in a group) or your \ay Personal Evac AA\aw.");
WriteChatf(PLUGIN_MSG "/relocate \agteleport\aw to use your \ay AoE Teleport AA\aw.");
WriteChatf(PLUGIN_MSG "Valid \aoTranslocate\ax options are:\aw");
WriteChatf(PLUGIN_MSG "/translocate\aw to \ayTranslocate\aw your target to their bind.");
WriteChatf(PLUGIN_MSG "/translocate\aw \arRedBot\aw to \ayTranslocate\aw \arRedBot\aw to their bind.");
}
void ReloCmd(const PlayerClient* pChar, const char* szLine)
{
if (!InGame()) {
return;
}
//Get our parameters
char Arg[MAX_STRING] = { 0 };
GetMaybeQuotedArg(Arg, MAX_STRING, szLine, 1);
if (Arg[0] == '\0' || ci_equals(Arg, "help")) {
Help();
return;
}
// Try convertible teleport items (Wishing Lamp, Zueria Slide, etc.)
if (HandleConvertibleTeleport(Arg)) {
return;
}
// Try simple item teleports (brell, bronze, etc.)
if (HandleSimpleItemTeleport(Arg)) {
return;
}
if (ci_equals(Arg, "pok")) {
// we want to use the options that don't require a consumable first
for (const auto& pokItem : pokItems) {
if (FindItemByName(pokItem.itemName)
&& !pokItem.bNeedQuintessence
&& IsClickyReadyByItemName(pokItem.itemName)) {
sprintf_s(reloClicky, pokItem.itemName);
if (UseClickyByItemName(reloClicky)) {
return;
}
}
}
// we want to use the options that do require a consumable last
for (const auto& pokItem : pokItems) {
if (FindItemByName(pokItem.itemName)
&& pokItem.bNeedQuintessence
&& FindItemCountByName("Quintessence of Knowledge")
&& IsClickyReadyByItemName(pokItem.itemName)) {
sprintf_s(reloClicky, pokItem.itemName);
if (UseClickyByItemName(reloClicky)) {
return;
}
}
}
WriteChatf(PLUGIN_MSG "\aoDOH!\ar You don't have a \aypok \arclicky that is ready!");
return;
}
// Gate - AA or clicky
if (ci_equals(Arg, "gate")) {
if (AmIAGateClass()) {
if (ActivateAAByName("Gate")) {
return;
}
}
for (auto& gateItem : gateItems) {
if (UseClickyByItemName(gateItem)) {
return;
}
}
WriteChatf(PLUGIN_MSG "\arI don't seem to have the ability to \aygate\ax, nor do you have a \aygate clicky\ax!\aw");
return;
}
// Origin - AA with special Crescent Reach handling
if (ci_equals(Arg, "origin")) {
if (ActivateAAByName("origin")) {
return;
}
// Crescent Reach starter city special case
if (pLocalPC->StartingCity == 394 && FindItemByName("Sceptre of Draconic Calling")) {
if (IsClickyReadyByItemName("Sceptre of Draconic Calling")) {
UseClickyByItemName("Sceptre of Draconic Calling");
return;
}
}
WriteChatf(PLUGIN_MSG "\arWe don't have a way to \ayOrigin\ax at the moment\aw.");
return;
}
// Anchor - try primary then secondary
// anchor1 and anchor2 are handled in SimpleItem
if (ci_equals(Arg, "anchor")) {
for (const auto& anchor : anchors) {
if (IsClickyReadyByItemName(anchor.name) && !FindItemCountByID(anchor.anchorItemID)) {
sprintf_s(reloClicky, anchor.name);
if (UseClickyByItemName(reloClicky)) {
return;
}
}
}
WriteChatf(PLUGIN_MSG "\arDOH!\aw I don't have an \ayanchor\ax clicky that is ready");
return;
}
// Fellowship - requires campfire and visibility
if (ci_equals(Arg, "fellow") || ci_equals(Arg, "fellowship")) {
const char* insignia = "Fellowship Registration Insignia";
if (!FindItemByName(insignia)) {
WriteChatf(PLUGIN_MSG "\arYou do not have a Fellowship Registration Insignia!\aw");
return;
}
if (!IsClickyReadyByItemName(insignia)) {
WriteChatf(PLUGIN_MSG "\ayFellowship Registration Insignia \aris not ready!\aw");
return;
}
if (!pLocalPlayer->Campfire) {
WriteChatf(PLUGIN_MSG "\arYou do not have a campfire up\aw.");
return;
}
if (pChar->HideMode) {
MakeMeVisible(pLocalPlayer, "");
}
UseClickyByItemName(insignia);
return;
}
// Lobby AA
if (ci_equals(Arg, "lobby")) {
ActivateAAByName("Throne of Heroes");
return;
}
// Blood AA
if (ci_equals(Arg, "blood")) {
ActivateAAByName("Harmonic Dissonance");
return;
}
// Evac - multiple AA options
if (ci_equals(Arg, "evac")) {
for (const auto& evacAA : evacAAs) {
// if we're in a group our size will be 1 or greater
// "solo" returns 0
const int iGroupSize = GroupSize();
if (iGroupSize > 0) {
if (ActivateAAByName("Exodus")) {
return;
}
}
if (!iGroupSize && !ci_equals(evacAA.name, "exodus")) {
if (ActivateAAByName(evacAA.name)) {
return;
}
}
}
// we've checked all our other evacs, let's check exodus too so we cover being solo
if (ActivateAAByName("Exodus")) {
return;
}
// Class-specific item fallback
if (pLocalPC->GetClass() == Druid || pLocalPC->GetClass() == Wizard) {
StatusItemCheck("Di`Zok Escape Staff");
return;
}
WriteChatf(PLUGIN_MSG "\arI don't seem to have the ability to \ayevac\ax!\aw");
return;
}
// Teleport AA
if (ci_equals(Arg, "teleport")) {
ActivateAAByName("Teleport");
return;
}
// If we got here, invalid argument
WriteChatf(PLUGIN_MSG "\arYou didn't provide a valid option for /relocate.\aw");
WriteChatf(PLUGIN_MSG "\arPlease do \ao\"\ay/relocate help\ao\"\ax for more information.\aw");
}
void TransloCmd(const PlayerClient* pChar, const char* szLine)
{
if (!InGame()) {
return;
}
char Arg[MAX_STRING] = { 0 };
GetArg(Arg, szLine, 1);
if (ci_equals(Arg, "help")) {
WriteChatf(PLUGIN_MSG "\agValid Translocate options are:\aw");
WriteChatf(PLUGIN_MSG "\ay/translocate \arRedBot\aw to Translocate \arRedBot\aw to their bind.");
return;
}
if (pLocalPC->GetClass() != Wizard) {
WriteChatf(PLUGIN_MSG "\arYou are not a Wizard! No Translocate for you\aw!");
return;
}
EQ_Spell* pSpell = GetSpellByName("Translocate");
if (!pSpell) {
WriteChatf(PLUGIN_MSG "\arCouldn't find Translocate spell!\aw");
return;
}
const bool haveAA = AltAbility(pSpell->Name) && AltAbility(pSpell->Name)->CurrentRank > 0;
if (!haveAA) {
WriteChatf(PLUGIN_MSG "\arI don't have the AA Translocate");
return;
}
PlayerClient* desiredTarget = nullptr;
// Determine target - from argument or current target
if (Arg[0] != '\0') {
desiredTarget = GetSpawnByName(Arg);
if (!desiredTarget) {
WriteChatf(PLUGIN_MSG "\arI can't find a player with the name \ay%s\aw", Arg);
return;
}
}
else if (MyTarget()) {
desiredTarget = MyTarget();
}
else {
WriteChatf(PLUGIN_MSG "\arPlease provide a target for \aytranslocate\aw.");
WriteChatf(PLUGIN_MSG "\arYou can physically target a player, or provide a name like: \ag/translocate RedBot\aw.");
return;
}
// Validate target
if (desiredTarget->Type != SPAWN_PLAYER) {
WriteChatf(PLUGIN_MSG "\ay%s\aw \aris not a Player!\aw", desiredTarget->Name);
return;
}
if (desiredTarget->SpawnID == pLocalPlayer->SpawnID) {
WriteChatf(PLUGIN_MSG "\arYou can't translocate yourself, knock it off!\aw");
return;
}
// Check range
if (GetDistance3D(desiredTarget->X, desiredTarget->Y, desiredTarget->Z, pLocalPlayer->X, pLocalPlayer->Y, pLocalPlayer->Z) > pSpell->Range) {
WriteChatf(PLUGIN_MSG "\arIt seems \ay%s\aw is out of range of \ay%s\aw.", desiredTarget->Name, pSpell->Name);
return;
}
pTarget = desiredTarget;
}
bool HaveAlias(const std::string& aliasName)
{
const std::string alias = GetPrivateProfileString("Aliases", aliasName, "None", gPathMQini);
return alias != "None";
}
PLUGIN_API void InitializePlugin()
{
if (HaveAlias("/relocate")) {
WriteChatf(PLUGIN_MSG "\arIt appears you already have an Alias for \ap/relocate\ar please type \"\ay/alias /relocate delete\ar\" then reload this plugin.");
EzCommand("/timed 10 /plugin MQ2Relocate Unload");
return;
}
if (HaveAlias("/translocate")) {
WriteChatf(PLUGIN_MSG "\arIt appears you already have an Alias for \ap/translocate\ar please type \"\ay/alias /translocate delete\ar\" then reload this plugin.");
EzCommand("/timed 10 /plugin MQ2Relocate Unload");
return;
}
AddCommand("/relocate", ReloCmd, false, true, true);
AddCommand("/translocate", TransloCmd, false, true, true);
}
PLUGIN_API void ShutdownPlugin()
{
RemoveCommand("/relocate");
RemoveCommand("/translocate");
}
PLUGIN_API void OnPulse()
{
if (++iPulse < iPulseDelay) {
return;
}
iPulse = 0;
if (!InGame()) {
return;
}
// Base case - nothing to do
if (convertoption[0] == '\0' && !bAmConverting && !needsUsing) {
return;
}
if (ImDucking() || Casting() || Moving(pLocalPlayer)) {
return;
}
char temp[MAX_STRING] = "";
if (bAmConverting) {
// convertoption needs a bExact and reloClicky needs !bExact
if (!FindItemByName(convertoption, true) && FindItemByName(reloClicky)) {
sprintf_s(temp, "/convertitem \"%s\"", reloClicky);
const char* fullReloItemName = FindItemByName(reloClicky)->GetName();
WriteChatf(PLUGIN_MSG "Converting Item: \ay%s \awto \ag%s", fullReloItemName, convertoption);
EzCommand(temp);
}
else {
bAmConverting = false;
needsUsing = true;
}
}
if (needsUsing && FindItemByName(convertoption, true)) {
UseClickyByItemName(convertoption);
needsUsing = false;
sprintf_s(convertoption, "");
}
}
PLUGIN_API void SetGameState(const int GameState)
{
if (GameState != GAMESTATE_INGAME) {
bAmConverting = false;
needsUsing = false;
sprintf_s(convertoption, "");
}
}
bool StatusItemCheck(const char* szItemName)
{
if (!FindItemByName(szItemName)) {
WriteChatf(PLUGIN_MSG "\arYou do not have a \ay%s\aw!", szItemName);
return false;
}
if (!IsClickyReadyByItemName(szItemName)) {
WriteChatf(PLUGIN_MSG "%s \aris not ready\aw!", szItemName);
return false;
}
return UseClickyByItemName(szItemName);
}
bool UseClickyByItemName(const char* pItem)
{
if (const ItemClient* item = FindItemByName(pItem)) {
if (EQ_Spell* itemSpell = GetSpellByID(item->GetSpellID(ItemSpellType_Clicky))) {
if (ItemReady(item->GetName())) {
UseItem(item->GetName());
return true;
}
}
}
return false;
}
bool IsClickyReadyByItemName(const char* pItem)
{
if (const ItemClient* item = FindItemByName(pItem)) {
if (EQ_Spell* itemSpell = GetSpellByID(item->GetSpellID(ItemSpellType_Clicky))) {
return ItemReady(item->GetName());
}
}
return false;
}
bool IsTargetPlayer()
{
return pTarget && pTarget->Type == SPAWN_PLAYER;
}
inline bool InGame()
{
return (GetGameState() == GAMESTATE_INGAME && pLocalPC && pLocalPlayer && GetPcProfile());
}
CAltAbilityData* AltAbility(const char* szAltName)
{
for (int nAbility = 0; nAbility < AA_CHAR_MAX_REAL; nAbility++) {
if (CAltAbilityData* pAbility = GetAAById(pLocalPC->GetAlternateAbilityId(nAbility), pLocalPlayer->Level)) {
if (const char* pName = pCDBStr->GetString(pAbility->nName, eAltAbilityName)) {
if (ci_equals(szAltName, pName)) {
return pAbility;
}
}
}
}
return nullptr;
}
void BardStopSinging()
{
if (pLocalPlayer->GetClass() == Bard) {
EzCommand("/stopsong");
if (IsPluginLoaded("mq2twist")) {
EzCommand("/twist off");
}
WriteChatf(PLUGIN_MSG "We are going to /stopsong and /twist off, to use our relocate items.");
}
}
bool CastingCheck()
{
if (pLocalPlayer->GetClass() == Bard) {
BardStopSinging();
return false;
}
return Casting();
}
bool AltAbilityReady(const char* szLine, const unsigned long TargetID)
{
if (!InGame() || !pLocalPlayer || GlobalLastTimeUsed >= GetTickCount64() || IsSpellBookOpen() || IAmDead()) {
return false;
}
if (CastingCheck()) {
return false;
}
for (auto nAbility = 0; nAbility < AA_CHAR_MAX_REAL; nAbility++) {
if (CAltAbilityData* pAbility = GetAAByIdWrapper(pLocalPC->GetAlternateAbilityId(nAbility), pLocalPlayer->Level)) {
if (const char* pName = pCDBStr->GetString(pAbility->nName, eAltAbilityName)) {
if (ci_equals(szLine, pName)) {
if (pAbility->SpellID != -1) {
if (const EQ_Spell* myAltAbility = GetSpellByID(pAbility->SpellID)) {
if (myAltAbility->CastTime && Moving(pLocalPlayer)) {
return false;
}
if (DiscReady(myAltAbility)) {
return pAltAdvManager->IsAbilityReady(pLocalPC, pAbility, nullptr);
}
}
}
}
}
}
}
return false;
}
int GroupSize()
{
if (pLocalPC && pLocalPC->Group) {
return static_cast<int>(pLocalPC->Group->GetNumberOfMembers());
}
return 0;
}
PlayerClient* MyTarget()
{
return pTarget;
}
unsigned int MyTargetID()
{
return pTarget ? pTarget->SpawnID : 0;
}
bool ImDucking()
{
return pLocalPlayer && pLocalPlayer->StandState == STANDSTATE_DUCK;
}
bool Casting()
{
return pLocalPlayer->CastingData.IsCasting();
}
bool Moving(PlayerClient* pSpawn)
{
// 0.01f gets reported when levitating
return FindSpeed(pSpawn) >= 0.01f;
}
bool ItemReady(const char* szItem)
{
if (GlobalLastTimeUsed >= GetTickCount64()) {
return false;
}
if (pLocalPC->GetClass() != Bard && Casting()) {
return false;
}
if (ItemClient* item = FindItemByName(szItem, true)) {
if (item->GetSpellRecastTime(ItemSpellType_Clicky) != -1) {
const uint32_t timer = GetItemTimer(item);
if (timer == 0 && !Moving(pLocalPlayer)) {
return true;
}
}
}
return false;
}
void UseItem(const char* pItem)
{
if (GlobalLastTimeUsed >= GetTickCount64()) {
return;
}
char temp[MAX_STRING] = "/useitem \"";
strcat_s(temp, MAX_STRING, pItem);
strcat_s(temp, MAX_STRING, "\"");
EzCommand(temp);
WriteChatf(PLUGIN_MSG "\agRelocating with: \ay%s", pItem);
GlobalLastTimeUsed = GetTickCount64() + GlobalSkillDelay;
}
bool IsSpellBookOpen()
{
return pSpellBookWnd->IsVisible();
}
bool IAmDead()
{
return pLocalPlayer && pLocalPlayer->RespawnTimer;
}
bool Invis(const PlayerClient* pSpawn)
{
return pSpawn->HideMode;
}
bool DiscReady(const EQ_Spell* pSpell)
{
if (!InGame()) {
return false;
}
const time_t timeNow = time(nullptr);
if (pLocalPC->GetCombatAbilityTimer(pSpell->ReuseTimerIndex, pSpell->SpellGroup) < timeNow) {
return true;
}
return false;
}