54 lines
1.3 KiB
Rust
54 lines
1.3 KiB
Rust
//bevy system signatures often violate these rules
|
|
#![allow(clippy::type_complexity)]
|
|
#![allow(clippy::too_many_arguments)]
|
|
|
|
use avian3d::prelude::*;
|
|
use bevy::prelude::*;
|
|
use combat::Attacked;
|
|
use state::GameSystemSet;
|
|
|
|
pub struct CombatDamagersPlugin;
|
|
|
|
impl Plugin for CombatDamagersPlugin {
|
|
fn build(&self, app: &mut App) {
|
|
app.add_systems(
|
|
FixedUpdate,
|
|
deal_contact_damage.in_set(GameSystemSet::DealDamage),
|
|
);
|
|
}
|
|
}
|
|
|
|
#[derive(Component)]
|
|
#[require(CollisionEventsEnabled)]
|
|
pub struct ContactDamage {
|
|
pub amount: f32,
|
|
}
|
|
|
|
fn deal_contact_damage(
|
|
mut reader: EventReader<CollisionStarted>,
|
|
query: Query<&ContactDamage>,
|
|
mut commands: Commands,
|
|
) {
|
|
for event in reader.read() {
|
|
if let Ok(contact) = query.get(event.0) {
|
|
commands.trigger_targets(
|
|
Attacked {
|
|
attacker: Some(event.0),
|
|
amount: contact.amount,
|
|
..default()
|
|
},
|
|
event.1,
|
|
);
|
|
}
|
|
if let Ok(contact) = query.get(event.1) {
|
|
commands.trigger_targets(
|
|
Attacked {
|
|
attacker: Some(event.1),
|
|
amount: contact.amount,
|
|
..default()
|
|
},
|
|
event.0,
|
|
);
|
|
}
|
|
}
|
|
}
|