Major amounts of progress

This commit is contained in:
2022-06-03 16:35:18 +02:00
parent c194c5d209
commit 310bf857d2
37 changed files with 1558 additions and 29 deletions

View File

@@ -1,2 +1,86 @@
use crate::dynamic_data::script_handling::script::Script;
use crate::dynamic_data::script_handling::script_set::ScriptSet;
pub mod script;
pub mod script_set;
#[macro_export]
macro_rules! script_hook {
($hook_name: ident, $source: ident, $($parameters: expr),*) => {
let mut aggregator = $source.get_script_iterator();
while let Some(script) = aggregator.get_next() {
if script.is_suppressed() {
continue;
}
script.$hook_name($($parameters),*);
}
};
}
pub trait ScriptSource {
fn get_script_iterator(&self) -> ScriptAggregator {
todo!()
}
fn get_script_count(&self);
}
pub enum ScriptWrapper<'a> {
Script(&'a Box<dyn Script>),
Set(&'a ScriptSet),
}
pub struct ScriptAggregator<'a> {
scripts: Vec<Option<ScriptWrapper<'a>>>,
size: i32,
index: i32,
set_index: i32,
}
impl<'a> ScriptAggregator<'a> {
pub fn new(scripts: Vec<Option<ScriptWrapper<'a>>>) -> Self {
let len = scripts.len();
Self {
scripts,
size: len as i32,
index: -1,
set_index: -1,
}
}
fn increment_to_next_value(&mut self) -> bool {
if self.index != -1 {
if let Some(wrapper) = &self.scripts[self.index as usize] {
if let ScriptWrapper::Set(set) = wrapper {
self.set_index += 1;
if self.set_index as usize >= set.count() {
self.set_index = -1;
} else {
return true;
}
}
}
}
self.index += 1;
for index in self.index..self.size {
self.index = index;
if let Some(wrapper) = &self.scripts[index as usize] {
if let ScriptWrapper::Set(..) = wrapper {
self.set_index = 0;
}
return true;
}
}
false
}
pub fn get_next(&mut self) -> Option<&Box<dyn Script>> {
if !self.increment_to_next_value() {
return None;
}
return match self.scripts[self.index as usize].as_ref().unwrap() {
ScriptWrapper::Script(script) => Some(script),
ScriptWrapper::Set(set) => Some(set.at(self.set_index as usize)),
};
}
}

View File

@@ -1 +1,63 @@
pub trait Script {}
use crate::dynamic_data::models::pokemon::Pokemon;
use std::fmt::{Debug, Formatter};
pub trait Script {
fn is_suppressed(&self) -> bool {
self.get_suppressed_count() > 0
}
fn get_suppressed_count(&self) -> usize;
fn add_suppression(&self);
fn remove_suppression(&self);
// FIXME: add missing parameters
fn stack(&self);
fn on_remove(&self);
fn on_initialize(&self);
fn on_before_turn(&self);
fn change_speed(&self);
fn change_priority(&self);
fn change_attack(&self);
fn change_number_of_hits(&self);
fn prevent_attack(&self);
fn fail_attack(&self);
fn stop_before_attack(&self);
fn on_before_attack(&self);
fn fail_incoming_attack(&self);
fn is_invulnerable(&self);
fn on_attack_miss(&self);
fn change_attack_type(&self);
fn block_critical(&self);
fn override_base_power(&self);
fn change_damage_stats_user(&self);
fn bypass_defensive_stat(&self);
fn bypass_offensive_stat(&self);
fn change_stat_modifier(&self);
fn change_damage_modifier(&self);
fn change_damage(&self);
fn change_incoming_damage(&self);
fn on_incoming_hit(&self);
fn on_opponent_faints(&self);
fn prevent_stat_boost_change(&self);
fn change_stat_boost_change(&self);
fn on_secondary_effect(&self);
fn on_after_hits(&self);
fn prevent_self_switch(&self);
fn prevent_opponent_switch(&self);
fn modify_effect_chance(&self);
fn modify_incoming_effect_change(&self);
fn on_fail(&self);
fn on_opponent_fail(&self);
fn prevent_self_run_away(&self);
fn prevent_opponent_run_away(&self);
fn on_end_turn(&self);
fn on_damage(&self);
fn on_faint(&self);
fn on_switch_in<'b>(&self, pokemon: &'b Pokemon);
fn on_after_held_item_consume(&self);
}
impl Debug for dyn Script {
fn fmt(&self, _f: &mut Formatter<'_>) -> std::fmt::Result {
Ok(())
}
}

View File

@@ -1 +1,14 @@
use crate::dynamic_data::script_handling::script::Script;
#[derive(Debug)]
pub struct ScriptSet {}
impl ScriptSet {
pub fn count(&self) -> usize {
todo!()
}
pub fn at(&self, _index: usize) -> &Box<dyn Script> {
todo!()
}
}