diff --git a/src/dynamic_data/models/pokemon.rs b/src/dynamic_data/models/pokemon.rs index 950a6a6..91b17a2 100755 --- a/src/dynamic_data/models/pokemon.rs +++ b/src/dynamic_data/models/pokemon.rs @@ -50,8 +50,8 @@ struct PokemonData { level: Atomic, /// The amount of experience of the Pokemon. experience: AtomicU32, - /// A unique random number for this Pokemon. - unique_identifier: u32, + /// The personality value of the Pokemon. + personality_value: u32, /// The gender of the Pokemon. gender: RwLock, @@ -171,7 +171,7 @@ impl Pokemon { display_form: None, level: Atomic::new(level), experience: AtomicU32::new(experience), - unique_identifier, + personality_value: unique_identifier, gender: RwLock::new(gender), coloring, held_item: RwLock::new(None), @@ -239,16 +239,19 @@ impl Pokemon { } } /// The current level of the Pokemon. + /// [See also](https://bulbapedia.bulbagarden.net/wiki/Level) pub fn level(&self) -> LevelInt { self.data.level.load(Ordering::Relaxed) } /// The amount of experience of the Pokemon. + /// [See also](https://bulbapedia.bulbagarden.net/wiki/Experience) pub fn experience(&self) -> u32 { self.data.experience.load(Ordering::Relaxed) } - /// A unique random number for this Pokemon. - pub fn unique_identifier(&self) -> u32 { - self.data.unique_identifier + /// The personality value of the Pokemon. + /// [See also](https://bulbapedia.bulbagarden.net/wiki/Personality_value) + pub fn personality_value(&self) -> u32 { + self.data.personality_value } /// The gender of the Pokemon. pub fn gender(&self) -> Gender { diff --git a/src/dynamic_data/models/pokemon_party.rs b/src/dynamic_data/models/pokemon_party.rs index db4d2b7..f35084b 100755 --- a/src/dynamic_data/models/pokemon_party.rs +++ b/src/dynamic_data/models/pokemon_party.rs @@ -3,7 +3,7 @@ use parking_lot::lock_api::RwLockReadGuard; use parking_lot::{RawRwLock, RwLock}; use crate::dynamic_data::models::pokemon::Pokemon; -use crate::VecExt; +use crate::{PkmnError, VecExt}; /// A list of Pokemon belonging to a trainer. #[derive(Debug)] @@ -43,8 +43,18 @@ impl PokemonParty { } /// Swaps two Pokemon in the party around. - pub fn switch(&self, a: usize, b: usize) { + pub fn switch(&self, a: usize, b: usize) -> Result<()> { + let write_lock = self.pokemon.write(); + if a >= write_lock.len() || b >= write_lock.len() { + return Err(PkmnError::IndexOutOfBounds { + index: if a >= write_lock.len() { a } else { b }, + len: write_lock.len(), + } + .into()); + } + self.pokemon.write().swap(a, b); + Ok(()) } /// Sets the Pokemon at an index to a Pokemon, returning the old Pokemon. diff --git a/src/ffi/dynamic_data/models/pokemon.rs b/src/ffi/dynamic_data/models/pokemon.rs index 64ceaf0..464df65 100644 --- a/src/ffi/dynamic_data/models/pokemon.rs +++ b/src/ffi/dynamic_data/models/pokemon.rs @@ -76,21 +76,24 @@ extern "C" fn pokemon_display_form(handle: FFIHandle) -> FFIHandle) -> LevelInt { handle.from_ffi_handle().level() } /// The experience of the Pokemon. +/// [See also](https://bulbapedia.bulbagarden.net/wiki/Experience) #[no_mangle] extern "C" fn pokemon_experience(handle: FFIHandle) -> u32 { handle.from_ffi_handle().experience() } -/// The unique identifier of the Pokemon. +/// The personality value of the Pokemon. +/// [See also](https://bulbapedia.bulbagarden.net/wiki/Personality_value) #[no_mangle] -extern "C" fn pokemon_unique_identifier(handle: FFIHandle) -> u32 { - handle.from_ffi_handle().unique_identifier() +extern "C" fn pokemon_personality_value(handle: FFIHandle) -> u32 { + handle.from_ffi_handle().personality_value() } /// The gender of the Pokemon. diff --git a/src/ffi/dynamic_data/models/pokemon_party.rs b/src/ffi/dynamic_data/models/pokemon_party.rs index 4e63682..c39187d 100644 --- a/src/ffi/dynamic_data/models/pokemon_party.rs +++ b/src/ffi/dynamic_data/models/pokemon_party.rs @@ -19,10 +19,10 @@ extern "C" fn pokemon_party_at(ptr: FFIHandle>, index: usize) } } -/// Gets a Pokemon at an index in the party. +/// Swaps two Pokemon in the party around. #[no_mangle] -extern "C" fn pokemon_party_switch(ptr: FFIHandle>, a: usize, b: usize) { - ptr.from_ffi_handle().switch(a, b); +extern "C" fn pokemon_party_switch(ptr: FFIHandle>, a: usize, b: usize) -> FFIResult<()> { + ptr.from_ffi_handle().switch(a, b).into() } /// Sets the Pokemon at an index to a Pokemon, returning the old Pokemon. diff --git a/src/script_implementations/wasm/export_registry/dynamic_data/pokemon.rs b/src/script_implementations/wasm/export_registry/dynamic_data/pokemon.rs index b58aabe..6b5e8f1 100755 --- a/src/script_implementations/wasm/export_registry/dynamic_data/pokemon.rs +++ b/src/script_implementations/wasm/export_registry/dynamic_data/pokemon.rs @@ -448,11 +448,11 @@ register! { wasm_ok(get_value_call_getter!(pokemon.experience(), env)) } - fn pokemon_get_unique_identifier( + fn pokemon_get_personality_value( env: FunctionEnvMut, pokemon: ExternRef, ) -> WasmResult { - wasm_ok(get_value_call_getter!(pokemon.unique_identifier(), env)) + wasm_ok(get_value_call_getter!(pokemon.personality_value(), env)) } fn pokemon_get_coloring( diff --git a/tests/data/Moves.json b/tests/data/Moves.json index d12c890..207e2f6 100755 --- a/tests/data/Moves.json +++ b/tests/data/Moves.json @@ -63,7 +63,7 @@ "mirror" ], "effect": { - "name": "ChangeTargetSpDef", + "name": "change_target_special_defense", "chance": 10, "parameters": [ -1 @@ -83,7 +83,7 @@ "snatch" ], "effect": { - "name": "ChangeTargetDef", + "name": "change_target_defense", "chance": -1, "parameters": [ 2 @@ -127,7 +127,7 @@ "ballistics" ], "effect": { - "name": "ChangeTargetSpDef", + "name": "change_target_special_defense", "chance": -1, "parameters": [ -2 @@ -150,7 +150,7 @@ "distance" ], "effect": { - "name": "Acrobatics", + "name": "acrobatics", "chance": -1 } }, @@ -165,7 +165,7 @@ "category": "status", "flags": [], "effect": { - "name": "Acupressure", + "name": "acupressure", "chance": -1 } }, @@ -200,7 +200,7 @@ "distance" ], "effect": { - "name": "IncreasedCriticalStage" + "name": "increased_critical_stage" } }, { @@ -216,7 +216,7 @@ "ignore-substitute" ], "effect": { - "name": "AfterYou" + "name": "after_you" } }, { @@ -232,7 +232,7 @@ "snatch" ], "effect": { - "name": "ChangeTargetSpeed", + "name": "change_target_speed", "parameters": [ 2 ] @@ -252,7 +252,7 @@ "mirror" ], "effect": { - "name": "IncreasedCriticalStage" + "name": "increased_critical_stage" } }, { @@ -270,7 +270,7 @@ "distance" ], "effect": { - "name": "Flinch", + "name": "flinch", "chance": 30 } }, @@ -323,7 +323,7 @@ "snatch" ], "effect": { - "name": "ChangeTargetSpDef", + "name": "change_target_special_defense", "parameters": [ 2 ] @@ -344,7 +344,7 @@ "mirror" ], "effect": { - "name": "PreventFoeRunning" + "name": "prevent_foes_exit" } }, { @@ -361,7 +361,7 @@ "mirror" ], "effect": { - "name": "ChangeAllTargetStats", + "name": "change_all_target_stats", "chance": 10, "parameters": [ 1 @@ -396,7 +396,7 @@ "snatch" ], "effect": { - "name": "HealEachEndOfTurn", + "name": "heal_each_end_of_turn", "parameters": [ 6.25 ] @@ -432,7 +432,7 @@ "mirror" ], "effect": { - "name": "2_5HitMove" + "name": "2_5_hit_move" } }, { @@ -449,7 +449,7 @@ "distance" ], "effect": { - "name": "CurePartyStatus" + "name": "cure_party_status" } }, { @@ -465,7 +465,7 @@ "ignore-substitute" ], "effect": { - "name": "ChangeTargetSpDef", + "name": "change_target_special_defense", "parameters": [ 1 ] @@ -500,7 +500,7 @@ "mirror" ], "effect": { - "name": "Assurance" + "name": "double_power_if_target_damaged_in_turn" } }, { @@ -536,7 +536,7 @@ "mirror" ], "effect": { - "name": "IncreasedCriticalStage" + "name": "increased_critical_stage" } }, { @@ -556,7 +556,7 @@ "mental" ], "effect": { - "name": "Attract" + "name": "attract" } }, { @@ -590,9 +590,11 @@ "mirror" ], "effect": { - "name": "ChangeTargetAtt", + "name": "change_target_attack", "chance": 10, - "parameters": [-1] + "parameters": [ + -1 + ] } }, { @@ -621,7 +623,7 @@ "snatch" ], "effect": { - "name": "Automize" + "name": "automize" } }, { @@ -639,7 +641,7 @@ "mirror" ], "effect": { - "name": "ModifyDamageIfHitByTarget" + "name": "double_power_user_damaged_by_target_in_turn" } }, { @@ -657,8 +659,10 @@ "mirror" ], "effect": { - "name": "ChangeTargetAtt", - "parameters": [-1] + "name": "change_target_attack", + "parameters": [ + -1 + ] } }, { diff --git a/tests/data/gen7_scripts.wasm b/tests/data/gen7_scripts.wasm index 62c45c2..a1b304c 100755 Binary files a/tests/data/gen7_scripts.wasm and b/tests/data/gen7_scripts.wasm differ diff --git a/tests/integration.rs b/tests/integration.rs index bb7bfaa..70783d2 100755 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -115,14 +115,18 @@ fn validate_assurance() { battle.sides()[1].set_pokemon(0, Some(p2.clone())).unwrap(); let script = lib - .load_script(ScriptOwnerData::None, ScriptCategory::Move, &"assurance".into()) + .load_script( + ScriptOwnerData::None, + ScriptCategory::Move, + &"double_power_if_target_damaged_in_turn".into(), + ) .unwrap() .unwrap(); let mv = p1.learned_moves().read()[0].as_ref().unwrap().clone(); let choice = Arc::new(TurnChoice::Move(MoveChoice::new(p1.clone(), mv.clone(), 1, 0))); script.on_before_turn(&choice).unwrap(); - assert!(battle.sides()[1].has_volatile_script(&"assurance_data".into())); + assert!(battle.sides()[1].has_volatile_script(&"double_power_if_target_damaged_in_turn_data".into())); let executing_move = Arc::new(ExecutingMove::new( vec![], @@ -136,7 +140,7 @@ fn validate_assurance() { script.change_base_power(&executing_move, &p2, 0, &mut v).unwrap(); assert_eq!(v, 20_u8); - let s = battle.sides()[1].get_volatile_script(&"assurance_data".into()); + let s = battle.sides()[1].get_volatile_script(&"double_power_if_target_damaged_in_turn_data".into()); let binding = s.as_ref().unwrap().get().unwrap().read(); let data_script = binding.as_ref().unwrap(); @@ -147,5 +151,5 @@ fn validate_assurance() { assert_eq!(v, 40_u8); data_script.on_end_turn().unwrap(); - assert!(!battle.sides()[1].has_volatile_script(&"assurance_data".into())); + assert!(!battle.sides()[1].has_volatile_script(&"double_power_if_target_damaged_in_turn_data".into())); }