Skip to main content

ExpProvider

Trait ExpProvider 

Source
pub trait ExpProvider: MonsterProvider {
    // Required methods
    fn exp_for_level(&self, species: Self::SpeciesId, level: u8) -> u32;
    fn max_level(&self) -> u8;

    // Provided methods
    fn levelup_current_hp(
        &self,
        old_max_hp: u16,
        new_max_hp: u16,
        current_hp: u16,
    ) -> u16 { ... }
    fn learn_moves_on_levelup(
        &self,
        species: Self::SpeciesId,
        level: u8,
        moves: &mut Vec<MoveSlot<Self>>,
    ) -> Vec<Self::MoveId>
       where Self: Sized { ... }
}
Expand description

Total EXP / leveling hooks. Layered on top of MonsterProvider so the same id types are reused.

Required Methods§

Source

fn exp_for_level(&self, species: Self::SpeciesId, level: u8) -> u32

Total EXP required to be at level for this species’ growth group.

Source

fn max_level(&self) -> u8

Maximum attainable level (Gen-1 = 100).

Provided Methods§

Source

fn levelup_current_hp( &self, old_max_hp: u16, new_max_hp: u16, current_hp: u16, ) -> u16

Decide the new current HP when the monster levels up and its max HP changes from old_max_hp to new_max_hp.

This is the engine’s HP-growth policy hook. The default is the game-agnostic “preserve absolute HP, clamp to the new max” behavior (matching MonsterInstance::recalc_stats). Games that want the Gen-1 behavior — grow current HP by the max-HP delta — override this to return current_hp + (new_max_hp - old_max_hp).

The engine clamps the returned value to new_max_hp regardless, so an override cannot produce HP above the new maximum.

Source

fn learn_moves_on_levelup( &self, species: Self::SpeciesId, level: u8, moves: &mut Vec<MoveSlot<Self>>, ) -> Vec<Self::MoveId>
where Self: Sized,

Learn any moves the monster gains by reaching level, mutating its moves list, and return the ids of the moves that were newly learned.

This is the engine’s move-learning hook. It is called once per level crossed (in ascending order) during MonsterInstance::gain_exp. The default learns nothing (returns an empty Vec) so the engine never needs to know any move data. Games override this to consult their learnset and insert moves into moves using whatever slot/PP rules they use; the ids returned here are surfaced in LevelUp::learned_moves.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§