-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
3816 lines (3586 loc) · 186 KB
/
bot.js
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
/* Discord */
const { Client, Intents, ApplicationCommandOptionType, Options, GatewayIntentBits } = require('discord.js');
global.client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildWebhooks, GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMessageReactions, GatewayIntentBits.DirectMessages, GatewayIntentBits.DirectMessageReactions],
sweepers: {
...Options.DefaultSweeperSettings,
messages: {
interval: 900, // Every 15 minutes...
lifetime: 900, // Remove messages older than 15 minutes.
},
}
});
config = require("./config.json");
/**
JSON for Big Number
**/
BigInt.prototype.toJSON = function () {
return this.toString()
}
/**
This really should be changed to use modules once I've made more progress on the split
**/
var fs = require('fs');
// file is included here:
eval(fs.readFileSync('ai.js')+'');
eval(fs.readFileSync('game.js')+'');
eval(fs.readFileSync('cloning.js')+'');
require("./sql.js")();
/* Setup */
client.on("ready", async () => {
// on bot ready
registerCommands();
// load db state
sqlSetup();
await sleep(1000);
loadFromDB();
});
/** GLOBAL VARIABLES **/
var games = [];
var gamesHistory = [];
var gamesInterfaces = [];
var players = [];
var outstandingChallenge = [];
/** Load / Save to / from DT **/
async function saveToDB() {
let a = await sqlProm("UPDATE data SET value=" + connection.escape(JSON.stringify(games)) + " WHERE id=0");
let b = await sqlProm("UPDATE data SET value=" + connection.escape(JSON.stringify(gamesHistory)) + " WHERE id=1");
let c = await sqlProm("UPDATE data SET value=" + connection.escape(JSON.stringify(gamesInterfaces)) + " WHERE id=2");
let d = await sqlProm("UPDATE data SET value=" + connection.escape(JSON.stringify(players)) + " WHERE id=3");
let e = await sqlProm("UPDATE data SET value=" + connection.escape(JSON.stringify(outstandingChallenge)) + " WHERE id=4");
let f = await sqlProm("UPDATE data SET value=" + connection.escape(lastDay) + " WHERE id=5");
let g = await sqlProm("UPDATE data SET value=" + connection.escape(JSON.stringify(dailyWinners)) + " WHERE id=6");
return await Promise.all([a, b, c, d, e, f, g]);
}
async function loadFromDB() {
let a = await sqlPromOne("SELECT * FROM data WHERE id=0");
let b = await sqlPromOne("SELECT * FROM data WHERE id=1");
let c = await sqlPromOne("SELECT * FROM data WHERE id=2");
let d = await sqlPromOne("SELECT * FROM data WHERE id=3");
let e = await sqlPromOne("SELECT * FROM data WHERE id=4");
let f = await sqlPromOne("SELECT * FROM data WHERE id=5");
let g = await sqlPromOne("SELECT * FROM data WHERE id=6");
await Promise.all([a, b, c, d, e, f, g]);
let gamesRestore = JSON.parse(a.value ?? "[]");
let gamesHistoryRestore = JSON.parse(b.value ?? "[]");
let gamesInterfacesRestore = JSON.parse(c.value ?? "[]");
players = JSON.parse(d.value ?? "[]");
outstandingChallenge = JSON.parse(e.value ?? "[]");
lastDay = f.value ?? -1;
dailyWinners = JSON.parse(g.value ?? "[]");
games = [];
gamesHistory = [];
gamesInterfaces = [];
// filter out deleted games to reduce open games
let newId = 0;
for(let i = 0; i < gamesRestore.length; i++) {
if(gamesRestore[i] !== null) {
console.log(`Restoring Game #${i} as ${newId}.`);
gamesRestore[i].id = newId;
gamesHistoryRestore[i].id = newId;
gamesInterfacesRestore[i].id = newId;
games.push(gamesRestore[i]);
gamesHistory.push(gamesHistoryRestore[i]);
gamesInterfaces.push(gamesInterfacesRestore[i]);
players = players.map(el => [el[0], el[1] === i ? newId : el[1]]);
newId++;
console.log(gamesRestore[i]);
} else {
console.log(`Deleting Game #${i}.`);
}
}
console.log(`Restored ${games.length} games!`);
console.log(`Restored ${gamesHistory.length} histories!`);
console.log(`Restored ${gamesInterfaces.length} interfaces!`);
console.log(`Restored ${players.length} players!`);
console.log(`Restored ${outstandingChallenge.length} outstanding challenges!`);
// restore spectator board message references
for(let i = 0; i < gamesInterfaces.length; i++) {
let tgi = gamesInterfaces[i];
if(tgi === null) continue;
// find spectator boards
if((tgi?.spectator?.type === "discord") && (tgi?.spectator?.msg ?? null) && !(tgi.spectator.msg.edit)) {
let g = client.guilds.cache.get(tgi.spectator.msg.guildId);
let c = g.channels.cache.get(tgi.spectator.msg.channelId);
let m = await c.messages.fetch(tgi.spectator.msg.id);
tgi.spectator.msg = m;
console.log(`Reconstructed a spectator board reference for Game #${i}.`);
}
}
// check who's turn it is
for(let i = 0; i < games.length; i++) {
let tg = games[i];
if(tg === null) continue;
let tp = tg.players[tg.turn];
console.log(`Players in Game #${i}: ${tg.players.join(',')}. Current Turn: ${tg.turn}`);
if(tp === null) {
if(tg.players.filter(el => el).length > 0) {
console.log(`Game #${i} has an AI turn: Restarting turn.`);
AImove(tg.turn, tg);
sendMessage(tg.id, `${tg.players.filter(el => el).map(el => '<@' + el + '>').join(',')} due to a bot restart your game has been interrupted. Please wait for the bot to finish its turn and then run \`/resend\` to get an updated version of the board. If the bot never seems to finish its turn try running the command anyway after around 30 seconds.`);
} else {
console.log(`Game #${i} has no valid players: Destroy.`);
destroyGame(tg.id);
}
} else {
console.log(`Game #${i} has a player turn: No action taken.`);
sendMessage(tg.id, `${tg.players.filter(el => el).map(el => '<@' + el + '>').join(',')} due to a bot restart your game has been interrupted. You should be able to continue playing as usual. If the board is not working, try running \`/resend\`.`);
}
}
}
/**
sendMessage
Sends a <message> to interfaces of the game with <gameid>
*/
function sendMessage(gameid, message) {
let guild = client.guilds.cache.get(gamesInterfaces[gameid].guild);
let channel = guild.channels.cache.get(gamesInterfaces[gameid].channel);
channel.send(message);
}
/**
updateSpectatorBoard
Updates the spectator (public) board for a certain game
**/
function updateSpectatorBoard(gameid) {
if(gamesInterfaces[gameid].spectator.type == "discord") {
let msgSpec = displayBoard(games[gameid], "Spectator Board", [], -1);
msgSpec.ephemeral = false;
gamesInterfaces[gameid].spectator.msg.edit(msgSpec);
}
}
/**
requireAction
Requires a player interaction
**/
function requireAction(game, actionType, metadata, interaction) {
switch(actionType) {
case "promote_white": {
let kings = ["Hooker","Idiot","Crowd Seeker","Aura Teller"];
let knights = ["Royal Knight","Amnesiac"];
let rooks = ["Fortune Teller","Runner","Witch"];
if(metadata.piece.name == "White Pawn") {
kings = ["White King"];
knights = ["White Knight"];
rooks = ["White Rook"];
}
let promoteKing = kings[Math.floor(Math.random() * kings.length)];
let promoteKnight = knights[Math.floor(Math.random() * knights.length)];
let promoteRook = rooks[Math.floor(Math.random() * rooks.length)];
let components = [];
components.push({ type: 2, label: promoteKing + " " + getUnicode(getChessName(promoteKing), 0), style: 1, custom_id: "promote-"+metadata.to+"-"+promoteKing });
components.push({ type: 2, label: promoteKnight + " " + getUnicode(getChessName(promoteKnight), 0), style: 1, custom_id: "promote-"+metadata.to+"-" + promoteKnight });
components.push({ type: 2, label: promoteRook + " " + getUnicode(getChessName(promoteRook), 0), style: 1, custom_id: "promote-"+metadata.to+"-" + promoteRook });
interaction.editReply(displayBoard(game, "Promote " + metadata.to, [{ type: 1, components: components }] ));
} break;
case "promote_black": {
let kings = ["Alpha Wolf","Psychic Wolf","Sneaking Wolf"];
let knights = ["Direwolf","Clairvoyant Fox","Fox"];
let rooks = ["Warlock","Scared Wolf","Saboteur Wolf"];
if(metadata.piece.name == "Black Pawn") {
kings = ["Black King"];
knights = ["Black Knight"];
rooks = ["Black Rook"];
}
let promoteKing = kings[Math.floor(Math.random() * kings.length)];
let promoteKnight = knights[Math.floor(Math.random() * knights.length)];
let promoteRook = rooks[Math.floor(Math.random() * rooks.length)];
let components = [];
components.push({ type: 2, label: promoteKing + " " + getUnicode(getChessName(promoteKing), 1), style: 1, custom_id: "promote-"+metadata.to+"-"+promoteKing });
components.push({ type: 2, label: promoteKnight + " " + getUnicode(getChessName(promoteKnight), 1), style: 1, custom_id: "promote-"+metadata.to+"-" + promoteKnight });
components.push({ type: 2, label: promoteRook + " " + getUnicode(getChessName(promoteRook), 1), style: 1, custom_id: "promote-"+metadata.to+"-" + promoteRook });
interaction.editReply(displayBoard(game, "Promote " + metadata.to, [{ type: 1, components: components }] ));
} break;
}
}
/**
check if user is a Game Master
**/
function isGameMaster(member) {
if(!member) return false;
return member && member.roles && member.roles.cache.get("584767449078169601");
}
// log utility function
function log(txt1, txt2 = "", txt3 = "", txt4 = "", txt5 = "") {
let txt = txt1 + " " + txt2 + " " + txt3 + " " + txt4 + " " + txt5;
console.log(txt);
/**let guild = client.guilds.cache.get("584765921332297775");
let channel;
if(guild) channel = guild.channels.cache.get("1047920491089895565")
if(channel) channel.send(txt);**/
}
// check if player is playing
function isPlaying(id) {
return players.map(el => el[0]).indexOf(id) != -1;
}
// check if player has an outstanding challenge
function isOutstanding(id) {
return outstandingChallenge.map(el => el[0]).indexOf(id) != -1;
}
// get the id of the game the player is playing
function getPlayerGameId(id) {
let ind = players.map(el => el[0]).indexOf(id);
return players[ind][1];
}
function turnStart(interaction, gameid, turn, mode = "editreply", firstMessage = false) {
// register message
console.log("turnstart", mode, turn, interaction.message ? interaction.message.id : null);
if(mode != "followup" && mode != "reply" && interaction.message && !firstMessage) gamesInterfaces[gameid].interfaces[turn] = { type: "discord", msg: interaction.message.id };
// abilities
let availableAbilities = showMoves(gameid, turn, true, "Select a Piece (ABILITY)");
// show buttons?
if(availableAbilities.components[0].components.length == 1) turnMove(interaction, gameid, turn, mode); // no
else response(gameid, interaction, availableAbilities, mode); // yes
}
function turnStartNot(interaction, gameid, turn, mode = "editreply") {
// register message
console.log("turnstartnot", mode, turn, interaction.message ? interaction.message.id : null);
if(mode != "followup" && mode != "reply" && interaction.message) gamesInterfaces[gameid].interfaces[turn] = { type: "discord", msg: interaction.message.id };
// waiting
let board = renderBoard(games[gameid], "Waiting on Opponent");
let noButtons = { content: board, ephemeral: true, fetchReply: true, components: [{ type: 1, components: [{ type: 2, label: "Start Game", style: 4, custom_id: "start" }] }] };
response(gameid, interaction, noButtons, mode); // show Start Game Button
}
function turnMove(interaction, gameid, turn, mode = "editreply") {
// register message
console.log("turnmove", mode, turn, interaction.message ? interaction.message.id : null);
if(mode != "followup" && mode != "reply" && interaction.message) gamesInterfaces[gameid].interfaces[turn] = { type: "discord", msg: interaction.message.id };
// update spec board
updateSpectatorBoard(gameid)
// show movable pieces
let availableMoves = showMoves(gameid, turn, false, "Select a Piece (MOVE)");
response(gameid, interaction, availableMoves, mode);
}
function response(gameid, interaction, resp, mode) {
switch(mode) {
case "reply":
interaction.reply(resp).then(m => {
gamesInterfaces[gameid].interfaces[games[gameid].turn] = { type: "discord", msg: m.id };
});
break;
case "update":
interaction.update(resp);
break;
case "followup":
interaction.followUp(resp);
break;
case "edit":
interaction.edit(resp);
break;
case "editreply":
interaction.editReply(resp);
break;
}
}
/**
A Wrapper for movePiece, handling discord interactions
**/
function movePieceWrapper(interaction, moveCurGame, from, to, repl = null) {
let result = movePiece(moveCurGame, from, to, repl);
switch(result.action) {
case "promote_white": {
requireAction(moveCurGame, "promote_white", { piece: result.piece, to: result.to }, interaction);
} break;
case "promote_black": {
requireAction(moveCurGame, "promote_black", { piece: result.piece, to: result.to }, interaction);
} break;
case "turn_done": {
turnDoneWrapper(interaction, moveCurGame, "Waiting on Opponent");
} break;
}
}
const turnMinDuration = 5000;
async function turnDoneWrapper(interaction, game, message) {
if(!game.ai) {
// buffer if move too fast
let thisMove = Date.now();
let moveDiff = thisMove - gamesInterfaces[game.id].lastMove;
gamesInterfaces[game.id].lastMove = thisMove;
if(moveDiff < turnMinDuration) {
await sleep(turnMinDuration - moveDiff);
}
// update spectator message
updateSpectatorBoard(game.id);
if(game.solo && gamesInterfaces[game.id].lastInteraction && !game.blackEliminated && !game.whiteEliminated && !game.goldEliminated) {
try {
// update prev player board
await gamesInterfaces[game.id].lastInteraction.editReply(displayBoard(game, "Waiting on Opponent", [], gamesInterfaces[game.id].lastInteractionTurn));
} catch (err) {
console.log("Error during Board update. May happen due to a game restart.");
}
}
// update player message
if(interaction) {
await interaction.editReply(displayBoard(game, message));
busyWaiting(interaction, game.id, game.turn);
}
// inner turn done
turnDone(game, message)
} else {
// always run next turn
nextTurn(game);
}
}
function displayBoard(game, message, comp = [], turnOverride = null) {
return { content: renderBoard(game, message, turnOverride), components: comp, ephemeral: true, fetchReply: true };
}
function emptyMessage() {
return { content: "*Loading...*", components: [], ephemeral: true, fetchReply: true };
}
async function busyWaiting(interaction, gameid, player, firstMessage = false) {
await sleep(900);
while(true) {
await sleep(100);
// game disappeared
if(!games[gameid]) return;
// game concluded
if(games[gameid].concluded) {
interaction.editReply(displayBoard(games[gameid], "Game Concluded", [], player));
destroyGame(gameid);
return;
}
// attempt turn
if(games[gameid].turn == player) {
await sleep(100);
if(games[gameid].players[player] == null) {
console.log("INCORRECT BUSY WAITING");
return;
}
// if edit fails retry;
try {
if(interaction && interaction.replied) {
turnStart(interaction, gameid, player, "editreply", firstMessage);
return;
}
} catch (err) {
console.log(err);
await sleep(500);
}
}
}
}
async function delayedDestroy(gameid) {
await sleep(2000);
if(games[gameid]) destroyGame(gameid);
}
/**
**
**
**
**
^ Moved
v Not Moved
**
**
**
**/
// returns all possible ability targets as interactions
function getAbilityTargets(curGame, abilityPiece, arg1) {
let aPositions, aInteractions, aComponents = [];
let abilitySelection = nameToXY(arg1);
// provide options
switch(abilityPiece.name) {
default: case null:
aComponents = interactionsFromPositions([], arg1, "turnstart", 3);
break;
// Target targetable enemy
case "Fortune Teller":
case "Warlock":
aPositions = generatePositions(curGame.state, arg1);
aPositions = aPositions.filter(el => el[2]).map(el => [el[0], el[1]]).filter(el => curGame.state[el[1]][el[0]].enemyVisibleStatus < 7); // only select moves with targets
aComponents = interactionsFromPositions(aPositions, arg1, "turnstart", "investigate", 3);
break;
case "Infecting Wolf":
case "Saboteur Wolf":
case "Horseman of Pestilence":
aPositions = generatePositions(curGame.state, arg1);
aPositions = aPositions.filter(el => el[2]).map(el => [el[0], el[1]]); // only select moves with targets
aComponents = interactionsFromPositions(aPositions, arg1, "turnstart", abilityPiece.name == "Infecting Wolf" ? "infect" : "sabotage", 3);
break;
// Target targetable ally
case "Witch":
case "Royal Knight":
let modGame = stateClone(curGame.state);
let protTeam = modGame[abilitySelection.y][abilitySelection.x].team;
modGame[abilitySelection.y][abilitySelection.x].team = (protTeam + 1) % 2;
aPositions = generatePositions(modGame, arg1);
aPositions = aPositions.filter(el => el[2]).map(el => [el[0], el[1]]).filter(el => curGame.state[el[1]][el[0]].team == protTeam); // only select moves with targets
aComponents = interactionsFromPositions(aPositions, arg1, "turnstart", "protect", 3);
break;
// Target all enemy
case "Clairvoyant Fox":
aPositions = [];
for(let y = 0; y < curGame.height; y++) {
for(let x = 0; x < curGame.width; x++) {
let xyPiece = curGame.state[y][x];
if(xyPiece.name != null && xyPiece.team != abilityPiece.team && xyPiece.enemyVisibleStatus < 7) {
aPositions.push([x, y]);
}
}
}
aComponents = interactionsFromPositions(aPositions, arg1, "turnstart", "investigate", 3);
break;
case "Crowd Seeker":
case "Archivist Fox":
case "Psychic Wolf":
aPositions = [];
for(let y = 0; y < curGame.height; y++) {
for(let x = 0; x < curGame.width; x++) {
let xyPiece = curGame.state[y][x];
if(xyPiece.name != null && xyPiece.team != abilityPiece.team && xyPiece.enemyVisibleStatus < 4) {
aPositions.push([x, y]);
}
}
}
aComponents = interactionsFromPositions(aPositions, arg1, "turnstart", "investigate", 3);
break;
case "Aura Teller":
aPositions = [];
for(let y = 0; y < curGame.height; y++) {
for(let x = 0; x < curGame.width; x++) {
let xyPiece = curGame.state[y][x];
if(xyPiece.name != null && xyPiece.team != abilityPiece.team && xyPiece.enemyVisibleStatus < 5 && !xyPiece.atChecked) {
aPositions.push([x, y]);
}
}
}
aComponents = interactionsFromPositions(aPositions, arg1, "turnstart", "investigate", 3);
break;
// unenchanted enemy
case "Flute Player":
aPositions = [];
for(let y = 0; y < curGame.height; y++) {
for(let x = 0; x < curGame.width; x++) {
let xyPiece = curGame.state[y][x];
if(xyPiece.name != null && xyPiece.team != abilityPiece.team && !xyPiece.enchanted) {
aPositions.push([x, y]);
}
}
}
aComponents = interactionsFromPositions(aPositions, arg1, "turnstart", "enchant", 3);
break;
// undemonized enemy
case "Vampire":
aPositions = [];
for(let y = 0; y < curGame.height; y++) {
for(let x = 0; x < curGame.width; x++) {
let xyPiece = curGame.state[y][x];
if(xyPiece.name != null && xyPiece.team != abilityPiece.team && !xyPiece.demonized) {
aPositions.push([x, y]);
}
}
}
if(aPositions.length == 0) {
for(let y = 0; y < curGame.height; y++) {
for(let x = 0; x < curGame.width; x++) {
if(curGame.state[y][x].name == "Vampire") {
curGame.state[y][x] = getPiece("Empowered Vampire");
}
}
}
}
aComponents = interactionsFromPositions(aPositions, arg1, "turnstart", "demonize", 3);
break;
// Target all ally
case "Tanner":
case "Horseman of Famine":
aPositions = [];
for(let y = 0; y < curGame.height; y++) {
for(let x = 0; x < curGame.width; x++) {
let xyPiece = curGame.state[y][x];
if(xyPiece.name != null && xyPiece.team == abilityPiece.team) {
aPositions.push([x, y]);
}
}
}
aComponents = interactionsFromPositions(aPositions, arg1, "turnstart", abilityPiece.name == "Tanner" ? "disguise" : "disguise_hm", 3);
break;
// Dog
case "Dog":
aInteractions = [{ type: 2, label: "Back", style: 4, custom_id: "turnstart" }];
aInteractions.push({ type: 2, label: "Wolf Cub " + getUnicode("Pawn", 1), style: 3, custom_id: "transform-" + arg1 + "-Wolf Cub" });
aInteractions.push({ type: 2, label: "Fox " + getUnicode("Knight", 1), style: 3, custom_id: "transform-" + arg1 + "-Fox" });
aComponents = [{ type: 1, components: aInteractions }];
break;
// Ghast
case "Ghast":
aInteractions = [{ type: 2, label: "Back", style: 4, custom_id: "turnstart" }];
if((abilitySelection.y + 1) < curGame.height && curGame.state[abilitySelection.y + 1][abilitySelection.x].name == null) aInteractions.push({ type: 2, label: "Create Fireball (Below)", style: 3, custom_id: "createfb-" + arg1 + "-down" });
if((abilitySelection.y - 1) >= 0 && curGame.state[abilitySelection.y - 1][abilitySelection.x].name == null) aInteractions.push({ type: 2, label: "Create Fireball (Above)", style: 3, custom_id: "createfb-" + arg1 + "-up" });
aComponents = [{ type: 1, components: aInteractions }];
break;
// Ghast
case "FireballUp":
aInteractions = [{ type: 2, label: "Back", style: 4, custom_id: "turnstart" }];
let fbuName = xyToName(abilitySelection.x, abilitySelection.y - 1);
if((abilitySelection.y - 1) >= 0 && curGame.state[abilitySelection.y - 1][abilitySelection.x].team != 2) aInteractions.push({ type: 2, label: "Move Up (" + fbuName + ")", style: 3, custom_id: "teleport-" + arg1 + "-" + fbuName });
aComponents = [{ type: 1, components: aInteractions }];
break;
case "FireballDown":
aInteractions = [{ type: 2, label: "Back", style: 4, custom_id: "turnstart" }];
let fbdName = xyToName(abilitySelection.x, abilitySelection.y + 1);
if((abilitySelection.y + 1) < curGame.height && curGame.state[abilitySelection.y + 1][abilitySelection.x].team != 2) aInteractions.push({ type: 2, label: "Move Down (" + fbdName + ")", style: 3, custom_id: "teleport-" + arg1 + "-" + fbdName });
aComponents = [{ type: 1, components: aInteractions }];
break;
// Bloody Butcher
case "Bloody Butcher":
aInteractions = [{ type: 2, label: "Back", style: 4, custom_id: "turnstart" }];
aInteractions.push({ type: 2, label: "Reveal", style: 3, custom_id: "transformreveal-" + arg1 + "-Revealed Bloody Butcher" });
aComponents = [{ type: 1, components: aInteractions }];
break;
// Hooker - Surrounding fields
case "Bat":
case "Hooker":
aInteractions = [];
if(inBounds(curGame.width, curGame.height, abilitySelection.x, abilitySelection.y-1) && curGame.state[abilitySelection.y-1][abilitySelection.x].team == abilityPiece.team) aInteractions.push([abilitySelection.x, abilitySelection.y-1]);
if(inBounds(curGame.width, curGame.height, abilitySelection.x, abilitySelection.y+1) && curGame.state[abilitySelection.y+1][abilitySelection.x].team == abilityPiece.team) aInteractions.push([abilitySelection.x, abilitySelection.y+1]);
if(inBounds(curGame.width, curGame.height, abilitySelection.x-1, abilitySelection.y-1) && curGame.state[abilitySelection.y-1][abilitySelection.x-1].team == abilityPiece.team) aInteractions.push([abilitySelection.x-1, abilitySelection.y-1]);
if(inBounds(curGame.width, curGame.height, abilitySelection.x-1, abilitySelection.y) && curGame.state[abilitySelection.y][abilitySelection.x-1].team == abilityPiece.team) aInteractions.push([abilitySelection.x-1, abilitySelection.y]);
if(inBounds(curGame.width, curGame.height, abilitySelection.x-1, abilitySelection.y+1) && curGame.state[abilitySelection.y+1][abilitySelection.x-1].team == abilityPiece.team) aInteractions.push([abilitySelection.x-1, abilitySelection.y+1]);
if(inBounds(curGame.width, curGame.height, abilitySelection.x+1, abilitySelection.y-1) && curGame.state[abilitySelection.y-1][abilitySelection.x+1].team == abilityPiece.team) aInteractions.push([abilitySelection.x+1, abilitySelection.y-1]);
if(inBounds(curGame.width, curGame.height, abilitySelection.x+1, abilitySelection.y) && curGame.state[abilitySelection.y][abilitySelection.x+1].team == abilityPiece.team) aInteractions.push([abilitySelection.x+1, abilitySelection.y]);
if(inBounds(curGame.width, curGame.height, abilitySelection.x+1, abilitySelection.y+1) && curGame.state[abilitySelection.y+1][abilitySelection.x+1].team == abilityPiece.team) aInteractions.push([abilitySelection.x+1, abilitySelection.y+1]);
aInteractions = aInteractions.map(el => {
return new Object({ type: 2, label: xyToName(el[0], el[1]), style: 3, custom_id: "hide-" + arg1 + "-" + xyToName(el[0], el[1]) });
});
aInteractions.unshift({ type: 2, label: "Back", style: 4, custom_id: "turnstart" });
aComponents = [{ type: 1, components: aInteractions.slice(0, 5) }];
if(aInteractions.length > 5) aComponents.push({ type: 1, components: aInteractions.slice(5, 10) });
break;
// HoD - Surrounding fields
case "Horseman of Death":
aInteractions = [];
if(inBounds(curGame.width, curGame.height, abilitySelection.x, abilitySelection.y-1) && curGame.state[abilitySelection.y-1][abilitySelection.x].team == 0) aInteractions.push([abilitySelection.x, abilitySelection.y-1]);
if(inBounds(curGame.width, curGame.height, abilitySelection.x, abilitySelection.y+1) && curGame.state[abilitySelection.y+1][abilitySelection.x].team == 0) aInteractions.push([abilitySelection.x, abilitySelection.y+1]);
if(inBounds(curGame.width, curGame.height, abilitySelection.x-1, abilitySelection.y-1) && curGame.state[abilitySelection.y-1][abilitySelection.x-1].team == 0) aInteractions.push([abilitySelection.x-1, abilitySelection.y-1]);
if(inBounds(curGame.width, curGame.height, abilitySelection.x-1, abilitySelection.y) && curGame.state[abilitySelection.y][abilitySelection.x-1].team == 0) aInteractions.push([abilitySelection.x-1, abilitySelection.y]);
if(inBounds(curGame.width, curGame.height, abilitySelection.x-1, abilitySelection.y+1) && curGame.state[abilitySelection.y+1][abilitySelection.x-1].team == 0) aInteractions.push([abilitySelection.x-1, abilitySelection.y+1]);
if(inBounds(curGame.width, curGame.height, abilitySelection.x+1, abilitySelection.y-1) && curGame.state[abilitySelection.y-1][abilitySelection.x+1].team == 0) aInteractions.push([abilitySelection.x+1, abilitySelection.y-1]);
if(inBounds(curGame.width, curGame.height, abilitySelection.x+1, abilitySelection.y) && curGame.state[abilitySelection.y][abilitySelection.x+1].team == 0) aInteractions.push([abilitySelection.x+1, abilitySelection.y]);
if(inBounds(curGame.width, curGame.height, abilitySelection.x+1, abilitySelection.y+1) && curGame.state[abilitySelection.y+1][abilitySelection.x+1].team == 0) aInteractions.push([abilitySelection.x+1, abilitySelection.y+1]);
if(inBounds(curGame.width, curGame.height, abilitySelection.x, abilitySelection.y-1) && curGame.state[abilitySelection.y-1][abilitySelection.x].team == 1) aInteractions.push([abilitySelection.x, abilitySelection.y-1]);
if(inBounds(curGame.width, curGame.height, abilitySelection.x, abilitySelection.y+1) && curGame.state[abilitySelection.y+1][abilitySelection.x].team == 1) aInteractions.push([abilitySelection.x, abilitySelection.y+1]);
if(inBounds(curGame.width, curGame.height, abilitySelection.x-1, abilitySelection.y-1) && curGame.state[abilitySelection.y-1][abilitySelection.x-1].team == 1) aInteractions.push([abilitySelection.x-1, abilitySelection.y-1]);
if(inBounds(curGame.width, curGame.height, abilitySelection.x-1, abilitySelection.y) && curGame.state[abilitySelection.y][abilitySelection.x-1].team == 1) aInteractions.push([abilitySelection.x-1, abilitySelection.y]);
if(inBounds(curGame.width, curGame.height, abilitySelection.x-1, abilitySelection.y+1) && curGame.state[abilitySelection.y+1][abilitySelection.x-1].team == 1) aInteractions.push([abilitySelection.x-1, abilitySelection.y+1]);
if(inBounds(curGame.width, curGame.height, abilitySelection.x+1, abilitySelection.y-1) && curGame.state[abilitySelection.y-1][abilitySelection.x+1].team == 1) aInteractions.push([abilitySelection.x+1, abilitySelection.y-1]);
if(inBounds(curGame.width, curGame.height, abilitySelection.x+1, abilitySelection.y) && curGame.state[abilitySelection.y][abilitySelection.x+1].team == 1) aInteractions.push([abilitySelection.x+1, abilitySelection.y]);
if(inBounds(curGame.width, curGame.height, abilitySelection.x+1, abilitySelection.y+1) && curGame.state[abilitySelection.y+1][abilitySelection.x+1].team == 1) aInteractions.push([abilitySelection.x+1, abilitySelection.y+1]);
aInteractions = aInteractions.map(el => {
return new Object({ type: 2, label: xyToName(el[0], el[1]), style: 3, custom_id: "destroy-" + arg1 + "-" + xyToName(el[0], el[1]) });
});
aInteractions.unshift({ type: 2, label: "Back", style: 4, custom_id: "turnstart" });
aComponents = [{ type: 1, components: aInteractions.slice(0, 5) }];
if(aInteractions.length > 5) aComponents.push({ type: 1, components: aInteractions.slice(5, 10) });
break;
// Alpha Wolf - All allies with available slot
case "Alpha Wolf":
aPositions = [];
for(let y = 1; y < curGame.height; y++) {
for(let x = 0; x < curGame.width; x++) {
let xyPiece = curGame.state[y][x];
let x0Piece = curGame.state[0][x];
if(xyPiece.name != null && xyPiece.team == abilityPiece.team && x0Piece.name == null) {
aPositions.push([x, y]);
}
}
}
aComponents = interactionsFromPositions(aPositions, arg1, "turnstart", "recall", 3);
break;
// HoW Wolf - All allies with available slot
case "Horseman of War":
aPositions = [];
for(let y = 1; y < curGame.height; y++) {
for(let x = 0; x < curGame.width; x++) {
let xyPiece = curGame.state[y][x];
let x0Piece = curGame.state[2][x];
if(xyPiece.name != null && xyPiece.team == abilityPiece.team && x0Piece.name == null) {
aPositions.push([x, y]);
}
}
}
aComponents = interactionsFromPositions(aPositions, arg1, "turnstart", "cecall", 3);
break;
}
return aComponents;
}
function countSoloPieces(game) {
let counter = 0;
for(let y = 0; y < game.height; y++) {
for(let x = 0; x < game.width; x++) {
if(game.state[y][x].team == 2) counter++;
}
}
return counter;
}
/* New Slash Command */
client.on('interactionCreate', async interaction => {
if(interaction.isButton()) {
try {
console.log("INTERACTION", interaction.customId);
let type = interaction.customId.split("-")[0];
let arg1 = interaction.customId.split("-")[1];
let arg2 = interaction.customId.split("-")[2];
let gameID = getPlayerGameId(interaction.member.id);
let curGame = games[gameID];
if(type != "deny" && type != "accept") {
// check if its still a valid message
if(gamesInterfaces[gameID].interfaces[curGame.turn] && gamesInterfaces[gameID].interfaces[curGame.turn].msg != interaction.message.id) {
console.log(gamesInterfaces[gameID].interfaces[curGame.turn].msg);
console.log(interaction.message.id);
console.log("OUTDATED MESSAGE");
interaction.update({content: "✘", components: []});
return;
}
gamesInterfaces[gameID].lastInteraction = interaction;
gamesInterfaces[gameID].lastInteractionTurn = curGame.turn;
}
switch(type) {
// deny challenge
case "deny":
if(!isOutstanding(interaction.member.id)) {
interaction.reply({ content: "**Error:** You have no outstanding challenges!", ephemeral: true });
} else {
let id = getPlayerGameId(interaction.member.id);
concludeGame(id);
destroyGame(id);
interaction.channel.send("**Challenge:** " + interaction.member.user.username + " denied the challenge!");
console.log("DENY");
interaction.message.delete();
}
break;
case "accept":
if(!isOutstanding(interaction.member.id)) {
interaction.reply({ content: "**Error:** You have no outstanding challenges!", ephemeral: true });
} else {
let challenge = outstandingChallenge.filter(el => el[0] == interaction.member.id)[0];
console.log("CHALLENGE", challenge);
interaction.channel.send("**Challenge**: <@" + challenge[1] + "> Your challenge has been accepted by <@" + interaction.member.id + ">!");
interaction.reply(displayBoard(games[challenge[2]], "Waiting on Opponent", [], 1));
busyWaiting(interaction, challenge[2], 1, true);
outstandingChallenge = outstandingChallenge.filter(el => el[0] != interaction.member.id);
interaction.message.delete();
}
break;
// start game if starting is black
case "start":
await interaction.update(displayBoard(curGame, "Starting Game", []));
turnDoneWrapper(interaction, curGame, "Waiting on Opponent");
break;
// select a piece; show available moves
case "select":
let selection = nameToXY(arg1);
let currentGame = gameClone(curGame);
// generate list of possible moves
//console.log("BOARD AT SELECT", currentGame.state.map(el => el.map(el2 => el2.name).join(",")).join("\n"));
let positions = generatePositions(currentGame.state, arg1);
console.log("AVAILABLE POSITIONS", positions.map(el => xyToName(el[0], el[1])).join(","));
let components = interactionsFromPositions(positions, arg1, "turnmove", "move");
//console.log(components);
currentGame.selectedPiece = shallowCopy(currentGame.state[selection.y][selection.x]);
currentGame.state[selection.y][selection.x] = getPiece("Selected");
interaction.update(displayBoard(currentGame, "Pick a Move", components));
break;
// move a piece to another location; update board
case "move":
try {
await interaction.update(displayBoard(curGame, "Executing Move", []));
movePieceWrapper(interaction, games[gameID], arg1, arg2);
} catch (err) {
console.log(err);
console.log("ERROR ON MOVE. IGNORING");
}
break;
// promote a piece; update board
case "promote":
await interaction.update(displayBoard(curGame, "Executing Move", []));
movePieceWrapper(interaction, games[gameID], arg1, arg1, getPiece(arg2));
break;
// back to turn start menu
case "turnstart":
turnStart(interaction, gameID, curGame.turn, "update");
break;
// back to turn move menu
case "turnmove":
// continue
turnMove(interaction, gameID, curGame.turn, "update");
break;
// select an ability piece; show available actions
case "ability":
let abilitySelection = nameToXY(arg1);
let abilityPiece = curGame.state[abilitySelection.y][abilitySelection.x];
// get ability interactions
let aComponents = getAbilityTargets(curGame, abilityPiece, arg1);
// update message
interaction.update(displayBoard(curGame, "Pick a Target", aComponents));
break;
/** ACTIVE ABILITIES **/
// investigate
case "investigate":
let investigatorC = nameToXY(arg1);
let investigator = curGame.state[investigatorC.y][investigatorC.x];
let investTarget = nameToXY(arg2);
executeActiveAbility(curGame, "Invest", [investigatorC.x, investigatorC.y], [investTarget.x, investTarget.y]);
turnMove(interaction, gameID, curGame.turn, "update")
break;
// transform
case "transform":
let transformer = nameToXY(arg1);
executeActiveAbility(curGame, "Transform", [transformer.x, transformer.y], arg2);
turnMove(interaction, gameID, curGame.turn, "update");
break;
// transform
case "createfb":
let creator = nameToXY(arg1);
executeActiveAbility(curGame, "CreateFireball", [creator.x, creator.y], arg2);
if(countSoloPieces(curGame) == 1) {
await interaction.update(displayBoard(curGame, "Skipping Move"));
turnDoneWrapper(interaction, curGame, "Waiting on Opponent", true); // no move after ability use
} else {
turnMove(interaction, gameID, curGame.turn, "update");
}
break;
case "teleport":
let teleportFrom = nameToXY(arg1);
let teleportTo = nameToXY(arg2)
executeActiveAbility(curGame, "Teleport", [teleportFrom.x, teleportFrom.y], [teleportTo.x, teleportTo.y]);
turnMove(interaction, gameID, curGame.turn, "update");
break;
// transform reveal
case "transformreveal":
let transformer2 = nameToXY(arg1);
executeActiveAbility(curGame, "TransformReveal", [transformer2.x, transformer2.y], arg2);
turnMove(interaction, gameID, curGame.turn, "update");
break;
// infect
case "infect":
let iwSource = nameToXY(arg1);
let iwTarget = nameToXY(arg2);
executeActiveAbility(curGame, "Infect", [iwSource.x, iwSource.y], [iwTarget.x, iwTarget.y]);
turnMove(interaction, gameID, curGame.turn, "update");
break;
// active protect
case "protect":
let protectTarget = nameToXY(arg2);
executeActiveAbility(curGame, "Protect", null, [protectTarget.x, protectTarget.y]);
turnMove(interaction, gameID, curGame.turn, "update");
break;
// sabotage
case "sabotage":
let sabotageTarget = nameToXY(arg2);
executeActiveAbility(curGame, "Sabotage", null, [sabotageTarget.x, sabotageTarget.y]);
turnMove(interaction, gameID, curGame.turn, "update");
break;
// enchant
case "enchant":
let enchantSource = nameToXY(arg1);
let enchantTarget = nameToXY(arg2);
executeActiveAbility(curGame, "Enchant", [enchantSource.x, enchantSource.y], [enchantTarget.x, enchantTarget.y]);
if(countSoloPieces(curGame) == 1) {
await interaction.update(displayBoard(curGame, "Skipping Move"));
turnDoneWrapper(interaction, curGame, "Waiting on Opponent", true); // no move after ability use
} else {
turnMove(interaction, gameID, curGame.turn, "update");
}
break;
// demonize
case "demonize":
let demonizeSource = nameToXY(arg1);
let demonizeTarget = nameToXY(arg2);
executeActiveAbility(curGame, "Demonize", [demonizeSource.x, demonizeSource.y], [demonizeTarget.x, demonizeTarget.y]);
if(countSoloPieces(curGame) == 1) {
await interaction.update(displayBoard(curGame, "Skipping Move"));
turnDoneWrapper(interaction, curGame, "Waiting on Opponent", true); // no move after ability use
} else {
turnMove(interaction, gameID, curGame.turn, "update");
}
break;
// hooker hide
case "hide":
let hideSubject = nameToXY(arg1);
let hideTarget = nameToXY(arg2);
executeActiveAbility(curGame, "Hide", [hideSubject.x, hideSubject.y], [hideTarget.x, hideTarget.y]);
turnMove(interaction, gameID, curGame.turn, "update");
break;
// hod destroy
case "destroy":
let destroySubject = nameToXY(arg1);
let destroyTarget = nameToXY(arg2);
executeActiveAbility(curGame, "Destroy", [destroySubject.x, destroySubject.y], [destroyTarget.x, destroyTarget.y]);
turnMove(interaction, gameID, curGame.turn, "update");
break;
// tanner tan
case "disguise":
// show tan options
let disInteractions = [{ type: 2, label: "Back", style: 4, custom_id: "ability-" + arg1 }];
disInteractions.push({ type: 2, label: "Wolf " + getUnicode("Pawn", 1), style: 3, custom_id: "tan-" + arg2 + "-Wolf" });
disInteractions.push({ type: 2, label: "Psychic Wolf " + getUnicode("King", 1), style: 3, custom_id: "tan-" + arg2 + "-Psychic Wolf" });
disInteractions.push({ type: 2, label: "Fox " + getUnicode("Knight", 1), style: 3, custom_id: "tan-" + arg2 + "-Fox" });
disInteractions.push({ type: 2, label: "Scared Wolf " + getUnicode("Rook", 1), style: 3, custom_id: "tan-" + arg2 + "-Scared Wolf" });
let disComponents = [{ type: 1, components: disInteractions }];
// update message
interaction.update(displayBoard(curGame, "Pick a Disguise", disComponents));
break;
// horseman tan
case "disguise_hm":
// show tan options
let dis2Interactions = [{ type: 2, label: "Back", style: 4, custom_id: "ability-" + arg1 }];
dis2Interactions.push({ type: 2, label: "Lamb " + getUnicode("Pawn", 1), style: 3, custom_id: "tan-" + arg2 + "-Lamb" });
dis2Interactions.push({ type: 2, label: "Horseman of War " + getUnicode("King", 1), style: 3, custom_id: "tan-" + arg2 + "-Horseman of War" });
dis2Interactions.push({ type: 2, label: "Horseman of Death " + getUnicode("King", 1), style: 3, custom_id: "tan-" + arg2 + "-Horseman of Death" });
dis2Interactions.push({ type: 2, label: "Horseman of Pestilence " + getUnicode("Rook", 1), style: 3, custom_id: "tan-" + arg2 + "-Horseman of Pestilence" });
let dis2Components = [{ type: 1, components: dis2Interactions }];
// update message
interaction.update(displayBoard(curGame, "Pick a Disguise", dis2Components));
break;
// tanner tan
case "tan":
let tanSubject = nameToXY(arg1);
executeActiveAbility(curGame, "Tan", null, [tanSubject, arg2], true);
turnMove(interaction, gameID, curGame.turn, "update")
break;
// alpha wolf recall
case "recall":
let recallSubject = nameToXY(arg2);
executeActiveAbility(curGame, "Recall", null, [recallSubject.x, recallSubject.y]);
turnMove(interaction, gameID, curGame.turn, "update");
break;
// HoW cecall
case "cecall":
let cecallSubject = nameToXY(arg2);
executeActiveAbility(curGame, "Cecall", null, [cecallSubject.x, cecallSubject.y]);
turnMove(interaction, gameID, curGame.turn, "update");
break;
}
} catch(err) {
console.log("INTERACTION ERROR");
console.log(err);
}
}
if(!interaction.isCommand()) return; // ignore non-slash commands
let soloGame = false;
let dailyGame = false;
switch(interaction.commandName) {
case "ping":
// Send pinging message
interaction.reply({ content: "**Ping:** Ping", fetchReply: true, ephemeral: true })
.then(m => {
// Get values
let latency = m.createdTimestamp - interaction.createdTimestamp;
let ping = Math.round(client.ws.ping);
interaction.editReply("**Ping:** Pong! Latency is " + latency + "ms. API Latency is " + ping + "ms");
})
break;
case "help":
// Send pinging message
interaction.reply({ content: findEmoji("WWRess") + " **WWRess** " + findEmoji("WWRess") + "\nWWRess is a variant of chess, played on a 5x5 grid. In each game, each of the two sides (white/town & black/wolves) gets 5 pieces. Each piece comes with a movement type (Pawn, King, Knight, Rook or Queen) and an ability. Each team has 17 unique pieces (6 pawns, 4 kings, 3 knights, 3 rooks, 1 queen). The pieces of the teams differ, so the two sides usually have completely different abilities. Look up what pieces there are using `/pieces <team name>`.\n\nEach turn consists of two actions: first, using an active ability (if a piece with an active ability is available) and second, moving a piece. The game is won if the enemy cannot make a move (Kings are not part of the win condition in any way).\n\nThe only available special move is Pawn Promotion.\n\nInitially, all enemy pieces are hidden. The movement type of enemy pieces will automatically be marked where possible (only a knight can jump so that move makes the piece clearly identifiable as a knight (though not which knight), moving a single step forward does not) and additionally investigative pieces may be used to reveal them. Sometimes this is not fully accurate, as some pieces can change role (e.g. Dog) and some can be disguised (e.g. Sneaking Wolf).\n\nStart a game against the AI with `/play`, challenge another player with `/challenge <name>`. Accept or deny a challenge with `/accept` and `/deny`. Use `/resign` to give up." });
break;
case "pieces":
let team = interaction.options.get('team').value;
let pieces = [];
let teamColor = "White";
let teamName = "";
let teamColorDec = "";
switch(team) {
case "townsfolk":
pieces = [["Citizen","Ranger","Huntress","Bartender⁎","Fortune Apprentice","Child","Bard⁎⁎","Butcher**"],["Hooker⁎","Idiot","Crowd Seeker","Aura Teller"],["Royal Knight","Alcoholic⁎","Amnesiac"],["Fortune Teller","Runner","Witch"],["Cursed Civilian⁎"],[]];
teamColor = "White";
teamName = "Townsfolk (White)";
teamColorDec = 16777215;
break;
case "werewolf":
pieces = [["Wolf","Wolf Cub","Tanner","Archivist Fox","Recluse","Dog","Bloody Butcher⁎⁎","Packless Wolf⁎⁎"],["Infecting Wolf⁎","Alpha Wolf","Psychic Wolf","Sneaking Wolf"],["Direwolf⁎","Clairvoyant Fox","Fox"],["Warlock","Scared Wolf","Saboteur Wolf"],["White Werewolf⁎"],[]];
teamColor = "Black";
teamName = "Werewolves (Black)";
teamColorDec = 1;
break;
case "solo":
pieces = [["Zombie","Corpse","Undead","Angel","Apprentice","Lamb"],["Bat","Ghast","Horseman of Death","Horseman of War"],[],["Flute Player","Vampire","Apprentice Vampire","Horseman of Pestilence","Horseman of Famine"],[],["Bear", "Angry Bear"]];
teamColor = "Gold";
teamName = "Solo (Gold)";
teamColorDec = 14850359;
break;
}
let limitations = [false, false];
let fields = ["Pawns","Kings","Knights","Rooks","Queens","Bishops"];
let embed = { title: findEmoji("WWRess") + " **" + teamName + " Piece List:** " + findEmoji("WWRess"), color: teamColorDec, fields: [] };
for(let i = 0; i < pieces.length; i++) {
let field = { name: fields[i], value: "" };
for(let j = 0; j < pieces[i].length; j++) {
let pieceName = pieces[i][j].replace(/\⁎/g, "");
let limitation = (pieces[i][j].match(/\⁎/g) || []).length
limitations[limitation - 1] = true;
field.value += findEmoji(teamColor + getChessName(pieceName)) + " " + findEmoji(pieceName) + " **" + pieces[i][j] + ":** " + getAbilityText(pieceName) + "\n";
}
if(field.value.length > 0) {
embed.fields.push(field);
}
}
if(limitations.filter(el => el).length > 0) {
let field = { name: "** **", value: "" };
if(limitations[0]) field.value += "\⁎ Not available in simplified mode.\n";
if(limitations[1]) field.value += "\⁎\⁎ Only available in advanced mode.\n";
embed.fields.push(field);
}
// Send pinging message
//console.log(embed);
interaction.reply({ embeds: [embed] });
break;
case "play_daily":
dailyGame = true;
case "play_solo":
soloGame = true;
case "play":
case "boss":
if(isPlaying(interaction.member.id)) {
interaction.reply({ content: "**Error:** You're already in a game! If you do not believe this is accurate use `/resign`.", ephemeral: true });
} else {
let players;
let rand = Math.floor(Math.random() * 100);
let teamSelArg = interaction.options.get("team")?.value ?? null;
let soloArg = interaction.options.get("solo")?.value ?? null;
let modeArg = interaction.options.get("mode")?.value ?? null;
let aiArg = interaction.options.get("ai_strength")?.value ?? null;
if(aiArg == "weak") {