add impaler scaffolding and teams
This commit is contained in:
parent
af45237701
commit
6659fe8e5a
12 changed files with 151 additions and 21 deletions
|
|
@ -12,6 +12,12 @@ impl Plugin for CombatPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Component, Clone, Debug, PartialEq, Eq)]
|
||||
pub enum Team {
|
||||
Core,
|
||||
Immune,
|
||||
}
|
||||
|
||||
#[derive(Event, Debug)]
|
||||
pub struct Attacked {
|
||||
pub attacker: Option<Entity>,
|
||||
|
|
@ -70,13 +76,21 @@ impl Defense {
|
|||
fn on_attack(
|
||||
trigger: Trigger<Attacked>,
|
||||
mut commands: Commands,
|
||||
mut query: Query<(&mut Health, Option<&Defense>)>,
|
||||
attacker_query: Query<&Team>,
|
||||
mut attacked_query: Query<(&mut Health, Option<&Defense>, Option<&Team>)>,
|
||||
names: Query<&Name>,
|
||||
) {
|
||||
let Ok((mut health, opt_defense)) = query.get_mut(trigger.target()) else {
|
||||
let Ok((mut health, opt_defense, opt_team)) = attacked_query.get_mut(trigger.target()) else {
|
||||
warn!("tried to attack entity without health");
|
||||
return;
|
||||
};
|
||||
if let Some(Ok(attacker_team)) = trigger.event().attacker.map(|a| attacker_query.get(a))
|
||||
&& let Some(team) = opt_team
|
||||
&& team == attacker_team
|
||||
{
|
||||
info!("avoiding friendly fire!");
|
||||
return;
|
||||
}
|
||||
let defense = opt_defense.cloned().unwrap_or_default();
|
||||
let damage_taken = defense.calc_damage(trigger.event().amount);
|
||||
health.current = (health.current - damage_taken).max(0.0);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue