Unit tests for basic Rune registration
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -5,10 +5,7 @@
|
||||
|
||||
use std::sync::{Arc, LazyLock};
|
||||
|
||||
use pkmn_lib::dynamic_data::{
|
||||
Battle, BattleParty, DamageSource, DynamicLibrary, ExecutingMove, MoveChoice, PassChoice, PokemonBuilder,
|
||||
PokemonParty, ScriptCategory, ScriptContainer, ScriptOwnerData, TurnChoice, VolatileScriptsOwner,
|
||||
};
|
||||
use pkmn_lib::dynamic_data::{DynamicLibrary, PassChoice, PokemonBuilder, ScriptCategory, ScriptOwnerData, TurnChoice};
|
||||
|
||||
use crate::common::library_loader;
|
||||
|
||||
@@ -106,75 +103,3 @@ fn load_non_existing_wasm_script() {
|
||||
|
||||
assert!(script.is_none());
|
||||
}
|
||||
|
||||
/// Assurance has the interesting properties that it creates a special data script internally, and
|
||||
/// deletes that data script through the get_owner functionality.
|
||||
#[test]
|
||||
fn validate_assurance() {
|
||||
let lib = get_library();
|
||||
let p1 = PokemonBuilder::new(lib.clone(), "charizard".into(), 100)
|
||||
.learn_move("assurance".into())
|
||||
.build()
|
||||
.unwrap();
|
||||
let p2 = PokemonBuilder::new(lib.clone(), "venusaur".into(), 100)
|
||||
.build()
|
||||
.unwrap();
|
||||
let party1 = Arc::new(
|
||||
BattleParty::new(
|
||||
Arc::new(PokemonParty::new_from_vec(vec![Some(p1.clone())])),
|
||||
vec![(0, 0)],
|
||||
)
|
||||
.unwrap(),
|
||||
);
|
||||
let party2 = Arc::new(
|
||||
BattleParty::new(
|
||||
Arc::new(PokemonParty::new_from_vec(vec![Some(p2.clone())])),
|
||||
vec![(1, 0)],
|
||||
)
|
||||
.unwrap(),
|
||||
);
|
||||
|
||||
let battle = Battle::new(lib.clone(), vec![party1, party2], false, 2, 1, None);
|
||||
|
||||
battle.sides()[0].set_pokemon(0, Some(p1.clone())).unwrap();
|
||||
battle.sides()[1].set_pokemon(0, Some(p2.clone())).unwrap();
|
||||
|
||||
let script = lib
|
||||
.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(&"double_power_if_target_damaged_in_turn_data".into()));
|
||||
|
||||
let executing_move = Arc::new(ExecutingMove::new(
|
||||
vec![],
|
||||
1,
|
||||
p1,
|
||||
mv.clone(),
|
||||
mv.move_data().clone(),
|
||||
ScriptContainer::default(),
|
||||
));
|
||||
let mut v = 20_u8;
|
||||
script.change_base_power(&executing_move, &p2, 0, &mut v).unwrap();
|
||||
assert_eq!(v, 20_u8);
|
||||
|
||||
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();
|
||||
|
||||
data_script.on_damage(&p2, DamageSource::Misc, 100, 50).unwrap();
|
||||
|
||||
let mut v = 20_u8;
|
||||
script.change_base_power(&executing_move, &p2, 0, &mut v).unwrap();
|
||||
assert_eq!(v, 40_u8);
|
||||
|
||||
data_script.on_end_turn().unwrap();
|
||||
assert!(!battle.sides()[1].has_volatile_script(&"double_power_if_target_damaged_in_turn_data".into()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user