70 lines
2.1 KiB
Rust
Executable File
70 lines
2.1 KiB
Rust
Executable File
use std::fmt::Debug;
|
|
use std::sync::Arc;
|
|
|
|
use hashbrown::HashSet;
|
|
|
|
use crate::dynamic_data::choices::{MoveChoice, TurnChoice};
|
|
use crate::dynamic_data::Pokemon;
|
|
use crate::dynamic_data::{LearnedMove, MoveLearnMethod};
|
|
use crate::static_data::{MoveCategory, MoveData, MoveTarget, SecondaryEffect};
|
|
use crate::StringKey;
|
|
|
|
/// The misc library holds several misc functions required for the battle to run.
|
|
pub trait MiscLibrary: Debug {
|
|
/// Returns whether or not a Pokemon is allowed to flee or switch out.
|
|
fn can_flee(&self, choice: &TurnChoice) -> bool;
|
|
/// Returns the move we need to use if we can't use another move. Typically Struggle.
|
|
fn replacement_move(&self, user: &Arc<Pokemon>, target_side: u8, target_index: u8) -> TurnChoice;
|
|
// TODO: can evolve from level up?
|
|
// TODO: get time
|
|
}
|
|
|
|
/// A gen 7 implementation for the MiscLibrary.
|
|
#[derive(Debug)]
|
|
pub struct Gen7MiscLibrary {
|
|
/// The learned move data for struggle.
|
|
struggle_learned_move: Arc<LearnedMove>,
|
|
}
|
|
|
|
impl Gen7MiscLibrary {
|
|
/// Instantiates a new MiscLibrary.
|
|
pub fn new() -> Self {
|
|
let struggle_data = Arc::new(MoveData::new(
|
|
&StringKey::new("struggle"),
|
|
0.into(),
|
|
MoveCategory::Physical,
|
|
50,
|
|
255,
|
|
255,
|
|
MoveTarget::Any,
|
|
0,
|
|
Some(SecondaryEffect::new(-1.0, StringKey::new("struggle"), vec![])),
|
|
HashSet::new(),
|
|
));
|
|
let struggle_learned_move = Arc::new(LearnedMove::new(&struggle_data, MoveLearnMethod::Unknown));
|
|
Self { struggle_learned_move }
|
|
}
|
|
}
|
|
|
|
impl Default for Gen7MiscLibrary {
|
|
fn default() -> Self {
|
|
Self::new()
|
|
}
|
|
}
|
|
|
|
impl MiscLibrary for Gen7MiscLibrary {
|
|
fn can_flee(&self, _choice: &TurnChoice) -> bool {
|
|
todo!()
|
|
}
|
|
|
|
fn replacement_move(&self, user: &Arc<Pokemon>, target_side: u8, target_index: u8) -> TurnChoice {
|
|
self.struggle_learned_move.restore_all_uses();
|
|
TurnChoice::Move(MoveChoice::new(
|
|
user.clone(),
|
|
self.struggle_learned_move.clone(),
|
|
target_side,
|
|
target_index,
|
|
))
|
|
}
|
|
}
|