Registration fixes and improvements.
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:
@@ -47,8 +47,10 @@ pub enum ScriptCategory {
|
||||
Side = 4,
|
||||
/// A script that can be attached to the entire battle.
|
||||
Battle = 5,
|
||||
/// A special script for weather, for use on battles.
|
||||
Weather = 6,
|
||||
/// A special script for held items. As they're part of a held item, they're attached to a Pokemon.
|
||||
ItemBattleTrigger = 6,
|
||||
ItemBattleTrigger = 7,
|
||||
}
|
||||
|
||||
/// A basic empty script resolver, that always returns None.
|
||||
|
||||
@@ -11,12 +11,12 @@ use crate::dynamic_data::models::battle_party::BattleParty;
|
||||
use crate::dynamic_data::models::battle_random::BattleRandom;
|
||||
use crate::dynamic_data::models::battle_side::BattleSide;
|
||||
use crate::dynamic_data::models::pokemon::Pokemon;
|
||||
use crate::dynamic_data::ChoiceQueue;
|
||||
use crate::dynamic_data::DynamicLibrary;
|
||||
use crate::dynamic_data::Script;
|
||||
use crate::dynamic_data::ScriptSet;
|
||||
use crate::dynamic_data::VolatileScriptsOwner;
|
||||
use crate::dynamic_data::{is_valid_target, ScriptWrapper};
|
||||
use crate::dynamic_data::{ChoiceQueue, ScriptContainer};
|
||||
use crate::dynamic_data::{ScriptCategory, ScriptSource, ScriptSourceData};
|
||||
use crate::{script_hook, PkmnResult, StringKey};
|
||||
|
||||
@@ -48,6 +48,8 @@ pub struct Battle {
|
||||
event_hook: EventHook,
|
||||
/// The index of the current turn. 0 until all choices
|
||||
current_turn: AtomicU32,
|
||||
/// The current weather of the battle.
|
||||
weather: ScriptContainer,
|
||||
/// All the volatile scripts attached to a Pokemon
|
||||
volatile_scripts: Arc<ScriptSet>,
|
||||
/// The time the last turn took to run. Defaults to 0.
|
||||
@@ -91,6 +93,7 @@ impl Battle {
|
||||
result: RwLock::new(BattleResult::Inconclusive),
|
||||
event_hook: Default::default(),
|
||||
current_turn: AtomicU32::new(0),
|
||||
weather: Default::default(),
|
||||
volatile_scripts: Default::default(),
|
||||
last_turn_time: Default::default(),
|
||||
script_source_data: Default::default(),
|
||||
@@ -331,6 +334,30 @@ impl Battle {
|
||||
.store(time.num_nanoseconds().unwrap() as u64, Ordering::SeqCst);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Sets the current weather for the battle. If None is passed, this clears the weather.
|
||||
pub fn set_weather(&self, weather: Option<StringKey>) {
|
||||
if let Some(weather) = weather {
|
||||
let script = self
|
||||
.library()
|
||||
.load_script(self.into(), ScriptCategory::Weather, &weather)
|
||||
.unwrap()
|
||||
.expect(format!("Couldn't find weather script by name {}", weather).as_str());
|
||||
self.weather.set(script);
|
||||
} else {
|
||||
self.weather.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the current weather of the battle. If no weather is present, this returns None.
|
||||
pub fn weather_name(&self) -> Option<StringKey> {
|
||||
if let Some(script) = self.weather.get() {
|
||||
let lock = script.read();
|
||||
Some(lock.as_ref().unwrap().name().clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl VolatileScriptsOwner for Battle {
|
||||
@@ -353,6 +380,7 @@ impl ScriptSource for Battle {
|
||||
}
|
||||
|
||||
fn get_own_scripts(&self, scripts: &mut Vec<ScriptWrapper>) {
|
||||
scripts.push((&self.weather).into());
|
||||
scripts.push((&self.volatile_scripts).into());
|
||||
}
|
||||
|
||||
|
||||
@@ -282,6 +282,11 @@ impl Pokemon {
|
||||
pub fn weight(&self) -> f32 {
|
||||
self.weight.load(Ordering::Relaxed)
|
||||
}
|
||||
/// Sets the weight of the Pokemon in kilograms.
|
||||
pub fn set_weight(&self, weight: f32) {
|
||||
self.weight.store(weight, Ordering::Relaxed)
|
||||
}
|
||||
|
||||
/// The height of the Pokemon in meters.
|
||||
pub fn height(&self) -> f32 {
|
||||
self.height.load(Ordering::Relaxed)
|
||||
@@ -685,6 +690,11 @@ impl Pokemon {
|
||||
let move_data = self.library.static_data().moves().get(move_name).unwrap();
|
||||
learned_moves[move_pos.unwrap()] = Some(Arc::new(LearnedMove::new(move_data, learn_method)));
|
||||
}
|
||||
|
||||
/// Removes the current non-volatile status from the Pokemon.
|
||||
pub fn clear_status(&self) {
|
||||
self.status_script.clear()
|
||||
}
|
||||
}
|
||||
|
||||
/// The data of the Pokemon related to being in a battle.
|
||||
@@ -780,6 +790,8 @@ pub enum DamageSource {
|
||||
MoveDamage = 0,
|
||||
/// The damage is done by something else.
|
||||
Misc = 1,
|
||||
/// The damage is done because of struggling.
|
||||
Struggle = 2,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user