Rename unique_identifier --> personality_value, minor fixes
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2023-07-09 11:17:43 +02:00
parent bc9b3ed964
commit f6df95a824
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
8 changed files with 70 additions and 46 deletions

View File

@ -50,8 +50,8 @@ struct PokemonData {
level: Atomic<LevelInt>, level: Atomic<LevelInt>,
/// The amount of experience of the Pokemon. /// The amount of experience of the Pokemon.
experience: AtomicU32, experience: AtomicU32,
/// A unique random number for this Pokemon. /// The personality value of the Pokemon.
unique_identifier: u32, personality_value: u32,
/// The gender of the Pokemon. /// The gender of the Pokemon.
gender: RwLock<Gender>, gender: RwLock<Gender>,
@ -171,7 +171,7 @@ impl Pokemon {
display_form: None, display_form: None,
level: Atomic::new(level), level: Atomic::new(level),
experience: AtomicU32::new(experience), experience: AtomicU32::new(experience),
unique_identifier, personality_value: unique_identifier,
gender: RwLock::new(gender), gender: RwLock::new(gender),
coloring, coloring,
held_item: RwLock::new(None), held_item: RwLock::new(None),
@ -239,16 +239,19 @@ impl Pokemon {
} }
} }
/// The current level of the Pokemon. /// The current level of the Pokemon.
/// [See also](https://bulbapedia.bulbagarden.net/wiki/Level)
pub fn level(&self) -> LevelInt { pub fn level(&self) -> LevelInt {
self.data.level.load(Ordering::Relaxed) self.data.level.load(Ordering::Relaxed)
} }
/// The amount of experience of the Pokemon. /// The amount of experience of the Pokemon.
/// [See also](https://bulbapedia.bulbagarden.net/wiki/Experience)
pub fn experience(&self) -> u32 { pub fn experience(&self) -> u32 {
self.data.experience.load(Ordering::Relaxed) self.data.experience.load(Ordering::Relaxed)
} }
/// A unique random number for this Pokemon. /// The personality value of the Pokemon.
pub fn unique_identifier(&self) -> u32 { /// [See also](https://bulbapedia.bulbagarden.net/wiki/Personality_value)
self.data.unique_identifier pub fn personality_value(&self) -> u32 {
self.data.personality_value
} }
/// The gender of the Pokemon. /// The gender of the Pokemon.
pub fn gender(&self) -> Gender { pub fn gender(&self) -> Gender {

View File

@ -3,7 +3,7 @@ use parking_lot::lock_api::RwLockReadGuard;
use parking_lot::{RawRwLock, RwLock}; use parking_lot::{RawRwLock, RwLock};
use crate::dynamic_data::models::pokemon::Pokemon; use crate::dynamic_data::models::pokemon::Pokemon;
use crate::VecExt; use crate::{PkmnError, VecExt};
/// A list of Pokemon belonging to a trainer. /// A list of Pokemon belonging to a trainer.
#[derive(Debug)] #[derive(Debug)]
@ -43,8 +43,18 @@ impl PokemonParty {
} }
/// Swaps two Pokemon in the party around. /// 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); self.pokemon.write().swap(a, b);
Ok(())
} }
/// Sets the Pokemon at an index to a Pokemon, returning the old Pokemon. /// Sets the Pokemon at an index to a Pokemon, returning the old Pokemon.

View File

@ -76,21 +76,24 @@ extern "C" fn pokemon_display_form(handle: FFIHandle<Pokemon>) -> FFIHandle<Arc<
} }
/// The level of the Pokemon. /// The level of the Pokemon.
/// [See also](https://bulbapedia.bulbagarden.net/wiki/Level)
#[no_mangle] #[no_mangle]
extern "C" fn pokemon_level(handle: FFIHandle<Pokemon>) -> LevelInt { extern "C" fn pokemon_level(handle: FFIHandle<Pokemon>) -> LevelInt {
handle.from_ffi_handle().level() handle.from_ffi_handle().level()
} }
/// The experience of the Pokemon. /// The experience of the Pokemon.
/// [See also](https://bulbapedia.bulbagarden.net/wiki/Experience)
#[no_mangle] #[no_mangle]
extern "C" fn pokemon_experience(handle: FFIHandle<Pokemon>) -> u32 { extern "C" fn pokemon_experience(handle: FFIHandle<Pokemon>) -> u32 {
handle.from_ffi_handle().experience() 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] #[no_mangle]
extern "C" fn pokemon_unique_identifier(handle: FFIHandle<Pokemon>) -> u32 { extern "C" fn pokemon_personality_value(handle: FFIHandle<Pokemon>) -> u32 {
handle.from_ffi_handle().unique_identifier() handle.from_ffi_handle().personality_value()
} }
/// The gender of the Pokemon. /// The gender of the Pokemon.

View File

@ -19,10 +19,10 @@ extern "C" fn pokemon_party_at(ptr: FFIHandle<Arc<PokemonParty>>, index: usize)
} }
} }
/// Gets a Pokemon at an index in the party. /// Swaps two Pokemon in the party around.
#[no_mangle] #[no_mangle]
extern "C" fn pokemon_party_switch(ptr: FFIHandle<Arc<PokemonParty>>, a: usize, b: usize) { extern "C" fn pokemon_party_switch(ptr: FFIHandle<Arc<PokemonParty>>, a: usize, b: usize) -> FFIResult<()> {
ptr.from_ffi_handle().switch(a, b); ptr.from_ffi_handle().switch(a, b).into()
} }
/// Sets the Pokemon at an index to a Pokemon, returning the old Pokemon. /// Sets the Pokemon at an index to a Pokemon, returning the old Pokemon.

View File

@ -448,11 +448,11 @@ register! {
wasm_ok(get_value_call_getter!(pokemon.experience(), env)) wasm_ok(get_value_call_getter!(pokemon.experience(), env))
} }
fn pokemon_get_unique_identifier( fn pokemon_get_personality_value(
env: FunctionEnvMut<WebAssemblyEnv>, env: FunctionEnvMut<WebAssemblyEnv>,
pokemon: ExternRef<Pokemon>, pokemon: ExternRef<Pokemon>,
) -> WasmResult<u32> { ) -> WasmResult<u32> {
wasm_ok(get_value_call_getter!(pokemon.unique_identifier(), env)) wasm_ok(get_value_call_getter!(pokemon.personality_value(), env))
} }
fn pokemon_get_coloring( fn pokemon_get_coloring(

View File

@ -63,7 +63,7 @@
"mirror" "mirror"
], ],
"effect": { "effect": {
"name": "ChangeTargetSpDef", "name": "change_target_special_defense",
"chance": 10, "chance": 10,
"parameters": [ "parameters": [
-1 -1
@ -83,7 +83,7 @@
"snatch" "snatch"
], ],
"effect": { "effect": {
"name": "ChangeTargetDef", "name": "change_target_defense",
"chance": -1, "chance": -1,
"parameters": [ "parameters": [
2 2
@ -127,7 +127,7 @@
"ballistics" "ballistics"
], ],
"effect": { "effect": {
"name": "ChangeTargetSpDef", "name": "change_target_special_defense",
"chance": -1, "chance": -1,
"parameters": [ "parameters": [
-2 -2
@ -150,7 +150,7 @@
"distance" "distance"
], ],
"effect": { "effect": {
"name": "Acrobatics", "name": "acrobatics",
"chance": -1 "chance": -1
} }
}, },
@ -165,7 +165,7 @@
"category": "status", "category": "status",
"flags": [], "flags": [],
"effect": { "effect": {
"name": "Acupressure", "name": "acupressure",
"chance": -1 "chance": -1
} }
}, },
@ -200,7 +200,7 @@
"distance" "distance"
], ],
"effect": { "effect": {
"name": "IncreasedCriticalStage" "name": "increased_critical_stage"
} }
}, },
{ {
@ -216,7 +216,7 @@
"ignore-substitute" "ignore-substitute"
], ],
"effect": { "effect": {
"name": "AfterYou" "name": "after_you"
} }
}, },
{ {
@ -232,7 +232,7 @@
"snatch" "snatch"
], ],
"effect": { "effect": {
"name": "ChangeTargetSpeed", "name": "change_target_speed",
"parameters": [ "parameters": [
2 2
] ]
@ -252,7 +252,7 @@
"mirror" "mirror"
], ],
"effect": { "effect": {
"name": "IncreasedCriticalStage" "name": "increased_critical_stage"
} }
}, },
{ {
@ -270,7 +270,7 @@
"distance" "distance"
], ],
"effect": { "effect": {
"name": "Flinch", "name": "flinch",
"chance": 30 "chance": 30
} }
}, },
@ -323,7 +323,7 @@
"snatch" "snatch"
], ],
"effect": { "effect": {
"name": "ChangeTargetSpDef", "name": "change_target_special_defense",
"parameters": [ "parameters": [
2 2
] ]
@ -344,7 +344,7 @@
"mirror" "mirror"
], ],
"effect": { "effect": {
"name": "PreventFoeRunning" "name": "prevent_foes_exit"
} }
}, },
{ {
@ -361,7 +361,7 @@
"mirror" "mirror"
], ],
"effect": { "effect": {
"name": "ChangeAllTargetStats", "name": "change_all_target_stats",
"chance": 10, "chance": 10,
"parameters": [ "parameters": [
1 1
@ -396,7 +396,7 @@
"snatch" "snatch"
], ],
"effect": { "effect": {
"name": "HealEachEndOfTurn", "name": "heal_each_end_of_turn",
"parameters": [ "parameters": [
6.25 6.25
] ]
@ -432,7 +432,7 @@
"mirror" "mirror"
], ],
"effect": { "effect": {
"name": "2_5HitMove" "name": "2_5_hit_move"
} }
}, },
{ {
@ -449,7 +449,7 @@
"distance" "distance"
], ],
"effect": { "effect": {
"name": "CurePartyStatus" "name": "cure_party_status"
} }
}, },
{ {
@ -465,7 +465,7 @@
"ignore-substitute" "ignore-substitute"
], ],
"effect": { "effect": {
"name": "ChangeTargetSpDef", "name": "change_target_special_defense",
"parameters": [ "parameters": [
1 1
] ]
@ -500,7 +500,7 @@
"mirror" "mirror"
], ],
"effect": { "effect": {
"name": "Assurance" "name": "double_power_if_target_damaged_in_turn"
} }
}, },
{ {
@ -536,7 +536,7 @@
"mirror" "mirror"
], ],
"effect": { "effect": {
"name": "IncreasedCriticalStage" "name": "increased_critical_stage"
} }
}, },
{ {
@ -556,7 +556,7 @@
"mental" "mental"
], ],
"effect": { "effect": {
"name": "Attract" "name": "attract"
} }
}, },
{ {
@ -590,9 +590,11 @@
"mirror" "mirror"
], ],
"effect": { "effect": {
"name": "ChangeTargetAtt", "name": "change_target_attack",
"chance": 10, "chance": 10,
"parameters": [-1] "parameters": [
-1
]
} }
}, },
{ {
@ -621,7 +623,7 @@
"snatch" "snatch"
], ],
"effect": { "effect": {
"name": "Automize" "name": "automize"
} }
}, },
{ {
@ -639,7 +641,7 @@
"mirror" "mirror"
], ],
"effect": { "effect": {
"name": "ModifyDamageIfHitByTarget" "name": "double_power_user_damaged_by_target_in_turn"
} }
}, },
{ {
@ -657,8 +659,10 @@
"mirror" "mirror"
], ],
"effect": { "effect": {
"name": "ChangeTargetAtt", "name": "change_target_attack",
"parameters": [-1] "parameters": [
-1
]
} }
}, },
{ {

Binary file not shown.

View File

@ -115,14 +115,18 @@ fn validate_assurance() {
battle.sides()[1].set_pokemon(0, Some(p2.clone())).unwrap(); battle.sides()[1].set_pokemon(0, Some(p2.clone())).unwrap();
let script = lib 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()
.unwrap(); .unwrap();
let mv = p1.learned_moves().read()[0].as_ref().unwrap().clone(); 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))); let choice = Arc::new(TurnChoice::Move(MoveChoice::new(p1.clone(), mv.clone(), 1, 0)));
script.on_before_turn(&choice).unwrap(); 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( let executing_move = Arc::new(ExecutingMove::new(
vec![], vec![],
@ -136,7 +140,7 @@ fn validate_assurance() {
script.change_base_power(&executing_move, &p2, 0, &mut v).unwrap(); script.change_base_power(&executing_move, &p2, 0, &mut v).unwrap();
assert_eq!(v, 20_u8); 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 binding = s.as_ref().unwrap().get().unwrap().read();
let data_script = binding.as_ref().unwrap(); let data_script = binding.as_ref().unwrap();
@ -147,5 +151,5 @@ fn validate_assurance() {
assert_eq!(v, 40_u8); assert_eq!(v, 40_u8);
data_script.on_end_turn().unwrap(); 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()));
} }