Reverted changes to melee system that were added to when beam was initially in melee system.

This commit is contained in:
Sam 2020-09-05 11:41:11 -05:00
parent 46563e7008
commit a679a34a7b
7 changed files with 13 additions and 83 deletions

View File

@ -8,7 +8,6 @@ use serde::{Deserialize, Serialize};
use specs::{Component, FlaggedStorage, VecStorage};
use specs_idvs::IdvStorage;
use std::collections::VecDeque;
use vek::Vec3;
/// Data returned from character behavior fn's to Character Behavior System.
pub struct StateUpdate {
@ -150,9 +149,6 @@ pub struct Attacking {
pub applied: bool,
pub hit_count: u32,
pub knockback: f32,
pub is_melee: bool,
pub lifesteal_eff: f32,
pub look_dir: Option<Vec3<f32>>,
}
impl Component for Attacking {

View File

@ -63,9 +63,6 @@ impl CharacterBehavior for Data {
applied: false,
hit_count: 0,
knockback: self.knockback,
is_melee: true,
lifesteal_eff: 0.0,
look_dir: None,
});
update.character = CharacterState::BasicMelee(Data {

View File

@ -212,9 +212,6 @@ impl CharacterBehavior for Data {
applied: false,
hit_count: 0,
knockback: 0.0,
is_melee: true,
lifesteal_eff: 0.0,
look_dir: None,
});
>>>>>>> 8e6d0821c... Beams now have spherical hit detection.

View File

@ -80,9 +80,6 @@ impl CharacterBehavior for Data {
applied: false,
hit_count: 0,
knockback: 25.0,
is_melee: true,
lifesteal_eff: 0.0,
look_dir: None,
});
update.character = CharacterState::LeapMelee(Data {

View File

@ -153,9 +153,6 @@ impl CharacterBehavior for Data {
applied: false,
hit_count: 0,
knockback: 10.0,
is_melee: true,
lifesteal_eff: 0.0,
look_dir: None,
});
CharacterState::TripleStrike(Data {

View File

@ -151,7 +151,7 @@ impl<'a> System<'a> for Sys {
}
// Weapon gives base damage
let source = DamageSource::Melee;
let source = DamageSource::Energy;
let mut damage = Damage {
healthchange: -(beam.damage as f32),

View File

@ -88,7 +88,12 @@ impl<'a> System<'a> for Sys {
&bodies,
)
.join()
{
{
// 2D versions
let pos2 = Vec2::from(pos.0);
let pos_b2 = Vec2::<f32>::from(pos_b.0);
let ori2 = Vec2::from(*ori.0);
// Scales
let scale = scale_maybe.map_or(1.0, |s| s.0);
let scale_b = scale_b_maybe.map_or(1.0, |s| s.0);
@ -97,26 +102,10 @@ impl<'a> System<'a> for Sys {
// Check if it is a damaging hit
if entity != b
&& !stats_b.is_dead
&& ((attack.is_melee
&& cylindrical_hit_detection(
*pos,
*ori,
*pos_b,
rad_b,
scale,
attack.range,
attack.max_angle,
))
|| (!attack.is_melee
&& spherical_hit_detection(
*pos,
*pos_b,
rad_b,
scale,
attack.range,
attack.max_angle,
attack.look_dir.unwrap_or(*ori.0),
)))
// Spherical wedge shaped attack field
&& pos.0.distance_squared(pos_b.0) < (rad_b + scale * attack.range).powi(2)
&& ori2.angle_between(pos_b2 - pos2) < attack.max_angle + (rad_b / pos2.distance(pos_b2)).atan()
{
// See if entities are in the same group
let same_group = groups
@ -139,10 +128,8 @@ impl<'a> System<'a> for Sys {
// Weapon gives base damage
let source = if is_heal {
DamageSource::Healing
} else if attack.is_melee {
DamageSource::Melee
} else {
DamageSource::Energy
DamageSource::Melee
};
let healthchange = if is_heal {
attack.base_heal as f32
@ -171,16 +158,6 @@ impl<'a> System<'a> for Sys {
cause,
},
});
if attack.lifesteal_eff > 0.0 && is_damage {
server_emitter.emit(ServerEvent::Damage {
uid: *uid,
change: HealthChange {
amount: (-damage.healthchange * attack.lifesteal_eff)
as i32,
cause: HealthSource::Healing { by: Some(*uid) },
},
});
}
attack.hit_count += 1;
}
}
@ -200,35 +177,4 @@ impl<'a> System<'a> for Sys {
std::sync::atomic::Ordering::Relaxed,
);
}
}
fn cylindrical_hit_detection(
pos: Pos,
ori: Ori,
pos_b: Pos,
rad_b: f32,
scale: f32,
range: f32,
angle: f32,
) -> bool {
// 2D versions
let pos2 = Vec2::from(pos.0);
let pos_b2 = Vec2::<f32>::from(pos_b.0);
let ori2 = Vec2::from(*ori.0);
return pos.0.distance_squared(pos_b.0) < (rad_b + scale * range).powi(2)
&& ori2.angle_between(pos_b2 - pos2) < angle + (rad_b / pos2.distance(pos_b2)).atan();
}
fn spherical_hit_detection(
pos: Pos,
pos_b: Pos,
rad_b: f32,
scale: f32,
range: f32,
angle: f32,
ori: Vec3<f32>,
) -> bool {
return pos.0.distance_squared(pos_b.0) < (rad_b + scale * range).powi(2)
&& ori.angle_between(pos_b.0 - pos.0) < angle + (rad_b / pos.0.distance(pos_b.0)).atan();
}
}