Changeset 55701f0 for components/blackjack/BlackjackHeader.jsx
- Timestamp:
- 07/16/22 11:18:24 (2 years ago)
- Branches:
- main
- Children:
- e007fcd
- Parents:
- 433e0c5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.