227 lines
8.3 KiB
Rust
227 lines
8.3 KiB
Rust
use crate::defines::LevelInt;
|
|
use crate::dynamic_data::{DamageSource, EventBatchId, Pokemon};
|
|
use crate::script_implementations::rune::wrappers::dynamic_data::resolve_script_data;
|
|
use crate::script_implementations::rune::wrappers::static_data::form::RuneForm;
|
|
use crate::script_implementations::rune::wrappers::static_data::item::RuneItem;
|
|
use crate::script_implementations::rune::wrappers::{impl_rune_wrapper, RuneStringKey, RuneWrapper};
|
|
use crate::static_data::{Gender, Statistic};
|
|
use rune::runtime::Value;
|
|
use rune::Any;
|
|
|
|
pub fn register(module: &mut rune::Module) -> anyhow::Result<()> {
|
|
module.ty::<DamageSource>()?;
|
|
|
|
module.ty::<RunePokemon>()?;
|
|
module.function_meta(RunePokemon::library)?;
|
|
module.function_meta(RunePokemon::species)?;
|
|
module.function_meta(RunePokemon::form)?;
|
|
module.function_meta(RunePokemon::has_different_display_species)?;
|
|
module.function_meta(RunePokemon::display_species)?;
|
|
module.function_meta(RunePokemon::has_different_display_form)?;
|
|
module.function_meta(RunePokemon::display_form)?;
|
|
module.function_meta(RunePokemon::level)?;
|
|
module.function_meta(RunePokemon::experience)?;
|
|
module.function_meta(RunePokemon::personality_value)?;
|
|
module.function_meta(RunePokemon::gender)?;
|
|
module.function_meta(RunePokemon::coloring)?;
|
|
module.function_meta(RunePokemon::held_item)?;
|
|
module.function_meta(RunePokemon::has_held_item)?;
|
|
module.function_meta(RunePokemon::set_held_item)?;
|
|
module.function_meta(RunePokemon::remove_held_item)?;
|
|
module.function_meta(RunePokemon::consume_held_item)?;
|
|
module.function_meta(RunePokemon::current_health)?;
|
|
module.function_meta(RunePokemon::max_health)?;
|
|
module.function_meta(RunePokemon::weight)?;
|
|
module.function_meta(RunePokemon::set_weight)?;
|
|
module.function_meta(RunePokemon::height)?;
|
|
module.function_meta(RunePokemon::happiness)?;
|
|
module.function_meta(RunePokemon::nickname)?;
|
|
module.function_meta(RunePokemon::real_ability)?;
|
|
module.function_meta(RunePokemon::types)?;
|
|
module.function_meta(RunePokemon::learned_moves)?;
|
|
module.function_meta(RunePokemon::flat_stats)?;
|
|
module.function_meta(RunePokemon::is_egg)?;
|
|
module.function_meta(RunePokemon::boosted_stats)?;
|
|
module.function_meta(RunePokemon::stat_boost)?;
|
|
module.function_meta(RunePokemon::change_stat_boost)?;
|
|
module.function_meta(RunePokemon::get_individual_value)?;
|
|
module.function_meta(RunePokemon::get_effort_value)?;
|
|
module.function_meta(RunePokemon::get_battle)?;
|
|
module.function_meta(RunePokemon::get_battle_side_index)?;
|
|
module.function_meta(RunePokemon::get_battle_index)?;
|
|
module.function_meta(RunePokemon::is_ability_overridden)?;
|
|
module.function_meta(RunePokemon::active_ability)?;
|
|
module.function_meta(RunePokemon::allowed_experience_gain)?;
|
|
module.function_meta(RunePokemon::nature)?;
|
|
module.function_meta(RunePokemon::change_form)?;
|
|
module.function_meta(RunePokemon::is_usable)?;
|
|
module.function_meta(RunePokemon::is_fainted)?;
|
|
module.function_meta(RunePokemon::damage)?;
|
|
module.function_meta(RunePokemon::heal)?;
|
|
module.function_meta(RunePokemon::status_script)?;
|
|
module.function_meta(RunePokemon::clear_status)?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[derive(Any, Clone, Debug)]
|
|
pub struct RunePokemon(pub Pokemon);
|
|
|
|
impl RunePokemon {
|
|
#[rune::function]
|
|
fn library(&self) -> Value { self.0.library().wrap() }
|
|
|
|
#[rune::function]
|
|
fn species(&self) -> Value { self.0.species().wrap() }
|
|
|
|
#[rune::function]
|
|
fn form(&self) -> Value { self.0.form().wrap() }
|
|
|
|
#[rune::function]
|
|
fn has_different_display_species(&self) -> bool { self.0.has_different_display_species() }
|
|
|
|
#[rune::function]
|
|
fn display_species(&self) -> Value { self.0.display_species().wrap() }
|
|
|
|
#[rune::function]
|
|
fn has_different_display_form(&self) -> bool { self.0.has_different_display_form() }
|
|
|
|
#[rune::function]
|
|
fn display_form(&self) -> Value { self.0.display_form().wrap() }
|
|
|
|
#[rune::function]
|
|
fn level(&self) -> LevelInt { self.0.level() }
|
|
|
|
#[rune::function]
|
|
fn experience(&self) -> u32 { self.0.experience() }
|
|
|
|
#[rune::function]
|
|
fn personality_value(&self) -> u32 { self.0.personality_value() }
|
|
|
|
#[rune::function]
|
|
fn gender(&self) -> Gender { self.0.gender() }
|
|
|
|
#[rune::function]
|
|
fn coloring(&self) -> u8 { self.0.coloring() }
|
|
|
|
#[rune::function]
|
|
fn held_item(&self) -> Option<Value> { self.0.held_item().map(|v| v.wrap()) }
|
|
|
|
#[rune::function]
|
|
fn has_held_item(&self, key: RuneStringKey) -> bool { self.0.has_held_item(&key.0) }
|
|
|
|
#[rune::function]
|
|
fn set_held_item(&mut self, key: RuneItem) -> Option<Value> { self.0.set_held_item(&key.0).map(|v| v.wrap()) }
|
|
|
|
#[rune::function]
|
|
fn remove_held_item(&mut self) -> Option<Value> { self.0.remove_held_item().map(|v| v.wrap()) }
|
|
|
|
#[rune::function]
|
|
fn consume_held_item(&mut self) -> anyhow::Result<bool> { self.0.consume_held_item() }
|
|
|
|
#[rune::function]
|
|
fn current_health(&self) -> u32 { self.0.current_health() }
|
|
|
|
#[rune::function]
|
|
fn max_health(&self) -> u32 { self.0.max_health() }
|
|
|
|
#[rune::function]
|
|
fn weight(&self) -> f32 { self.0.weight() }
|
|
|
|
#[rune::function]
|
|
fn set_weight(&mut self, value: f32) { self.0.set_weight(value); }
|
|
|
|
#[rune::function]
|
|
fn height(&self) -> f32 { self.0.height() }
|
|
|
|
#[rune::function]
|
|
fn happiness(&self) -> u8 { self.0.happiness() }
|
|
|
|
#[rune::function]
|
|
fn nickname(&self) -> Option<String> { self.0.nickname().clone() }
|
|
|
|
#[rune::function]
|
|
fn real_ability(&self) -> (bool, u8) { (self.0.real_ability().hidden, self.0.real_ability().index) }
|
|
|
|
#[rune::function]
|
|
fn types(&self) -> Vec<u8> { self.0.types().iter().map(|v| u8::from(*v)).collect() }
|
|
|
|
#[rune::function]
|
|
fn learned_moves(&self) -> Vec<Option<Value>> {
|
|
let l = self.0.learned_moves().read();
|
|
l.iter().map(|v| v.as_ref().map(|l| l.wrap())).collect()
|
|
}
|
|
|
|
#[rune::function]
|
|
fn flat_stats(&self) -> Value { self.0.flat_stats().wrap() }
|
|
|
|
#[rune::function]
|
|
fn is_egg(&self) -> bool { self.0.is_egg() }
|
|
|
|
#[rune::function]
|
|
fn boosted_stats(&self) -> Value { self.0.boosted_stats().wrap() }
|
|
|
|
#[rune::function]
|
|
fn stat_boost(&self, stat: Statistic) -> i8 { self.0.stat_boost(stat) }
|
|
|
|
#[rune::function]
|
|
fn change_stat_boost(&mut self, stat: Statistic, diff_amount: i8, self_inflicted: bool) -> anyhow::Result<bool> {
|
|
self.0.change_stat_boost(stat, diff_amount, self_inflicted)
|
|
}
|
|
|
|
#[rune::function]
|
|
fn get_individual_value(&self, stat: Statistic) -> u8 { self.0.individual_values().get_stat(stat) }
|
|
|
|
#[rune::function]
|
|
fn get_effort_value(&self, stat: Statistic) -> u8 { self.0.effort_values().get_stat(stat) }
|
|
|
|
#[rune::function]
|
|
fn get_battle(&self) -> Option<Value> { self.0.get_battle().map(|v| v.wrap()) }
|
|
|
|
#[rune::function]
|
|
fn get_battle_side_index(&self) -> Option<u8> { self.0.get_battle_side_index() }
|
|
|
|
#[rune::function]
|
|
fn get_battle_index(&self) -> Option<u8> { self.0.get_battle_index() }
|
|
|
|
#[rune::function]
|
|
fn is_ability_overridden(&self) -> bool { self.0.is_ability_overridden() }
|
|
|
|
#[rune::function]
|
|
fn active_ability(&self) -> anyhow::Result<Value> { self.0.active_ability().map(|v| v.wrap()) }
|
|
|
|
#[rune::function]
|
|
fn allowed_experience_gain(&self) -> bool { self.0.allowed_experience_gain() }
|
|
|
|
#[rune::function]
|
|
fn nature(&self) -> Value { self.0.nature().wrap() }
|
|
|
|
#[rune::function]
|
|
fn change_form(&self, form: RuneForm) -> anyhow::Result<()> { self.0.change_form(&form.0) }
|
|
|
|
#[rune::function]
|
|
fn is_usable(&self) -> bool { self.0.is_usable() }
|
|
|
|
#[rune::function]
|
|
fn is_fainted(&self) -> bool { self.0.is_fainted() }
|
|
|
|
#[rune::function]
|
|
fn damage(&self, amount: u32, source: DamageSource) -> anyhow::Result<()> {
|
|
self.0.damage(amount, source, EventBatchId::default())
|
|
}
|
|
|
|
#[rune::function]
|
|
fn heal(&self, amount: u32, allow_revive: bool) -> bool { self.0.heal(amount, allow_revive) }
|
|
|
|
#[rune::function]
|
|
fn clear_status(&self) { self.0.clear_status() }
|
|
|
|
#[rune::function]
|
|
fn status_script(&self) -> Option<Value> { resolve_script_data(&self.0.status()) }
|
|
|
|
#[rune::function]
|
|
fn ability_script(&self) -> Option<Value> { resolve_script_data(&self.0.ability_script()) }
|
|
}
|
|
|
|
impl_rune_wrapper!(&Pokemon, RunePokemon);
|