A lot more documentation, some initial work on the script resolver.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -13,69 +13,99 @@ use crate::dynamic_data::TargetList;
|
||||
use crate::static_data::MoveData;
|
||||
use crate::{PkmnResult, PokemonError};
|
||||
|
||||
/// A hit data is the data for a single hit, on a single target.
|
||||
#[derive(Default, Debug)]
|
||||
pub struct HitData {
|
||||
/// Whether or not the hit is critical.
|
||||
critical: AtomicBool,
|
||||
/// The base power of the hit.
|
||||
base_power: AtomicU8,
|
||||
/// The type effectiveness of the hit.
|
||||
effectiveness: Atomic<f32>,
|
||||
/// The actual damage of the hit.
|
||||
damage: AtomicU32,
|
||||
/// The type id of the type used for the hit.
|
||||
move_type: AtomicU8,
|
||||
/// Whether or not the hit has failed.
|
||||
has_failed: AtomicBool,
|
||||
}
|
||||
|
||||
impl HitData {
|
||||
/// Whether or not the hit is critical.
|
||||
pub fn is_critical(&self) -> bool {
|
||||
self.critical.load(Ordering::Relaxed)
|
||||
}
|
||||
/// The base power of the hit.
|
||||
pub fn base_power(&self) -> u8 {
|
||||
self.base_power.load(Ordering::Relaxed)
|
||||
}
|
||||
/// The type effectiveness of the hit.
|
||||
pub fn effectiveness(&self) -> f32 {
|
||||
self.effectiveness.load(Ordering::Relaxed)
|
||||
}
|
||||
/// The actual damage of the hit.
|
||||
pub fn damage(&self) -> u32 {
|
||||
self.damage.load(Ordering::Relaxed)
|
||||
}
|
||||
/// The type id of the type used for the hit.
|
||||
pub fn move_type(&self) -> u8 {
|
||||
self.move_type.load(Ordering::Relaxed)
|
||||
}
|
||||
/// Whether or not the hit has failed.
|
||||
pub fn has_failed(&self) -> bool {
|
||||
self.has_failed.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
/// Sets whether or not the hit is critical.
|
||||
pub fn set_critical(&self, value: bool) {
|
||||
self.critical.store(value, Ordering::SeqCst);
|
||||
}
|
||||
/// Sets the base power of the hit.
|
||||
pub fn set_base_power(&self, value: u8) {
|
||||
self.base_power.store(value, Ordering::SeqCst);
|
||||
}
|
||||
/// Sets the type effectiveness of the hit.
|
||||
pub fn set_effectiveness(&self, value: f32) {
|
||||
self.effectiveness.store(value, Ordering::SeqCst);
|
||||
}
|
||||
/// Sets the actual damage of the hit.
|
||||
pub fn set_damage(&self, value: u32) {
|
||||
self.damage.store(value, Ordering::SeqCst);
|
||||
}
|
||||
/// Sets the move type id of the hit.
|
||||
pub fn set_move_type(&self, value: u8) {
|
||||
self.move_type.store(value, Ordering::SeqCst);
|
||||
}
|
||||
/// Marks the hit as failed.
|
||||
pub fn fail(&self) {
|
||||
self.has_failed.store(true, Ordering::SeqCst);
|
||||
}
|
||||
}
|
||||
|
||||
/// An executing move is the data of the move for while it is executing.
|
||||
#[derive(Debug)]
|
||||
pub struct ExecutingMove<'own, 'battle, 'library> {
|
||||
/// The number of hits this move has.
|
||||
number_of_hits: u8,
|
||||
/// A list of hits for this move. For multi target multi hit moves, this stores the hits linearly,
|
||||
/// for example: (target1, hit1), (target1, hit2), (target2, hit1), (target2, hit2), etc.
|
||||
hits: Vec<HitData>,
|
||||
/// The user of the move.
|
||||
user: Arc<Pokemon<'battle, 'library>>,
|
||||
/// The move the user has actually chosen to do.
|
||||
chosen_move: Arc<LearnedMove<'library>>,
|
||||
/// The move that the user is actually going to do.
|
||||
use_move: &'own MoveData,
|
||||
/// The script of the move.
|
||||
script: ScriptContainer,
|
||||
/// The targets for this move.
|
||||
targets: &'own TargetList<'battle, 'library>,
|
||||
/// Data required for this to be a script source.
|
||||
script_source_data: RwLock<ScriptSourceData>,
|
||||
}
|
||||
|
||||
impl<'own, 'battle, 'library> ExecutingMove<'own, 'battle, 'library> {
|
||||
/// Instantiates an executing move.
|
||||
pub fn new(
|
||||
targets: &'own TargetList<'battle, 'library>,
|
||||
number_of_hits: u8,
|
||||
@@ -100,26 +130,33 @@ impl<'own, 'battle, 'library> ExecutingMove<'own, 'battle, 'library> {
|
||||
script_source_data: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The number of targets this move has.
|
||||
pub fn target_count(&self) -> usize {
|
||||
self.targets.len()
|
||||
}
|
||||
/// The number of hits this move has per target.
|
||||
pub fn number_of_hits(&self) -> u8 {
|
||||
self.number_of_hits
|
||||
}
|
||||
/// The user of the move.
|
||||
pub fn user(&self) -> &Arc<Pokemon<'battle, 'library>> {
|
||||
&self.user
|
||||
}
|
||||
/// The move the user has actually chosen to do.
|
||||
pub fn chosen_move(&self) -> &Arc<LearnedMove<'library>> {
|
||||
&self.chosen_move
|
||||
}
|
||||
|
||||
/// The move that the user is actually going to do.
|
||||
pub fn use_move(&self) -> &'own MoveData {
|
||||
self.use_move
|
||||
}
|
||||
/// The script of the move.
|
||||
pub fn script(&self) -> &ScriptContainer {
|
||||
&self.script
|
||||
}
|
||||
|
||||
/// Gets a hit data for a target, with a specific index.
|
||||
pub fn get_hit_data<'func>(
|
||||
&'func self,
|
||||
for_target: &'func Arc<Pokemon<'battle, 'library>>,
|
||||
@@ -136,6 +173,7 @@ impl<'own, 'battle, 'library> ExecutingMove<'own, 'battle, 'library> {
|
||||
Err(PokemonError::InvalidTargetRequested)
|
||||
}
|
||||
|
||||
/// Checks whether a Pokemon is a target for this move.
|
||||
pub fn is_pokemon_target(&self, pokemon: &Arc<Pokemon<'battle, 'library>>) -> bool {
|
||||
for target in self.targets.iter().flatten() {
|
||||
if std::ptr::eq(target.deref().deref(), pokemon.deref().deref()) {
|
||||
@@ -145,6 +183,7 @@ impl<'own, 'battle, 'library> ExecutingMove<'own, 'battle, 'library> {
|
||||
false
|
||||
}
|
||||
|
||||
/// Gets the index of the hits in this move where the hits for a specific target start.
|
||||
pub(crate) fn get_index_of_target(&self, for_target: &Arc<Pokemon<'battle, 'library>>) -> PkmnResult<usize> {
|
||||
for (index, target) in self.targets.iter().enumerate() {
|
||||
if let Some(target) = target {
|
||||
@@ -157,6 +196,7 @@ impl<'own, 'battle, 'library> ExecutingMove<'own, 'battle, 'library> {
|
||||
Err(PokemonError::InvalidTargetRequested)
|
||||
}
|
||||
|
||||
/// Gets a hit based on its raw index.
|
||||
pub(crate) fn get_hit_from_raw_index(&self, index: usize) -> &HitData {
|
||||
&self.hits[index]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user