Implements Drain moves
This commit is contained in:
		
							
								
								
									
										53
									
								
								gen_7_scripts/src/moves/drain.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								gen_7_scripts/src/moves/drain.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,53 @@ | ||||
| use crate::script; | ||||
| use atomic_float::AtomicF32; | ||||
| use core::any::Any; | ||||
| use core::sync::atomic::Ordering; | ||||
| use pkmn_lib_interface::app_interface::list::ImmutableList; | ||||
| use pkmn_lib_interface::app_interface::{DynamicLibrary, EffectParameter, ExecutingMove, Pokemon}; | ||||
| use pkmn_lib_interface::handling::{Script, ScriptCapabilities}; | ||||
|  | ||||
| script!(Drain, "drain", heal_modifier: AtomicF32); | ||||
|  | ||||
| impl Script for Drain { | ||||
|     fn new() -> Self { | ||||
|         Self { | ||||
|             heal_modifier: Default::default(), | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     fn get_name(&self) -> &'static str { | ||||
|         Self::get_const_name() | ||||
|     } | ||||
|  | ||||
|     fn get_capabilities(&self) -> &[ScriptCapabilities] { | ||||
|         &[ | ||||
|             ScriptCapabilities::Initialize, | ||||
|             ScriptCapabilities::OnSecondaryEffect, | ||||
|         ] | ||||
|     } | ||||
|  | ||||
|     fn on_initialize( | ||||
|         &self, | ||||
|         _library: &DynamicLibrary, | ||||
|         parameters: Option<ImmutableList<EffectParameter>>, | ||||
|     ) { | ||||
|         self.heal_modifier.store( | ||||
|             parameters.unwrap().get(0).unwrap().as_float(), | ||||
|             Ordering::SeqCst, | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|     fn on_secondary_effect(&self, mv: ExecutingMove, target: Pokemon, hit: u8) { | ||||
|         let hit_data = mv.get_hit_data(&target, hit); | ||||
|         let damage = hit_data.damage(); | ||||
|         let mut modifier = self.heal_modifier.load(Ordering::SeqCst); | ||||
|         if mv.user().has_held_item("big_root") { | ||||
|             modifier *= 1.3; | ||||
|         } | ||||
|         mv.user().heal((damage as f32 * modifier) as u32, false); | ||||
|     } | ||||
|  | ||||
|     fn as_any(&self) -> &dyn Any { | ||||
|         self | ||||
|     } | ||||
| } | ||||
| @@ -9,6 +9,7 @@ pub mod automize; | ||||
| pub mod change_all_target_stats; | ||||
| pub mod change_target_stats; | ||||
| pub mod cure_party_status; | ||||
| pub mod drain; | ||||
| pub mod light_screen; | ||||
| pub mod multi_hit_move; | ||||
| pub mod reflect; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user