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: WeatherCurrent weather condition.
terrain: TerrainCurrent terrain condition.
turn_count: u32Number of turns elapsed.
Implementations§
Source§impl<P: BattleProvider + ?Sized> BattleState<P>
impl<P: BattleProvider + ?Sized> BattleState<P>
Sourcepub fn new(
player_battlers: Vec<BattlerState<P>>,
opponent_battlers: Vec<BattlerState<P>>,
) -> Self
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}Sourcepub fn active_player(&self) -> Option<&BattlerState<P>>
pub fn active_player(&self) -> Option<&BattlerState<P>>
Get a reference to the active player battler (first in party).
Sourcepub fn active_player_mut(&mut self) -> Option<&mut BattlerState<P>>
pub fn active_player_mut(&mut self) -> Option<&mut BattlerState<P>>
Get a mutable reference to the active player battler.
Sourcepub fn active_opponent(&self) -> Option<&BattlerState<P>>
pub fn active_opponent(&self) -> Option<&BattlerState<P>>
Get a reference to the active opponent battler.
Sourcepub fn active_opponent_mut(&mut self) -> Option<&mut BattlerState<P>>
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>
impl<P: BattleProvider + ?Sized> Clone for BattleState<P>
Auto Trait Implementations§
impl<P> Freeze for BattleState<P>where
P: ?Sized,
impl<P> RefUnwindSafe for BattleState<P>where
<P as BattleProvider>::Species: RefUnwindSafe,
<P as BattleProvider>::Status: RefUnwindSafe,
<P as BattleProvider>::Move: RefUnwindSafe,
<P as BattleProvider>::Stat: RefUnwindSafe,
P: ?Sized,
impl<P> Send for BattleState<P>where
<P as BattleProvider>::Species: Send,
<P as BattleProvider>::Status: Send,
<P as BattleProvider>::Move: Send,
<P as BattleProvider>::Stat: Send,
P: ?Sized,
impl<P> Sync for BattleState<P>where
<P as BattleProvider>::Species: Sync,
<P as BattleProvider>::Status: Sync,
<P as BattleProvider>::Move: Sync,
<P as BattleProvider>::Stat: Sync,
P: ?Sized,
impl<P> Unpin for BattleState<P>where
<P as BattleProvider>::Species: Unpin,
<P as BattleProvider>::Status: Unpin,
<P as BattleProvider>::Move: Unpin,
<P as BattleProvider>::Stat: Unpin,
P: ?Sized,
impl<P> UnsafeUnpin for BattleState<P>where
P: ?Sized,
impl<P> UnwindSafe for BattleState<P>where
<P as BattleProvider>::Species: UnwindSafe,
<P as BattleProvider>::Status: UnwindSafe,
<P as BattleProvider>::Move: UnwindSafe,
<P as BattleProvider>::Stat: UnwindSafe,
P: ?Sized,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more