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, MoveDataImpl, MoveTarget, SecondaryEffectImpl}; use crate::{StringKey, ValueIdentifiable, ValueIdentifier}; /// The misc library holds several misc functions required for the battle to run. pub trait MiscLibrary: Debug + ValueIdentifiable { /// 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, 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 { /// A unique identifier so we know what value this is. identifier: ValueIdentifier, /// The learned move data for struggle. struggle_learned_move: Arc, } impl Gen7MiscLibrary { /// Instantiates a new MiscLibrary. pub fn new() -> Self { let struggle_data: Arc = Arc::new(MoveDataImpl::new( &StringKey::new("struggle"), 0.into(), MoveCategory::Physical, 50, 255, 255, MoveTarget::Any, 0, Some(Box::new(SecondaryEffectImpl::new( -1.0, StringKey::new("struggle"), vec![], ))), HashSet::new(), )); let struggle_learned_move = Arc::new(LearnedMove::new(struggle_data, MoveLearnMethod::Unknown)); Self { identifier: Default::default(), 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, 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, )) } } impl ValueIdentifiable for Gen7MiscLibrary { fn value_identifier(&self) -> ValueIdentifier { self.identifier } }