From 5529ab59b1d9fe0219279eb3111732d2c7ad8a5f Mon Sep 17 00:00:00 2001 From: mramirez Date: Sun, 28 Jul 2024 22:09:51 -0400 Subject: [PATCH] Changed immunity to component and also added card configuration for hitbox damage and immunity --- assets/config/card.ron | 3 ++- src/game/actor/player.rs | 2 +- src/game/card/action.rs | 24 ++++++++++++++++++------ src/game/cleanup.rs | 1 - src/game/combat/damage.rs | 2 ++ src/game/combat/hit.rs | 32 +++++++++++++------------------- 6 files changed, 36 insertions(+), 28 deletions(-) diff --git a/assets/config/card.ron b/assets/config/card.ron index 5fe4835..94ff9d2 100644 --- a/assets/config/card.ron +++ b/assets/config/card.ron @@ -78,7 +78,8 @@ action: Step, action_modifier: CardActionModifier( remove_on_beat: 8, - immune_during_action: true, + hitbox_damage: (15.0, 0.5), + immunity: Some(0.5), ), ), /*"splits": Card( diff --git a/src/game/actor/player.rs b/src/game/actor/player.rs index 1509c66..516fc2c 100644 --- a/src/game/actor/player.rs +++ b/src/game/actor/player.rs @@ -60,7 +60,7 @@ pub fn player(key: impl Into) -> impl EntityCommand { FaceCursor, // Contact hitbox was for testing, but it's funny, so I'm leaving it in. Hitbox, - HitboxDamage(15.0), + HitboxDamage(0.0), HitboxKnockback(5.0), HurtSfx, DeathSfx, diff --git a/src/game/card/action.rs b/src/game/card/action.rs index 4b47ac0..8f6c5ee 100644 --- a/src/game/card/action.rs +++ b/src/game/card/action.rs @@ -11,7 +11,9 @@ use crate::game::card::attack::AimTowardsFacing; use crate::game::card::attack::AttackOnBeat; use crate::game::card::movement::MoveTowardsFacing; use crate::game::cleanup::RemoveOnBeat; -use crate::game::combat::hit::Hurtbox; +use crate::game::cleanup::RemoveOnTimer; +use crate::game::combat::damage::HitboxDamage; +use crate::game::combat::hit::Immune; use crate::util::prelude::*; pub(super) fn plugin(app: &mut App) { @@ -44,9 +46,19 @@ impl FromWorld for CardActionMap { modifier.remove_on_beat, )); - // TODO: Remove player check if we decide immunity should apply to all - if entity.contains::() && modifier.immune_during_action { - entity.remove::(); + // Player actor has extra benefits + if entity.contains::() { + entity.insert(RemoveOnTimer::bundle( + HitboxDamage(modifier.hitbox_damage.0), + Timer::from_seconds(modifier.hitbox_damage.1, TimerMode::Once), + )); + + if let Some(timer) = modifier.immunity { + entity.insert(RemoveOnTimer::bundle( + Immune, + Timer::from_seconds(timer, TimerMode::Once), + )); + } } }, ), @@ -112,8 +124,8 @@ pub struct CardActionModifier { /// Remove component when this timer finishes. remove_on_timer: Timer, attack: Attack, - // if true, actor is immune while performing this action - immune_during_action: bool, + immunity: Option, + hitbox_damage: (f32, f32), // damage, time heal_percent: f32, heal_flat: f32, } diff --git a/src/game/cleanup.rs b/src/game/cleanup.rs index b8eb4bd..96ac6e6 100644 --- a/src/game/cleanup.rs +++ b/src/game/cleanup.rs @@ -180,7 +180,6 @@ impl Configure for RemoveOnTimer { } } -#[allow(dead_code)] impl RemoveOnTimer { pub fn new(timer: Timer) -> Self { Self { diff --git a/src/game/combat/damage.rs b/src/game/combat/damage.rs index 0fca9d1..dd701d2 100644 --- a/src/game/combat/damage.rs +++ b/src/game/combat/damage.rs @@ -1,5 +1,6 @@ use bevy::prelude::*; +use crate::game::cleanup::RemoveOnTimer; use crate::game::combat::hit::OnHit; use crate::util::prelude::*; @@ -18,6 +19,7 @@ impl Configure for HitboxDamage { fn configure(app: &mut App) { app.register_type::(); app.observe(apply_hitbox_damage); + app.configure::>(); } } diff --git a/src/game/combat/hit.rs b/src/game/combat/hit.rs index ce42250..cc0571d 100644 --- a/src/game/combat/hit.rs +++ b/src/game/combat/hit.rs @@ -3,12 +3,12 @@ use bevy::prelude::*; use bevy_kira_audio::prelude::*; use crate::core::UpdateSet; -use crate::game::audio::music::on_full_beat; +use crate::game::cleanup::RemoveOnTimer; use crate::screen::playing::PlayingAssets; use crate::util::prelude::*; pub(super) fn plugin(app: &mut App) { - app.configure::<(Hitbox, Hurtbox, OnHit, HurtSfx)>(); + app.configure::<(Hitbox, Hurtbox, OnHit, HurtSfx, Immune)>(); } #[derive(Component, Reflect)] @@ -23,28 +23,22 @@ impl Configure for Hitbox { #[derive(Component, Reflect)] #[reflect(Component)] -pub struct Hurtbox; +pub struct Immune; -impl Configure for Hurtbox { +impl Configure for Immune { fn configure(app: &mut App) { app.register_type::(); - - app.add_systems( - Update, - readd_hurtbox - .in_set(UpdateSet::SyncEarly) - .run_if(on_full_beat(2)), - ); + app.configure::>(); } } -fn readd_hurtbox( - mut commands: Commands, - hitbox_query: Query, Without)>, -) { - for entity in &hitbox_query { - let mut entity = c!(commands.get_entity(entity)); - entity.insert(Hurtbox); +#[derive(Component, Reflect)] +#[reflect(Component)] +pub struct Hurtbox; + +impl Configure for Hurtbox { + fn configure(app: &mut App) { + app.register_type::(); } } @@ -62,7 +56,7 @@ fn trigger_hit( mut commands: Commands, mut collision_events: EventReader, hitbox_query: Query<(), With>, - hurtbox_query: Query<(), With>, + hurtbox_query: Query<(), (With, Without)>, ) { for &CollisionStarted(a, b) in collision_events.read() { for (a, b) in [(a, b), (b, a)] {