Loads more work on battling, initial stretch to run a turn done.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-06-16 17:59:33 +02:00
parent a33369afcc
commit ff541b0696
50 changed files with 105871 additions and 497 deletions

View File

@@ -1,3 +1,4 @@
use crate::dynamic_data::flow::target_resolver::TargetList;
use crate::dynamic_data::models::learned_move::LearnedMove;
use crate::dynamic_data::models::pokemon::Pokemon;
use crate::dynamic_data::script_handling::script::ScriptContainer;
@@ -5,9 +6,9 @@ use crate::dynamic_data::script_handling::{ScriptSource, ScriptSourceData, Scrip
use crate::static_data::MoveData;
use crate::{PkmnResult, PokemonError};
use parking_lot::RwLock;
use std::ops::Deref;
use std::sync::Arc;
#[derive(Default)]
#[derive(Default, Debug)]
pub struct HitData {
critical: bool,
base_power: u8,
@@ -57,24 +58,25 @@ impl HitData {
}
}
pub struct ExecutingMove<'a, 'b> {
#[derive(Debug)]
pub struct ExecutingMove<'own, 'battle, 'library> {
number_of_hits: u8,
hits: Vec<HitData>,
user: &'a Pokemon<'b>,
chosen_move: &'a LearnedMove<'a>,
use_move: &'a MoveData,
user: Arc<RwLock<Pokemon<'battle, 'library>>>,
chosen_move: Arc<RwLock<LearnedMove<'library>>>,
use_move: &'own MoveData,
script: ScriptContainer,
targets: Vec<Option<&'a Pokemon<'b>>>,
targets: &'own TargetList<'battle, 'library>,
script_source_data: RwLock<ScriptSourceData>,
}
impl<'a, 'b> ExecutingMove<'a, 'b> {
impl<'own, 'battle, 'library> ExecutingMove<'own, 'battle, 'library> {
pub fn new(
targets: Vec<Option<&'a Pokemon<'b>>>,
targets: &'own TargetList<'battle, 'library>,
number_of_hits: u8,
user: &'a Pokemon<'b>,
chosen_move: &'a LearnedMove,
use_move: &'a MoveData,
user: Arc<RwLock<Pokemon<'battle, 'library>>>,
chosen_move: Arc<RwLock<LearnedMove<'library>>>,
use_move: &'own MoveData,
script: ScriptContainer,
) -> Self {
let total_hits = number_of_hits as usize * targets.len();
@@ -99,23 +101,28 @@ impl<'a, 'b> ExecutingMove<'a, 'b> {
pub fn number_of_hits(&self) -> u8 {
self.number_of_hits
}
pub fn user(&self) -> &'a Pokemon<'b> {
self.user
pub fn user(&self) -> &Arc<RwLock<Pokemon<'battle, 'library>>> {
&self.user
}
pub fn chosen_move(&self) -> &'a LearnedMove {
self.chosen_move
pub fn chosen_move(&self) -> &Arc<RwLock<LearnedMove<'library>>> {
&self.chosen_move
}
pub fn use_move(&self) -> &'a MoveData {
pub fn use_move(&self) -> &'own MoveData {
self.use_move
}
pub fn script(&self) -> &ScriptContainer {
&self.script
}
pub fn get_hit_data(&self, for_target: &Pokemon<'b>, hit: u8) -> PkmnResult<&HitData> {
pub fn get_hit_data<'func>(
&'func self,
for_target: &'func Arc<RwLock<Pokemon<'battle, 'library>>>,
hit: u8,
) -> PkmnResult<&'func HitData> {
for (index, target) in self.targets.iter().enumerate() {
if let Some(target) = target {
if std::ptr::eq(target.deref(), for_target) {
if std::ptr::eq(target.data_ptr(), for_target.data_ptr()) {
let i = index * self.number_of_hits as usize + hit as usize;
return Ok(&self.hits[i]);
}
@@ -124,29 +131,39 @@ impl<'a, 'b> ExecutingMove<'a, 'b> {
Err(PokemonError::InvalidTargetRequested)
}
pub fn get_target_slice(&self, for_target: &Pokemon<'b>) -> PkmnResult<&[HitData]> {
pub fn is_pokemon_target(&self, pokemon: &Arc<RwLock<Pokemon<'battle, 'library>>>) -> bool {
for target in self.targets.iter().flatten() {
if std::ptr::eq(target.data_ptr(), pokemon.data_ptr()) {
return true;
}
}
false
}
pub(crate) fn get_index_of_target(
&self,
for_target: &Arc<RwLock<Pokemon<'battle, 'library>>>,
) -> PkmnResult<usize> {
for (index, target) in self.targets.iter().enumerate() {
if let Some(target) = target {
if std::ptr::eq(target.deref(), for_target) {
if std::ptr::eq(target.data_ptr(), for_target.data_ptr()) {
let i = index * self.number_of_hits as usize;
return Ok(&self.hits[i..i + self.number_of_hits as usize]);
return Ok(i);
}
}
}
Err(PokemonError::InvalidTargetRequested)
}
pub fn is_pokemon_target(&self, pokemon: &Pokemon<'b>) -> bool {
for target in self.targets.iter().flatten() {
if std::ptr::eq(target.deref(), pokemon) {
return true;
}
}
false
pub(crate) fn get_hit_from_raw_index(&self, index: usize) -> &HitData {
&self.hits[index]
}
pub(crate) fn get_hit_from_raw_index_mut(&mut self, index: usize) -> &mut HitData {
&mut self.hits[index]
}
}
impl<'a, 'b> ScriptSource<'a> for ExecutingMove<'a, 'b> {
impl<'own, 'battle, 'library> ScriptSource<'own> for ExecutingMove<'own, 'battle, 'library> {
fn get_script_count(&self) -> usize {
1
}
@@ -161,6 +178,6 @@ impl<'a, 'b> ScriptSource<'a> for ExecutingMove<'a, 'b> {
fn collect_scripts(&self, scripts: &mut Vec<ScriptWrapper>) {
self.get_own_scripts(scripts);
self.user.get_own_scripts(scripts);
self.user.read().get_own_scripts(scripts);
}
}