-
Notifications
You must be signed in to change notification settings - Fork 27
/
game.js
103 lines (95 loc) · 2.57 KB
/
game.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
import { capitalize } from './utils.js';
export function getResult(p1, p2) {
let gameResult;
if (RPSChoices[p1.objectName] && RPSChoices[p1.objectName][p2.objectName]) {
// o1 wins
gameResult = {
win: p1,
lose: p2,
verb: RPSChoices[p1.objectName][p2.objectName],
};
} else if (
RPSChoices[p2.objectName] &&
RPSChoices[p2.objectName][p1.objectName]
) {
// o2 wins
gameResult = {
win: p2,
lose: p1,
verb: RPSChoices[p2.objectName][p1.objectName],
};
} else {
// tie -- win/lose don't
gameResult = { win: p1, lose: p2, verb: 'tie' };
}
return formatResult(gameResult);
}
function formatResult(result) {
const { win, lose, verb } = result;
return verb === 'tie'
? `<@${win.id}> and <@${lose.id}> draw with **${win.objectName}**`
: `<@${win.id}>'s **${win.objectName}** ${verb} <@${lose.id}>'s **${lose.objectName}**`;
}
// this is just to figure out winner + verb
const RPSChoices = {
rock: {
description: 'sedimentary, igneous, or perhaps even metamorphic',
virus: 'outwaits',
computer: 'smashes',
scissors: 'crushes',
},
cowboy: {
description: 'yeehaw~',
scissors: 'puts away',
wumpus: 'lassos',
rock: 'steel-toe kicks',
},
scissors: {
description: 'careful ! sharp ! edges !!',
paper: 'cuts',
computer: 'cuts cord of',
virus: 'cuts DNA of',
},
virus: {
description: 'genetic mutation, malware, or something inbetween',
cowboy: 'infects',
computer: 'corrupts',
wumpus: 'infects',
},
computer: {
description: 'beep boop beep bzzrrhggggg',
cowboy: 'overwhelms',
paper: 'uninstalls firmware for',
wumpus: 'deletes assets for',
},
wumpus: {
description: 'the purple Discord fella',
paper: 'draws picture on',
rock: 'paints cute face on',
scissors: 'admires own reflection in',
},
paper: {
description: 'versatile and iconic',
virus: 'ignores',
cowboy: 'gives papercut to',
rock: 'covers',
},
};
export function getRPSChoices() {
return Object.keys(RPSChoices);
}
// Function to fetch shuffled options for select menu
export function getShuffledOptions() {
const allChoices = getRPSChoices();
const options = [];
for (let c of allChoices) {
// Formatted for select menus
// https://discord.com/developers/docs/interactions/message-components#select-menu-object-select-option-structure
options.push({
label: capitalize(c),
value: c.toLowerCase(),
description: RPSChoices[c]['description'],
});
}
return options.sort(() => Math.random() - 0.5);
}