Changeset aac3b2b for pages/api/poker
- Timestamp:
- 07/07/22 23:53:57 (2 years ago)
- Branches:
- main
- Children:
- 95ce58b
- Parents:
- 189cd8f
- Location:
- pages/api/poker
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pages/api/poker/index.js
r189cd8f raac3b2b 47 47 }, 48 48 }], 49 onlyOnePlayerLeft: false, 49 50 winners: [], 50 51 splitWinners: false, … … 281 282 const { success, table } = getTableAndPlayer(req.query.session_id) 282 283 283 if (success && !table.started ) {284 if (success && !table.started && !table.ended && table.players.filter(e=>e.isSatDown===true).length >= 2) { 284 285 table.players.forEach(player => { 285 286 axios.get(`${process.env.HOME_URL}/api/postgre/?action=check_if_logged_in&session_id=${player.id}`).then(postgreRes => { … … 342 343 player.isFolded = true; 343 344 344 if (table.players[table.turnIdx] !== undefined && table.players[table.turnIdx] === player) { 345 setNextPlayerIdx(table.id); 345 if (table.started) { 346 if (table.players[table.turnIdx] !== undefined && table.players[table.turnIdx] === player) { 347 setNextPlayerIdx(table.id); 348 } 349 } 350 else { 351 table.players = table.players.filter(e=>e.isGhost === false); 346 352 } 347 353 } -
pages/api/poker/tableSpecific.js
r189cd8f raac3b2b 62 62 const tableIdx = tables.map(e=>e.id).indexOf(tableId); 63 63 64 if (tables[tableIdx] !== undefined) { 65 const table = tables[tableIdx]; 64 if (tables[tableIdx] !== undefined && !tables[tableIdx].ended) { 65 const table = tables[tableIdx]; 66 67 const remainingPlayers = table.players.filter(e=>e.isSatDown===true).filter(e=>e.isGhost===false); 68 if (remainingPlayers.length === 1) { 69 setWinnerDirect(table.id, remainingPlayers[0]); 70 71 return ; 72 } 73 74 const remainingPlayersWithCredits = table.players.filter(e=>e.isSatDown===true).filter(e=>e.isGhost===false).filter(e=>e.isFolded===false).filter(e=>e.credits > 0); 75 if (remainingPlayersWithCredits.length === 1) { 76 progressRoundTillTheEnd(table.id); 77 78 return ; 79 } 66 80 67 81 if (table.turnTimeout !== null) clearTimeout(table.turnTimeout); … … 83 97 if (table.players[table.turnIdx] !== undefined) { 84 98 table.players[table.turnIdx].isFolded = true; 85 99 86 100 setNextPlayerIdx(table.id); 87 101 } … … 136 150 table.ended = false; 137 151 table.round = 0; 138 table.turnIdx = 0;152 table.turnIdx = -1; 139 153 table.turnTimeout = null; 140 154 table.pot = 0; … … 143 157 table.deck = [...deck]; 144 158 145 table.players = table.players.filter(e=>e.isGhost === false); 146 table.players = table.players.filter(e=>e.credits >= 20); 159 table.players = table.players.filter(e=>e.isGhost === false).filter(e=>e.credits >= 20); 147 160 148 161 table.players.forEach(player => { … … 157 170 } 158 171 }) 172 173 table.onlyOnePlayerLeft = false; 159 174 table.winners = []; 160 175 table.splitWinners = false; … … 168 183 if (tables[tableIdx] !== undefined) { 169 184 const table = tables[tableIdx]; 170 171 const satDownPlayers = table.players.filter(e => e.isSatDown === true);172 const satDownCount = satDownPlayers.length;173 185 174 186 table.players.forEach(player => { … … 212 224 } 213 225 226 export function setWinnerDirect(tableId, player) { 227 const tableIdx = tables.map(e=>e.id).indexOf(tableId); 228 229 if (tables[tableIdx] !== undefined) { 230 const table = tables[tableIdx]; 231 232 table.turnIdx = -1; 233 table.started = false; 234 table.ended = true; 235 236 table.onlyOnePlayerLeft = true; 237 table.winners = [player]; 238 239 giveMoneyToTheWinners(table.id); 240 } 241 } 242 214 243 export function setWinner(tableId) { 215 244 const tableIdx = tables.map(e=>e.id).indexOf(tableId); … … 259 288 } 260 289 290 export function progressRoundTillTheEnd(tableId) { 291 const tableIdx = tables.map(e=>e.id).indexOf(tableId); 292 293 if (tables[tableIdx] !== undefined) { 294 const table = tables[tableIdx]; 295 296 while (table.round < 4) { 297 table.round++; 298 getCardsOnTable(table.id); 299 } 300 301 table.started = false; 302 table.ended = true; 303 if (table.ended && table.winners.length === 0) { 304 setWinner(table.id); 305 } 306 } 307 } 308 261 309 export function progressRoundIfNeeded(tableId) { 262 310 const tableIdx = tables.map(e=>e.id).indexOf(tableId); … … 277 325 } 278 326 else { 327 table.started = false; 279 328 table.ended = true; 280 329 }
Note:
See TracChangeset
for help on using the changeset viewer.