1
- import { container } from '@sapphire/framework' ;
2
1
import { Action , actions , Card , Game , presets } from 'engine-blackjack-ts' ;
3
2
import _ from 'lodash' ;
4
3
@@ -86,29 +85,13 @@ const getGameState = (game: Game): GameState => {
86
85
Starts a blackjack game for a given player and returns the new game's state
87
86
*/
88
87
export const startGame = ( amount : number , playerId : string , channelId : string ) : GameState | null => {
89
- const { logger } = container ;
90
- logger . info ( {
91
- event : 'blackjack_start' ,
92
- amount,
93
- channelId,
94
- playerId
95
- } ) ;
96
-
97
88
// if player started a game more than a minute ago, allow them to start another one in case the game got stuck
98
89
if ( gamesByPlayerId . has ( playerId ) ) {
99
90
// player already has a game in progress, get the start time of the existing game
100
91
const startedAt = gamesByPlayerId . get ( playerId ) ?. startedAt . getTime ( ) ;
101
92
const now = new Date ( ) . getTime ( ) ;
102
93
if ( startedAt && now - startedAt < 60000 ) {
103
94
// game was started in the past minute, don't start a new one
104
- logger . info ( {
105
- event : 'blackjack_start_exists' ,
106
- startedAt,
107
- now,
108
- amount,
109
- channelId,
110
- playerId
111
- } ) ;
112
95
return null ;
113
96
}
114
97
}
@@ -124,34 +107,19 @@ export const startGame = (amount: number, playerId: string, channelId: string):
124
107
End blackjack game for a given player
125
108
*/
126
109
export const endGame = ( playerId : string ) : void => {
127
- const { logger } = container ;
128
- logger . info ( { event : 'blackjack_end' , playerId } ) ;
129
110
gamesByPlayerId . delete ( playerId ) ;
130
111
} ;
131
112
132
113
/*
133
114
Perform a player action and returns the game state after that action
134
115
*/
135
116
export const performGameAction = ( playerId : string , actionName : BlackjackAction ) : GameState | null => {
136
- const { logger } = container ;
137
- logger . info ( {
138
- event : 'blackjack_action' ,
139
- actionName,
140
- playerId
141
- } ) ;
142
-
143
117
// get game and action
144
118
const game = gamesByPlayerId . get ( playerId ) ?. game ;
145
119
const gameAction = gameActionsMap . get ( actionName ) ;
146
120
147
121
if ( ! game || ! gameAction ) {
148
122
// no game state if game does not exist or if action is in valid
149
- logger . info ( {
150
- event : 'blackjack_action_error' ,
151
- error : ! game ? 'game does not exist for player' : 'invalid action' ,
152
- actionName,
153
- playerId
154
- } ) ;
155
123
return null ;
156
124
}
157
125
0 commit comments