62 lines
1.3 KiB
Rust
62 lines
1.3 KiB
Rust
use crate::common_usings::*;
|
|
|
|
script!(
|
|
AssuranceData,
|
|
"assurance_data",
|
|
for_position: u8,
|
|
has_hit: AtomicBool
|
|
);
|
|
|
|
impl Script for AssuranceData {
|
|
fn new() -> Self {
|
|
Self {
|
|
for_position: 0,
|
|
has_hit: AtomicBool::new(false),
|
|
}
|
|
}
|
|
|
|
fn get_name(&self) -> &'static str {
|
|
Self::get_const_name()
|
|
}
|
|
|
|
fn get_capabilities(&self) -> &[ScriptCapabilities] {
|
|
&[ScriptCapabilities::OnEndTurn, ScriptCapabilities::OnDamage]
|
|
}
|
|
|
|
fn on_end_turn(&self) -> PkmnResult<()> {
|
|
let side = self.get_owner().unwrap().as_side();
|
|
side.remove_volatile(self)?;
|
|
Ok(())
|
|
}
|
|
|
|
fn on_damage(
|
|
&self,
|
|
pokemon: Pokemon,
|
|
_source: DamageSource,
|
|
_old_health: u32,
|
|
_new_health: u32,
|
|
) -> PkmnResult<()> {
|
|
if pokemon.battle_index()? == self.for_position {
|
|
self.has_hit.store(true, Ordering::Relaxed);
|
|
}
|
|
Ok(())
|
|
}
|
|
|
|
fn as_any(&self) -> &dyn Any {
|
|
self
|
|
}
|
|
}
|
|
|
|
impl AssuranceData {
|
|
pub fn create_for_assurance(for_position: u8) -> Box<dyn Script> {
|
|
Box::new(Self {
|
|
for_position,
|
|
has_hit: AtomicBool::new(false),
|
|
})
|
|
}
|
|
|
|
pub fn has_hit(&self) -> bool {
|
|
self.has_hit.load(Ordering::Relaxed)
|
|
}
|
|
}
|