Changeset d0ef259
- Timestamp:
- 07/12/22 00:13:20 (2 years ago)
- Branches:
- main
- Children:
- e9f11ac
- Parents:
- 95ce58b
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
components/roulette/Ball.jsx
r95ce58b rd0ef259 5 5 const Ball = () => { 6 6 const playerState = useSelector(state => state.player); 7 const styleState = useSelector(state => state.style);8 7 9 8 return ( 10 9 <> 11 { (playerState.rouletteGame. timeToStart > styleState.roulette.COUNTDOWN_FROM || playerState.rouletteGame.timeToStart <= 0) &&10 { (playerState.rouletteGame.game.timeToStart > playerState.rouletteGame.game.COUNTDOWN_FROM || playerState.rouletteGame.game.timeToStart <= 0) && 12 11 <img id="rouletteBall" src="/images/roulette-ball.png" alt="Roulette ball"/> 13 12 } -
components/roulette/BetModal.jsx
r95ce58b rd0ef259 30 30 31 31 function placeBet() { 32 axios.get(`/api/roulette?action=place_bet&session_id=${localStorage.CAESSINO_SESSION_ID}&betAmount=${styleState.roulette.inputControls.bet.chosenCredits}&whichBets=${styleState.roulette.whichBets.toString()}`).then(res => { 33 if (res.data?.success) { 34 dispatch(setPlayer({ 35 ...playerState.player, 36 credits: res.data?.credits, 37 })); 32 axios.get(`/api/roulette?action=place_bet&session_id=${localStorage.CAESSINO_SESSION_ID}&betAmount=${styleState.roulette.inputControls.bet.chosenCredits}&whichBets=${styleState.roulette.whichBets.toString()}&coinPlacedX=${styleState.roulette.coinPlaced.x}&coinPlacedY=${styleState.roulette.coinPlaced.y}`); 38 33 39 dispatch(setRouletteGame(res.data?.game)); 40 41 closeModal(false); 42 } 43 }); 34 closeModal(); 44 35 } 45 36 46 function closeModal(removeCoin = true) { 47 if (removeCoin) { 48 dispatch(setRoulette({ 49 ...styleState.roulette, 50 displays: { 51 ...styleState.roulette.displays, 52 betModal: false, 53 }, 54 showCoin: false, 55 })) 56 } 57 else { 58 dispatch(setRoulette({ 59 ...styleState.roulette, 60 displays: { 61 ...styleState.roulette.displays, 62 betModal: false, 63 }, 64 showCoin: true, 65 })); 66 } 37 function closeModal() { 38 dispatch(setRoulette({ 39 ...styleState.roulette, 40 displays: { 41 ...styleState.roulette.displays, 42 betModal: false, 43 }, 44 })); 67 45 } 68 46 69 47 return ( 70 <div className="rouletteBetModal" style={{display: styleState.roulette.displays.betModal && playerState.rouletteGame. timeToStart > 10? 'flex' : 'none'}}>48 <div className="rouletteBetModal" style={{display: styleState.roulette.displays.betModal && playerState.rouletteGame.game.timeToStart > 10 && playerState.rouletteGame.game.timeToStart <= playerState.rouletteGame.game.COUNTDOWN_FROM ? 'flex' : 'none'}}> 71 49 <p>You have chosen to bet on: <span>{styleState.roulette.whichBets.map((bet, i) => `${bet} `)}</span><br/>Please select the amount you will bet</p> 72 50 <div> -
components/roulette/BetsImage.jsx
r95ce58b rd0ef259 25 25 let clicked = getClickedArray(xOffset, singleX, yOffset, singleY); 26 26 27 if (clicked.length > 0 && playerState.rouletteGame.status.substr(1, 1) === '1') { 28 const playerIdx = playerState.rouletteGame.players.map(e=>e.session_id).indexOf(localStorage.CAESSINO_SESSION_ID); 29 if (playerIdx !== -1 && playerState.rouletteGame.players[playerIdx].status.substr(1, 1) === '1') { 27 if (clicked.length > 0 && playerState.rouletteGame.game.status.includes("_1_")) { 28 if (playerState.rouletteGame.player.status.includes("_1_")) { 30 29 openModal(clicked, e); 31 30 } -
components/roulette/CoinOnTable.jsx
r95ce58b rd0ef259 4 4 5 5 const CoinOnTable = () => { 6 const styleState = useSelector(state => state.style);6 const playerState = useSelector(state => state.player); 7 7 8 8 return ( 9 9 <> 10 { styleState.roulette.showCoin && <img id="coinOnTable" src="/gold-coin.cur" alt="Gold coin" style={{zIndex: 20, position: 'absolute', left: `${styleState.roulette.coinPlaced.x}px`, top: `${styleState.roulette.coinPlaced.y}px`, transform: 'translate(-50%, -50%)'}}/>}10 {playerState.rouletteGame?.player.coinPlaced.x && playerState.rouletteGame.player.coinPlaced.x !== -1 && <img id="coinOnTable" src="/gold-coin.cur" alt="Gold coin" style={{zIndex: 20, position: 'absolute', left: `${playerState.rouletteGame.player.coinPlaced.x}px`, top: `${playerState.rouletteGame.player.coinPlaced.y}px`, transform: 'translate(-50%, -50%)'}}/>} 11 11 </> 12 12 ) -
components/roulette/PlayersDisplay.jsx
r95ce58b rd0ef259 5 5 const PlayersDisplay = () => { 6 6 const playerState = useSelector(state => state.player); 7 const styleState = useSelector(state => state.style);8 7 9 8 // See results. 10 if (playerState.rouletteGame. timeToStart > styleState.roulette.COUNTDOWN_FROM) {9 if (playerState.rouletteGame.game.timeToStart > playerState.rouletteGame.game.COUNTDOWN_FROM) { 11 10 return ( 12 11 <div className="roulettePlayersContainer"> … … 14 13 <p>Winners:</p> 15 14 <hr/> 16 {playerState.rouletteGame?. players.map((player, i) => (15 {playerState.rouletteGame?.game.players.map((player, i) => ( 17 16 player.betAmount > 0 && player.outcome === 'won' ? <p key={player + i}>{player.name} <span style={{color: '#ead24d'}}>[{player.whichBets.toString()}]</span></p> : <span key={player + i}></span> 18 17 ))} … … 21 20 <p>Losers:</p> 22 21 <hr/> 23 {playerState.rouletteGame?. players.map((player, i) => (22 {playerState.rouletteGame?.game.players.map((player, i) => ( 24 23 player.betAmount > 0 && player.outcome === 'lost' ? <p key={player + i}>{player.name} <span style={{color: '#ead24d'}}>[{player.whichBets.toString()}]</span></p> : <span key={player + i}></span> 25 24 ))} … … 35 34 <p>Online:</p> 36 35 <hr/> 37 {playerState.rouletteGame?. players.map((player, i) => (36 {playerState.rouletteGame?.game.players.map((player, i) => ( 38 37 player.status.substr(1, 1) === '1' ? <p key={player + i}>{player.name}</p> : <span key={player + i}></span> 39 38 ))} … … 42 41 <p>Betted:</p> 43 42 <hr/> 44 {playerState.rouletteGame?. players.map((player, i) => (43 {playerState.rouletteGame?.game.players.map((player, i) => ( 45 44 player.status.substr(1, 1) === '2' ? <p key={player + i}>{player.name} <span style={{color: '#ead24d'}}>[{player.whichBets.toString()}]</span></p> : <span key={player + i}></span> 46 45 ))} -
components/roulette/RouletteHeader.jsx
r95ce58b rd0ef259 24 24 25 25 useEffect(() => { 26 function spin_wheel(magicNumber, winningBets) { 27 document.getElementById('rouletteWheelImg').classList.add('spin'); 28 29 setTimeout(() => { 30 document.getElementById('rouletteWheelImg').classList.remove('spin'); 31 32 const extraSpin = ( 5 + numbersOfWheel.indexOf(playerState.rouletteGame.game?.magicNumber) * (360 / 37.0) ) + 'deg'; 33 document.getElementById('rouletteWheelImg').style.transform = `translate(-50%, -50%) rotateZ(${extraSpin})`; 34 35 setTimeout(() => { 36 dispatch(setStyle({ 37 ...styleState.style, 38 alert: { 39 show: true, 40 title: `Winning number: ${magicNumber}`, 41 subtitle: `Winning bets: [${winningBets.join(', ')}]`, 42 button: { 43 text: 'Continue', 44 action: '', 45 } 46 } 47 })) 48 }, 2000); 49 }, 4000); 50 } 51 26 52 // display loading screen 27 53 dispatch(setStyle({ … … 29 55 displayLoadingScreen: true, 30 56 })); 57 58 let interval = null; 31 59 32 60 axios.get(`/api/roulette?action=get_player_info_on_enter&session_id=${localStorage.CAESSINO_SESSION_ID}`).then(res => { … … 39 67 })); 40 68 41 dispatch(setRouletteGame(res.data?.game)); 69 interval = setInterval(() => { 70 axios.get(`/api/roulette?action=update_state&session_id=${localStorage.CAESSINO_SESSION_ID}`).then(newRes => { 71 if (newRes.data?.success) { 72 dispatch(setRouletteGame(newRes.data?.rouletteGame)); 73 74 if (newRes.data?.extraAction === "spin_wheel") { 75 spin_wheel(newRes.data.magicNumber ?? -1, newRes.data.winningBets ?? -1); 76 } 77 78 if (newRes.data?.rouletteGame?.player?.credits !== playerState.player.credits && newRes.data?.rouletteGame?.player?.credits > 0) { 79 dispatch(setPlayer({ 80 ...playerState.player, 81 credits: newRes.data?.rouletteGame?.player?.credits, 82 })) 83 } 84 } 85 }); 86 }, 1000); 42 87 43 88 dispatch(setRoulette({ … … 91 136 } 92 137 138 // 10 starts from 5deg 139 const numbersOfWheel = [10, 23, 8, 30, 11, 36, 13, 27, 6, 34, 17, 25, 2, 21, 4, 19, 15, 32, 0, 26, 3, 35, 12, 28, 7, 29, 18, 22, 9, 31, 14, 20, 1, 33, 16, 24, 5]; 140 93 141 export default RouletteHeader -
components/roulette/Timer.jsx
r95ce58b rd0ef259 14 14 const styleState = useSelector(state => state.style); 15 15 16 useEffect(() => { 17 let interval = setInterval(() => { 18 dispatch(setRouletteGame({ 19 ...playerState.rouletteGame, 20 timeToStart: playerState.rouletteGame.timeToStart - 1, 21 })) 16 function getTimer() { 17 const timer = playerState.rouletteGame.game.timeToStart; 22 18 23 if (playerState.rouletteGame.timeToStart === 0) { 24 axios.get(`/api/roulette?action=timer_done&session_id=${localStorage.CAESSINO_SESSION_ID}`).then(res => { 25 if (res.data?.success) { 26 document.getElementById('rouletteWheelImg').classList.add('spin'); 27 28 setTimeout(() => { 29 document.getElementById('rouletteWheelImg').classList.remove('spin'); 30 31 const extraSpin = ( 5 + numbersOfWheel.indexOf(res.data?.magicNumber) * (360 / 37.0) ) + 'deg'; 32 document.getElementById('rouletteWheelImg').style.transform = `translate(-50%, -50%) rotateZ(${extraSpin})`; 33 34 setTimeout(() => { 35 dispatch(setStyle({ 36 ...styleState.style, 37 alert: { 38 show: true, 39 title: `Winning number: ${res.data?.magicNumber}`, 40 subtitle: `Winning bets: [${res.data?.winningBets.join(', ')}]`, 41 button: { 42 text: 'Continue', 43 action: '', 44 } 45 } 46 })) 47 48 dispatch(setPlayer({ 49 ...playerState.player, 50 credits: res.data?.credits, 51 })) 52 53 dispatch(setRouletteGame(res.data?.game)); 54 }, 600); 55 }, 4000); 56 } 57 }); 58 } 59 else if (playerState.rouletteGame.timeToStart === 10) { 60 dispatch(setRoulette({ 61 ...styleState.roulette, 62 displays: { 63 ...styleState.roulette.displays, 64 betModal: false, 65 } 66 })) 67 } 68 else if (playerState.rouletteGame.timeToStart === styleState.roulette.COUNTDOWN_FROM) { 69 axios.get(`/api/roulette?action=reset_game&session_id=${localStorage.CAESSINO_SESSION_ID}`).then(res => { 70 if (res.data?.success) { 71 dispatch(setRouletteGame(res.data?.game)); 72 73 dispatch(setRoulette({ 74 ...styleState.roulette, 75 showCoin: false, 76 })) 77 } 78 }); 79 } 80 }, 1000); 81 82 return () => clearInterval(interval); 83 }, [dispatch, playerState.rouletteGame.timeToStart, playerState.rouletteGame]); 84 85 function getTimer() { 86 const timer = playerState.rouletteGame.timeToStart; 87 88 const timeString = (timer < 0 || timer > styleState.roulette.COUNTDOWN_FROM - 2) ? '00:00' : '0' + parseInt(timer/60) + ':' + (timer%60 < 10 ? '0' : '') + (timer%60); 19 const timeString = (timer < 0 || timer > playerState.rouletteGame.game.COUNTDOWN_FROM - 2) ? '00:00' : '0' + parseInt(timer/60) + ':' + (timer%60 < 10 ? '0' : '') + (timer%60); 89 20 90 21 return timeString; … … 93 24 return ( 94 25 <div className="rouletteTimer"> 95 {playerState.rouletteGame. timeToStart > 0 && playerState.rouletteGame.timeToStart <= styleState.roulette.COUNTDOWN_FROM - 2 && <span style={{fontSize: '1rem'}}>Wheel will spin in:</span>}26 {playerState.rouletteGame.game.timeToStart > 0 && playerState.rouletteGame.game.timeToStart <= playerState.rouletteGame.game.COUNTDOWN_FROM - 2 && <span style={{fontSize: '1rem'}}>Wheel will spin in:</span>} 96 27 97 28 <span>{getTimer()}</span> 98 29 99 {playerState.rouletteGame. timeToStart > 10 && playerState.rouletteGame.timeToStart <= styleState.roulette.COUNTDOWN_FROM - 2 && <span style={{fontSize: '1rem'}}>Make your bets.</span>}30 {playerState.rouletteGame.game.timeToStart > 10 && playerState.rouletteGame.game.timeToStart <= playerState.rouletteGame.game.COUNTDOWN_FROM - 2 && <span style={{fontSize: '1rem'}}>Make your bets.</span>} 100 31 101 {playerState.rouletteGame. timeToStart <= 10 && <span style={{fontSize: '1rem'}}>Betting time is over.</span>}32 {playerState.rouletteGame.game.timeToStart <= 10 && <span style={{fontSize: '1rem'}}>Betting time is over.</span>} 102 33 103 {playerState.rouletteGame. timeToStart > styleState.roulette.COUNTDOWN_FROM && <span style={{fontSize: '1rem'}}>Time to see who won :)</span>}104 {playerState.rouletteGame. timeToStart > styleState.roulette.COUNTDOWN_FROM && <span style={{fontSize: '.7rem'}}>(And prepare, you can bet again soon.)</span>}34 {playerState.rouletteGame.game.timeToStart > playerState.rouletteGame.game.COUNTDOWN_FROM && <span style={{fontSize: '1rem'}}>Time to see who won :)</span>} 35 {playerState.rouletteGame.game.timeToStart > playerState.rouletteGame.game.COUNTDOWN_FROM && <span style={{fontSize: '.7rem'}}>(And prepare, you can bet again soon.)</span>} 105 36 </div> 106 37 ) 107 38 } 108 39 109 // 10 starts from 5deg110 const numbersOfWheel = [10, 23, 8, 30, 11, 36, 13, 27, 6, 34, 17, 25, 2, 21, 4, 19, 15, 32, 0, 26, 3, 35, 12, 28, 7, 29, 18, 22, 9, 31, 14, 20, 1, 33, 16, 24, 5];111 112 40 export default Timer -
pages/api/poker/index.js
r95ce58b rd0ef259 256 256 /** 257 257 * /---------------------- GET ----------------------/ 258 * Creates the table and enters the user inside258 * Updates the state periodically 259 259 * @action update_state 260 260 * @param session_id … … 265 265 const { success, table, player } = getTableAndPlayer(session_id); 266 266 267 if ( table.started && !table.ended) {267 if (success && table.started && !table.ended) { 268 268 const d = Date.now(); 269 269 … … 272 272 table.players[table.turnIdx].isFolded = true; 273 273 274 table.lastActivity = Date.now(); 274 275 setNextPlayerIdx(table.id); 275 276 } -
pages/api/roulette/index.js
r95ce58b rd0ef259 2 2 3 3 require('dotenv').config(); 4 5 let samplePlayer = { 6 session_id: '', 7 name: '', 8 whichBets: [], 9 coinPlaced: { 10 x: -1, 11 y: -1, 12 }, 13 credits: -1, 14 betAmount: 0, 15 wonAmount: 0, 16 status: '_1_', 17 outcome: 'none', 18 gotResults: false, 19 } 4 20 5 21 function getWinningBets(magicNumber) { … … 36 52 37 53 function updateGameWithWinners() { 38 const winningBets = getWinningBets(magicNumber);39 40 54 for (let i = 0; i < game.players.length; i++) { 41 55 const player = game.players[i]; … … 43 57 let playerWon = false; 44 58 player.whichBets.forEach(bet => { 45 if ( winningBets.indexOf(bet) !== -1) {59 if (game.winningBets.indexOf(bet) !== -1) { 46 60 playerWon = true; 47 61 } … … 49 63 50 64 if (playerWon) { 51 game.players[i].outcome = 'won';65 player.outcome = 'won'; 52 66 } 53 67 else { 54 game.players[i].outcome = 'lost'; 55 } 56 } 57 } 58 59 function resetPlayers() { 68 player.outcome = 'lost'; 69 } 70 71 player.wonAmount = calculateWinnings(player); 72 73 axios.get(`${process.env.HOME_URL}/api/postgre/?action=add_credits&session_id=${player.session_id}&credits=${player.wonAmount}&game=roulette&outcome=${player.outcome}`).then(postgreRes => { 74 if (postgreRes.data?.success) { 75 player.credits = postgreRes.data?.credits; 76 } 77 }); 78 } 79 } 80 81 function resetGame() { 82 game.magicNumber = -1; 83 game.winningBets = []; 84 game.status = '_1_ongoing_timer'; 85 60 86 game.players.forEach(player => { 61 87 player.whichBets = []; 62 88 player.betAmount = 0; 89 player.wonAmount = 0; 90 player.coinPlaced = { 91 x: -1, 92 y: -1, 93 }, 63 94 player.outcome = 'none'; 64 95 player.status = '_1_no_placed_bet'; 96 player.gotResults = false; 65 97 }) 66 98 } … … 74 106 if (bets[0] === 'Even' || bets[0] === 'Odd') return 2 * bet; 75 107 else if (bets[0] === 'Red' || bets[0] === 'Black') return 2 * bet; 76 else if (bets[0]. contains('Remainder')) return 3 * bet;108 else if (bets[0].includes('Remainder')) return 3 * bet; 77 109 else if (bets[0] === '1-12' || bets[0] === '13-24' || bets[0] === '25-36') return 3 * bet; 78 110 else if (bets[0] === '1-18' || bets[0] === '19-36') return 2 * bet; … … 84 116 } 85 117 86 const COUNTDOWN_FROM = 30;87 const WAIT_BEFORE = 20;88 89 let magicNumber = -1;90 91 118 (function() { 92 119 setInterval(() => { … … 95 122 // WAIT_BEFORE seconds is the time allocated for spinning the wheel and seeing the results. 96 123 if (game.timeToStart == 0) { 97 game.timeToStart = COUNTDOWN_FROM + WAIT_BEFORE; 124 game.timeToStart = game.COUNTDOWN_FROM + game.WAIT_BEFORE; 125 126 game.magicNumber = Math.floor(Math.random() * 37); 127 game.winningBets = getWinningBets(game.magicNumber); 128 129 setTimeout(() => { 130 updateGameWithWinners(); 131 }, 6000) 98 132 } 99 133 else if (game.timeToStart == 10) { 100 magicNumber = Math.floor(Math.random() * 37);101 134 game.status = '_2_spinning'; 102 135 } 103 else if (game.timeToStart == COUNTDOWN_FROM) { 104 game.status = '_1_ongoing_timer'; 105 } 106 else if (game.timeToStart == COUNTDOWN_FROM + 5) { 107 resetPlayers(); 136 else if (game.timeToStart == game.COUNTDOWN_FROM) { 137 resetGame(); 108 138 } 109 139 … … 113 143 let game = { 114 144 status: '_1_ongoing_timer', // statuses: _1_ongoing_timer, _2_spinning, 115 timeToStart: COUNTDOWN_FROM, // in seconds 116 players: [] , // example player -> { session_id, name, whichBet, betAmount, status, outcome } // statuses: _1_no_placed_bet, _2_placed_bet 145 timeToStart: 30, // in seconds 146 COUNTDOWN_FROM: 30, 147 WAIT_BEFORE: 20, 148 magicNumber: -1, 149 winningBets: [], 150 players: [], 117 151 } 118 152 … … 123 157 name: name, 124 158 whichBets: [], 159 coinPlaced: { 160 x: -1, 161 y: -1, 162 }, 163 credits: -1, 125 164 betAmount: 0, 165 wonAmount: 0, 126 166 status: '_1_no_placed_bet', 127 167 outcome: 'none', 168 gotResults: false, 128 169 }) 170 } 171 } 172 173 export function getPlayer(session_id) { 174 const playerIdx = game.players.map(e=>e.session_id).indexOf(session_id); 175 176 if (playerIdx !== -1) { 177 return { 178 success: true, 179 player: game.players[playerIdx], 180 } 181 } 182 183 return { 184 success: false, 185 player: {...samplePlayer}, 186 }; 187 } 188 189 export function restrictGameInfo() { 190 const restrictedPlayers = game.players.map(player=>({...player, session_id: ""})) 191 192 return { 193 ...game, 194 players: restrictedPlayers, 129 195 } 130 196 } … … 140 206 /** 141 207 * /---------------------- GET ----------------------/ 142 * Return to the user info for starting a new game.143 * @action reset_game144 * @param session_id145 */146 if (req.query.action === 'reset_game' && req.query?.session_id) {147 const session_id = req.query.session_id;148 const playerIdx = game.players.map(e=>e.session_id).indexOf(session_id);149 150 if (playerIdx !== -1) {151 res.json({152 success: true,153 game: game,154 })155 }156 else {157 res.json({158 success: false,159 })160 }161 }162 163 /**164 * /---------------------- GET ----------------------/165 * Timer done on client side.166 * @action timer_done167 * @param session_id168 */169 if (req.query.action === 'timer_done' && req.query?.session_id) {170 const session_id = req.query.session_id;171 const playerIdx = game.players.map(e=>e.session_id).indexOf(session_id);172 173 if (playerIdx !== -1 && game.status.substr(1, 1) === '2') {174 updateGameWithWinners();175 176 const playerWinnings = calculateWinnings(game.players[playerIdx]);177 178 axios.get(`${process.env.HOME_URL}/api/postgre/?action=add_credits&session_id=${session_id}&credits=${playerWinnings}&game=roulette&outcome=${game.players[playerIdx].outcome}`).then(postgreRes => {179 if (postgreRes.data?.success) {180 res.json({181 success: true,182 game: game,183 magicNumber: magicNumber,184 winningBets: getWinningBets(magicNumber),185 credits: postgreRes.data?.credits,186 })187 }188 else {189 res.json({190 success: false,191 })192 }193 });194 }195 else {196 res.json({197 success: false,198 })199 }200 }201 202 /**203 * /---------------------- GET ----------------------/204 208 * Place a bet. 205 209 * @action place_bet … … 207 211 * @param betAmount 208 212 * @param whichBets 213 * @param coinPlacedX 214 * @param coinPlacedY 209 215 */ 210 if (req.query.action === 'place_bet' && req.query?.session_id && req.query?.betAmount && req.query?.whichBets ) {216 if (req.query.action === 'place_bet' && req.query?.session_id && req.query?.betAmount && req.query?.whichBets && req.query?.coinPlacedX && req.query?.coinPlacedY) { 211 217 const session_id = req.query.session_id; 212 const playerIdx = game.players.map(e=>e.session_id).indexOf(session_id); 213 214 if (playerIdx !== -1 && game.status.substr(1, 1) === '1' && game.players[playerIdx].status.substr(1, 1) === '1') { 215 game.players[playerIdx].betAmount = parseInt(req.query.betAmount); 216 game.players[playerIdx].whichBets = req.query.whichBets.split(','); 217 game.players[playerIdx].status = '_2_placed_bet'; 218 218 219 const { success, player } = getPlayer(session_id); 220 221 if (success && game.status.includes('_1_') && player.status.includes('_1_')) { 219 222 axios.get(`${process.env.HOME_URL}/api/postgre?action=take_credits&session_id=${session_id}&credits=${req.query.betAmount}`).then(postgreRes => { 220 223 if (postgreRes.data?.success) { 221 res.json({ 222 success: true, 223 game: game, 224 credits: postgreRes.data?.credits, 225 }) 226 } 227 else { 228 res.json({ 229 success: false, 230 }) 224 player.betAmount = parseInt(req.query.betAmount); 225 player.whichBets = req.query.whichBets.split(','); 226 player.status = '_2_placed_bet'; 227 player.coinPlaced = { 228 x: req.query.coinPlacedX, 229 y: req.query.coinPlacedY, 230 }, 231 player.credits = postgreRes.data?.credits; 231 232 } 232 233 }); 233 234 } 235 236 res.end(); 237 } 238 239 /** 240 * /---------------------- GET ----------------------/ 241 * Updates the state periodically 242 * @action update_state 243 * @param session_id 244 */ 245 if (req.query.action === 'update_state' && req.query?.session_id) { 246 const session_id = req.query.session_id; 247 248 const { success, player } = getPlayer(session_id); 249 250 let extraAction = ""; 251 let magicNumber = -1; 252 let winningBets = []; 253 254 if (success) { 255 if (game.timeToStart > game.COUNTDOWN_FROM && !player.gotResults) { 256 extraAction = "spin_wheel"; 257 magicNumber = game.magicNumber; 258 winningBets = game.winningBets; 259 260 player.gotResults = true; 261 } 262 } 263 264 res.json({ 265 success: true, 266 rouletteGame: { 267 game: restrictGameInfo(), 268 player: player, 269 }, 270 extraAction: extraAction, 271 magicNumber: magicNumber, 272 winningBets: winningBets, 273 }) 234 274 } 235 275 -
redux/reducers/playerSlice.js
r95ce58b rd0ef259 16 16 }, 17 17 rouletteGame: { 18 status: '', 19 timeToStart: 0, 20 players: [], 18 game: { 19 status: '_1_ongoing_timer', 20 timeToStart: 30, 21 COUNTDOWN_FROM: 30, 22 WAIT_BEFORE: 20, 23 magicNumber: -1, 24 winningBets: [], 25 players: [], 26 }, 27 player: { 28 session_id: '', 29 name: '', 30 whichBets: [], 31 coinPlaced: { 32 x: -1, 33 y: -1, 34 }, 35 credits: -1, 36 betAmount: 0, 37 wonAmount: 0, 38 status: '_1_', 39 outcome: 'none', 40 gotResults: false, 41 }, 21 42 }, 22 43 pokerGame: { -
redux/reducers/styleSlice.js
r95ce58b rd0ef259 83 83 // roulette 84 84 roulette: { 85 COUNTDOWN_FROM: 30,86 85 displays: { 87 86 betModal: false, … … 94 93 whichBets: [], 95 94 coinPlaced: { 96 x: 0, 97 y: 0, 98 }, 99 showCoin: false, 95 x: -1, 96 y: -1, 97 } 100 98 }, 101 99 // poker
Note:
See TracChangeset
for help on using the changeset viewer.