From 6e2787d792de64c003eff03b62a2df798ef851c0 Mon Sep 17 00:00:00 2001 From: salmonik Date: Thu, 29 Oct 2026 20:43:09 +0100 Subject: v2.3.0: add crash with local multiplier and pushed crash event --- src/client/games/manager.rs | 90 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) (limited to 'src/client/games/manager.rs') diff --git a/src/client/games/manager.rs b/src/client/games/manager.rs index 4e0218b..4d9e6a8 100644 --- a/src/client/games/manager.rs +++ b/src/client/games/manager.rs @@ -1,9 +1,11 @@ use super::blackjack::BlackjackGame; +use super::crash::CrashGame; use super::response::{RouletteResult, SpinResult}; use super::roulette::RouletteGame; use super::slots::SlotsGame; use super::traits::{Game, GameError, GamePhase, GameState}; use crate::blackjack::BlackjackState; +use crate::crash::{payout, CrashState}; use crate::roulette::Bets; use std::collections::HashMap; @@ -18,6 +20,7 @@ impl GameManager { games.insert("slots".to_string(), Box::new(SlotsGame::new())); games.insert("roulette".to_string(), Box::new(RouletteGame::new())); games.insert("blackjack".to_string(), Box::new(BlackjackGame::new())); + games.insert("crash".to_string(), Box::new(CrashGame::new())); Self { current_session: None, @@ -57,6 +60,10 @@ impl GameManager { } else if game_type == "blackjack" { data.insert("status".to_string(), "ready".to_string()); 10 + } else if game_type == "crash" { + data.insert("status".to_string(), "ready".to_string()); + data.insert("multiplier".to_string(), "1.00".to_string()); + 10 } else { 10 }; @@ -173,11 +180,19 @@ impl GameManager { session.data.remove("winnings"); session.data.remove("number"); session.data.remove("color"); + session.data.remove("payout"); + session.data.remove("crash_point"); if session.game_type == "roulette" { session .data .insert("status".to_string(), "place".to_string()); } + if session.game_type == "crash" { + session + .data + .insert("status".to_string(), "ready".to_string()); + session.data.remove("session_id"); + } session.data.insert("error".to_string(), message.into()); } @@ -309,6 +324,81 @@ impl GameManager { } } + pub fn apply_crash_state(&mut self, state: CrashState) { + let Some(session) = self.current_session.as_mut() else { + return; + }; + let running = state.is_running(); + session.phase = if running { + GamePhase::Playing + } else { + GamePhase::Finished + }; + session.bet_amount = state.bet; + session.data.remove("error"); + for key in ["crash_point", "payout"] { + session.data.remove(key); + } + session.data.insert("status".to_string(), state.phase.clone()); + session + .data + .insert("session_id".to_string(), state.session_id); + session + .data + .insert("balance".to_string(), state.balance.to_string()); + session + .data + .insert("multiplier".to_string(), format!("{:.2}", state.multiplier)); + session + .data + .insert("potential".to_string(), state.potential.to_string()); + session + .data + .insert("payout".to_string(), state.payout.to_string()); + if let Some(crash_point) = state.crash_point { + session + .data + .insert("crash_point".to_string(), format!("{crash_point:.2}")); + } + } + + /// Redraw the live multiplier from the client's local clock. + pub fn set_crash_multiplier(&mut self, multiplier: f64) { + let Some(session) = self.current_session.as_mut() else { + return; + }; + let bet = session.bet_amount; + session + .data + .insert("multiplier".to_string(), format!("{multiplier:.2}")); + session + .data + .insert("potential".to_string(), payout(bet, multiplier).to_string()); + } + + pub fn set_crash_status(&mut self, status: &str) { + if let Some(session) = self.current_session.as_mut() { + session + .data + .insert("status".to_string(), status.to_string()); + } + } + + pub fn crash_status(&self) -> String { + self.current_session + .as_ref() + .and_then(|session| session.data.get("status")) + .cloned() + .unwrap_or_else(|| "ready".to_string()) + } + + pub fn crash_session_id(&self) -> Option { + self.current_session + .as_ref() + .and_then(|session| session.data.get("session_id")) + .cloned() + } + pub fn get_current_game(&self) -> Option<&dyn Game> { self.current_session .as_ref() -- cgit v1.2.3