DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

5916aa702101682406ba7448cd796105e172b981 — Jonni Liljamo 1 year, 4 months ago c48f91e
feat(client): new cards, advanced currency roll
M client/assets/card_manifest.yaml => client/assets/card_manifest.yaml +34 -0
@@ 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


M client/src/api/game/mod.rs => client/src/api/game/mod.rs +5 -0
@@ 70,6 70,11 @@ pub enum Command {
        amount: usize,
        sides: usize,
    },
    RollForCurrencyAdvanced {
        amount: usize,
        sides: usize,
        pairs: Vec<(usize, usize)>,
    },
    GivePlays {
        amount: usize,
    },

M client/src/game_status/parser.rs => client/src/game_status/parser.rs +36 -0
@@ 280,6 280,42 @@ fn parse_action(action: &Action, game: &Game, game_status: &mut GameStatus) {
                    ))]));
            }
        }
        Command::RollForCurrencyAdvanced { 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);

                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::<Vec<String>>()
                            .join(" "),
                        results.iter().sum::<usize>(),
                    ))]));
            }
        }
        Command::GivePlays { amount } => {
            target.plays += amount;
        }

M client/src/util/action_to_log.rs => client/src/util/action_to_log.rs +6 -0
@@ 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 "),