Small fixes

This commit is contained in:
Socksonme 2022-07-12 21:01:47 +00:00 committed by Marcel
parent 7bd4686187
commit 3f0f1c423c
4 changed files with 49 additions and 44 deletions

View File

@ -1,4 +1,4 @@
use crate::{combat::DamageContributor, comp, uid::Uid};
use crate::{combat::DamageContributor, comp, uid::Uid, DamageSource};
use comp::{beam, item::Reagent, poise::PoiseState, skillset::SkillGroupKind, UtteranceKind};
use hashbrown::HashSet;
use serde::{Deserialize, Serialize};
@ -10,6 +10,7 @@ pub struct HealthChangeInfo {
pub crit: bool,
pub target: Uid,
pub by: Option<DamageContributor>,
pub cause: Option<DamageSource>,
pub instance: u64,
}

View File

@ -81,6 +81,7 @@ pub fn handle_health_change(server: &Server, entity: EcsEntity, change: HealthCh
amount: change.amount,
by: change.by,
target: *uid,
cause: change.cause,
crit: change.crit,
instance: change.instance,
},
@ -571,9 +572,9 @@ pub fn handle_land_on_ground(server: &Server, entity: EcsEntity, vel: Vec3<f32>)
let stats = ecs.read_storage::<Stats>();
let time = ecs.read_resource::<Time>();
let msm = ecs.read_resource::<MaterialStatManifest>();
let server_eventbus = ecs.read_resource::<EventBus<ServerEvent>>();
// Handle health change
if let Some(mut health) = ecs.write_storage::<comp::Health>().get_mut(entity) {
// Emit health change
let damage = Damage {
source: DamageSource::Falling,
kind: DamageKind::Crushing,
@ -594,13 +595,10 @@ pub fn handle_land_on_ground(server: &Server, entity: EcsEntity, vel: Vec3<f32>)
*time,
rand::random(),
);
health.change_by(change);
let server_eventbus = ecs.read_resource::<EventBus<ServerEvent>>();
server_eventbus.emit_now(ServerEvent::HealthChange { entity, change });
}
// Handle poise change
if let Some(mut poise) = ecs.write_storage::<comp::Poise>().get_mut(entity) {
server_eventbus.emit_now(ServerEvent::HealthChange { entity, change });
// Emit poise change
let poise_damage = -(mass.0 * vel.magnitude_squared() / 1500.0);
let poise_change =
Poise::apply_poise_reduction(poise_damage, inventories.get(entity), &msm);
@ -611,8 +609,10 @@ pub fn handle_land_on_ground(server: &Server, entity: EcsEntity, vel: Vec3<f32>)
cause: None,
time: *time,
};
poise.change(poise_change);
}
server_eventbus.emit_now(ServerEvent::PoiseChange {
entity,
change: poise_change,
});
}
}

View File

@ -103,6 +103,7 @@ use common::{
outcome::Outcome,
terrain::{BlockKind, TerrainChunk},
uid::Uid,
DamageSource,
};
use common_state::State;
use event_mapper::SfxEventMapper;
@ -527,8 +528,10 @@ impl SfxMgr {
);
},
Outcome::HealthChange { pos, info, .. } => {
// Don't emit sound effects from positive damage (healing)
if info.amount < Health::HEALTH_EPSILON {
// Ignore positive damage (healing) and buffs for now
if info.amount < Health::HEALTH_EPSILON
&& !matches!(info.cause, Some(DamageSource::Buff(_)))
{
let sfx_trigger_item = triggers.get_key_value(&SfxEvent::Damage);
audio.emit_sfx(sfx_trigger_item, *pos, Some(1.5), underwater);
}

View File

@ -2192,7 +2192,8 @@ impl Hud {
let font_col = font_col(font_size, crit);
// Timer sets the widget offset
let y = if crit {
ui_widgets.win_h * (floater.rand as f64 % 0.1) + ui_widgets.win_h * 0.05
ui_widgets.win_h * (floater.rand as f64 % 0.075)
+ ui_widgets.win_h * 0.05
} else {
(floater.timer as f64 / crate::ecs::sys::floater::HP_SHOWTIME as f64
* number_speed)