pub trait BattleProvider {
type Monster: Clone + Debug;
type Move: Clone + Debug;
type Ability: Clone + Debug;
type Status: Clone + PartialEq + Debug;
type Stat: Copy + PartialEq + Debug;
type Species: Clone + Debug;
type Type: Clone + PartialEq + Debug;
type Item: Clone + Debug;
// Required methods
fn calculate_damage(
&self,
move_: &Self::Move,
attacker: &BattlerState<Self>,
defender: &BattlerState<Self>,
random: u8,
is_critical: bool,
) -> DamageResult;
fn select_move(
&self,
battler: &BattlerState<Self>,
state: &BattleState<Self>,
) -> Self::Move;
fn apply_move_effect(
&self,
effect: MoveEffect,
user: &mut BattlerState<Self>,
target: &mut BattlerState<Self>,
) -> EffectResult;
fn create_monster(
&self,
species: Self::Species,
level: u8,
) -> BattlerState<Self>;
// Provided methods
fn check_faint(&self, battler: &BattlerState<Self>) -> bool { ... }
fn move_cost(&self, _move_: &Self::Move) -> &[(u16, u16)] { ... }
fn turn_order_key(
&self,
_state: &BattleState<Self>,
_who: BattlerRef,
_action: &BattleAction<Self>,
_rng: &mut dyn BattleRng,
) -> OrderKey
where Self: Sized { ... }
fn before_move(
&self,
_state: &mut BattleState<Self>,
_who: BattlerRef,
_action: &BattleAction<Self>,
_rng: &mut dyn BattleRng,
) -> MoveGate<Self>
where Self: Sized { ... }
fn accuracy_check(
&self,
_state: &BattleState<Self>,
_who: BattlerRef,
_target: BattlerRef,
_move_: &Self::Move,
_rng: &mut dyn BattleRng,
) -> bool
where Self: Sized { ... }
fn end_of_turn(
&self,
_state: &mut BattleState<Self>,
_rng: &mut dyn BattleRng,
) -> Vec<EffectResult>
where Self: Sized { ... }
fn roll_critical(
&self,
_state: &BattleState<Self>,
_who: BattlerRef,
_target: BattlerRef,
_move_: &Self::Move,
_rng: &mut dyn BattleRng,
) -> bool
where Self: Sized { ... }
}Expand description
Central trait for battle system data and formula implementations.
Implementations provide concrete types for monsters, moves, abilities, statuses, stats, species, and types, along with methods for damage calculation, monster creation, move selection, and effect application.
All methods take &self — the provider is a read-only data source.
§Associated Types
| Type | Purpose |
|---|---|
Monster | Full monster/character data (species + stats + HP) |
Move | Move identifier (ID or inline data struct) |
Ability | Passive ability identifier |
Status | Status condition identifier (burn, sleep, etc.) |
Stat | Stat identifier (HP, ATK, DEF, SPD, etc.) |
Species | Species/monster-type identifier |
Type | Elemental type identifier |
Item | Usable item identifier |
Required Associated Types§
Required Methods§
Sourcefn calculate_damage(
&self,
move_: &Self::Move,
attacker: &BattlerState<Self>,
defender: &BattlerState<Self>,
random: u8,
is_critical: bool,
) -> DamageResult
fn calculate_damage( &self, move_: &Self::Move, attacker: &BattlerState<Self>, defender: &BattlerState<Self>, random: u8, is_critical: bool, ) -> DamageResult
Calculate damage for a move against a defender.
The provider is responsible for implementing the damage formula, consulting the type chart, and applying stat stage modifiers.
Sourcefn select_move(
&self,
battler: &BattlerState<Self>,
state: &BattleState<Self>,
) -> Self::Move
fn select_move( &self, battler: &BattlerState<Self>, state: &BattleState<Self>, ) -> Self::Move
Select a move for the given battler. Typically delegates to a
BattleAI implementation.
Sourcefn apply_move_effect(
&self,
effect: MoveEffect,
user: &mut BattlerState<Self>,
target: &mut BattlerState<Self>,
) -> EffectResult
fn apply_move_effect( &self, effect: MoveEffect, user: &mut BattlerState<Self>, target: &mut BattlerState<Self>, ) -> EffectResult
Apply a move’s effect after damage has been dealt. Typically
delegates to an EffectHandler implementation.
Sourcefn create_monster(
&self,
species: Self::Species,
level: u8,
) -> BattlerState<Self>
fn create_monster( &self, species: Self::Species, level: u8, ) -> BattlerState<Self>
Construct a battler state from species and level data.
The provider looks up base stats, learnable moves, and type information for the given species at the given level.
Provided Methods§
Sourcefn check_faint(&self, battler: &BattlerState<Self>) -> bool
fn check_faint(&self, battler: &BattlerState<Self>) -> bool
Check whether a battler has fainted (HP = 0).
Sourcefn move_cost(&self, _move_: &Self::Move) -> &[(u16, u16)]
fn move_cost(&self, _move_: &Self::Move) -> &[(u16, u16)]
The resource cost of move_ as a list of (resource_id, amount) pairs.
The engine assigns the resources no meaning (it is not “MP” to the engine
— the ids are game-defined and opaque). Before resolving a Fight action,
the StackDriver checks the actor can
pay all of these against its ResourcePool; if it cannot, the move is
prevented (the existing BeforeMove/Fail prevention path), and if it
can, the engine deducts each cost. The check and deduction are pure
arithmetic and consume no rng, so a game that declares costs keeps its
exact draw order.
The default is &[] ⇒ no cost ⇒ the gate is inert, so a battler with no
resources behaves exactly as today.
Sourcefn turn_order_key(
&self,
_state: &BattleState<Self>,
_who: BattlerRef,
_action: &BattleAction<Self>,
_rng: &mut dyn BattleRng,
) -> OrderKeywhere
Self: Sized,
fn turn_order_key(
&self,
_state: &BattleState<Self>,
_who: BattlerRef,
_action: &BattleAction<Self>,
_rng: &mut dyn BattleRng,
) -> OrderKeywhere
Self: Sized,
Return the OrderKey used to sequence who’s action this turn.
The engine stable-sorts actors ascending by this key (C4). The game
encodes the priority bracket, effective speed (after paralysis cut,
badge boosts, …), and any tie-break — e.g. the Gen-1 speed-tie coin
flip drawn from rng. The default treats every actor as equal, so the
driver falls back to stable submission order.
Sourcefn before_move(
&self,
_state: &mut BattleState<Self>,
_who: BattlerRef,
_action: &BattleAction<Self>,
_rng: &mut dyn BattleRng,
) -> MoveGate<Self>where
Self: Sized,
fn before_move(
&self,
_state: &mut BattleState<Self>,
_who: BattlerRef,
_action: &BattleAction<Self>,
_rng: &mut dyn BattleRng,
) -> MoveGate<Self>where
Self: Sized,
Pre-move status gate: may who act with action this turn?
The game owns sleep (counter decremented before the move), freeze, the full-paralysis roll, flinch, Hyper Beam recharge, confusion self-hit, partial-trap continuation, etc. The default always allows the action.
Sourcefn accuracy_check(
&self,
_state: &BattleState<Self>,
_who: BattlerRef,
_target: BattlerRef,
_move_: &Self::Move,
_rng: &mut dyn BattleRng,
) -> boolwhere
Self: Sized,
fn accuracy_check(
&self,
_state: &BattleState<Self>,
_who: BattlerRef,
_target: BattlerRef,
_move_: &Self::Move,
_rng: &mut dyn BattleRng,
) -> boolwhere
Self: Sized,
Accuracy check for who’s move_ against target (incl. the Gen-1
1/256 miss). Returns true if the move connects. Default: always hits.
Sourcefn end_of_turn(
&self,
_state: &mut BattleState<Self>,
_rng: &mut dyn BattleRng,
) -> Vec<EffectResult>where
Self: Sized,
fn end_of_turn(
&self,
_state: &mut BattleState<Self>,
_rng: &mut dyn BattleRng,
) -> Vec<EffectResult>where
Self: Sized,
End-of-turn residual hook: poison/burn tick, leech seed, wrap damage,
weather, etc. The game owns ordering and numbers; it returns the
resulting EffectResults for the UI. Default: no residuals.
Sourcefn roll_critical(
&self,
_state: &BattleState<Self>,
_who: BattlerRef,
_target: BattlerRef,
_move_: &Self::Move,
_rng: &mut dyn BattleRng,
) -> boolwhere
Self: Sized,
fn roll_critical(
&self,
_state: &BattleState<Self>,
_who: BattlerRef,
_target: BattlerRef,
_move_: &Self::Move,
_rng: &mut dyn BattleRng,
) -> boolwhere
Self: Sized,
Roll whether who’s move_ against target lands a critical hit.
The driver calls this before calculate_damage
and feeds the result back in as its is_critical argument, then surfaces
it into the TurnEvent::Damage
event’s critical flag — so a provider-computed crit reaches both the
damage formula and the UI/event stream.
The game owns the crit-rate math (base speed / Focus Energy / high-crit
moves and every Gen-1 quirk), drawing from rng as needed. The default
never crits and draws no randomness, so pre-existing providers and
other games keep their exact draw sequence unchanged.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".