Easier swimming, better damage calculation for explosions

This commit is contained in:
timokoesters
2020-03-23 12:50:08 +01:00
parent fb16106960
commit 5194cef03a
8 changed files with 14 additions and 6 deletions

View File

@ -132,6 +132,7 @@ impl Component for CharacterState {
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Attacking { pub struct Attacking {
pub base_damage: u32, pub base_damage: u32,
pub range: f32,
pub max_angle: f32, pub max_angle: f32,
pub applied: bool, pub applied: bool,
pub hit_count: u32, pub hit_count: u32,

View File

@ -44,6 +44,7 @@ impl CharacterBehavior for Data {
// Hit attempt // Hit attempt
data.updater.insert(data.entity, Attacking { data.updater.insert(data.entity, Attacking {
base_damage: self.base_damage, base_damage: self.base_damage,
range: self.range,
max_angle: self.max_angle.to_radians(), max_angle: self.max_angle.to_radians(),
applied: false, applied: false,
hit_count: 0, hit_count: 0,

View File

@ -1,5 +1,6 @@
use crate::{ use crate::{
comp::{Attacking, CharacterState, EnergySource, StateUpdate}, comp::{Attacking, CharacterState, EnergySource, StateUpdate},
states::utils::*,
sys::character_behavior::*, sys::character_behavior::*,
util::safe_slerp, util::safe_slerp,
}; };
@ -53,6 +54,7 @@ impl CharacterBehavior for Data {
// Hit attempt // Hit attempt
data.updater.insert(data.entity, Attacking { data.updater.insert(data.entity, Attacking {
base_damage: self.base_damage, base_damage: self.base_damage,
range: 3.5,
max_angle: 180_f32.to_radians(), max_angle: 180_f32.to_radians(),
applied: false, applied: false,
hit_count: 0, hit_count: 0,
@ -67,6 +69,7 @@ impl CharacterBehavior for Data {
}); });
} else if self.recover_duration != Duration::default() { } else if self.recover_duration != Duration::default() {
// Recovery // Recovery
handle_move(data, &mut update);
update.character = CharacterState::DashMelee(Data { update.character = CharacterState::DashMelee(Data {
buildup_duration: self.buildup_duration, buildup_duration: self.buildup_duration,
recover_duration: self recover_duration: self

View File

@ -53,6 +53,7 @@ impl CharacterBehavior for Data {
// Swing hits // Swing hits
data.updater.insert(data.entity, Attacking { data.updater.insert(data.entity, Attacking {
base_damage: self.base_damage * (self.stage as u32 + 1), base_damage: self.base_damage * (self.stage as u32 + 1),
range: 3.5,
max_angle: 75_f32.to_radians(), max_angle: 75_f32.to_radians(),
applied: false, applied: false,
hit_count: 0, hit_count: 0,

View File

@ -92,6 +92,7 @@ impl CharacterBehavior for Data {
// Try to deal damage in second half of stage // Try to deal damage in second half of stage
data.updater.insert(data.entity, Attacking { data.updater.insert(data.entity, Attacking {
base_damage: dmg, base_damage: dmg,
range: 3.5,
max_angle: 180_f32.to_radians(), max_angle: 180_f32.to_radians(),
applied: false, applied: false,
hit_count: 0, hit_count: 0,

View File

@ -82,9 +82,8 @@ fn swim_move(data: &JoinData, update: &mut StateUpdate) {
handle_orientation(data, update, if data.physics.on_ground { 9.0 } else { 2.0 }); handle_orientation(data, update, if data.physics.on_ground { 9.0 } else { 2.0 });
// Force players to pulse jump button to swim up // Swim
if data.inputs.jump.is_pressed() && !data.inputs.jump.is_long_press(Duration::from_millis(600)) if data.inputs.jump.is_pressed() {
{
update.vel.0.z = update.vel.0.z =
(update.vel.0.z + data.dt.0 * GRAVITY * 2.25).min(BASE_HUMANOID_WATER_SPEED); (update.vel.0.z + data.dt.0 * GRAVITY * 2.25).min(BASE_HUMANOID_WATER_SPEED);
} }

View File

@ -97,7 +97,7 @@ impl<'a> System<'a> for Sys {
if entity != b if entity != b
&& !stats_b.is_dead && !stats_b.is_dead
// Spherical wedge shaped attack field // Spherical wedge shaped attack field
&& pos.0.distance_squared(pos_b.0) < (rad_b + scale * ATTACK_RANGE).powi(2) && 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() && ori2.angle_between(pos_b2 - pos2) < attack.max_angle + (rad_b / pos2.distance(pos_b2)).atan()
{ {
// Weapon gives base damage // Weapon gives base damage

View File

@ -194,6 +194,7 @@ pub fn handle_respawn(server: &Server, entity: EcsEntity) {
pub fn handle_explosion(server: &Server, pos: Vec3<f32>, power: f32, owner: Option<Uid>) { pub fn handle_explosion(server: &Server, pos: Vec3<f32>, power: f32, owner: Option<Uid>) {
// Go through all other entities // Go through all other entities
let hit_range = 2.0 * power;
let ecs = &server.state.ecs(); let ecs = &server.state.ecs();
for (b, uid_b, pos_b, ori_b, character_b, stats_b) in ( for (b, uid_b, pos_b, ori_b, character_b, stats_b) in (
&ecs.entities(), &ecs.entities(),
@ -205,14 +206,15 @@ pub fn handle_explosion(server: &Server, pos: Vec3<f32>, power: f32, owner: Opti
) )
.join() .join()
{ {
let distance_squared = pos.distance_squared(pos_b.0);
// Check if it is a hit // Check if it is a hit
if !stats_b.is_dead if !stats_b.is_dead
// Spherical wedge shaped attack field // Spherical wedge shaped attack field
// RADIUS // RADIUS
&& pos.distance_squared(pos_b.0) < 10_f32.powi(2) && distance_squared < hit_range.powi(2)
{ {
// Weapon gives base damage // Weapon gives base damage
let mut dmg = power as u32 * 2; let mut dmg = ((1.0 - distance_squared / hit_range.powi(2)) * power * 5.0) as u32;
if rand::random() { if rand::random() {
dmg += 1; dmg += 1;