Skip to content

Commit

Permalink
Refine new hitreg pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
haihala committed Dec 29, 2023
1 parent 5de2cf4 commit 8c4ff9a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 20 deletions.
57 changes: 38 additions & 19 deletions client/lib/src/damage/hitreg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
use super::{hitboxes::ProjectileMarker, Combo, Defense, HitTracker, HitboxSpawner};

#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub(super) enum ContactType {
pub(super) enum ConnectionType {
Strike,
Block,
Parry,
Expand All @@ -31,13 +31,13 @@ pub(super) enum ContactType {
}

#[derive(Debug, PartialEq, Clone)]
pub(super) struct Contact {
pub(super) struct AttackConnection {
attacker: Entity,
defender: Entity,
hitbox: Entity,
overlap: Area,
attack: Attack,
contact_type: ContactType,
contact_type: ConnectionType,
}

#[derive(WorldQuery)]
Expand Down Expand Up @@ -135,7 +135,7 @@ pub(super) fn detect_hits(
players: Res<Players>,
hurtboxes: Query<(&Hurtbox, &Owner)>,
defenders: Query<(&Transform, &PlayerState, &InputParser)>,
) -> Vec<Contact> {
) -> Vec<AttackConnection> {
hitboxes
.iter_mut()
.filter_map(
Expand Down Expand Up @@ -191,22 +191,25 @@ pub(super) fn detect_hits(
handle_blocking(height, parser.get_relative_stick_position());

if parrying {
(Some("Parry!".into()), ContactType::Parry)
(Some("Parry!".into()), ConnectionType::Parry)
} else if blocked && state.can_block() {
(Some(reason), ContactType::Block)
(Some(reason), ConnectionType::Block)
} else {
(None, ContactType::Strike)
(None, ConnectionType::Strike)
}
}
BlockType::Grab => {
if combo.is_some() {
(Some("Can't grab from stun".into()), ContactType::Stunlock)
(
Some("Can't grab from stun".into()),
ConnectionType::Stunlock,
)
} else if yomi_teched(parser)
&& (state.can_block() && !state.action_in_progress())
{
(Some("Teched".into()), ContactType::Tech)
(Some("Teched".into()), ConnectionType::Tech)
} else {
(None, ContactType::Throw)
(None, ConnectionType::Throw)
}
}
};
Expand All @@ -220,7 +223,7 @@ pub(super) fn detect_hits(
notifications.add(attacking_player, "Meaty!".to_owned());
}

Some(Contact {
Some(AttackConnection {
defender,
attacker,
hitbox: hitbox_entity,
Expand All @@ -234,7 +237,7 @@ pub(super) fn detect_hits(
}

pub(super) fn apply_connections(
In(hits): In<Vec<Contact>>,
In(hits): In<Vec<AttackConnection>>,
mut commands: Commands,
mut notifications: ResMut<Notifications>,
combo: Option<Res<Combo>>,
Expand All @@ -245,9 +248,11 @@ pub(super) fn apply_connections(
) {
if hits.len() == 2 {
// TODO: Handle strike and throw clash
// Ideally, one should be strike invincible while throw animation is active
// In a throw vs strike situation, the winner ought to be consistent.
if hits
.iter()
.all(|hit| hit.contact_type == ContactType::Throw)
.all(|hit| hit.contact_type == ConnectionType::Throw)
{
// Two grabs can't hit on the same frame
for mut player in &mut players {
Expand All @@ -256,6 +261,20 @@ pub(super) fn apply_connections(
.add_impulse(player.facing.mirror_vec2(Vec2::X * -10.0));
notifications.add(*player.player, "Throw clash".to_owned());
}

particles.spawn(ParticleRequest {
effect: VisualEffect::Clash,
// TODO: This can be refined more
position: hits
.iter()
.map(|hit| hit.overlap.center())
.reduce(|a, b| a + b)
.unwrap()
.extend(0.0)
* 0.5,
});

sounds.play(SoundEffect::Whoosh); // TODO change sound effect
}
return;
}
Expand All @@ -270,7 +289,7 @@ pub(super) fn apply_connections(
}

let (mut attacker_actions, mut defender_actions, sound, particle) = match hit.contact_type {
ContactType::Strike | ContactType::Throw => {
ConnectionType::Strike | ConnectionType::Throw => {
// Handle blocking and state transitions here
attacker.state.register_hit();
defender.defense.reset();
Expand All @@ -281,8 +300,8 @@ pub(super) fn apply_connections(
VisualEffect::Hit,
)
}
ContactType::Block => {
attacker.state.register_hit(); // TODO: Specify it was blocked
ConnectionType::Block => {
attacker.state.register_hit();
defender.defense.bump_streak(clock.frame);
defender
.properties
Expand All @@ -307,7 +326,7 @@ pub(super) fn apply_connections(
VisualEffect::Block,
)
}
ContactType::Parry => (
ConnectionType::Parry => (
vec![],
vec![
ActionEvent::ModifyResource(ResourceType::Meter, GI_PARRY_METER_GAIN),
Expand All @@ -316,9 +335,9 @@ pub(super) fn apply_connections(
SoundEffect::Clash,
VisualEffect::Clash,
),
ContactType::Tech | ContactType::Stunlock => (
ConnectionType::Tech | ConnectionType::Stunlock => (
vec![Movement::impulse(Vec2::X * -4.0).into()],
vec![],
vec![Movement::impulse(Vec2::X * -8.0).into()],
SoundEffect::Clash,
VisualEffect::Clash,
),
Expand Down
2 changes: 1 addition & 1 deletion client/lib/src/player/move_activation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ pub(super) fn automatic_activation(
_ => {
// This may happen if follow up and grab land on the same frame
velocity.add_impulse(facing.mirror_vec2(Vec2::X * -10.0));
notifications.add(*player, "Throw clash".to_owned());
notifications.add(*player, "Twin starters".to_owned());
}
}
}
Expand Down

0 comments on commit 8c4ff9a

Please sign in to comment.