Implements Aurora Veil
This commit is contained in:
parent
19d2705221
commit
c29201b36f
|
@ -16,6 +16,7 @@ pub mod moves;
|
||||||
pub mod pokemon;
|
pub mod pokemon;
|
||||||
pub mod util_scripts;
|
pub mod util_scripts;
|
||||||
pub(crate) mod utils;
|
pub(crate) mod utils;
|
||||||
|
pub mod weather;
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
|
|
|
@ -0,0 +1,101 @@
|
||||||
|
use crate::moves::light_screen::LightScreenEffect;
|
||||||
|
use crate::moves::reflect::ReflectEffect;
|
||||||
|
use crate::script;
|
||||||
|
use crate::weather::hail::Hail;
|
||||||
|
use alloc::boxed::Box;
|
||||||
|
use core::any::Any;
|
||||||
|
use core::sync::atomic::{AtomicU32, Ordering};
|
||||||
|
use pkmn_lib_interface::app_interface::{BattleSide, ExecutingMove, MoveCategory, Pokemon};
|
||||||
|
use pkmn_lib_interface::handling::ScriptCapabilities::OnEndTurn;
|
||||||
|
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
|
||||||
|
|
||||||
|
script!(AuroraVeil, "aurora_veil");
|
||||||
|
|
||||||
|
impl Script for AuroraVeil {
|
||||||
|
fn new() -> Self {
|
||||||
|
Self {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_name(&self) -> &'static str {
|
||||||
|
Self::get_const_name()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_capabilities(&self) -> &[ScriptCapabilities] {
|
||||||
|
&[ScriptCapabilities::OnSecondaryEffect]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_secondary_effect(&self, mv: ExecutingMove, target: Pokemon, hit: u8) {
|
||||||
|
if target.battle().unwrap().has_weather(Hail::get_const_name()) {
|
||||||
|
return mv.get_hit_data(&target, hit).fail();
|
||||||
|
}
|
||||||
|
let script = target
|
||||||
|
.battle_side()
|
||||||
|
.add_volatile(Box::new(AuroraVeilEffect::new()))
|
||||||
|
.as_any()
|
||||||
|
.downcast_ref::<AuroraVeilEffect>()
|
||||||
|
.unwrap();
|
||||||
|
if mv.user().has_held_item("light_clay") {
|
||||||
|
script.turns.store(8, Ordering::SeqCst);
|
||||||
|
} else {
|
||||||
|
script.turns.store(5, Ordering::SeqCst);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn as_any(&self) -> &dyn Any {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
script!(AuroraVeilEffect, "aurora_veil_effect", turns: AtomicU32);
|
||||||
|
|
||||||
|
impl Script for AuroraVeilEffect {
|
||||||
|
fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
turns: Default::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_name(&self) -> &'static str {
|
||||||
|
Self::get_const_name()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_capabilities(&self) -> &[ScriptCapabilities] {
|
||||||
|
&[ScriptCapabilities::ChangeIncomingDamage, OnEndTurn]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn change_incoming_damage(
|
||||||
|
&self,
|
||||||
|
mv: ExecutingMove,
|
||||||
|
target: Pokemon,
|
||||||
|
hit: u8,
|
||||||
|
damage: &mut u32,
|
||||||
|
) {
|
||||||
|
if mv.get_hit_data(&target, hit).is_critical() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let side: BattleSide = self.get_owner().unwrap();
|
||||||
|
if side.has_volatile(ReflectEffect::get_const_name())
|
||||||
|
&& mv.use_move().category() == MoveCategory::Physical
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if side.has_volatile(LightScreenEffect::get_const_name())
|
||||||
|
&& mv.use_move().category() == MoveCategory::Special
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let mut modifier = 2.0;
|
||||||
|
if target.battle().unwrap().pokemon_per_side() > 1 {
|
||||||
|
modifier = 1.5
|
||||||
|
}
|
||||||
|
*damage = (*damage as f32 / modifier) as u32;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_end_turn(&self) {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn as_any(&self) -> &dyn Any {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
// TODO: Implementation
|
||||||
|
|
||||||
|
use crate::script;
|
||||||
|
script!(LightScreenEffect, "light_screen_effect");
|
|
@ -4,4 +4,7 @@ pub mod after_you;
|
||||||
pub mod assist;
|
pub mod assist;
|
||||||
pub mod assurance;
|
pub mod assurance;
|
||||||
pub mod attract;
|
pub mod attract;
|
||||||
|
pub mod aurora_veil;
|
||||||
|
pub mod light_screen;
|
||||||
pub mod multi_hit_move;
|
pub mod multi_hit_move;
|
||||||
|
pub mod reflect;
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
use crate::script;
|
||||||
|
|
||||||
|
// TODO: Implementation
|
||||||
|
|
||||||
|
script!(ReflectEffect, "reflect_effect");
|
|
@ -0,0 +1,25 @@
|
||||||
|
use crate::script;
|
||||||
|
use core::any::Any;
|
||||||
|
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
|
||||||
|
script!(Hail, "hail");
|
||||||
|
|
||||||
|
impl Script for Hail {
|
||||||
|
fn new() -> Self
|
||||||
|
where
|
||||||
|
Self: Sized,
|
||||||
|
{
|
||||||
|
Self {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_name(&self) -> &'static str {
|
||||||
|
Self::get_const_name()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_capabilities(&self) -> &[ScriptCapabilities] {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn as_any(&self) -> &dyn Any {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
pub mod hail;
|
|
@ -3,7 +3,7 @@ use crate::handling::cached_value::CachedValue;
|
||||||
use crate::handling::Cacheable;
|
use crate::handling::Cacheable;
|
||||||
use crate::{
|
use crate::{
|
||||||
cached_value, cached_value_getters, wasm_value_getters, DynamicLibrary, ExternRef,
|
cached_value, cached_value_getters, wasm_value_getters, DynamicLibrary, ExternRef,
|
||||||
ExternalReferenceType, ImmutableList, VecExternRef,
|
ExternalReferenceType, ImmutableList, StringKey, VecExternRef,
|
||||||
};
|
};
|
||||||
use alloc::rc::Rc;
|
use alloc::rc::Rc;
|
||||||
|
|
||||||
|
@ -56,6 +56,25 @@ impl Battle {
|
||||||
battle_find_party_for_pokemon(self.inner.reference, pokemon.reference()).get_value()
|
battle_find_party_for_pokemon(self.inner.reference, pokemon.reference()).get_value()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "mock_data")]
|
||||||
|
pub fn weather_name(&self) -> Option<StringKey> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "mock_data"))]
|
||||||
|
pub fn weather_name(&self) -> Option<StringKey> {
|
||||||
|
unsafe { battle_get_weather_name(self.inner.reference).get_value() }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn has_weather(&self, name: &str) -> bool {
|
||||||
|
if let Some(weather) = self.weather_name() {
|
||||||
|
if weather.eq(name) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wasm_value_getters! {
|
wasm_value_getters! {
|
||||||
|
@ -90,4 +109,6 @@ extern "wasm" {
|
||||||
r: ExternRef<Battle>,
|
r: ExternRef<Battle>,
|
||||||
mon: ExternRef<Pokemon>,
|
mon: ExternRef<Pokemon>,
|
||||||
) -> ExternRef<BattleParty>;
|
) -> ExternRef<BattleParty>;
|
||||||
|
|
||||||
|
fn battle_get_weather_name(r: ExternRef<Battle>) -> ExternRef<StringKey>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,15 @@ impl BattleSide {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "mock_data"))]
|
#[cfg(not(feature = "mock_data"))]
|
||||||
pub fn add_volatile(&self, script: Box<dyn Script>) -> &dyn Script {
|
pub fn has_volatile(&self, script_name: &str) -> bool {
|
||||||
|
unsafe {
|
||||||
|
let script_name = CString::new(script_name).unwrap();
|
||||||
|
battleside_has_volatile(self.inner.reference, script_name.into_raw())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "mock_data"))]
|
||||||
|
pub fn add_volatile<'a, 'b>(&'a self, script: Box<dyn Script>) -> &'b dyn Script {
|
||||||
unsafe {
|
unsafe {
|
||||||
battleside_add_volatile(self.inner.reference, ScriptPtr::new(script))
|
battleside_add_volatile(self.inner.reference, ScriptPtr::new(script))
|
||||||
.val()
|
.val()
|
||||||
|
|
|
@ -5,7 +5,7 @@ use crate::{cached_value, cached_value_getters, ExternRef, ExternalReferenceType
|
||||||
use alloc::rc::Rc;
|
use alloc::rc::Rc;
|
||||||
|
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Eq, PartialEq)]
|
||||||
pub enum MoveCategory {
|
pub enum MoveCategory {
|
||||||
Physical = 0,
|
Physical = 0,
|
||||||
Special = 1,
|
Special = 1,
|
||||||
|
@ -13,7 +13,7 @@ pub enum MoveCategory {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Eq, PartialEq)]
|
||||||
pub enum MoveTarget {
|
pub enum MoveTarget {
|
||||||
Adjacent,
|
Adjacent,
|
||||||
AdjacentAlly,
|
AdjacentAlly,
|
||||||
|
|
|
@ -68,6 +68,10 @@ impl StringKey {
|
||||||
pub fn hash(&self) -> u32 {
|
pub fn hash(&self) -> u32 {
|
||||||
self.data.hash.borrow().unwrap()
|
self.data.hash.borrow().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn eq(&self, other: &str) -> bool {
|
||||||
|
self.hash() == get_hash(other)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq for StringKey {
|
impl PartialEq for StringKey {
|
||||||
|
|
Loading…
Reference in New Issue