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 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}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>
impl<P> RefUnwindSafe for BattleState<P>
impl<P> Send for BattleState<P>
impl<P> Sync for BattleState<P>
impl<P> Unpin for BattleState<P>
impl<P> UnsafeUnpin for BattleState<P>
impl<P> UnwindSafe for BattleState<P>
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