From ea466a600aca8e1271271e1bca531edeb5c391e5 Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Wed, 24 May 2023 16:55:24 +0300 Subject: [PATCH] feat(client): RollForPlays, and some log stuff --- client/src/api/game/mod.rs | 4 +++ client/src/game_status/parser.rs | 43 +++++++++++++++++++++++++++++++- client/src/util/action_to_log.rs | 6 +++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/client/src/api/game/mod.rs b/client/src/api/game/mod.rs index e5a488f..0a79ea5 100644 --- a/client/src/api/game/mod.rs +++ b/client/src/api/game/mod.rs @@ -73,6 +73,10 @@ pub enum Command { GivePlays { amount: usize, }, + RollForPlays { + amount: usize, + sides: usize, + }, GiveBuys { amount: usize, }, diff --git a/client/src/game_status/parser.rs b/client/src/game_status/parser.rs index 4d46678..4496cfe 100644 --- a/client/src/game_status/parser.rs +++ b/client/src/game_status/parser.rs @@ -253,17 +253,58 @@ fn parse_action(action: &Action, game: &Game, game_status: &mut GameStatus) { target.state = *state; } Command::RollForCurrency { amount, sides } => { + let mut results: Vec = Vec::with_capacity(*amount); for _ in 0..*amount { let result = Rng::with_seed(action.seed.parse::().unwrap()).usize(1..=*sides); target.currency += result; + + results.push(result); + } + + if *amount == 1 { game_status.log.push(LogEntry::from_sections([ - LogSection::bold(&format!(" {}", result.to_string())), + LogSection::bold(&results.first().unwrap().to_string()), + ])); + } else { + game_status.log.push(LogEntry::from_sections([ + LogSection::bold( + &format!( + " {} = {}", + results.iter().map(ToString::to_string).collect::>().join(" "), + results.iter().sum::(), + ) + ), ])); } } Command::GivePlays { amount } => { target.plays += amount; } + Command::RollForPlays { amount, sides } => { + let mut results: Vec = Vec::with_capacity(*amount); + for _ in 0..*amount { + let result = Rng::with_seed(action.seed.parse::().unwrap()).usize(1..=*sides); + target.plays += result; + + results.push(result); + } + + if *amount == 1 { + game_status.log.push(LogEntry::from_sections([ + LogSection::bold(&results.first().unwrap().to_string()), + ])); + } else { + game_status.log.push(LogEntry::from_sections([ + LogSection::bold( + &format!( + " {} = {}", + results.iter().map(ToString::to_string).collect::>().join(" "), + results.iter().sum::(), + ) + ), + ])); + } + } Command::GiveBuys { amount } => { target.buys += amount; } diff --git a/client/src/util/action_to_log.rs b/client/src/util/action_to_log.rs index 7d66783..c06640f 100644 --- a/client/src/util/action_to_log.rs +++ b/client/src/util/action_to_log.rs @@ -94,6 +94,12 @@ pub fn action_to_log(action: &Action, game_status: &GameStatus) -> LogEntry { LogSection::bold(&format!("{}d{}", amount, sides)), LogSection::normal(" for currency:"), ]), + Command::RollForPlays { amount, sides } => LogEntry::from_sections(vec![ + LogSection::bold(invoker_name), + LogSection::normal(" rolled "), + LogSection::bold(&format!("{}d{}", amount, sides)), + LogSection::normal(" for plays:"), + ]), #[allow(unreachable_patterns)] _ => LogEntry { sections: vec![LogSection::normal("No log configuration for this command")], -- 2.44.1