2026-02-08 23:47:57 -08:00
|
|
|
use log::debug;
|
|
|
|
|
use spacetimedb::{ReducerContext, Table, rand::seq::SliceRandom, reducer};
|
|
|
|
|
|
|
|
|
|
use super::hand::deal_hands;
|
|
|
|
|
use crate::tables::*;
|
|
|
|
|
use jong_types::*;
|
|
|
|
|
|
|
|
|
|
#[reducer]
|
|
|
|
|
pub fn shuffle_deal(ctx: &ReducerContext, lobby_id: u32) {
|
|
|
|
|
debug!("lobby_id: {lobby_id}");
|
|
|
|
|
let mut lobby = ctx.db.lobby().id().find(lobby_id).unwrap();
|
|
|
|
|
|
|
|
|
|
lobby.game_state = GameState::Deal;
|
|
|
|
|
let mut lobby = ctx.db.lobby().id().update(lobby);
|
|
|
|
|
|
|
|
|
|
let tiles = new_shuffled_wall(ctx);
|
|
|
|
|
ctx.db.wall().insert(Wall {
|
|
|
|
|
// id: 0,
|
|
|
|
|
lobby_id,
|
|
|
|
|
tiles,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
deal_hands(ctx, lobby_id);
|
|
|
|
|
|
|
|
|
|
lobby.game_state = GameState::Play;
|
2026-02-10 01:40:13 -08:00
|
|
|
lobby.turn_state = TurnState::Tsumo;
|
2026-02-08 23:47:57 -08:00
|
|
|
ctx.db.lobby().id().update(lobby);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn new_shuffled_wall(ctx: &ReducerContext) -> Vec<Tile> {
|
|
|
|
|
let mut rng = ctx.rng();
|
|
|
|
|
let mut wall = tiles();
|
|
|
|
|
wall.shuffle(&mut rng);
|
|
|
|
|
|
|
|
|
|
wall
|
|
|
|
|
}
|