Implements event batch id to events to display multiple events at the same time
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-06-30 11:32:00 +02:00
parent 0163c7a105
commit bc9b3ed964
11 changed files with 217 additions and 106 deletions

View File

@@ -9,12 +9,13 @@ use parking_lot::lock_api::RwLockReadGuard;
use parking_lot::{RawRwLock, RwLock};
use crate::defines::{LevelInt, MAX_MOVES};
use crate::dynamic_data::event_hooks::Event;
use crate::dynamic_data::event_hooks::EventData;
use crate::dynamic_data::models::battle::Battle;
use crate::dynamic_data::models::learned_move::{LearnedMove, MoveLearnMethod};
use crate::dynamic_data::script_handling::{ScriptSource, ScriptSourceData, ScriptWrapper};
use crate::dynamic_data::{
DynamicLibrary, Script, ScriptCategory, ScriptContainer, ScriptSet, VolatileScriptsOwner, WeakBattleReference,
DynamicLibrary, EventBatchId, Script, ScriptCategory, ScriptContainer, ScriptSet, VolatileScriptsOwner,
WeakBattleReference,
};
use crate::static_data::AbilityIndex;
use crate::static_data::Form;
@@ -396,12 +397,15 @@ impl Pokemon {
if changed {
if let Some(battle) = self.get_battle() {
let new_value = self.stat_boost(stat);
battle.event_hook().trigger(Event::StatBoostChange {
user: self,
stat,
old_value,
new_value,
})
battle.event_hook().trigger(
EventData::StatBoostChange {
user: self.clone(),
stat,
old_value,
new_value,
},
Default::default(),
)
}
self.recalculate_boosted_stats()?;
}
@@ -531,11 +535,14 @@ impl Pokemon {
let r = self.data.battle_data.read();
if let Some(battle_data) = &r.deref() {
if let Some(battle) = battle_data.battle() {
battle.event_hook().trigger(Event::SpeciesChange {
pokemon: self,
species,
form,
})
battle.event_hook().trigger(
EventData::SpeciesChange {
pokemon: self.clone(),
species,
form,
},
Default::default(),
)
}
}
Ok(())
@@ -597,10 +604,13 @@ impl Pokemon {
let r = self.data.battle_data.read();
if let Some(battle_data) = r.deref() {
if let Some(battle) = battle_data.battle() {
battle.event_hook().trigger(Event::FormChange {
pokemon: self,
form: form.clone(),
})
battle.event_hook().trigger(
EventData::FormChange {
pokemon: self.clone(),
form: form.clone(),
},
Default::default(),
)
}
};
Ok(())
@@ -679,7 +689,7 @@ impl Pokemon {
}
/// Damages the Pokemon by a certain amount of damage, from a damage source.
pub fn damage(&self, mut damage: u32, source: DamageSource) -> Result<()> {
pub fn damage(&self, mut damage: u32, source: DamageSource, evt_batch_id: EventBatchId) -> Result<()> {
if damage > self.current_health() {
damage = self.current_health();
}
@@ -689,12 +699,15 @@ impl Pokemon {
let new_health = self.current_health() - damage;
if let Some(battle_data) = &self.data.battle_data.read().deref() {
if let Some(battle) = battle_data.battle() {
battle.event_hook().trigger(Event::Damage {
pokemon: self,
source,
original_health: self.current_health(),
new_health,
});
battle.event_hook().trigger(
EventData::Damage {
pokemon: self.clone(),
source,
original_health: self.current_health(),
new_health,
},
evt_batch_id,
);
}
}
if self
@@ -719,7 +732,9 @@ impl Pokemon {
let r = self.data.battle_data.read();
if let Some(battle_data) = r.deref() {
if let Some(battle) = battle_data.battle() {
battle.event_hook().trigger(Event::Faint { pokemon: self });
battle
.event_hook()
.trigger(EventData::Faint { pokemon: self.clone() }, Default::default());
script_hook!(on_faint, self, self, source);
script_hook!(on_remove, self,);
@@ -752,11 +767,14 @@ impl Pokemon {
let new_health = self.current_health() + max_amount;
if let Some(battle_data) = &self.data.battle_data.read().deref() {
if let Some(battle) = battle_data.battle() {
battle.event_hook().trigger(Event::Heal {
pokemon: self,
original_health: self.current_health(),
new_health,
});
battle.event_hook().trigger(
EventData::Heal {
pokemon: self.clone(),
original_health: self.current_health(),
new_health,
},
Default::default(),
);
}
}
self.data.current_health.store(new_health, Ordering::SeqCst);