@@ -9,6 +9,35 @@ import { Card, DebugState, DebugStateType, UnoGame } from "../types.js";
99import { getPlayerMember , hasStarted , SettingsSelectMenu , shuffle , toTitleCase , updateStats , without } from "../utils.js" ;
1010import { games , makeStartMessage , sendGameMessage } from "./index.js" ;
1111
12+ export function makeDrawCardProxy ( startedGame : UnoGame < true > , userId : string , t , p , n ) {
13+ t [ p ] = n ;
14+ if ( p === "length" ) startedGame . _debug . pushState ( {
15+ type : "set-cards" ,
16+ newState : t ,
17+ meetsEndCondition : [ p === "length" && n === 0 , n ]
18+ } ) ;
19+ if ( p === "length" && n === 0 ) {
20+ // TODO: check that the card shown here is the correct one and dont just pray it is
21+ const card = startedGame . currentCard ;
22+ const winner = getPlayerMember ( startedGame , userId ) ;
23+ timeouts . delete ( startedGame . channelID ) ;
24+ updateStats ( startedGame , userId ) ;
25+ delete games [ startedGame . channelID ] ;
26+ sendMessage ( startedGame . channelID , {
27+ content : `**${ winner ?. nick ?? winner ?. username } ** played ${ cardEmotes [ card ] } ${ toTitleCase ( card ) } , and won` ,
28+ components : new ComponentBuilder < MessageActionRow > ( )
29+ . addInteractionButton ( {
30+ style : ButtonStyles . SUCCESS ,
31+ label : "gg" ,
32+ emoji : ComponentBuilder . emojiToPartial ( "🏆" , "default" ) ,
33+ disabled : true ,
34+ customID : "we-have-a-nerd-here🤓"
35+ } )
36+ . toJSON ( )
37+ } ) ;
38+ }
39+ }
40+
1241const drawUntilNotSpecial = ( game : UnoGame < true > ) => {
1342 let card = game . draw ( 1 ) . cards [ 0 ] ;
1443 while ( uniqueVariants . includes ( card ) ) {
@@ -52,7 +81,7 @@ export function startGame(game: UnoGame<false>, automatic: boolean) {
5281 timeouts . delete ( game . channelID ) ;
5382 games [ game . channelID ] . started = true ;
5483
55- const settings = game . settings || { ...defaultSettings } ;
84+ const settings = { ...defaultSettings , ... game . settings } ;
5685 const playerList = game . settings . randomizePlayerList ? shuffle ( game . players ) : game . players ;
5786 const players = new Proxy ( playerList , {
5887 deleteProperty ( t , p ) {
@@ -86,12 +115,15 @@ export function startGame(game: UnoGame<false>, automatic: boolean) {
86115 uid : game . uid ,
87116 started : true ,
88117 message : game . message ,
118+ // TODO: proxy to push to playersWhoLeft?
89119 players,
120+ playersWhoLeft : [ ] ,
90121 host : game . host ,
91122 deck : shuffle ( dupe ( [ ...cards , ...uniqueVariants ] ) ) ,
92123 drawStackCounter : 0 ,
93124 currentPlayer : players [ 0 ] ,
94125 lastPlayer : { id : null , duration : 0 } ,
126+ turn : 0 ,
95127 settings,
96128 saboteurs : { } ,
97129 channelID : game . channelID ,
@@ -114,32 +146,7 @@ export function startGame(game: UnoGame<false>, automatic: boolean) {
114146 Object . keys ( cardsToBeUsed ) . forEach ( id => {
115147 cardsToBeUsed [ id ] = new Proxy ( cardsToBeUsed [ id ] , {
116148 set ( t , p , n ) {
117- t [ p ] = n ;
118- if ( p === "length" ) startedGame . _debug . pushState ( {
119- type : "set-cards" ,
120- newState : t ,
121- meetsEndCondition : [ p === "length" && n === 0 , n ]
122- } ) ;
123- if ( p === "length" && n === 0 ) {
124- // TODO: check that the card shown here is the correct one and dont just pray it is
125- const card = startedGame . currentCard ;
126- const winner = getPlayerMember ( startedGame , id ) ;
127- timeouts . delete ( game . channelID ) ;
128- updateStats ( startedGame , id ) ;
129- delete games [ startedGame . channelID ] ;
130- sendMessage ( startedGame . channelID , {
131- content : `**${ winner ?. nick ?? winner ?. username } ** played ${ cardEmotes [ card ] } ${ toTitleCase ( card ) } , and won` ,
132- components : new ComponentBuilder < MessageActionRow > ( )
133- . addInteractionButton ( {
134- style : ButtonStyles . SUCCESS ,
135- label : "gg" ,
136- emoji : ComponentBuilder . emojiToPartial ( "🏆" , "default" ) ,
137- disabled : true ,
138- customID : "we-have-a-nerd-here🤓"
139- } )
140- . toJSON ( )
141- } ) ;
142- }
149+ makeDrawCardProxy ( startedGame , id , t , p , n ) ;
143150 return true ;
144151 }
145152 } ) ;
@@ -158,6 +165,7 @@ export function startGame(game: UnoGame<false>, automatic: boolean) {
158165function drawFactory ( game : UnoGame < true > ) : ( amount : number ) => { cards : Card [ ] , newDeck : Card [ ] } {
159166 let { deck } = game ;
160167 return ( amount : number ) => {
168+ if ( amount > 50 ) amount = 50 ;
161169 if ( deck . length < amount ) deck = deck . concat ( shuffle ( dupe ( [ ...cards , ...uniqueVariants ] ) ) ) ;
162170 const takenCards = deck . splice ( 0 , amount ) ;
163171 return { cards : takenCards , newDeck : deck } ;
@@ -214,6 +222,10 @@ export function onSettingsChange(ctx: ComponentInteraction<ComponentTypes.STRING
214222 game . settings . resendGameMessage = ! game . settings . resendGameMessage ;
215223 break ;
216224 }
225+ case SettingsIDs . ALLOW_REJOINING : {
226+ game . settings . canRejoin = ! game . settings . canRejoin ;
227+ break ;
228+ }
217229 default : {
218230 ctx . createFollowup ( {
219231 content : `The **${ ctx . data . values . raw [ 0 ] } ** setting is missing a handler. this is a bug`
0 commit comments