use crate::dynamic_data::{ExecutingMove, HitData, LearnedMove, Pokemon}; use crate::script_implementations::wasm::export_registry::register; use crate::script_implementations::wasm::extern_ref::ExternRef; use crate::script_implementations::wasm::script::WebAssemblyScript; use crate::script_implementations::wasm::script_resolver::WebAssemblyEnv; use crate::static_data::MoveData; use wasmer::FunctionEnvMut; register! { fn executing_move_get_user( env: FunctionEnvMut, executing_move: ExternRef, ) -> ExternRef { ExternRef::func_new(&env, executing_move.value_func(&env).unwrap().user().as_ref()) } fn executing_move_get_use_move( env: FunctionEnvMut, executing_move: ExternRef, ) -> ExternRef { ExternRef::func_new(&env, executing_move.value_func(&env).unwrap().use_move()) } fn executing_move_get_chosen_move( env: FunctionEnvMut, executing_move: ExternRef, ) -> ExternRef { ExternRef::func_new(&env, executing_move.value_func_arc(&env).unwrap().chosen_move().as_ref()) } fn executing_move_get_number_of_hits( env: FunctionEnvMut, executing_move: ExternRef, ) -> u8 { executing_move.value_func(&env).unwrap().number_of_hits() } fn executing_move_get_hit_data( env: FunctionEnvMut, executing_move: ExternRef, target: ExternRef, hit: u8 ) -> ExternRef { ExternRef::func_new(&env, executing_move.value_func(&env).unwrap().get_hit_data(target.value_func(&env).unwrap(), hit).unwrap()) } fn executing_move_get_number_of_targets( env: FunctionEnvMut, executing_move: ExternRef, ) -> u32 { executing_move.value_func(&env).unwrap().target_count() as u32 } fn executing_move_is_pokemon_target( env: FunctionEnvMut, executing_move: ExternRef, pokemon: ExternRef ) -> u8 { let pokemon = pokemon.value_func_arc(&env).unwrap(); if executing_move.value_func(&env).unwrap().is_pokemon_target(&pokemon) { 1 } else { 0 } } fn executing_move_get_script( env: FunctionEnvMut, executing_move: ExternRef, ) -> (u32 , u32) { let executing_move = executing_move.value_func(&env).unwrap(); if let Some(script) = executing_move.script().get() { let read_lock = script.read(); if let Some(script) = read_lock.as_ref() { let s = script.as_any().downcast_ref::().unwrap().get_wasm_pointer(); return (s, s + 4) } } (0, 0) } }