forked from AlphaKretin/carby-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
carby.ts
2071 lines (2000 loc) · 69.6 KB
/
carby.ts
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
import * as Eris from "eris";
import * as fs from "mz/fs";
import { Job } from "./job";
import { Monster } from "./monster";
const auth = JSON.parse(fs.readFileSync("auth.json", "utf8"));
if (!auth.token) {
console.error("Bot token not found at auth.json.token!");
process.exit();
}
const bot = new Eris.Client(auth.token);
const classes: Job[] = [];
let jobList: {
[userID: string]: string[];
} = {
"316052390442958860": ["Mime", "Mime", "Mime", "Mime"]
};
const monsters: Monster[] = [];
interface IMiscStats {
victims: number;
kinuVictims: number;
rodsBroken: number;
}
let stats: IMiscStats = {
kinuVictims: 0,
rodsBroken: 0,
victims: 0
};
interface ICannonMix {
name: string;
item: string;
text?: string;
shot?: string;
cannon?: string;
burst?: string;
}
const combines: ICannonMix[] = [];
interface IChemMix {
name: string;
snes?: string;
desc: string;
mixes: string[][];
}
const mixes: IChemMix[] = [];
const dataFile = "data.json";
const proms: Array<Promise<void>> = [];
async function loadData() {
if (await fs.exists(dataFile)) {
await fs.readFile(dataFile, "utf8").then(file => {
stats = JSON.parse(file);
});
}
}
proms.push(loadData());
const jobFile = "jobs.json";
async function loadJobs() {
if (await fs.exists(jobFile)) {
await fs.readFile(jobFile, "utf8").then(file => {
jobList = JSON.parse(file);
});
}
}
proms.push(loadJobs());
const monsterFile = "monsterdata.json";
proms.push(
fs.readFile(monsterFile, "utf8").then(file => {
const list = JSON.parse(file);
for (const monster of list) {
monsters.push(new Monster(monster));
}
})
);
const classFile = "classes.json";
proms.push(
fs.readFile(classFile, "utf8").then(file => {
const list = JSON.parse(file);
for (const job of list) {
classes.push(new Job(job));
}
})
);
const combFile = "combine.json";
proms.push(
fs.readFile(combFile, "utf8").then(file => {
const list = JSON.parse(file);
for (const comb of list) {
combines.push(comb);
}
})
);
const mixFile = "mixes.json";
proms.push(
fs.readFile(mixFile, "utf8").then(file => {
const list = JSON.parse(file);
for (const curMix of list) {
mixes.push(curMix);
}
})
);
bot.on("ready", () => {
console.log("Logged in as %s - %s\n", bot.user.username, bot.user.id);
});
bot.on("disconnect", async () => {
console.error("Bot disconnected! Reconnecting...");
await bot.connect();
});
interface ICommand {
func: (msg: Eris.Message) => Promise<void>;
names: string[];
chk?: (msg: Eris.Message) => boolean;
}
enum mainModes {
MODE_NORMAL,
MODE_RANDOM,
MODE_CHAOS,
MODE_PURE,
MODE_ADV
}
const commands: ICommand[] = [
{
func: mcalc,
names: ["mcalc"]
},
{
func: almagest,
names: ["almagest"]
},
{
func: diyFiesta(mainModes.MODE_NORMAL),
names: ["normal"]
},
{
func: diyFiesta(mainModes.MODE_RANDOM),
names: ["random"]
},
{
func: sevenFifty,
names: ["750"]
},
{
func: noSevenFifty,
names: ["no750"]
},
{
func: chaosSevenFifty,
names: ["chaos750"]
},
{
func: chaosNoSevenFifty,
names: ["chaosno750"]
},
{
func: diyFiesta(mainModes.MODE_CHAOS),
names: ["chaos"]
},
{
func: diyFiesta(mainModes.MODE_PURE),
names: ["purechaos"]
},
{
func: diyFiesta(mainModes.MODE_ADV),
names: ["advance", "gba"]
},
{
func: dd,
names: ["dd"]
},
{
func: trapped,
names: ["trapped"]
},
{
func: victim,
names: ["victims"]
},
{
func: breakRod,
names: ["break"]
},
{
func: broken,
names: ["broken"]
},
{
func: countdown,
names: ["timer", "fiestatimer", "countdown"]
},
{ func: rundown, names: ["therun", "runtimer", "rundown"] },
{
func: jobs,
names: ["jobs"]
},
{
func: forbiddenRisk,
names: ["winnerrisk"]
},
{
func: forbiddenLite,
names: ["winnerlite"]
},
{
func: forbidden,
names: ["forbidden"]
},
{
chk: (msg: Eris.Message) => auth.owners && auth.owners.indexOf(msg.author.id) > -1,
func: purify,
names: ["purify"]
},
{
func: attributes,
names: ["attributes"]
},
{
func: info("profile"),
names: ["info", "enemy"]
},
{
func: info("ai"),
names: ["ai"]
},
{
func: info("loot"),
names: ["loot"]
},
{
func: info("stats"),
names: ["stat"]
},
{
func: info("weak"),
names: ["weak"]
},
{
func: info("ability"),
names: ["abilit"]
},
{
func: randcolour,
names: ["color", "colour", "snescolour", "snescolor"]
},
{
func: deathByMaths,
names: ["math", "deathbymath"] // "maths" handled because it only checks the start
},
{
func: jobData,
names: ["class"]
},
{
func: combine,
names: ["combine", "cannon"]
},
{
func: mix,
names: ["mix", "drug"]
},
{
func: isBowBetter,
names: ["isbowbetter"]
},
{
func: order,
names: ["order", "firstchar"]
},
{
func: zeninage,
names: ["zeninage", "giltoss"]
},
{
func: loadsOfMoney,
names: ["loadsofmoney"]
}
];
const responses: { [key: string]: string } = {
500:
"KARNAK 500 TREASURE CHEST MAP, IT'S COOL AND GOOD: " +
"https://www.gamefaqs.com/ps/562810-final-fantasy-v/faqs/49618?raw=1",
address:
"GBA Memory Address list is here: http://tinyurl.com/leq4gje\n" +
"Song boosts are stored at 0x0201EE85/86/88/89 for Strength/Agility/Magic/Level!",
algorithm: "Algorithms guide: http://www.kyrosiris.com/ff5algorithm.html",
badfaq: "oh my god I love <:rod:455233447565459471> http://www.gamefaqs.com/snes/588331-final-fantasy-v/faqs/21687",
badfiesta: "The worst fiesta ever happened here: https://www.twitch.tv/dragondarchsda/v/48967944",
badmod:
"`No balance, at all` -mod author http://kyrosiris.com/changes_overview.txt " +
"https://www.romhacking.net/forum/index.php?topic=26501.0 (DON'T PLAY THIS)",
beginner:
"alcharagia's beginner guide to the game's Jobs:\n" +
"https://forums.somethingawful.com/showthread.php?threadid=3857516&userid=0" +
"&perpage=40&pagenumber=13#post484858103",
blue: "Blue Magic acquisition guide: http://shrines.rpgclassics.com/snes/ff5/bluestrat.shtml",
catch: "Need catch suggestions? Kyro made a spreadsheet: http://tinyurl.com/catchspreadsheet",
chemchart:
"!Mix Picture Guide: http://i.imgur.com/MBJBNvG.gif\nFor a version with the cruft removed, click here: " +
"<https://cdn.discordapp.com/attachments/315364661832843265/600020062413258762/mixchart-improved.gif>",
crystelle: "Those are easy to catch, right? http://i.imgur.com/WD40MES.png",
dance: "It's *sensual.* https://i.imgur.com/qX3ElWK.gif",
encounter:
"Indoor enemy list per zone/encounter is here: " +
"https://www.dropbox.com/s/l9cxdjz2atp7ey2/encounter_survey.txt\n" +
"World 3 encounter map is here: http://www.cavesofnarshe.com/ff5/finalworld.php\n" +
"disastranagant 20/06/2018\n" +
"jfc why haven't I posted the sea chart yet https://i.imgur.com/52t2S15.gif\n" +
"the grey areas are great abp and gil, the light blue area has stingray " +
"and the yellow area has the highest gil and abp of any random battle outside the void.",
enkibot: "Asterism's Enkibot guide is here: http://enkibot.herokuapp.com/",
equipharps: "http://lparchive.org/Final-Fantasy-V-Advance-%28by-Dr-Pepper%29/1-MaximumTruckStyleLove.gif",
flee:
"foolofsound made a guide on which encounters you can or can't easily run from:\n" +
"https://docs.google.com/document/d/1Kb-lretuvYNOcEEdyHIWq3zz69088EEQ6TBO8j78i9c/edit?usp=sharing",
fork: "Fork Tower: Magic Left, Physical Right",
gaia: "THAT HIPPIE SHIT AIN'T MAGIC http://i.imgur.com/JkwTg5O.png",
happyworm: "https://gifsound.com/?gif=i.imgur.com/UaOsyZS.gif&v=y6Sxv-sUYtM&s=11",
help:
"I have a lot of commands, too many to list in this Discord PM." +
" Check this readme: https://tinyurl.com/ybh7lrz2",
iainuki: "That's a good ability! http://gfycat.com/TenseArtisticCobra",
karnak:
"KARNAK 500 TREASURE CHEST MAP, IT'S COOL AND GOOD: " +
"https://www.gamefaqs.com/ps/562810-final-fantasy-v/faqs/49618?raw=1",
lamp:
"Magic Lamp cast order: Bahamut, Leviathan, Odin, Syldra, Carbuncle, Catoblepas, " +
"Golem, Titan, Ifrit, Ramuh, Shiva, Remora, Sylph, Chocobo.",
level5death: "Possibly the best ability! http://gfycat.com/TerrificKeyEmperorshrimp",
ned: "Neo-Exdeath Picture Guide: https://i.imgur.com/m0E61iK.png",
numbers:
"**PREMIUM TACTICAL INFORMATION ITT**\nDragondarch's team is Monk, Mystic Knight, Beastmaster, Dancer. " +
"Here's his foolproof strategy for dealing with the Seal Guardians in Moore Forest.\n\n" +
"1. After getting the wind drake from Bal Castle, go to Kuza and grind to level 32.\n" +
"2. Proceed with the game until the Barrier Tower. Grind there for Reflect Rings.\n" +
"3. Go to Drakenvale and get a Poison Eagle to cast Float on everyone.\n" +
"4. Go to the Gil Cave to grind out 370,000 Gil to buy Hermes Sandals with in World 3.\n" +
"5. Let the Aegis Shield be transformed into the Flame Shield.\n" +
"6. Make Bartz a Mystic Knight and weaken him to critical HP.\n" +
"7. Give Bartz the Flame Shield, give everyone else Reflect Rings.\n" +
"8. Reset the game because Bartz got one-shotted immediately in the Seal Guardian fight.\n" +
"9. Kill the Water, Earth and Wind Crystals.\n10. Kill off everyone except Bartz.\n" +
"11. Use !Focus + Drain Sword to kill the Fire Crystal.\n\nIt's easy!",
oracle: "https://www.youtube.com/watch?v=makazgIRzfg",
phoenix:
"Phoenix Tower door order: Left Left Right, " +
"Left Left Right, Left Left Right, Left Left Right, Right Left Right, Left Left Right, Center, Phoenix!",
physical:
"THIS SHIT AIN'T MAGIC (and will trigger React: Physical scripts): Item, Fight, Kick, Focus, Steal, " +
"Mug, Lance, Jump, Throw, Mineuchi, Zeninage, Animals, Aim, Rapid Fire, " +
"Call, Check, Scan, Release, Mix, Gaia, and Dance.",
piano: "The pianos are in: Tule, Carwen, Karnak, Jachol, Crescent, Regole, Moore, and Mirage",
pyramid: "https://i.imgur.com/YbXESCb.gif",
quickleak: "https://www.youtube.com/watch?v=1x7zRK-Fsv8&list=PLMthTW4vRq8bfi6MeqVHU-yWkN4BRE1DJ",
quicksave: "Hang on while I do some **ENCOUNTER MANIPULATION**",
rocksfall: "...and *NED* dies? sure, why not https://clips.twitch.tv/ProductiveSavoryHorseradishSoBayed",
runthenumbers:
"**PREMIUM TACTICAL INFORMATION ITT**\nDragondarch's team is Monk, Mystic Knight, Beastmaster, Dancer. " +
"Here's his foolproof strategy for dealing with the Seal Guardians in Moore Forest.\n\n" +
"1. After getting the wind drake from Bal Castle, go to Kuza and grind to level 32.\n" +
"2. Proceed with the game until the Barrier Tower. Grind there for Reflect Rings.\n" +
"3. Go to Drakenvale and get a Poison Eagle to cast Float on everyone.\n" +
"4. Go to the Gil Cave to grind out 370,000 Gil to buy Hermes Sandals with in World 3.\n" +
"5. Let the Aegis Shield be transformed into the Flame Shield.\n" +
"6. Make Bartz a Mystic Knight and weaken him to critical HP.\n" +
"7. Give Bartz the Flame Shield, give everyone else Reflect Rings.\n" +
"8. Reset the game because Bartz got one-shotted immediately in the Seal Guardian fight.\n" +
"9. Kill the Water, Earth and Wind Crystals.\n10. Kill off everyone except Bartz.\n" +
"11. Use !Focus + Drain Sword to kill the Fire Crystal.\n\nIt's easy!",
sandworm: "http://kyrosiris.com/sandworm.gif",
sandworm2: "This is to go ***FURTHER BEYOND!!!*** http://kyrosiris.com/sandworm2.png",
sealed:
"<a:spinryu:587175221421670402>" +
"__alcharagia's Sealed Temple Guides: 「Don't Do It」__" +
"<a:spinryu:587175221421670402>\n" +
"2016:" +
" https://forums.somethingawful.com/showthread.php?threadid=3776693&pagenumber=87&perpage=40#post461344746\n" +
"2017:" +
" https://forums.somethingawful.com/showthread.php?threadid=3820741&pagenumber=22&perpage=40#post473264920\n" +
"2019:" +
" https://forums.somethingawful.com/showthread.php?threadid=3889977&perpage=40&pagenumber=12#post495764439",
seals: "Seal Guardians Picture Guide: http://i.imgur.com/c73swws.png",
spinryu: "**RUN COWARD RUN RUN RUN RUN RUN RUN RUN** https://i.imgur.com/mnarmy3.gif",
stats:
"Character stat bonuses are as follows:\nButz - +4 Str, +1 Agi, +3 Vit, +1 Mag\n" +
"Lenna: +1 Str, +2 Agi, +1 Vit, +4 Mag\nGaluf: +3 Str, +4 Vit\n " +
"Faris: +3 Str, +3 Agi, +2 Vit, +2 Mag\nKrile: +1 Str, +4 Agi, +3 Mag",
wand:
"Wonder Wand spell order: Cure, Poisona, Silence, Protect, Mini, Cura, Raise, Confuse, " +
"Blink, Shell, Esuna, Curaga, Reflect, Berserk, Arise, Holy, Dispel, " +
"Fire, Blizzard, Thunder, Poison, Sleep, Toad, Fira, Blizzara, Thundara, Drain, Break, Bio, " +
"Firaga, Blizzaga, Thundaga, Flare, Death, Osmose, repeat!",
wonder:
"Wonder Wand spell order: Cure, Poisona, Silence, Protect, Mini, Cura, Raise, Confuse, " +
"Blink, Shell, Esuna, Curaga, Reflect, Berserk, Arise, Holy, Dispel, " +
"Fire, Blizzard, Thunder, Poison, Sleep, Toad, Fira, Blizzara, Thundara, Drain, Break, Bio, " +
"Firaga, Blizzaga, Thundaga, Flare, Death, Osmose, repeat!",
yburns: "The Y-BURNS? My favorite team! http://i.imgur.com/aQ18OQF.png"
};
const prefixes = [".", "!"];
const queries: {
[userID: string]: {
list: Monster[];
type: string;
};
} = {};
bot.on("error", (err: Error) => {
console.dir(err);
});
// reads incoming messages for commands and redirects to functions to handle them
bot.on("messageCreate", async (msg: Eris.Message) => {
const lowMes = msg.content.toLowerCase();
if (!msg.author.bot) {
for (const cmd of commands) {
if (!cmd.chk || cmd.chk(msg)) {
for (const name of cmd.names) {
for (const pre of prefixes) {
if (lowMes.startsWith(pre + name)) {
await cmd.func(msg);
return;
}
}
}
}
}
if (lowMes.startsWith("zerky!")) {
await zerky(msg);
return;
}
for (const key in responses) {
if (responses.hasOwnProperty(key)) {
for (const pre of prefixes) {
if (lowMes.startsWith(pre + key)) {
await msg.channel.createMessage(responses[key]);
return;
}
}
}
}
// only continue enemy info stuff in DMs
if (msg.author.id in queries && msg.channel instanceof Eris.PrivateChannel) {
await enemyClarify(msg);
return;
}
}
});
bot.on("messageReactionAdd", async (msg: Eris.Message, emoji: Eris.EmojiBase, userID: string) => {
if (msg.id in dmReplies && emoji.name === "📬") {
const user = bot.users.get(userID);
if (user && !user.bot) {
const chan = await user.getDMChannel();
await chan.createMessage(dmReplies[msg.id]);
}
}
});
// .mcalc
interface IMCalc {
args: string[];
calc: (nums: number[]) => string;
}
const mcalcTable: { [name: string]: IMCalc } = {
bell: {
args: ["Level", "Magic", "Agility"],
calc: (nums: number[]) => {
const level = nums[0];
const mag = nums[1];
const agil = nums[2];
let m = Math.floor((level * mag) / 128);
const bonus = Math.floor((level * agil) / 128);
const n = Math.ceil((128 * (m + 1)) / mag);
const ns = Math.ceil((128 * (bonus + 1)) / agil);
m += bonus + 2;
return (
"At Level " +
level +
", with " +
mag +
" Magic and " +
agil +
" Agility, your Diamond Bell/Tinkerbell M is " +
m +
". To reach the next M, you need to reach level " +
n +
" for Strength and " +
ns +
" for Agility."
);
}
},
cannon: {
args: ["Level"],
calc: (nums: number[]) => {
const m = Math.floor((nums[0] * nums[0]) / 256 + 4);
let nextLevel = Math.ceil(256 * (m + 1 - 4));
nextLevel = Math.ceil(Math.sqrt(nextLevel));
return (
"At level " +
nums[0] +
", your Cannoneer M is " +
m +
". To reach the next M, you need to reach level " +
nextLevel +
"."
);
}
},
chicken: {
args: ["Level", "Strength", "Agility"],
calc: (nums: number[]) => {
const level = nums[0];
const str = nums[1];
const agil = nums[2];
let m = Math.floor((level * str) / 128);
const bonus = Math.floor((level * agil) / 128);
const n = Math.ceil((128 * (m + 1)) / str);
const ns = Math.ceil((128 * (bonus + 1)) / agil);
m += bonus + 2;
return (
"At Level " +
level +
", with " +
str +
" Strength and " +
agil +
" Agility, your Chicken Knife M is " +
m +
". To reach the next M, you need to reach level " +
n +
" for Strength and " +
ns +
" for Agility."
);
}
},
fists: {
args: ["Level", "Strength"],
calc: (nums: number[]) => {
const level = nums[0];
const str = nums[1];
const m = Math.floor((level * str) / 256 + 2);
const nextLevel = Math.ceil((256 * (m + 1 - 2)) / str);
const pow = level * 2 + 3;
return (
"At Level " +
level +
", with " +
str +
" Strength, your fist M is " +
m +
" (with " +
pow +
" attack power). To reach the next M, you need to reach level " +
nextLevel +
"."
);
}
},
knife: {
args: ["Level", "Strength", "Agility"],
calc: (nums: number[]) => {
const level = nums[0];
const str = nums[1];
const agil = nums[2];
let m = level;
let bonus = level;
m = m * str;
bonus = bonus * agil;
m = Math.floor(m / 128);
bonus = Math.floor(bonus / 128);
let ns = bonus;
let divider = bonus;
divider = Math.floor(divider / 2);
bonus -= divider;
bonus -= divider;
let n = m;
n++;
ns++;
n = n * 128;
ns = ns * 128;
n = Math.ceil(n / str);
ns = Math.ceil(ns / agil);
m += 2;
if (bonus === 0) {
return (
"At Level " +
level +
", with " +
str +
" Strength and " +
agil +
" Agility, your knife M is " +
m +
" (no Agility bonus). To reach the next M, you need to reach level " +
n +
" (Bonus Agility M gained at level " +
ns +
")."
);
} else {
// if bonus = 1
m = m + 1;
return (
"At Level " +
level +
", with " +
str +
" Strength and " +
agil +
" Agility, your knife M is " +
m +
" (including Agility bonus). To reach the next M, you need to reach level " +
n +
" (Bonus Agility M **LOST** at level " +
ns +
")."
);
}
}
},
magic: {
args: ["Level", "Magic"],
calc: (nums: number[]) => {
const m = Math.floor((nums[0] * nums[1]) / 256 + 4);
const nextLevel = Math.ceil((256 * (m + 1 - 4)) / nums[1]);
return (
"At Level " +
nums[0] +
", with " +
nums[1] +
" Magic, your magic M is " +
m +
". To reach the next M, you need to reach level " +
nextLevel +
""
);
}
},
physical: {
args: ["Level", "Strength"],
calc: (nums: number[]) => {
const m = Math.floor((nums[0] * nums[1]) / 128 + 2);
const nextLevel = Math.ceil((128 * (m + 1 - 2)) / nums[1]);
return (
"At Level " +
nums[0] +
", with " +
nums[1] +
" Strength, your physical M is " +
m +
". To reach the next M, you need to reach level " +
nextLevel +
""
);
}
},
rune: {
args: ["Level", "Strength", "Magic"],
calc: (nums: number[]) => {
const level = nums[0];
const str = nums[1];
const mag = nums[2];
let m = Math.floor((level * str) / 128);
const bonus = Math.floor((level * mag) / 128);
const n = Math.ceil((128 * (m + 1)) / str);
const ns = Math.ceil((128 * (bonus + 1)) / mag);
m += bonus + 2;
return (
"At Level " +
level +
", with " +
str +
" Strength and " +
mag +
" Magic, your Rune Weapon M is " +
m +
". To reach the next M, you need to reach level " +
n +
" for Strength and " +
ns +
" for Magic."
);
}
}
};
async function mcalc(msg: Eris.Message) {
const args = msg.content
.toLowerCase()
.split(/ +/)
.slice(1); // remove command name
const strs = args.filter((i: string) => isNaN(parseInt(i, 10))); // extracts strings
let type;
if (strs.length < 1) {
await msg.channel.createMessage(
"Sorry, you need to tell me what type of M you're calculating! Valid types: `" +
Object.keys(mcalcTable).join(", ") +
"`"
);
return;
} else {
type = strs[0].toLowerCase();
}
if (!(type in mcalcTable)) {
await msg.channel.createMessage(
"Sorry, you need to tell me what type of M you're calculating! Valid types: `" +
Object.keys(mcalcTable).join(", ") +
"`"
);
return;
}
const mtype = mcalcTable[type];
const nums = args.map((i: string) => parseInt(i, 10)).filter((i: number) => !isNaN(i)); // extracts numbers
if (nums.length < mtype.args.length) {
await msg.channel.createMessage(
"Sorry, I need more numbers! Arguments for `" + type + "`: " + mtype.args.join(", ")
);
return;
}
await msg.channel.createMessage(mtype.calc(nums));
}
const hps = [
0,
20,
25,
30,
40,
50,
60,
70,
80,
90,
100,
120,
140,
160,
180,
200,
220,
240,
260,
280,
300,
320,
340,
360,
380,
400,
420,
440,
460,
480,
500,
530,
560,
590,
620,
650,
690,
730,
770,
810,
850,
900,
950,
1000,
1050,
1100,
1160,
1220,
1280,
1340,
1400,
1460,
1520,
1580,
1640,
1700,
1760,
1820,
1880,
1940,
2000,
2050,
2100,
2150,
2200,
2250,
2300,
2350,
2400,
2450,
2500,
2550,
2600,
2650,
2700,
2750,
2800,
2850,
2900,
2950,
3000,
3050,
3100,
3150,
3200,
3250,
3300,
3350,
3400,
3450,
3500,
3550,
3600,
3650,
3700,
3750,
3800,
3850,
3900,
3950
];
// .almagest
async function almagest(msg: Eris.Message) {
const args = msg.content.toLowerCase().split(/ +/);
let vit = parseInt(args[1], 10);
if (isNaN(vit) || vit > 99) {
const query = args.slice(1).join("");
const result = classes.find((c: Job) =>
c.name
.toLowerCase()
.replace(/\s+/g, "")
.includes(query)
);
if (result && args.length > 1) {
vit = result.vit;
} else {
await msg.channel.createMessage(
"NED's Almagest can deal 1620 to 1665 Holy damage and inflict Sap. " +
"Good luck! (Only 720 to 740 damage if you have Shell! Yay!)"
);
return;
}
}
const target = Math.ceil((32 * 1665) / (vit + 32));
const buffTarget = Math.ceil((32 * 1725) / (vit + 32));
let level = 0;
let buffLevel = 1;
while (hps[level] < target || hps[buffLevel] < buffTarget) {
if (hps[level] < target) {
level++;
}
if (hps[buffLevel] < buffTarget) {
buffLevel++;
}
}
const finalHP = Math.floor((hps[level] * (vit + 32)) / 32);
const finalBuffHP = Math.floor((hps[buffLevel] * (vit + 32)) / 32);
let out =
"At " + vit + " vitality, you will need to be level " + level + " (" + finalHP + " HP) to survive Almagest";
if (level === buffLevel) {
out += " with a safe buffer.";
} else {
out += ", or level " + buffLevel + " (" + finalBuffHP + " HP) to survive Almagest with a safe buffer.";
}
await msg.channel.createMessage(out);
}
function clean(s: string): string {
return s.toLowerCase().replace(/\s+/g, "");
}
async function combine(msg: Eris.Message) {
const args = msg.content.toLowerCase().split(/\s+/);
args.shift();
const combName = args.join("");
const comb = combines.find(c => clean(c.name) === combName || clean(c.item) === combName);
if (comb) {
let out = "Combine shot with __" + comb.item + "__ for";
if (comb.text) {
out += ` **${comb.name} Shot**, **${comb.name} Burst**, **${comb.name} Cannon**\n${comb.text}`;
} else {
out += `:\n**${comb.name} Shot**\n${comb.shot!}\n**${comb.name} Burst**\n${comb.burst!}\n**${
comb.name
} Cannon**\n${comb.cannon!}`;
}
await msg.channel.createMessage(out);
} else {
await msg.channel.createMessage(
"Sorry, I don't have a combination for that item or name.\n" +
"If you're asking about an item, make sure you're using the GBA name, and I don't need the shot!\n" +
'If you\'re looking up a name, I don\'t need "Shot", "Burst" or "Cannon", just the first bit!'
);
}
}
async function getIngredientName(query: string): Promise<string | undefined> {
const q = clean(query);
const empty: string[] = [];
const ing = mixes
.reduce((prev, cur) => prev.concat(cur.mixes.reduce((p, c) => p.concat(c), empty)), empty)
.find(i => clean(i).includes(q));
return ing;
}
async function mix(msg: Eris.Message) {
const args = msg.content.toLowerCase().split(/\s+/);
args.shift();
const mode = args.shift();
const query = args.join("");
if (!mode || !(mode === "to" || mode === "from")) {
await msg.channel.createMessage(
"Sorry, I need to know which direction to search!\n" +
"Type `!mix from` to specify ingredients, or `!mix to` to specify the mix. " +
"If you're looking for the chart, use `.chemchart`."
);
return;
}
if (mode === "to") {
const curMix = mixes.find(m => clean(m.name).includes(query) || (!!m.snes && clean(m.snes).includes(query)));
if (curMix) {
const out =
"__**" +
curMix.name +
"**__\nEffects: " +
curMix.desc +
"\n" +
"Ingredients: " +
curMix.mixes.map(m => m.join(" + ")).join(", ");
await msg.channel.createMessage(out);
} else {
await msg.channel.createMessage("Sorry, I couldn't find a mix with that name!");
}
} else {
// if mode === "from"
const ingredients = query.split("+").slice(0, 2);
if (ingredients.length === 1) {
const ing = await getIngredientName(ingredients[0]);
if (!ing) {
await msg.channel.createMessage(
"Sorry, I don't know what ingredient you mean by `" + ingredients[0] + "`!"
);
return;
}
// filter for mixes including thecommands ingredient
const curMixes = mixes.filter(m => !!m.mixes.find(ings => ings.includes(ing)));
if (curMixes.length > 0) {
let out = "Mixing with __" + ing + "__:\n";
out += curMixes
.map(
m =>
m.name +
" (" +
m.mixes
.filter(i => i.includes(ing))
.map(i => {
if (i[0] === i[1]) {
return i[0];
}
return i.find(n => n !== ing);
})
.join("/") +
")"
)
.join("\n");
await msg.channel.createMessage(out);
} else {
await msg.channel.createMessage("Sorry, I couldn't find a mix using that ingredient!");
}
} else {
const quer1 = await getIngredientName(ingredients[0]);
if (!quer1) {
await msg.channel.createMessage(
"Sorry, I don't know what ingredient you mean by `" + ingredients[0] + "`!"
);
return;
}
const quer2 = await getIngredientName(ingredients[1]);
if (!quer2) {
await msg.channel.createMessage(
"Sorry, I don't know what ingredient you mean by `" + ingredients[1] + "`!"
);
return;
}
const curMix = mixes.find(
m => !!m.mixes.find(i => (i[0] === quer1 && i[1] === quer2) || (i[0] === quer2 && i[1] === quer1))