From 5916aa702101682406ba7448cd796105e172b981 Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Wed, 24 May 2023 21:38:19 +0300 Subject: [PATCH] feat(client): new cards, advanced currency roll --- client/assets/card_manifest.yaml | 34 ++++++++++++++++++++++++++++++ client/src/api/game/mod.rs | 5 +++++ client/src/game_status/parser.rs | 36 ++++++++++++++++++++++++++++++++ client/src/util/action_to_log.rs | 6 ++++++ 4 files changed, 81 insertions(+) diff --git a/client/assets/card_manifest.yaml b/client/assets/card_manifest.yaml index 7023fbf..583c8e8 100644 --- a/client/assets/card_manifest.yaml +++ b/client/assets/card_manifest.yaml @@ -68,3 +68,37 @@ cards: target_self: true to_be_trashed: false + - name: Test Card 5 + short_details: + - +2 buys + long_details: + - Get 2 buys + cost: 4 + actions: + - command: + !GiveBuys + amount: 2 + target_self: true + to_be_trashed: false + + - name: Test Card 6 + short_details: + - 1d20 currency, <15 = 0, 15-19 = 2, 20 = 6 + long_details: + - Roll 1d20 for currency + cost: 4 + actions: + - command: + !RollForCurrencyAdvanced + amount: 1 + sides: 20 + pairs: + - - 15 + - 0 + - - 19 + - 2 + - - 20 + - 6 + target_self: true + to_be_trashed: false + diff --git a/client/src/api/game/mod.rs b/client/src/api/game/mod.rs index 0a79ea5..4e4aff4 100644 --- a/client/src/api/game/mod.rs +++ b/client/src/api/game/mod.rs @@ -70,6 +70,11 @@ pub enum Command { amount: usize, sides: usize, }, + RollForCurrencyAdvanced { + amount: usize, + sides: usize, + pairs: Vec<(usize, usize)>, + }, GivePlays { amount: usize, }, diff --git a/client/src/game_status/parser.rs b/client/src/game_status/parser.rs index df67f48..a9d31ec 100644 --- a/client/src/game_status/parser.rs +++ b/client/src/game_status/parser.rs @@ -280,6 +280,42 @@ fn parse_action(action: &Action, game: &Game, game_status: &mut GameStatus) { ))])); } } + Command::RollForCurrencyAdvanced { amount, sides, pairs } => { + let mut results: Vec = Vec::with_capacity(*amount); + for _ in 0..*amount { + let result = Rng::with_seed(action.seed.parse::().unwrap()).usize(1..=*sides); + + let mut last = 0; + for (pos, res) in pairs { + if (last..=*pos).contains(&result) { + target.currency += res; + } + last = *pos; + } + + 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::GivePlays { amount } => { target.plays += amount; } diff --git a/client/src/util/action_to_log.rs b/client/src/util/action_to_log.rs index c06640f..89211d7 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::RollForCurrencyAdvanced { amount, sides, pairs: _ } => LogEntry::from_sections(vec![ + LogSection::bold(invoker_name), + LogSection::normal(" rolled "), + 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 "), -- 2.44.1