add coranth moving towards target and post-attack event
This commit is contained in:
parent
e9790f156d
commit
1f8ecf9a9e
15 changed files with 249 additions and 58 deletions
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
use std::time::Duration;
|
||||
|
||||
use avian3d::prelude::*;
|
||||
use bevy::prelude::*;
|
||||
use state::GameSystemSet;
|
||||
|
||||
|
|
@ -16,14 +17,25 @@ impl Plugin for CombatPlugin {
|
|||
.add_systems(
|
||||
FixedUpdate,
|
||||
tick_invulnerability.in_set(GameSystemSet::StatusEffects),
|
||||
);
|
||||
)
|
||||
.register_type::<Team>();
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component, Clone, Debug, PartialEq, Eq)]
|
||||
#[derive(PhysicsLayer, Default, Component, Clone, Debug, PartialEq, Eq, Reflect)]
|
||||
pub enum Team {
|
||||
#[default]
|
||||
Core,
|
||||
Immune,
|
||||
Inhabitant,
|
||||
}
|
||||
|
||||
impl Team {
|
||||
pub fn collision_layers(&self) -> CollisionLayers {
|
||||
match self {
|
||||
Team::Core => CollisionLayers::new(Team::Core, LayerMask::ALL),
|
||||
Team::Inhabitant => CollisionLayers::new(Team::Inhabitant, LayerMask::ALL),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Event, Debug, Default)]
|
||||
|
|
@ -33,6 +45,13 @@ pub struct Attacked {
|
|||
pub skip_invulnerability: bool,
|
||||
}
|
||||
|
||||
#[derive(Event, Debug)]
|
||||
pub struct GaveDamage {
|
||||
pub target: Entity,
|
||||
pub amount: f32,
|
||||
pub skip_invulnerability: bool,
|
||||
}
|
||||
|
||||
#[derive(Event, Debug)]
|
||||
pub struct Died {
|
||||
pub slayer: Option<Entity>,
|
||||
|
|
@ -133,12 +152,12 @@ fn on_attack(
|
|||
&& 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);
|
||||
let old_health = health.current;
|
||||
health.current = (old_health - damage_taken).max(0.0);
|
||||
info!(
|
||||
"{:?} attacked {:?} for {} damage. New health = {}",
|
||||
trigger
|
||||
|
|
@ -150,6 +169,16 @@ fn on_attack(
|
|||
damage_taken,
|
||||
health.current
|
||||
);
|
||||
if let Some(attacker) = trigger.event().attacker {
|
||||
commands.trigger_targets(
|
||||
GaveDamage {
|
||||
target: trigger.target(),
|
||||
amount: old_health - health.current,
|
||||
skip_invulnerability: trigger.event().skip_invulnerability,
|
||||
},
|
||||
attacker,
|
||||
);
|
||||
}
|
||||
if let Ok(mut ec) = commands.get_entity(trigger.target()) {
|
||||
if health.current <= 0. {
|
||||
ec.trigger(Died {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue