DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

7d5486e5144305656353cbfcdfd8a177c99cb88b — Jonni Liljamo 1 year, 6 months ago 0c4f861
feat(client): advanced roll action, log configs
M client/assets/card_manifest.yaml => client/assets/card_manifest.yaml +20 -6
@@ 83,22 83,36 @@ cards:

  - name: Test Card 6
    short_details:
      - 1d20 currency, <15 = 0, 15-19 = 2, 20 = 6
      - 1d20 for currency, <4 = -2VP, 4-15 = 0, 15-19 = 2, 20 = 6
    long_details:
      - Roll 1d20 for currency
      - Roll 1d20 for currency, with a possibility to lose VP
    cost: 4
    actions:
      - command:
          !RollForCurrencyAdvanced
          !RollForAdvanced
            amount: 1
            sides: 20
            pairs:
              - - 4
                - command:
                    !RemoveVP
                    amount: 2
                  target_self: true
              - - 15
                - 0
                - command:
                    !GiveCurrency
                    amount: 0
                  target_self: true
              - - 19
                - 2
                - command:
                    !GiveCurrency
                    amount: 2
                  target_self: true
              - - 20
                - 6
                - command:
                    !GiveCurrency
                    amount: 6
                  target_self: true
        target_self: true
    to_be_trashed: false


M client/src/api/game/mod.rs => client/src/api/game/mod.rs +10 -4
@@ 11,7 11,7 @@ use serde::{Deserialize, Serialize};
use serde_repr::Deserialize_repr;

use crate::{
    game_status::{Card, PlayerState},
    game_status::{Card, PlayerState, CardAction},
    seed_gen,
};



@@ 69,14 69,17 @@ pub enum Command {
    ChangePlayerState {
        state: PlayerState,
    },
    RollForCurrency {
    RollForAdvanced {
        amount: usize,
        sides: usize,
        pairs: Vec<(usize, CardAction)>,
    },
    GiveCurrency {
        amount: usize,
    },
    RollForCurrencyAdvanced {
    RollForCurrency {
        amount: usize,
        sides: usize,
        pairs: Vec<(usize, usize)>,
    },
    GivePlays {
        amount: usize,


@@ 91,6 94,9 @@ pub enum Command {
    GiveVP {
        amount: usize,
    },
    RemoveVP {
        amount: usize,
    },
    /// mark a card in the targets deck to be trashed on play.
    /// if index in None, a random card will be chosen
    MarkCardInDeckToBeTrashed {

M client/src/game_status/parser.rs => client/src/game_status/parser.rs +32 -11
@@ 248,15 248,36 @@ fn parse_action(action: &Action, game: &Game, game_status: &mut GameStatus) {
        Command::ChangePlayerState { state } => {
            target.state = *state;
        }
        Command::RollForCurrency { amount, sides } => {
        Command::RollForAdvanced { amount, sides, pairs } => {
            let mut results: Vec<usize> = Vec::with_capacity(*amount);
            for _ in 0..*amount {
                let result = Rng::with_seed(action.seed.parse::<u64>().unwrap()).usize(1..=*sides);
                target.currency += result;

                let mut last = 0;
                for (pos, res) in pairs {
                    if (last..=*pos).contains(&result) {
                        // TODO: check res.target_self, and select another
                        // player as target if false.
                        let action = Action::new(
                            &game.id,
                            &action.target,
                            &action.target,
                            &res.command,
                            current_seed!(action),
                        );
                        game_status
                            .actions
                            .insert(action_pos + 1, action.clone());

                        parse_action(&action, game, game_status);
                    }
                    last = *pos;
                }

                results.push(result);
            }

            /*
            if *amount == 1 {
                game_status
                    .log


@@ 276,19 297,16 @@ fn parse_action(action: &Action, game: &Game, game_status: &mut GameStatus) {
                        results.iter().sum::<usize>(),
                    ))]));
            }
            */
        }
        Command::GiveCurrency { amount } => {
            target.currency += amount;
        }
        Command::RollForCurrencyAdvanced { amount, sides, pairs } => {
        Command::RollForCurrency { amount, sides } => {
            let mut results: Vec<usize> = Vec::with_capacity(*amount);
            for _ in 0..*amount {
                let result = Rng::with_seed(action.seed.parse::<u64>().unwrap()).usize(1..=*sides);

                let mut last = 0;
                for (pos, res) in pairs {
                    if (last..=*pos).contains(&result) {
                        target.currency += res;
                    }
                    last = *pos;
                }
                target.currency += result;

                results.push(result);
            }


@@ 351,6 369,9 @@ fn parse_action(action: &Action, game: &Game, game_status: &mut GameStatus) {
        Command::GiveVP { amount } => {
            target.vp += amount;
        }
        Command::RemoveVP { amount } => {
            target.vp -= amount;
        }
        Command::MarkCardInDeckToBeTrashed { index } => {
            if target.deck.is_empty() {
                return;

M client/src/util/action_to_log.rs => client/src/util/action_to_log.rs +24 -5
@@ 88,17 88,21 @@ pub fn action_to_log(action: &Action, game_status: &GameStatus) -> LogEntry {
            LogSection::normal(" changed state to "),
            LogSection::bold(&format!("{:?}", state)),
        ]),
        Command::GiveCurrency { amount } => LogEntry::from_sections(vec![
            LogSection::bold(target_name),
            LogSection::bold(&format!("+{}", amount)),
            LogSection::normal(" currency"),
        ]),
        Command::RollForCurrency { amount, sides } => LogEntry::from_sections(vec![
            LogSection::bold(invoker_name),
            LogSection::normal(" rolled "),
            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::GivePlays { amount } => LogEntry::from_sections(vec![
            LogSection::bold(target_name),
            LogSection::bold(&format!("+{}", amount)),
            LogSection::normal(" plays"),
        ]),
        Command::RollForPlays { amount, sides } => LogEntry::from_sections(vec![
            LogSection::bold(invoker_name),


@@ 106,6 110,21 @@ pub fn action_to_log(action: &Action, game_status: &GameStatus) -> LogEntry {
            LogSection::bold(&format!("{}d{}", amount, sides)),
            LogSection::normal(" for plays:"),
        ]),
        Command::GiveBuys { amount } => LogEntry::from_sections(vec![
            LogSection::bold(target_name),
            LogSection::bold(&format!(" +{}", amount)),
            LogSection::normal(" buys"),
        ]),
        Command::GiveVP { amount } => LogEntry::from_sections(vec![
            LogSection::bold(target_name),
            LogSection::bold(&format!(" +{}", amount)),
            LogSection::normal(" VP"),
        ]),
        Command::RemoveVP { amount } => LogEntry::from_sections(vec![
            LogSection::bold(target_name),
            LogSection::bold(&format!(" -{}", amount)),
            LogSection::normal(" VP"),
        ]),
        #[allow(unreachable_patterns)]
        _ => LogEntry {
            sections: vec![LogSection::normal("No log configuration for this command")],