Changeset 55701f0
- Timestamp:
- 07/16/22 11:18:24 (2 years ago)
- Branches:
- main
- Children:
- e007fcd
- Parents:
- 433e0c5
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
components/Alert.jsx
r433e0c5 r55701f0 7 7 import axios from 'axios' 8 8 9 import { setBlackjack, setStyle } from '../redux/reducers/styleSlice' 10 import { setBlackjackGame } from '../redux/reducers/playerSlice' 9 import { setStyle } from '../redux/reducers/styleSlice' 11 10 12 11 const Alert = ({ onTop = false }) => { 13 const playerState = useSelector(state => state.player)14 12 const styleState = useSelector(state => state.style) 15 13 … … 19 17 20 18 function clicked() { 21 dispatch(setStyle({22 ...styleState.style,23 alert: {24 ...styleState.style.alert,25 show: false26 }27 }))28 29 19 if (styleState.style.alert.button.action === 'play_again') { 30 axios.get(`/api/blackjack?action=play_again&session_id=${localStorage.CAESSINO_SESSION_ID}`).then(res => { 31 if (res.data?.success && res.data?.game) { 32 dispatch(setBlackjackGame({ 33 ...playerState.blackjackGame, 34 status: res.data.game?.status, 35 playerCards: res.data.game?.playerCards, 36 dealerCards: res.data.game?.dealerCards, 37 sideBetName: res.data.game?.sideBetName, 38 })) 39 40 dispatch(setBlackjack({ 41 ...styleState.blackjack, 42 inputControls: { 43 ...styleState.blackjack.inputControls, 44 initialBet: { 45 ...styleState.blackjack.inputControls.initialBet, 46 chosenCredits: parseInt(playerState.player.credits/2), 47 }, 48 sideBet: { 49 ...styleState.blackjack.inputControls.sideBet, 50 chosenCredits: parseInt(0), 51 } 52 }, 53 displays: { 54 ...styleState.blackjack.displays, 55 initialBet: true, 56 hitStand: false, 57 } 58 })) 59 } 60 }); 20 axios.get(`/api/blackjack?action=play_again&session_id=${localStorage.CAESSINO_SESSION_ID}`); 61 21 } 62 22 else if (styleState.style.alert.button.action === 'continue_from_side_bet') { 63 dispatch(setBlackjack({64 ...styleState.blackjack,65 inputControls:{66 ...styleState.blackjack.inputControls,67 sideBet: {68 ...styleState.blackjack.inputControls.sideBet,69 chosenCredits: parseInt(0),70 }71 } ,23 axios.get(`/api/blackjack?action=continue_from_side_bet&session_id=${localStorage.CAESSINO_SESSION_ID}`); 24 } 25 else { 26 dispatch(setStyle({ 27 ...styleState.style, 28 alert: { 29 ...styleState.style.alert, 30 show: false 31 } 72 32 })) 73 33 } -
components/ManageCredits.jsx
r433e0c5 r55701f0 44 44 } : action === 'withdraw' ? { 45 45 show: true, 46 text: `Withdr awed $${styleState.style.withdrawModalInputs.amount} successfully`,46 text: `Withdrew $${Math.min(styleState.style.withdrawModalInputs.amount, playerState.player.credits)} successfully`, 47 47 status: 'success', 48 48 } : { -
components/blackjack/BlackjackHeader.jsx
r433e0c5 r55701f0 30 30 })); 31 31 32 dispatch(setBlackjack({ 33 ...styleState.blackjack, 34 inputControls: { 35 ...styleState.blackjack.inputControls, 36 initialBet: { 37 ...styleState.blackjack.inputControls.initialBet, 38 chosenCredits: parseInt(playerState.player.credits/2), 39 } 40 } 41 })); 42 32 let interval = null; 43 33 axios.get(`/api/blackjack?action=get_player_info_on_enter&session_id=${localStorage.CAESSINO_SESSION_ID}`).then(res => { 44 34 if (res.data?.success) { … … 48 38 session_id: res.data?.session_id, 49 39 credits: res.data?.credits, 50 }));51 52 dispatch(setBlackjackGame({53 ...playerState.blackjackGame,54 status: res.data?.status,55 playerCards: res.data?.playerCards,56 dealerCards: res.data?.dealerCards,57 40 })) 58 41 59 dispatch(setStyle({ 60 ...styleState.style, 61 displayLoadingScreen: false, 42 dispatch(setBlackjack({ 43 ...styleState.blackjack, 44 inputControls: { 45 ...styleState.blackjack.inputControls, 46 initialBet: { 47 ...styleState.blackjack.inputControls.initialBet, 48 chosenCredits: parseInt(playerState.player.credits/2), 49 }, 50 sideBet: { 51 ...styleState.blackjack.inputControls.sideBet, 52 chosenCredits: parseInt(playerState.player.credits/2), 53 } 54 }, 62 55 })) 63 56 64 if (parseInt(res.data?.status.toString().substr(1, 1)) == 5) { 65 dispatch(setBlackjack({ 66 ...styleState.blackjack, 67 inputControls: { 68 ...styleState.blackjack.inputControls, 69 initialBet: { 70 ...styleState.blackjack.inputControls.initialBet, 71 chosenCredits: parseInt(res.data?.initialBet), 72 }, 73 sideBet: { 74 ...styleState.blackjack.inputControls.sideBet, 75 chosenCredits: 0, 57 if (interval !== null) clearInterval(interval); 58 59 interval = setInterval(() => { 60 axios.get(`/api/blackjack?action=update_state&session_id=${localStorage.CAESSINO_SESSION_ID}`).then(newRes => { 61 if (newRes.data?.success) { 62 dispatch(setBlackjackGame(newRes.data?.blackjackGame)) 63 64 if (newRes.data?.blackjackGame?.credits !== playerState.player.credits && parseInt(newRes.data?.blackjackGame?.credits) > 0) { 65 dispatch(setPlayer({ 66 ...playerState.player, 67 displayName: res.data?.displayName, 68 session_id: res.data?.session_id, 69 credits: newRes.data?.blackjackGame?.credits, 70 })) 76 71 } 77 }, 78 displays: { 79 ...styleState.blackjack.displays, 80 initialBet: false, 81 hitStand: true, 72 73 dispatch(setStyle({ 74 ...styleState.style, 75 displayLoadingScreen: false, 76 notification: { 77 ...styleState.style.notification, 78 show: false, 79 }, 80 lostConnectionInfo: { 81 show: false, 82 message: '' 83 }, 84 alert: (newRes.data?.blackjackGame?.status?.includes('_5_') && !newRes.data?.blackjackGame?.betOutcomeMessageShown) ? { 85 show: true, 86 title: newRes.data?.blackjackGame?.messageTitle, 87 subtitle: newRes.data?.blackjackGame?.messageDescription, 88 button: { 89 text: 'Play Again', 90 action: 'play_again', 91 } 92 } : (newRes.data?.blackjackGame?.status?.includes('_4_') && !newRes.data?.blackjackGame?.sideBetOutcomeMessageShown && newRes.data?.blackjackGame?.sideBet > 0) ? { 93 show: true, 94 title: newRes.data?.blackjackGame?.messageTitle, 95 subtitle: newRes.data?.blackjackGame?.messageDescription, 96 button: { 97 text: 'Continue', 98 action: 'continue_from_side_bet', 99 } 100 } : { 101 ...styleState.style.alert, 102 show: false, 103 }, 104 })) 82 105 } 83 })) 84 85 if (res.data?.outcome === 'player_busted') { 106 }).catch(error => { 86 107 dispatch(setStyle({ 87 108 ...styleState.style, 88 alert: { 109 displayLoadingScreen: false, 110 lostConnectionInfo: { 89 111 show: true, 90 title: 'You busted!', 91 subtitle: `You lost $${-1*res.data?.earnings}`, 92 button: { 93 text: 'Play again', 94 action: 'play_again', 95 } 112 message: 'Game will resume upon reconnection to the server.' 96 113 } 97 114 })) 98 } 99 else if (res.data?.outcome === 'dealer_busted') { 100 dispatch(setStyle({ 101 ...styleState.style, 102 alert: { 103 show: true, 104 title: 'Dealer busted!', 105 subtitle: `You won $${res.data?.earnings}`, 106 button: { 107 text: 'Play again', 108 action: 'play_again', 109 } 110 } 111 })) 112 } 113 else if (res.data?.outcome === 'player_won') { 114 dispatch(setStyle({ 115 ...styleState.style, 116 alert: { 117 show: true, 118 title: 'You won!', 119 subtitle: `You won $${res.data?.earnings}`, 120 button: { 121 text: 'Play again', 122 action: 'play_again', 123 } 124 } 125 })) 126 } 127 else if (res.data?.outcome === 'player_lost') { 128 dispatch(setStyle({ 129 ...styleState.style, 130 alert: { 131 show: true, 132 title: 'You lost!', 133 subtitle: `You lost $${-1*res.data?.earnings}`, 134 button: { 135 text: 'Play again', 136 action: 'play_again', 137 } 138 } 139 })) 140 } 141 else if (res.data?.outcome === 'draw') { 142 dispatch(setStyle({ 143 ...styleState.style, 144 alert: { 145 show: true, 146 title: 'Draw!', 147 subtitle: `You got your $${res.data?.earnings} back`, 148 button: { 149 text: 'Play again', 150 action: 'play_again', 151 } 152 } 153 })) 154 } 155 } 156 157 if (parseInt(res.data?.status.toString().substr(1, 1)) == 4) { 158 dispatch(setBlackjack({ 159 ...styleState.blackjack, 160 inputControls: { 161 ...styleState.blackjack.inputControls, 162 initialBet: { 163 ...styleState.blackjack.inputControls.initialBet, 164 chosenCredits: parseInt(res.data?.initialBet), 165 }, 166 sideBet: { 167 ...styleState.blackjack.inputControls.sideBet, 168 chosenCredits: 0, 169 } 170 }, 171 displays: { 172 ...styleState.blackjack.displays, 173 initialBet: false, 174 hitStand: true, 175 } 176 })) 177 } 178 179 if (parseInt(res.data?.status.toString().substr(1, 1)) == 3) { 180 dispatch(setBlackjack({ 181 ...styleState.blackjack, 182 inputControls: { 183 ...styleState.blackjack.inputControls, 184 initialBet: { 185 ...styleState.blackjack.inputControls.initialBet, 186 chosenCredits: parseInt(res.data?.initialBet), 187 }, 188 sideBet: { 189 ...styleState.blackjack.inputControls.sideBet, 190 chosenCredits: parseInt(res.data?.sideBet), 191 } 192 }, 193 displays: { 194 ...styleState.blackjack.displays, 195 initialBet: false, 196 hitStand: true, 197 } 198 })) 199 } 200 201 if (parseInt(res.data?.status.toString().substr(1, 1)) == 2) { 202 dispatch(setBlackjack({ 203 ...styleState.blackjack, 204 inputControls: { 205 ...styleState.blackjack.inputControls, 206 initialBet: { 207 ...styleState.blackjack.inputControls.initialBet, 208 chosenCredits: parseInt(res.data?.initialBet), 209 } 210 }, 211 displays: { 212 ...styleState.blackjack.displays, 213 initialBet: false, 214 sideBet: true, 215 } 216 })) 217 } 218 219 if (parseInt(res.data?.status.toString().substr(1, 1)) == 1) { 220 dispatch(setBlackjack({ 221 ...styleState.blackjack, 222 inputControls: { 223 ...styleState.blackjack.inputControls, 224 initialBet: { 225 ...styleState.blackjack.inputControls.initialBet, 226 chosenCredits: parseInt(res.data?.credits/2), 227 } 228 }, 229 })) 230 } 115 }); 116 }, 1000); 231 117 } 232 118 else { … … 244 130 } 245 131 }); 132 133 return () => { 134 if (interval !== null) clearInterval(interval); 135 }; 246 136 }, []); 247 137 -
components/blackjack/DisplayBet.jsx
r433e0c5 r55701f0 6 6 const playerState = useSelector(state => state.player); 7 7 const styleState = useSelector(state => state.style); 8 9 8 let display = parseInt(playerState.blackjackGame.status.substr(1, 1)) >= 2 ? 'block' : 'none'; 10 let displaySideBet = ( parseInt(playerState.blackjackGame.status.substr(1, 1)) >= 3 && parseInt( styleState.blackjack.inputControls.sideBet.chosenCredits) > 0) ? 'block' : 'none';9 let displaySideBet = ( parseInt(playerState.blackjackGame.status.substr(1, 1)) >= 3 && parseInt(playerState.blackjackGame.sideBet) > 0 && !playerState.blackjackGame.sideBetOutcomeMessageShown ) ? 'block' : 'none'; 11 10 12 11 return ( 13 12 <div className="blackjackDisplayBet" style={{display: display}}> 14 <span>${ styleState.blackjack.inputControls.initialBet.chosenCredits}{displaySideBet === 'block' ? ` + $${styleState.blackjack.inputControls.sideBet.chosenCredits}` : ''}</span>13 <span>${playerState.blackjackGame.initialBet}{displaySideBet === 'block' ? ` + $${playerState.blackjackGame.sideBet}` : ''}</span> 15 14 </div> 16 15 ) -
components/blackjack/PlayButtons.jsx
r433e0c5 r55701f0 44 44 45 45 function placeInitialBetClicked() { 46 axios.get(`/api/blackjack?action=make_initial_bet&session_id=${localStorage.CAESSINO_SESSION_ID}&bet=${styleState.blackjack.inputControls.initialBet.chosenCredits}`).then(res => { 47 if (res.data?.success) { 48 dispatch(setBlackjackGame({ 49 ...playerState.blackjackGame, 50 status: res.data?.status, 51 })) 52 53 dispatch(setPlayer({ 54 ...playerState.player, 55 credits: res.data?.credits, 56 })) 57 58 dispatch(setBlackjack({ 59 ...styleState.blackjack, 60 displays: { 61 ...styleState.blackjack.displays, 62 initialBet: false, 63 sideBet: true, 64 } 65 })) 66 } 67 }); 46 axios.get(`/api/blackjack?action=make_initial_bet&session_id=${localStorage.CAESSINO_SESSION_ID}&bet=${styleState.blackjack.inputControls.initialBet.chosenCredits}`); 68 47 } 69 48 … … 124 103 const texts = splitTexts(e.target.innerHTML); 125 104 126 dispatch(setBlackjackGame({ 127 ...playerState.blackjackGame, 128 sideBetName: sideBetName 129 })) 130 131 dispatch(setBlackjack({ 132 ...styleState.blackjack, 105 dispatch(setBlackjack({ 106 ...styleState.blackjack, 107 sideBetName: sideBetName, 133 108 displays: { 134 109 ...styleState.blackjack.displays, … … 145 120 146 121 function placeSideBetClicked() { 147 axios.get(`/api/blackjack?action=make_side_bet&session_id=${localStorage.CAESSINO_SESSION_ID}&bet=${styleState.blackjack.inputControls.sideBet.chosenCredits}&betName=${ playerState.blackjackGame.sideBetName}`).then(res => {122 axios.get(`/api/blackjack?action=make_side_bet&session_id=${localStorage.CAESSINO_SESSION_ID}&bet=${styleState.blackjack.inputControls.sideBet.chosenCredits}&betName=${styleState.blackjack.sideBetName}`).then(res => { 148 123 if (res.data?.success) { 149 dispatch(setBlackjackGame({150 ...playerState.blackjackGame,151 status: res.data?.status,152 }))153 154 dispatch(setPlayer({155 ...playerState.player,156 credits: res.data?.credits,157 }))158 159 124 dispatch(setBlackjack({ 160 125 ...styleState.blackjack, … … 162 127 ...styleState.blackjack.displays, 163 128 sideBetsChooseCreditsModal: false, 164 sideBet: false,165 hitStand: true,166 129 } 167 130 })) … … 181 144 sideBetsModal: false, 182 145 sideBetsChooseCreditsModal: false, 183 sideBet: false,184 hitStand: true,185 },186 inputControls: {187 ...styleState.blackjack.inputControls,188 sideBet: {189 ...styleState.blackjack.inputControls.sideBet,190 chosenCredits: 0,191 }192 146 }, 193 147 })) … … 199 153 200 154 function getCards() { 201 axios.get(`/api/blackjack?action=get_initial_cards&session_id=${localStorage.CAESSINO_SESSION_ID}`).then(res => { 202 if (res.data?.success) { 203 dispatch(setBlackjackGame({ 204 ...playerState.blackjackGame, 205 status: res.data?.status, 206 playerCards: res.data?.playerCards, 207 dealerCards: res.data?.dealerCards, 208 })) 209 210 if (res.data?.sideBetOutcome !== '') { 211 if (res.data.sideBetOutcome === 'side_bet_won') { 212 dispatch(setBlackjackGame({ 213 ...playerState.blackjackGame, 214 credits: res.data?.credits, 215 })) 216 217 dispatch(setStyle({ 218 ...styleState.style, 219 alert: { 220 show: true, 221 title: 'You won the side bet!', 222 subtitle: `You won $${res.data?.sideBetEarnings}`, 223 button: { 224 text: 'Continue', 225 action: 'continue_from_side_bet', 226 } 227 } 228 })) 229 } 230 else if (res.data.sideBetOutcome === 'side_bet_lost') { 231 dispatch(setStyle({ 232 ...styleState.style, 233 alert: { 234 show: true, 235 title: 'You lost the side bet!', 236 subtitle: `You lost $${-1*res.data?.sideBetEarnings}`, 237 button: { 238 text: 'Continue', 239 action: 'continue_from_side_bet', 240 } 241 } 242 })) 243 } 244 } 245 } 246 }); 155 axios.get(`/api/blackjack?action=get_initial_cards&session_id=${localStorage.CAESSINO_SESSION_ID}`); 247 156 } 248 157 … … 282 191 283 192 function standClicked() { 284 axios.get(`/api/blackjack?action=stand&session_id=${localStorage.CAESSINO_SESSION_ID}`).then(res => { 285 if (res.data?.success) { 286 dispatch(setBlackjackGame({ 287 ...playerState.blackjackGame, 288 status: res.data?.status, 289 playerCards: res.data?.playerCards, 290 dealerCards: res.data?.dealerCards, 291 })) 292 293 if (res.data?.status.toString().substr(1, 1) === '5') { // game_over 294 dispatch(setPlayer({ 295 ...playerState.player, 296 credits: res.data?.credits, 297 })) 298 299 if (res.data?.outcome === 'dealer_busted') { 300 dispatch(setStyle({ 301 ...styleState.style, 302 alert: { 303 show: true, 304 title: 'Dealer busted!', 305 subtitle: `You won $${res.data?.earnings}`, 306 button: { 307 text: 'Play again', 308 action: 'play_again', 309 } 310 } 311 })) 312 } 313 else if (res.data?.outcome === 'player_won') { 314 dispatch(setStyle({ 315 ...styleState.style, 316 alert: { 317 show: true, 318 title: 'You won!', 319 subtitle: `You won $${res.data?.earnings}`, 320 button: { 321 text: 'Play again', 322 action: 'play_again', 323 } 324 } 325 })) 326 } 327 else if (res.data?.outcome === 'player_lost') { 328 dispatch(setStyle({ 329 ...styleState.style, 330 alert: { 331 show: true, 332 title: 'You lost!', 333 subtitle: `You lost $${-1*res.data?.earnings}`, 334 button: { 335 text: 'Play again', 336 action: 'play_again', 337 } 338 } 339 })) 340 } 341 else if (res.data?.outcome === 'draw') { 342 dispatch(setStyle({ 343 ...styleState.style, 344 alert: { 345 show: true, 346 title: 'Draw!', 347 subtitle: `You got your $${res.data?.earnings} back`, 348 button: { 349 text: 'Play again', 350 action: 'play_again', 351 } 352 } 353 })) 354 } 355 } 356 } 357 }); 193 axios.get(`/api/blackjack?action=stand&session_id=${localStorage.CAESSINO_SESSION_ID}`); 358 194 } 359 195 360 196 return ( 361 197 <div className="blackjackButtons"> 362 <div className="blackjackInitialBet" style={{display: styleState.blackjack.displays.initialBet? 'flex' : 'none'}}>198 <div className="blackjackInitialBet" style={{display: playerState.blackjackGame.status.includes('_1_') ? 'flex' : 'none'}}> 363 199 <div> 364 200 <input type="range" className="primarySlider" min={0} max={playerState.player.credits} step={1} value={styleState.blackjack.inputControls.initialBet.chosenCredits} onChange={(e) => chooseCoins(e)} /> … … 369 205 <button className="primaryButton" onClick={() => placeInitialBetClicked()}>Place Initial Bet <GiTwoCoins style={{marginTop: '3px', marginBottom: '-3px'}} /></button> 370 206 </div> 371 <div className="blackjackSideBet" style={{display: styleState.blackjack.displays.sideBet? 'flex' : 'none'}}>207 <div className="blackjackSideBet" style={{display: playerState.blackjackGame.status.includes('_2_') ? 'flex' : 'none'}}> 372 208 <button className="primaryButton" onClick={() => placeSideBetsClicked()}>Place Side Bets <GiTwoCoins style={{marginTop: '3px', marginBottom: '-3px'}} /></button> 373 209 <button className="primaryButton" onClick={() => skipSideBetsClicked()}>Skip <GiReturnArrow style={{marginTop: '3px', marginBottom: '-3px', transform: 'rotateZ(-15deg)'}} /></button> 374 210 </div> 375 <div className="blackjackHitStand" style={{display: styleState.blackjack.displays.hitStand? 'flex' : 'none'}}>211 <div className="blackjackHitStand" style={{display: parseInt(playerState.blackjackGame.status.toString().substr(1, 1)) >= 3 ? 'flex' : 'none'}}> 376 212 <button className="primaryButton" onClick={() => hitClicked()}>Hit <GiCardDraw style={{marginTop: '3px', marginBottom: '-3px'}} /></button> 377 213 <button className="primaryButton" onClick={() => standClicked()}>Stand <AiFillCheckCircle style={{marginTop: '3px', marginBottom: '-3px'}} /></button> -
components/poker/PokerHeader.jsx
r433e0c5 r55701f0 89 89 } 90 90 }); 91 92 return () => { 93 if (interval !== null) clearInterval(interval); 94 }; 91 95 }, []) 92 96 -
components/roulette/RouletteHeader.jsx
r433e0c5 r55701f0 138 138 } 139 139 }); 140 141 return () => { 142 if (interval !== null) clearInterval(interval); 143 }; 140 144 }, []); 141 145 -
pages/api/blackjack/gameStates.js
r433e0c5 r55701f0 1 import { rooms } from "../postgre"; 2 1 3 const singleDeck = ["SA", "S2", "S3", "S4", "S5", "S6", "S7", "S8", "S9", "SX", "SJ", "SQ", "SK", 2 4 "HA", "H2", "H3", "H4", "H5", "H6", "H7", "H8", "H9", "HX", "HJ", "HQ", "HK", … … 11 13 */ 12 14 export let game = { 15 credits: -1, 13 16 deck: [...deck], 14 17 status: '_1_room_created', // statuses: _1_room_created, _2_made_initial_bet, _3_made_side_bet, _4_cards_on_the_table, _5_game_over … … 23 26 sideBetOutcome: '', 24 27 sideBetEarnings: 0, 28 messageTitle: '', 29 messageDescription: '', 30 betOutcomeMessageShown: true, 31 sideBetOutcomeMessageShown: true, 32 } 33 34 export function getGame(session_id) { 35 if (rooms[session_id] !== undefined) { 36 return { 37 success: true, 38 game: rooms[session_id], 39 } 40 } 41 42 return { 43 success: false, 44 game: {...game, playerCards: [...game.playerCards], dealerCards: [...game.dealerCards]}, 45 }; 46 } 47 48 export function getRestrictedGameObject(session_id) { 49 const { success, game } = getGame(session_id) 50 51 return { 52 ...game, 53 dealerCards: game.status.includes('_5_') ? game.dealerCards : game.dealerCards.length > 0 ? [game.dealerCards[0]].concat(['back']) : [], 54 } 25 55 } 26 56 -
pages/api/blackjack/index.js
r433e0c5 r55701f0 3 3 require('dotenv').config(); 4 4 5 import { game, drawASingleCard, getInitialCards, calculateHandValue } from './gameStates';5 import { game, drawASingleCard, getInitialCards, calculateHandValue, getGame, getRestrictedGameObject } from './gameStates'; 6 6 import { calculateEarnings, calculateSideBetEarnings } from './calculateEarnings'; 7 7 … … 39 39 rooms[session_id] = {...game, playerCards: [...game.playerCards], dealerCards: [...game.dealerCards]}; 40 40 41 res.json({ 42 success: true, 43 game: rooms[session_id], 44 }) 41 rooms[session_id].betOutcomeMessageShown = true; 45 42 46 43 update_rooms_to_database(); 47 48 return ; 49 } 50 51 res.json({ 52 success: false, 53 }) 44 } 45 46 res.end(); 47 } 48 49 /** 50 * /---------------------- GET ----------------------/ 51 * If game status is _4_cards_on_the_table, turn off the alert for side bet outcome 52 * @action continue_from_side_bet 53 * @param session_id 54 */ 55 if (req.query.action === 'continue_from_side_bet' && req.query?.session_id) { 56 const session_id = req.query.session_id; 57 58 if (rooms[session_id] !== undefined && rooms[session_id].status.substr(1, 1) === '4') { 59 rooms[session_id].sideBetOutcomeMessageShown = true; 60 61 update_rooms_to_database(); 62 } 63 64 res.end(); 54 65 } 55 66 … … 88 99 room.earnings = calculateEarnings(room); 89 100 101 if (room.outcome === 'draw') { 102 room.messageTitle = 'Draw!'; 103 room.messageDescription = `You got your $${room.earnings} back` 104 } 105 else if (room.outcome === 'player_won') { 106 room.messageTitle = 'You won!'; 107 room.messageDescription = `You won $${room.earnings}` 108 } 109 else if (room.outcome === 'dealer_busted') { 110 room.messageTitle = `Dealer ${room.dealerName} busted!`; 111 room.messageDescription = `You won $${room.earnings}` 112 } 113 else if (room.outcome === 'player_lost') { 114 room.messageTitle = 'You lost!'; 115 room.messageDescription = `You lost $${-1*room.earnings}` 116 } 117 room.betOutcomeMessageShown = false; 118 90 119 rooms[session_id] = room; 91 120 92 121 axios.get(`${process.env.HOME_URL}/api/postgre/?action=add_credits&session_id=${session_id}&credits=${room.earnings}&game=blackjack&outcome=${room.outcome}`).then(postgreRes => { 93 122 if (postgreRes.data?.success) { 123 rooms[session_id].credits = postgreRes.data?.credits; 124 94 125 res.json({ 95 126 success: true, … … 139 170 room.status = '_5_game_over'; 140 171 room.outcome = 'player_busted'; 141 172 142 173 room.earnings = calculateEarnings(room); 174 175 room.messageTitle = 'You busted!'; 176 room.messageDescription = `You lost $${-1*room.earnings}` 177 178 room.betOutcomeMessageShown = false; 143 179 144 180 rooms[session_id] = room; … … 146 182 axios.get(`${process.env.HOME_URL}/api/postgre/?action=add_credits&session_id=${session_id}&credits=${room.earnings}&game=blackjack&outcome=${room.outcome}`).then(postgreRes => { 147 183 if (postgreRes.data?.success) { 184 rooms[session_id].credits = postgreRes.data?.credits; 185 148 186 res.json({ 149 187 success: true, … … 207 245 room.sideBetOutcome = room.sideBetEarnings > 0 ? 'side_bet_won' : 'side_bet_lost'; 208 246 247 if (room.sideBetOutcome === 'side_bet_won') { 248 room.messageTitle = `You won the side bet!`; 249 room.messageDescription = `You won $${room.sideBetEarnings}` 250 } 251 else if (room.sideBetOutcome === 'side_bet_lost') { 252 room.messageTitle = `You lost the side bet!`; 253 room.messageDescription = `You lost $${-1*room.sideBetEarnings}` 254 } 255 256 room.sideBetOutcomeMessageShown = false; 257 209 258 rooms[session_id] = room; 259 260 update_rooms_to_database(); 210 261 211 262 axios.get(`${process.env.HOME_URL}/api/postgre/?action=add_credits&session_id=${session_id}&credits=${room.sideBetEarnings}`).then(postgreRes => { 212 263 if (postgreRes.data?.success) { 213 res.json({ 214 success: true, 215 status: rooms[session_id].status, 216 playerCards: rooms[session_id].playerCards, 217 dealerCards: Array(rooms[session_id].dealerCards[0]).concat('back'), 218 sideBetOutcome: rooms[session_id].sideBetOutcome, 219 sideBetEarnings: rooms[session_id].sideBetEarnings, 220 credits: postgreRes.data?.credits, 221 }) 222 264 rooms[session_id].credits = postgreRes.data?.credits; 265 223 266 update_rooms_to_database(); 224 267 } 225 else {226 res.json({227 success: false,228 })229 }230 268 }); 231 269 } 232 else { 233 res.json({ 234 success: true, 235 status: rooms[session_id].status, 236 playerCards: rooms[session_id].playerCards, 237 dealerCards: Array(rooms[session_id].dealerCards[0]).concat('back'), 238 sideBetOutcome: rooms[session_id].sideBetOutcome, 239 sideBetEarnings: rooms[session_id].sideBetEarnings, 240 }) 241 242 update_rooms_to_database(); 243 } 244 245 return ; 246 } 247 248 res.json({ 249 success: false, 250 }) 270 } 271 272 res.end(); 251 273 } 252 274 … … 259 281 * @param betName 260 282 */ 261 283 if (req.query.action === 'make_side_bet' && req.query?.session_id && req.query?.bet && req.query?.betName) { 262 284 const session_id = req.query.session_id; 263 285 … … 269 291 axios.get(`${process.env.HOME_URL}/api/postgre?action=take_credits&session_id=${session_id}&credits=${req.query.bet}`).then(postgreRes => { 270 292 if (postgreRes.data?.success) { 293 rooms[session_id].credits = postgreRes.data?.credits; 294 271 295 const room = rooms[session_id]; 272 296 … … 279 303 res.json({ 280 304 success: true, 281 status: rooms[session_id].status,282 credits: postgreRes.data?.credits,283 305 }) 284 306 285 307 update_rooms_to_database(); 286 308 } 309 else { 310 res.end(); 311 } 287 312 }); 288 289 return ; 290 } 291 292 res.json({ 293 success: false, 294 }) 313 } 295 314 } 296 315 … … 310 329 axios.get(`${process.env.HOME_URL}/api/postgre?action=take_credits&session_id=${session_id}&credits=${req.query.bet}`).then(postgreRes => { 311 330 if (postgreRes.data?.success) { 331 rooms[session_id].credits = postgreRes.data?.credits; 332 312 333 const room = rooms[session_id]; 313 334 … … 316 337 317 338 rooms[session_id] = room; 318 319 res.json({320 success: true,321 status: rooms[session_id].status,322 credits: postgreRes.data?.credits,323 })324 339 325 340 update_rooms_to_database(); 326 341 } 327 else {328 res.json({329 success: false,330 })331 }332 342 }); 333 334 return ; 335 } 336 337 res.json({ 338 success: false, 339 }) 343 } 344 345 res.end(); 340 346 } 341 347 … … 358 364 359 365 update_rooms_to_database(); 366 } 367 368 /** 369 * /---------------------- GET ----------------------/ 370 * Updates the state periodically 371 * @action update_state 372 * @param session_id 373 */ 374 if (req.query.action === 'update_state' && req.query?.session_id) { 375 const session_id = req.query.session_id; 376 377 const { success, game } = getGame(session_id); 378 379 res.json({ 380 success: true, 381 blackjackGame: getRestrictedGameObject(session_id), 382 }) 360 383 } 361 384 -
pages/api/poker/index.js
r433e0c5 r55701f0 5 5 import { createTable, getRestrictedTablesArray, getRestrictedTableArray, getTable, getTableAndPlayer } from './gameStates'; 6 6 7 import { drawASingleCard, setNextPlayerIdx, progressRoundIfNeeded , progressRoundTillTheEnd} from './tableSpecific'8 9 import { tables, cleanTables, update_tables_to_database, load_tables_from_database } from '../postgre/index'7 import { drawASingleCard, setNextPlayerIdx, progressRoundIfNeeded } from './tableSpecific' 8 9 import { update_tables_to_database } from '../postgre/index' 10 10 11 11 /** -
pages/api/postgre/index.js
r433e0c5 r55701f0 324 324 return ; 325 325 } 326 if (parseInt(body?.data?.amount) > 5000) { 327 res.json({ 328 success: false, 329 message: 'Failed to deposit. Insufficient credit on card.', 330 }); 331 return ; 332 } 326 333 327 334 let session = sessions.find(session => session.id === body?.session_id) … … 338 345 credits: session.credits 339 346 }) 347 348 update_sessions_to_database(); 340 349 }); 341 350 } … … 415 424 credits: session.credits 416 425 }) 426 427 update_sessions_to_database(); 417 428 }); 418 429 } … … 762 773 } 763 774 load_rooms_from_database(); 764 -
pages/api/roulette/gameStates.js
r433e0c5 r55701f0 86 86 }) 87 87 } 88 else { 89 game.players[game.players.map(e=>e.session_id).indexOf(session_id)].credits = -1; 90 } 88 91 } 89 92 -
redux/reducers/playerSlice.js
r433e0c5 r55701f0 14 14 dealerCards: [], 15 15 sideBetName: '', 16 betAmount: 0, 17 sideBetAmount: 0, 16 18 }, 17 19 rouletteGame: { -
redux/reducers/styleSlice.js
r433e0c5 r55701f0 104 104 } 105 105 }, 106 sideBetName: '', 106 107 texts: { 107 108 sideBetsChooseCreditsText: '',
Note:
See TracChangeset
for help on using the changeset viewer.