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
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -9,7 +9,7 @@ use atomig::Atomic;
|
||||
use parking_lot::RwLock;
|
||||
|
||||
use crate::dynamic_data::choices::TurnChoice;
|
||||
use crate::dynamic_data::event_hooks::{Event, EventHook};
|
||||
use crate::dynamic_data::event_hooks::{EventData, EventHook};
|
||||
use crate::dynamic_data::models::battle_party::BattleParty;
|
||||
use crate::dynamic_data::models::battle_random::BattleRandom;
|
||||
use crate::dynamic_data::models::battle_side::BattleSide;
|
||||
@@ -333,7 +333,7 @@ impl Battle {
|
||||
}
|
||||
|
||||
self.data.current_turn_queue.write().take();
|
||||
self.data.event_hook.trigger(Event::EndTurn);
|
||||
self.data.event_hook.trigger(EventData::EndTurn, Default::default());
|
||||
let end_time = chrono::Utc::now();
|
||||
let time = end_time - start_time;
|
||||
match time.num_nanoseconds() {
|
||||
|
||||
@@ -8,7 +8,7 @@ use parking_lot::lock_api::RwLockReadGuard;
|
||||
use parking_lot::{RawRwLock, RwLock};
|
||||
|
||||
use crate::dynamic_data::choices::TurnChoice;
|
||||
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::pokemon::Pokemon;
|
||||
use crate::dynamic_data::script_handling::{ScriptSource, ScriptSourceData, ScriptWrapper};
|
||||
@@ -231,18 +231,24 @@ impl BattleSide {
|
||||
pokemon.mark_opponent_as_seen(opponent.weak());
|
||||
}
|
||||
}
|
||||
battle.event_hook().trigger(Event::Switch {
|
||||
side_index: self.data.index,
|
||||
index,
|
||||
pokemon: Some(pokemon.clone()),
|
||||
});
|
||||
battle.event_hook().trigger(
|
||||
EventData::Switch {
|
||||
side_index: self.data.index,
|
||||
index,
|
||||
pokemon: Some(pokemon.clone()),
|
||||
},
|
||||
Default::default(),
|
||||
);
|
||||
script_hook!(on_switch_in, pokemon, pokemon);
|
||||
} else {
|
||||
self.battle()?.event_hook().trigger(Event::Switch {
|
||||
side_index: self.data.index,
|
||||
index,
|
||||
pokemon: None,
|
||||
});
|
||||
self.battle()?.event_hook().trigger(
|
||||
EventData::Switch {
|
||||
side_index: self.data.index,
|
||||
index,
|
||||
pokemon: None,
|
||||
},
|
||||
Default::default(),
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -339,11 +345,14 @@ impl BattleSide {
|
||||
}
|
||||
|
||||
data.pokemon.write().swap(a as usize, b as usize);
|
||||
self.battle()?.event_hook().trigger(Event::Swap {
|
||||
side_index: data.index,
|
||||
index_a: a,
|
||||
index_b: b,
|
||||
});
|
||||
self.battle()?.event_hook().trigger(
|
||||
EventData::Swap {
|
||||
side_index: data.index,
|
||||
index_a: a,
|
||||
index_b: b,
|
||||
},
|
||||
Default::default(),
|
||||
);
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user