Changeset 285c3cc
- Timestamp:
- 06/16/22 17:01:08 (2 years ago)
- Branches:
- main
- Children:
- 9bd09b0
- Parents:
- ebf5e04
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
components/blackjack/BlackjackHeader.jsx
rebf5e04 r285c3cc 41 41 })); 42 42 43 axios.get(`/api/ postgre?action=get_player_info_on_enter&session_id=${localStorage.CAESSINO_SESSION_ID}`).then(postgreRes => {44 if ( postgreRes.data?.success) {43 axios.get(`/api/blackjack?action=get_player_info_on_enter&session_id=${localStorage.CAESSINO_SESSION_ID}`).then(res => { 44 if (res.data?.success) { 45 45 dispatch(setPlayer({ 46 46 ...playerState.player, 47 displayName: postgreRes.data?.displayName,48 session_id: postgreRes.data?.session_id,49 credits: postgreRes.data?.credits,47 displayName: res.data?.displayName, 48 session_id: res.data?.session_id, 49 credits: res.data?.credits, 50 50 })); 51 51 52 axios.get(`/api/blackjack?action=get_player_info_on_enter&session_id=${localStorage.CAESSINO_SESSION_ID}`).then(res => { 53 if (res.data?.success) { 54 dispatch(setGame({ 55 ...playerState.game, 56 status: res.data?.status, 57 playerCards: res.data?.playerCards, 58 dealerCards: res.data?.dealerCards, 59 })) 60 61 dispatch(setStyle({ 62 ...styleState.style, 63 displayLoadingScreen: false, 64 })) 65 66 if (parseInt(res.data?.status.toString().substr(1, 1)) == 5) { 67 dispatch(setBlackjack({ 68 ...styleState.blackjack, 69 inputControls: { 70 ...styleState.blackjack.inputControls, 71 initialBet: { 72 ...styleState.blackjack.inputControls.initialBet, 73 chosenCredits: parseInt(res.data?.initialBet), 74 }, 75 sideBet: { 76 ...styleState.blackjack.inputControls.sideBet, 77 chosenCredits: 0, 78 } 79 }, 80 displays: { 81 ...styleState.blackjack.displays, 82 initialBet: false, 83 hitStand: true, 84 } 85 })) 86 87 if (res.data?.outcome === 'player_busted') { 88 dispatch(setStyle({ 89 ...styleState.style, 90 alert: { 91 show: true, 92 title: 'You busted!', 93 subtitle: `You lost $${-1*res.data?.earnings}`, 94 button: { 95 text: 'Play again', 96 action: 'play_again', 97 } 98 } 99 })) 100 } 101 else if (res.data?.outcome === 'dealer_busted') { 102 dispatch(setStyle({ 103 ...styleState.style, 104 alert: { 105 show: true, 106 title: 'Dealer busted!', 107 subtitle: `You won $${res.data?.earnings}`, 108 button: { 109 text: 'Play again', 110 action: 'play_again', 111 } 112 } 113 })) 114 } 115 else if (res.data?.outcome === 'player_won') { 116 dispatch(setStyle({ 117 ...styleState.style, 118 alert: { 119 show: true, 120 title: 'You won!', 121 subtitle: `You won $${res.data?.earnings}`, 122 button: { 123 text: 'Play again', 124 action: 'play_again', 125 } 126 } 127 })) 128 } 129 else if (res.data?.outcome === 'player_lost') { 130 dispatch(setStyle({ 131 ...styleState.style, 132 alert: { 133 show: true, 134 title: 'You lost!', 135 subtitle: `You lost $${-1*res.data?.earnings}`, 136 button: { 137 text: 'Play again', 138 action: 'play_again', 139 } 140 } 141 })) 142 } 143 else if (res.data?.outcome === 'draw') { 144 dispatch(setStyle({ 145 ...styleState.style, 146 alert: { 147 show: true, 148 title: 'Draw!', 149 subtitle: `You got your $${res.data?.earnings} back`, 150 button: { 151 text: 'Play again', 152 action: 'play_again', 153 } 154 } 155 })) 156 } 157 } 158 159 if (parseInt(res.data?.status.toString().substr(1, 1)) == 4) { 160 dispatch(setBlackjack({ 161 ...styleState.blackjack, 162 inputControls: { 163 ...styleState.blackjack.inputControls, 164 initialBet: { 165 ...styleState.blackjack.inputControls.initialBet, 166 chosenCredits: parseInt(res.data?.initialBet), 167 }, 168 sideBet: { 169 ...styleState.blackjack.inputControls.sideBet, 170 chosenCredits: 0, 171 } 172 }, 173 displays: { 174 ...styleState.blackjack.displays, 175 initialBet: false, 176 hitStand: true, 177 } 178 })) 179 } 180 181 if (parseInt(res.data?.status.toString().substr(1, 1)) == 3) { 182 dispatch(setBlackjack({ 183 ...styleState.blackjack, 184 inputControls: { 185 ...styleState.blackjack.inputControls, 186 initialBet: { 187 ...styleState.blackjack.inputControls.initialBet, 188 chosenCredits: parseInt(res.data?.initialBet), 189 }, 190 sideBet: { 191 ...styleState.blackjack.inputControls.sideBet, 192 chosenCredits: parseInt(res.data?.sideBet), 193 } 194 }, 195 displays: { 196 ...styleState.blackjack.displays, 197 initialBet: false, 198 hitStand: true, 199 } 200 })) 201 } 202 203 if (parseInt(res.data?.status.toString().substr(1, 1)) == 2) { 204 dispatch(setBlackjack({ 205 ...styleState.blackjack, 206 inputControls: { 207 ...styleState.blackjack.inputControls, 208 initialBet: { 209 ...styleState.blackjack.inputControls.initialBet, 210 chosenCredits: parseInt(res.data?.initialBet), 211 } 212 }, 213 displays: { 214 ...styleState.blackjack.displays, 215 initialBet: false, 216 sideBet: true, 217 } 218 })) 219 } 220 221 if (parseInt(res.data?.status.toString().substr(1, 1)) == 1) { 222 dispatch(setBlackjack({ 223 ...styleState.blackjack, 224 inputControls: { 225 ...styleState.blackjack.inputControls, 226 initialBet: { 227 ...styleState.blackjack.inputControls.initialBet, 228 chosenCredits: parseInt(postgreRes.data?.credits/2), 229 } 230 }, 231 })) 232 } 233 } 234 }); 52 dispatch(setGame({ 53 ...playerState.game, 54 status: res.data?.status, 55 playerCards: res.data?.playerCards, 56 dealerCards: res.data?.dealerCards, 57 })) 58 59 dispatch(setStyle({ 60 ...styleState.style, 61 displayLoadingScreen: false, 62 })) 63 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, 76 } 77 }, 78 displays: { 79 ...styleState.blackjack.displays, 80 initialBet: false, 81 hitStand: true, 82 } 83 })) 84 85 if (res.data?.outcome === 'player_busted') { 86 dispatch(setStyle({ 87 ...styleState.style, 88 alert: { 89 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 } 96 } 97 })) 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(postgreRes.data?.credits/2), 227 } 228 }, 229 })) 230 } 235 231 } 236 232 else { -
components/blackjack/PlayButtons.jsx
rebf5e04 r285c3cc 44 44 45 45 function placeInitialBetClicked() { 46 axios.get(`/api/postgre?action=take_credits&session_id=${localStorage.CAESSINO_SESSION_ID}&credits=${styleState.blackjack.inputControls.initialBet.chosenCredits}`).then(postgreRes => { 47 if (postgreRes.data?.success) { 48 axios.get(`/api/blackjack?action=make_initial_bet&session_id=${localStorage.CAESSINO_SESSION_ID}&bet=${styleState.blackjack.inputControls.initialBet.chosenCredits}`).then(res => { 49 if (res.data?.success) { 50 dispatch(setGame({ 51 ...playerState.game, 52 status: res.data?.status, 53 })) 54 55 dispatch(setPlayer({ 56 ...playerState.player, 57 credits: postgreRes.data?.credits, 58 })) 59 60 dispatch(setBlackjack({ 61 ...styleState.blackjack, 62 displays: { 63 ...styleState.blackjack.displays, 64 initialBet: false, 65 sideBet: true, 66 } 67 })) 68 } 69 }); 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(setGame({ 49 ...playerState.game, 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 })) 70 66 } 71 67 }); … … 149 145 150 146 function placeSideBetClicked() { 151 axios.get(`/api/postgre?action=take_credits&session_id=${localStorage.CAESSINO_SESSION_ID}&credits=${styleState.blackjack.inputControls.sideBet.chosenCredits}`).then(postgreRes => { 152 if (postgreRes.data?.success) { 153 axios.get(`/api/blackjack?action=make_side_bet&session_id=${localStorage.CAESSINO_SESSION_ID}&bet=${styleState.blackjack.inputControls.sideBet.chosenCredits}&betName=${playerState.game.sideBetName}`).then(res => { 154 if (res.data?.success) { 155 dispatch(setGame({ 156 ...playerState.game, 157 status: res.data?.status, 158 })) 159 160 dispatch(setPlayer({ 161 ...playerState.player, 162 credits: postgreRes.data?.credits, 163 })) 164 165 dispatch(setBlackjack({ 166 ...styleState.blackjack, 167 displays: { 168 ...styleState.blackjack.displays, 169 sideBetsChooseCreditsModal: false, 170 sideBet: false, 171 hitStand: true, 172 } 173 })) 174 175 getCards(); 176 } 177 }); 147 axios.get(`/api/blackjack?action=make_side_bet&session_id=${localStorage.CAESSINO_SESSION_ID}&bet=${styleState.blackjack.inputControls.sideBet.chosenCredits}&betName=${playerState.game.sideBetName}`).then(res => { 148 if (res.data?.success) { 149 dispatch(setGame({ 150 ...playerState.game, 151 status: res.data?.status, 152 })) 153 154 dispatch(setPlayer({ 155 ...playerState.player, 156 credits: res.data?.credits, 157 })) 158 159 dispatch(setBlackjack({ 160 ...styleState.blackjack, 161 displays: { 162 ...styleState.blackjack.displays, 163 sideBetsChooseCreditsModal: false, 164 sideBet: false, 165 hitStand: true, 166 } 167 })) 168 169 getCards(); 178 170 } 179 171 }); -
pages/api/blackjack/index.js
rebf5e04 r285c3cc 255 255 } 256 256 257 const room = rooms[session_id]; 258 259 room.sideBet = parseInt(req.query.bet); 260 room.sideBetName = req.query.betName; 261 room.status = '_3_made_side_bet'; 262 263 rooms[session_id] = room; 264 265 res.json({ 266 success: true, 267 status: rooms[session_id].status, 268 }) 257 axios.get(`${process.env.HOME_URL}/api/postgre?action=take_credits&session_id=${session_id}&credits=${req.query.bet}`).then(postgreRes => { 258 if (postgreRes.data?.success) { 259 const room = rooms[session_id]; 260 261 room.sideBet = parseInt(req.query.bet); 262 room.sideBetName = req.query.betName; 263 room.status = '_3_made_side_bet'; 264 265 rooms[session_id] = room; 266 267 res.json({ 268 success: true, 269 status: rooms[session_id].status, 270 credits: postgreRes.data?.credits, 271 }) 272 } 273 }); 269 274 270 275 return ; … … 289 294 if (parseInt(req.query.bet) <= 0) return ; 290 295 291 const room = rooms[session_id]; 292 293 room.initialBet = parseInt(req.query.bet); 294 room.status = '_2_made_initial_bet'; 295 296 rooms[session_id] = room; 297 298 res.json({ 299 success: true, 300 status: rooms[session_id].status, 301 }) 296 axios.get(`${process.env.HOME_URL}/api/postgre?action=take_credits&session_id=${session_id}&credits=${req.query.bet}`).then(postgreRes => { 297 if (postgreRes.data?.success) { 298 const room = rooms[session_id]; 299 300 room.initialBet = parseInt(req.query.bet); 301 room.status = '_2_made_initial_bet'; 302 303 rooms[session_id] = room; 304 305 res.json({ 306 success: true, 307 status: rooms[session_id].status, 308 credits: postgreRes.data?.credits, 309 }) 310 } 311 else { 312 res.json({ 313 success: false, 314 }) 315 } 316 }); 302 317 303 318 return ; … … 337 352 const session_id = req.query.session_id; 338 353 339 if (rooms[session_id] !== undefined) { 340 341 } 342 else { 343 createARoom(session_id); 344 } 345 346 let dealerCardsTmp = []; 347 if (rooms[session_id].status.substr(1, 1) != '5') { // 5 == game_over 348 rooms[session_id].dealerCards.forEach((card, i) => { 349 if (i === 0) { 350 dealerCardsTmp.push(card); 354 axios.get(`${process.env.HOME_URL}/api/postgre?action=check_if_logged_in&session_id=${session_id}`).then(postgreRes => { 355 if (postgreRes.data?.success) { 356 if (rooms[session_id] !== undefined) { 357 // room exists 351 358 } 352 359 else { 353 dealerCardsTmp.push('back'); 354 } 355 }) 356 } 357 else { 358 dealerCardsTmp = rooms[session_id].dealerCards; 359 } 360 361 res.json({ 362 success: true, 363 status: rooms[session_id].status, 364 initialBet: rooms[session_id].initialBet, 365 sideBet: rooms[session_id].sideBet, 366 sideBetName: rooms[session_id].sideBetName, 367 playerCards: rooms[session_id].playerCards, 368 dealerCards: dealerCardsTmp, 369 outcome: rooms[session_id].outcome, 370 earnings: rooms[session_id].earnings, 371 }) 360 createARoom(session_id); 361 } 362 363 let dealerCardsTmp = []; 364 if (rooms[session_id].status.substr(1, 1) != '5') { // 5 == game_over 365 rooms[session_id].dealerCards.forEach((card, i) => { 366 if (i === 0) { 367 dealerCardsTmp.push(card); 368 } 369 else { 370 dealerCardsTmp.push('back'); 371 } 372 }) 373 } 374 else { 375 dealerCardsTmp = rooms[session_id].dealerCards; 376 } 377 378 res.json({ 379 success: true, 380 status: rooms[session_id].status, 381 initialBet: rooms[session_id].initialBet, 382 sideBet: rooms[session_id].sideBet, 383 sideBetName: rooms[session_id].sideBetName, 384 playerCards: rooms[session_id].playerCards, 385 dealerCards: dealerCardsTmp, 386 outcome: rooms[session_id].outcome, 387 earnings: rooms[session_id].earnings, 388 displayName: postgreRes.data?.displayName, 389 session_id: postgreRes.data?.session_id, 390 credits: postgreRes.data?.credits, 391 }) 392 } 393 else { 394 res.json({ 395 success: false, 396 }) 397 } 398 }); 372 399 } 373 400 } -
pages/api/postgre/index.js
rebf5e04 r285c3cc 170 170 /** 171 171 * /---------------------- GET ----------------------/ 172 * Returns the player's room, if the player was in one. 173 * Same as the one below, but this one is used in a game-specific context. 174 * @action get_player_info_on_enter 175 * @param session_id 176 */ 177 if (req.query?.action === 'get_player_info_on_enter' && req.query?.session_id) { 178 const session_id = req.query.session_id 179 const session = sessions.find(session => session.id === session_id) 180 181 if (session) { 182 res.json({ 183 success: true, 184 displayName: session.displayName, 185 session_id: session.id, 186 credits: session.credits, 187 }) 188 return ; 189 } 190 191 res.json({ 192 success: false, 193 }) 194 } 195 196 /** 197 * /---------------------- GET ----------------------/ 198 * Returns the player's room, if the player was in one. 199 * Same as the one above, but this one is used in a general context. 172 * Checks if the player is logged in, and returns his session if so. 200 173 * @action check_if_logged_in 201 174 * @param session_id
Note:
See TracChangeset
for help on using the changeset viewer.