Implements every script function
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-08-27 18:04:56 +02:00
parent bd62c1ac62
commit ba5992e925
19 changed files with 919 additions and 158 deletions

View File

@@ -92,8 +92,8 @@ impl Battle {
/// Executes a move choice.
fn execute_move_choice<'func>(&'func self, choice: &'func TurnChoice) -> PkmnResult<()> {
let choice = choice.get_move_turn_data();
let used_move = choice.used_move();
let move_choice = choice.get_move_turn_data();
let used_move = move_choice.used_move();
let move_data = {
let move_data_lock = used_move;
let move_data = move_data_lock.move_data();
@@ -103,7 +103,7 @@ impl Battle {
};
// FIXME: also change the script on the choice if changed;
let target_type = move_data.target();
let targets = resolve_targets(choice.target_side(), choice.target_index(), target_type, self);
let targets = resolve_targets(move_choice.target_side(), move_choice.target_index(), target_type, self);
let mut number_of_hits: u8 = 1;
script_hook!(change_number_of_hits, choice, choice, &mut number_of_hits);
@@ -116,7 +116,7 @@ impl Battle {
choice.user().clone(),
used_move.clone(),
move_data.clone(),
choice.script().clone(),
move_choice.script().clone(),
);
let mut prevented = false;
script_hook!(prevent_move, executing_move, &executing_move, &mut prevented);

View File

@@ -22,6 +22,7 @@ use crate::{script_hook, PkmnResult, StringKey};
/// A pokemon battle, with any amount of sides and pokemon per side.
#[derive(Debug)]
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
pub struct Battle {
/// The library the battle uses for handling.
library: Arc<DynamicLibrary>,

View File

@@ -84,6 +84,7 @@ impl HitData {
/// An executing move is the data of the move for while it is executing.
#[derive(Debug)]
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
pub struct ExecutingMove {
/// The number of hits this move has.
number_of_hits: u8,

View File

@@ -7,7 +7,7 @@ use std::thread::JoinHandle;
use parking_lot::{MappedRwLockReadGuard, RwLock, RwLockReadGuard};
use crate::dynamic_data::choices::{MoveChoice, TurnChoice};
use crate::dynamic_data::choices::TurnChoice;
use crate::dynamic_data::DamageSource;
use crate::dynamic_data::ExecutingMove;
use crate::dynamic_data::Pokemon;
@@ -79,11 +79,11 @@ pub trait Script: Send + Sync {
/// This function allows you to change the move that is used during execution. This is useful for
/// moves such as metronome, where the move chosen actually differs from the move used.
fn change_move(&self, _choice: &MoveChoice, _move_name: &mut StringKey) {}
fn change_move(&self, _choice: &TurnChoice, _move_name: &mut StringKey) {}
/// This function allows you to change a move into a multi-hit move. The number of hits set here
/// gets used as the number of hits. If set to 0, this will behave as if the move missed on its
/// first hit.
fn change_number_of_hits(&self, _choice: &MoveChoice, _number_of_hits: &mut u8) {}
fn change_number_of_hits(&self, _choice: &TurnChoice, _number_of_hits: &mut u8) {}
/// This function allows you to prevent a move from running. If this gets set to true, the move
/// ends execution here. No PP will be decreased in this case.