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 760)
701fn demo_battle() {
702    println!("\n╔══ BATTLE ENCOUNTER ═════════════════════╗");
703    let provider = HelloConfig::new();
704    let warrior = provider.create_monster(Species::Warrior, 5);
705    let mage = provider.create_monster(Species::Mage, 5);
706
707    println!(
708        "║ {} (HP:{}/{}) vs {} (HP:{}/{})",
709        warrior.species.name(),
710        warrior.hp,
711        warrior.max_hp,
712        mage.species.name(),
713        mage.hp,
714        mage.max_hp
715    );
716
717    // Warrior attacks with Slash → super effective (2×) vs Mage
718    let result = provider.calculate_damage(&MoveKind::Slash, &warrior, &mage, 100, false);
719    println!(
720        "║ {} uses Slash! {} damage ({}x effective)",
721        warrior.species.name(),
722        result.damage,
723        result.effectiveness
724    );
725
726    let mut enemy = mage.clone();
727    enemy.take_damage(result.damage);
728    println!("║ {} HP: {} → {}", mage.species.name(), mage.hp, enemy.hp);
729
730    // Mage attacks with Fireball → not very effective (0.5×) vs Warrior
731    let result = provider.calculate_damage(&MoveKind::Fireball, &mage, &warrior, 100, false);
732    println!(
733        "║ {} uses Fireball! {} damage ({}x effective)",
734        mage.species.name(),
735        result.damage,
736        result.effectiveness
737    );
738
739    let mut hero = warrior.clone();
740    hero.take_damage(result.damage);
741    println!(
742        "║ {} HP: {} → {}",
743        warrior.species.name(),
744        warrior.hp,
745        hero.hp
746    );
747
748    // EffectHandler
749    let mut user = warrior.clone();
750    let mut target = mage.clone();
751    let eff_result = HelloConfig::new().handle_effect(
752        MoveEffect::Damage,
753        &mut user,
754        &mut target,
755        &HelloConfig::new(),
756    );
757    println!("║ EffectHandler(Damage) → {:?}", eff_result);
758
759    // BattleAI
760    let state = BattleState::new(vec![warrior.clone()], vec![mage.clone()]);
761    let ai_move = BattleAI::select_move(&HelloConfig::default(), &warrior, &state);
762    println!("║ BattleAI chose: {}", ai_move.name());
763    println!("╚══════════════════════════════════════════╝");
764}
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§

§

impl<P> Freeze for BattleState<P>
where Vec<BattlerState<P>>: Freeze, P: ?Sized,

§

impl<P> RefUnwindSafe for BattleState<P>

§

impl<P> Send for BattleState<P>
where Vec<BattlerState<P>>: Send, P: ?Sized,

§

impl<P> Sync for BattleState<P>
where Vec<BattlerState<P>>: Sync, P: ?Sized,

§

impl<P> Unpin for BattleState<P>
where Vec<BattlerState<P>>: Unpin, P: ?Sized,

§

impl<P> UnsafeUnpin for BattleState<P>

§

impl<P> UnwindSafe for BattleState<P>
where Vec<BattlerState<P>>: UnwindSafe, P: ?Sized,

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 = !

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.