Skip to main content

BattleState

Struct BattleState 

Source
pub struct BattleState<P: BattleProvider + ?Sized> {
    pub player_battlers: Vec<BattlerState<P>>,
    pub opponent_battlers: Vec<BattlerState<P>>,
    pub turn_order: Vec<usize>,
    pub weather: Weather,
    pub terrain: Terrain,
    pub turn_count: u32,
}
Expand description

The complete state of an ongoing battle.

Tracks both sides’ parties, turn order, field conditions, and turn counter. Generic over the BattleProvider that supplies the concrete type identifiers.

Fields§

§player_battlers: Vec<BattlerState<P>>

The player’s party (one or more battlers).

§opponent_battlers: Vec<BattlerState<P>>

The opponent’s party (one or more battlers).

§turn_order: Vec<usize>

Turn order — indices into the combined battler list.

§weather: Weather

Current weather condition.

§terrain: Terrain

Current terrain condition.

§turn_count: u32

Number of turns elapsed.

Implementations§

Source§

impl<P: BattleProvider + ?Sized> BattleState<P>

Source

pub fn new( player_battlers: Vec<BattlerState<P>>, opponent_battlers: Vec<BattlerState<P>>, ) -> Self

Create a new battle state.

Examples found in repository?
examples/hello_dotzuki.rs (line 518)
483fn demo_battle() {
484    println!("\n╔══ BATTLE ENCOUNTER ═════════════════════╗");
485    let provider = HelloConfig::new();
486    let warrior = provider.create_monster(Species::Warrior, 5);
487    let mage = provider.create_monster(Species::Mage, 5);
488
489    println!("║ {} (HP:{}/{}) vs {} (HP:{}/{})",
490        warrior.species.name(), warrior.hp, warrior.max_hp,
491        mage.species.name(), mage.hp, mage.max_hp);
492
493    // Warrior attacks with Slash → super effective (2×) vs Mage
494    let result = provider.calculate_damage(&MoveKind::Slash, &warrior, &mage, 100, false);
495    println!("║ {} uses Slash! {} damage ({}x effective)",
496        warrior.species.name(), result.damage, result.effectiveness);
497
498    let mut enemy = mage.clone();
499    enemy.take_damage(result.damage);
500    println!("║ {} HP: {} → {}", mage.species.name(), mage.hp, enemy.hp);
501
502    // Mage attacks with Fireball → not very effective (0.5×) vs Warrior
503    let result = provider.calculate_damage(&MoveKind::Fireball, &mage, &warrior, 100, false);
504    println!("║ {} uses Fireball! {} damage ({}x effective)",
505        mage.species.name(), result.damage, result.effectiveness);
506
507    let mut hero = warrior.clone();
508    hero.take_damage(result.damage);
509    println!("║ {} HP: {} → {}", warrior.species.name(), warrior.hp, hero.hp);
510
511    // EffectHandler
512    let mut user = warrior.clone();
513    let mut target = mage.clone();
514    let eff_result = HelloConfig::new().handle_effect(MoveEffect::Damage, &mut user, &mut target, &HelloConfig::new());
515    println!("║ EffectHandler(Damage) → {:?}", eff_result);
516
517    // BattleAI
518    let state = BattleState::new(vec![warrior.clone()], vec![mage.clone()]);
519    let ai_move = BattleAI::select_move(&HelloConfig::default(), &warrior, &state);
520    println!("║ BattleAI chose: {}", ai_move.name());
521    println!("╚══════════════════════════════════════════╝");
522}
Source

pub fn active_player(&self) -> Option<&BattlerState<P>>

Get a reference to the active player battler (first in party).

Source

pub fn active_player_mut(&mut self) -> Option<&mut BattlerState<P>>

Get a mutable reference to the active player battler.

Source

pub fn active_opponent(&self) -> Option<&BattlerState<P>>

Get a reference to the active opponent battler.

Source

pub fn active_opponent_mut(&mut self) -> Option<&mut BattlerState<P>>

Get a mutable reference to the active opponent battler.

Trait Implementations§

Source§

impl<P: BattleProvider + ?Sized> Clone for BattleState<P>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<P: BattleProvider + ?Sized> Debug for BattleState<P>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.