2022-06-19 19:34:08 +00:00
|
|
|
use std::fmt::Debug;
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
use hashbrown::HashSet;
|
|
|
|
|
2022-06-30 15:34:57 +00:00
|
|
|
use crate::dynamic_data::choices::{MoveChoice, TurnChoice};
|
2022-06-19 19:34:08 +00:00
|
|
|
use crate::dynamic_data::Pokemon;
|
|
|
|
use crate::dynamic_data::{LearnedMove, MoveLearnMethod};
|
2022-06-16 15:59:33 +00:00
|
|
|
use crate::static_data::{MoveCategory, MoveData, MoveTarget, SecondaryEffect};
|
2022-06-30 15:34:57 +00:00
|
|
|
use crate::StringKey;
|
2022-06-16 15:59:33 +00:00
|
|
|
|
2022-06-30 15:34:57 +00:00
|
|
|
/// The misc library holds several misc functions required for the battle to run.
|
2022-08-20 11:17:20 +00:00
|
|
|
pub trait MiscLibrary: Debug {
|
2022-06-30 15:34:57 +00:00
|
|
|
/// 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.
|
2022-08-26 16:23:35 +00:00
|
|
|
fn replacement_move(&self, user: &Arc<Pokemon>, target_side: u8, target_index: u8) -> TurnChoice;
|
2022-06-16 15:59:33 +00:00
|
|
|
// TODO: can evolve from level up?
|
|
|
|
// TODO: get time
|
|
|
|
}
|
|
|
|
|
2022-06-30 15:34:57 +00:00
|
|
|
/// A gen 7 implementation for the MiscLibrary.
|
2022-06-16 15:59:33 +00:00
|
|
|
#[derive(Debug)]
|
2022-08-20 11:17:20 +00:00
|
|
|
pub struct Gen7MiscLibrary {
|
2022-06-30 15:34:57 +00:00
|
|
|
/// The learned move data for struggle.
|
2022-08-20 11:17:20 +00:00
|
|
|
struggle_learned_move: Arc<LearnedMove>,
|
2022-06-16 15:59:33 +00:00
|
|
|
}
|
|
|
|
|
2022-08-20 11:17:20 +00:00
|
|
|
impl Gen7MiscLibrary {
|
2022-06-30 15:34:57 +00:00
|
|
|
/// Instantiates a new MiscLibrary.
|
2022-06-16 15:59:33 +00:00
|
|
|
pub fn new() -> Self {
|
2022-08-20 11:17:20 +00:00
|
|
|
let struggle_data = Arc::new(MoveData::new(
|
2022-06-16 15:59:33 +00:00
|
|
|
&StringKey::new("struggle"),
|
2022-07-01 15:07:22 +00:00
|
|
|
0.into(),
|
2022-06-16 15:59:33 +00:00
|
|
|
MoveCategory::Physical,
|
|
|
|
50,
|
|
|
|
255,
|
2022-06-18 12:17:29 +00:00
|
|
|
255,
|
2022-06-16 15:59:33 +00:00
|
|
|
MoveTarget::Any,
|
|
|
|
0,
|
2022-06-19 10:07:54 +00:00
|
|
|
Some(SecondaryEffect::new(-1.0, StringKey::new("struggle"), vec![])),
|
2022-06-16 15:59:33 +00:00
|
|
|
HashSet::new(),
|
|
|
|
));
|
2022-08-26 16:23:35 +00:00
|
|
|
let struggle_learned_move = Arc::new(LearnedMove::new(&struggle_data, MoveLearnMethod::Unknown));
|
2022-08-20 11:17:20 +00:00
|
|
|
Self { struggle_learned_move }
|
2022-06-16 15:59:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-20 11:17:20 +00:00
|
|
|
impl Default for Gen7MiscLibrary {
|
2022-06-18 14:06:54 +00:00
|
|
|
fn default() -> Self {
|
|
|
|
Self::new()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-20 11:17:20 +00:00
|
|
|
impl MiscLibrary for Gen7MiscLibrary {
|
2022-06-30 15:34:57 +00:00
|
|
|
fn can_flee(&self, _choice: &TurnChoice) -> bool {
|
2022-06-16 15:59:33 +00:00
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
|
2022-08-26 16:23:35 +00:00
|
|
|
fn replacement_move(&self, user: &Arc<Pokemon>, target_side: u8, target_index: u8) -> TurnChoice {
|
2022-06-30 15:34:57 +00:00
|
|
|
self.struggle_learned_move.restore_all_uses();
|
2022-06-16 15:59:33 +00:00
|
|
|
TurnChoice::Move(MoveChoice::new(
|
|
|
|
user.clone(),
|
|
|
|
self.struggle_learned_move.clone(),
|
|
|
|
target_side,
|
|
|
|
target_index,
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|