103 lines
2.8 KiB
Rust
103 lines
2.8 KiB
Rust
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::{ExecutingMove, MoveCategory, Pokemon, WithVolatile};
|
|
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 binding = target.battle_side();
|
|
let script = binding
|
|
.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]
|
|
}
|
|
|
|
#[cfg(not(test))]
|
|
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: pkmn_lib_interface::app_interface::BattleSideImpl = 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
|
|
}
|
|
}
|