|
1 | | -import { ComponentBuilder } from "@oceanicjs/builders"; |
2 | | -import { ComponentInteraction, ComponentTypes, MessageActionRow, MessageFlags } from "oceanic.js"; |
| 1 | +import { ComponentInteraction, ComponentTypes, MessageFlags } from "oceanic.js"; |
3 | 2 |
|
4 | 3 | import { deleteMessage, sendMessage } from "../client.js"; |
5 | | -import { PickCardSelect } from "../components.js"; |
6 | | -import { cardEmotes, cards, colors, SelectIDs, uniqueVariants, variants } from "../constants.js"; |
| 4 | +import { CardColorSelect, PickCardSelect } from "../components.js"; |
| 5 | +import { cardEmotes, cards, colors, uniqueVariants, variants } from "../constants.js"; |
7 | 6 | import database from "../database.js"; |
8 | 7 | import { config } from "../index.js"; |
9 | 8 | import timeouts from "../timeouts.js"; |
@@ -124,19 +123,8 @@ export function onCardPlayed(ctx: ComponentInteraction<ComponentTypes.STRING_SEL |
124 | 123 | if (uniqueVariants.includes(color)) { |
125 | 124 | return ctx.createFollowup({ |
126 | 125 | content: "Choose a color", |
127 | | - components: new ComponentBuilder<MessageActionRow>() |
128 | | - .addSelectMenu({ |
129 | | - customID: SelectIDs.CHOOSE_COLOR, |
130 | | - options: Object.values(colors).map(c => { |
131 | | - return { |
132 | | - label: toTitleCase(c), |
133 | | - value: `${c}-${color}` |
134 | | - }; |
135 | | - }), |
136 | | - type: ComponentTypes.STRING_SELECT, |
137 | | - }) |
138 | | - .toJSON() |
139 | | - }); |
| 126 | + components: CardColorSelect(color as typeof uniqueVariants[number]) |
| 127 | + }).then(() => ctx.deleteOriginal()); |
140 | 128 | } |
141 | 129 |
|
142 | 130 | if (cardPlayed === "skip" && (!game.settings.allowSkipping || (game.lastPlayer.id !== game.currentPlayer && !wasLastTurnBlocked(game)))) |
@@ -183,33 +171,41 @@ You drew ${cardEmotes[newCards[0]]}`, |
183 | 171 | game.cards[ctx.member.id].splice(game.cards[ctx.member.id].indexOf(cardPlayed), 1); |
184 | 172 | delete game.saboteurs[game.lastPlayer.id]; |
185 | 173 |
|
186 | | - if (variant === "reverse") { |
187 | | - game.players = game.players.reverse(); |
188 | | - if (game.players.length === 2) { |
189 | | - game.currentPlayer = next(game.players, game.players.indexOf(game.currentPlayer)); |
190 | | - extraInfo = `**${getUsername(game.currentPlayer, true, ctx.guild)}** was skipped`; |
| 174 | + switch (variant) { |
| 175 | + case "reverse": { |
| 176 | + game.players = game.players.reverse(); |
| 177 | + if (game.players.length === 2) { |
| 178 | + game.currentPlayer = next(game.players, game.players.indexOf(game.currentPlayer)); |
| 179 | + extraInfo = `**${getUsername(game.currentPlayer, true, ctx.guild)}** was skipped`; |
| 180 | + } |
| 181 | + break; |
191 | 182 | } |
192 | | - } |
193 | | - |
194 | | - if (variant === "+2") { |
195 | | - const nextPlayer = next(game.players, game.players.indexOf(ctx.member.id)); |
196 | | - if (game.settings.allowStacking && game.cards[nextPlayer].some(c => c === "+4" || c.endsWith("+2"))) { |
197 | | - game.drawStackCounter += 2; |
| 183 | + case "+2": { |
| 184 | + const nextPlayer = next(game.players, game.players.indexOf(ctx.member.id)); |
| 185 | + if (game.settings.allowStacking && game.cards[nextPlayer].some(c => c === "+4" || c.endsWith("+2"))) { |
| 186 | + game.drawStackCounter += 2; |
| 187 | + } |
| 188 | + else if (game.cards[ctx.member.id].length > 0) { |
| 189 | + const { cards, newDeck } = game.draw(2 + game.drawStackCounter); |
| 190 | + game.cards[nextPlayer].push(...cards); |
| 191 | + game.deck = newDeck; |
| 192 | + extraInfo = `**${getUsername(nextPlayer, true, ctx.guild)}** drew **${2 + game.drawStackCounter}** cards and was skipped`; |
| 193 | + game.drawStackCounter = 0; |
| 194 | + game.currentPlayer = next(game.players, game.players.indexOf(game.currentPlayer)); |
| 195 | + } |
| 196 | + break; |
198 | 197 | } |
199 | | - else if (game.cards[ctx.member.id].length > 0) { |
200 | | - const { cards, newDeck } = game.draw(2 + game.drawStackCounter); |
201 | | - game.cards[nextPlayer].push(...cards); |
202 | | - game.deck = newDeck; |
203 | | - extraInfo = `**${getUsername(nextPlayer, true, ctx.guild)}** drew **${2 + game.drawStackCounter}** cards and was skipped`; |
204 | | - game.drawStackCounter = 0; |
| 198 | + case "block": { |
205 | 199 | game.currentPlayer = next(game.players, game.players.indexOf(game.currentPlayer)); |
| 200 | + extraInfo = `**${getUsername(game.currentPlayer, true, ctx.guild)}** was skipped`; |
| 201 | + break; |
| 202 | + } |
| 203 | + case "7": |
| 204 | + case "0": { |
| 205 | + // TODO |
206 | 206 | } |
207 | 207 | } |
208 | 208 |
|
209 | | - if (variant === "block") { |
210 | | - game.currentPlayer = next(game.players, game.players.indexOf(game.currentPlayer)); |
211 | | - extraInfo = `**${getUsername(game.currentPlayer, true, ctx.guild)}** was skipped`; |
212 | | - } |
213 | 209 | if (game.settings.allowSkipping) |
214 | 210 | game.currentPlayer = next(game.players, game.players.indexOf(game.currentPlayer)); |
215 | 211 | ctx.deleteOriginal(); |
|
0 commit comments