Skip to main content

oab_game/
lib.rs

1//! Open Auto Battler Game Modes
2//!
3//! Game-mode rules, session management, and validation built on top of
4//! the oab-battle engine. This crate is no_std compatible for use in blockchain pallets.
5
6#![cfg_attr(not(feature = "std"), no_std)]
7
8extern crate alloc;
9
10use parity_scale_codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
11use scale_info::TypeInfo;
12
13#[cfg(feature = "std")]
14use serde::{Deserialize, Serialize};
15
16pub mod constructed;
17pub mod sealed;
18pub mod state;
19pub mod view;
20
21// Re-export key types for convenience
22pub use state::{
23    derive_hand_indices_logic, GamePhase, GameSession, GameState, LocalGameState,
24};
25pub use view::*;
26
27/// Configuration for a game mode.
28///
29/// Controls mana progression, lives, win conditions, and other per-mode rules.
30/// The battle engine validates turns against whatever values are in ShopState;
31/// this config determines what those values are set to.
32#[derive(Debug, Clone, PartialEq, Encode, Decode, DecodeWithMemTracking, TypeInfo, MaxEncodedLen)]
33#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
34pub struct GameConfig {
35    /// Starting lives for the player.
36    pub starting_lives: i32,
37    /// Wins needed for victory.
38    pub wins_to_victory: i32,
39    /// Mana limit at round 1.
40    pub starting_mana_limit: i32,
41    /// Maximum mana limit (cap for progression).
42    pub max_mana_limit: i32,
43    /// If true, shop_mana is set to mana_limit at the start of each round
44    /// (players don't need to burn cards for mana).
45    pub full_mana_each_round: bool,
46    /// Number of board slots.
47    pub board_size: u32,
48    /// Number of cards drawn per round as the player's hand.
49    pub hand_size: u32,
50    /// Number of cards in the starting bag/deck.
51    pub bag_size: u32,
52}
53
54impl GameConfig {
55    /// Calculate the mana limit for a given round.
56    pub fn mana_limit_for_round(&self, round: i32) -> i32 {
57        (self.starting_mana_limit + round - 1).min(self.max_mana_limit)
58    }
59}
60
61#[cfg(feature = "bounded")]
62pub mod bounded;
63
64#[cfg(test)]
65mod tests;