Skip to main content

MonsterInstance

Struct MonsterInstance 

Source
pub struct MonsterInstance<P: MonsterProvider> {
    pub species: P::SpeciesId,
    pub level: u8,
    pub exp: u32,
    pub genetics: P::Genetics,
    pub training: P::Training,
    pub stats: StatSet<P>,
    pub current_hp: u16,
    pub status: MonsterStatus,
    pub moves: Vec<MoveSlot<P>>,
}
Expand description

A generic monster instance: species, level, exp, computed stats, status, and known moves. All numbers are delegated to the MonsterProvider.

Fields§

§species: P::SpeciesId

The species.

§level: u8

Current level.

§exp: u32

Total accumulated experience.

§genetics: P::Genetics

Per-instance genetics (opaque to the engine).

§training: P::Training

Accumulated training (opaque to the engine).

§stats: StatSet<P>

Cached computed stats, keyed by the provider’s stat order.

§current_hp: u16

Current HP.

§status: MonsterStatus

Status condition.

§moves: Vec<MoveSlot<P>>

Known moves.

Implementations§

Source§

impl<P: MonsterProvider> MonsterInstance<P>

Source

pub fn new( provider: &P, species: P::SpeciesId, level: u8, genetics: P::Genetics, training: P::Training, ) -> Self

Construct at a level. The caller supplies genetics/training; stats are computed from the provider and current_hp is initialized to full.

Source

pub fn recalc_stats(&mut self, provider: &P)

Recompute every stat from the provider.

Preserves the absolute current_hp, clamped to the new max HP (this matches Gen-1 recalculation behavior, where current HP is not scaled by ratio on a stat recompute).

Source

pub fn max_hp(&self, provider: &P) -> u16

Max HP, using the provider-declared HP stat.

Source

pub fn is_fainted(&self) -> bool

Whether the monster has fainted (0 HP).

Source§

impl<P: ExpProvider> MonsterInstance<P>

Source

pub fn gain_exp(&mut self, provider: &P, amount: u32) -> LevelUp<P>

Add EXP, advancing level while the threshold for the next level is met.

Recomputes stats on each level gained. Caps at the provider’s ExpProvider::max_level. Returns a summary of what happened.

Note: the engine drives the mechanism (cross thresholds, recalc). Any game-specific quirks (e.g. the Gen-1 experience underflow) live in the game’s ExpProvider::exp_for_level implementation and in how the game chooses to call this method.

Source§

impl<P: EvolutionProvider> MonsterInstance<P>

Source

pub fn try_evolve( &mut self, provider: &P, trigger: EvolutionTrigger<P::EvoItem>, ) -> Option<P::SpeciesId>

If the provider says we evolve, switch species and recalc stats.

Returns the new species id if evolution happened, otherwise None (the provider returning None is how evolution is canceled).

Source§

impl<P: MonsterProvider> MonsterInstance<P>

Source

pub fn to_battler<B, FS, FM, FST>( &self, provider: &P, map_species: FS, map_move: FM, map_stat: FST, ) -> BattlerState<B>
where B: BattleProvider, B::Stat: Copy + PartialEq, FS: FnMut(P::SpeciesId) -> B::Species, FM: FnMut(P::MoveId) -> B::Move, FST: FnMut(P::Stat) -> B::Stat,

Build a BattlerState snapshot for the battle engine.

This is the seam the later battle-migration milestone builds on. The engine’s BattlerState is generic over a single BattleProvider B, whose associated Species / Move / Stat types are independent of this monster’s MonsterProvider. To stay fully game-agnostic the caller supplies the conversions:

  • map_species: P::SpeciesId -> B::Species
  • map_move: P::MoveId -> B::Move
  • map_stat: P::Stat -> B::Stat

Stat stages start neutral, status defaults to None, and the live HP / level / species / stats / moves are carried over. Status is intentionally not mapped here (it is a battle-provider-defined Option<B::Status>); the caller can set bs.status afterwards if needed. This keeps the mapping total and the engine decoupled from any concrete status model.

Trait Implementations§

Source§

impl<P: Clone + MonsterProvider> Clone for MonsterInstance<P>

Source§

fn clone(&self) -> MonsterInstance<P>

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: Debug + MonsterProvider> Debug for MonsterInstance<P>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<P: Eq + MonsterProvider> Eq for MonsterInstance<P>
where P::SpeciesId: Eq, P::Genetics: Eq, P::Training: Eq,

Source§

impl<P: PartialEq + MonsterProvider> PartialEq for MonsterInstance<P>

Source§

fn eq(&self, other: &MonsterInstance<P>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<P: PartialEq + MonsterProvider> StructuralPartialEq for MonsterInstance<P>

Auto Trait Implementations§

§

impl<P> Freeze for MonsterInstance<P>

§

impl<P> RefUnwindSafe for MonsterInstance<P>

§

impl<P> Send for MonsterInstance<P>

§

impl<P> Sync for MonsterInstance<P>

§

impl<P> Unpin for MonsterInstance<P>

§

impl<P> UnsafeUnpin for MonsterInstance<P>

§

impl<P> UnwindSafe for MonsterInstance<P>

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.