Addressed comments.

This commit is contained in:
Sam 2020-11-01 11:15:46 -06:00
parent c48c022f7e
commit 87bff41a66
8 changed files with 40 additions and 50 deletions

View File

@ -120,10 +120,10 @@ impl Component for Health {
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
pub struct Dying {
pub struct Dead {
pub cause: HealthSource,
}
impl Component for Dying {
impl Component for Dead {
type Storage = IdvStorage<Self>;
}

View File

@ -1,4 +1,4 @@
use crate::combat::Damages;
use crate::{combat::Damages, effect::Effect};
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
@ -12,4 +12,5 @@ pub struct Explosion {
pub enum RadiusEffect {
Damages(Damages),
TerrainDestruction(f32),
EntityEffect(Effect),
}

View File

@ -10,6 +10,7 @@ use chrono::{NaiveTime, Timelike};
use common::{
cmd::{ChatCommand, CHAT_COMMANDS, CHAT_SHORTCUTS},
comp::{self, ChatType, Item, LightEmitter, WaypointArea},
effect::Effect,
event::{EventBus, ServerEvent},
msg::{DisconnectReason, Notification, PlayerListUpdate, ServerGeneral},
npc::{self, get_npc_name},
@ -18,7 +19,7 @@ use common::{
terrain::{Block, BlockKind, SpriteKind, TerrainChunkSize},
util::Dir,
vol::RectVolSize,
Damage, DamageSource, Damages, Explosion, LoadoutBuilder, RadiusEffect,
Explosion, LoadoutBuilder, RadiusEffect,
};
use rand::Rng;
use specs::{Builder, Entity as EcsEntity, Join, WorldExt};
@ -1157,16 +1158,10 @@ fn handle_explosion(
pos: pos.0,
explosion: Explosion {
effects: vec![
RadiusEffect::Damages(Damages::new(
Some(Damage {
source: DamageSource::Explosion,
value: 100.0 * power,
}),
Some(Damage {
source: DamageSource::Explosion,
value: 100.0 * power,
}),
)),
RadiusEffect::EntityEffect(Effect::Health(comp::HealthChange {
amount: (-100.0 * power) as i32,
cause: comp::HealthSource::Explosion { owner: None },
})),
RadiusEffect::TerrainDestruction(power),
],
radius: 3.0 * power,

View File

@ -516,15 +516,10 @@ pub fn handle_explosion(
// Add an outcome
// Uses radius as outcome power, makes negative if explosion has healing effect
#[allow(clippy::blocks_in_if_conditions)]
let outcome_power = explosion.radius
* if explosion.effects.iter().any(|e| {
if let RadiusEffect::Damages(d) = e {
d.contains_damage(DamageSource::Healing)
} else {
false
}
}) {
* if explosion.effects.iter().any(
|e| matches!(e, RadiusEffect::Damages(d) if d.contains_damage(DamageSource::Healing)),
) {
-1.0
} else {
1.0
@ -672,6 +667,16 @@ pub fn handle_explosion(
.cast();
}
},
RadiusEffect::EntityEffect(effect) => {
for (entity, pos_entity) in
(&ecs.entities(), &ecs.read_storage::<comp::Pos>()).join()
{
let distance_squared = pos.distance_squared(pos_entity.0);
if distance_squared < explosion.radius.powi(2) {
server.state().apply_effect(entity, effect);
}
}
},
}
}
}

View File

@ -20,7 +20,7 @@ use vek::*;
pub trait StateExt {
/// Updates a component associated with the entity based on the `Effect`
fn apply_effect(&mut self, entity: EcsEntity, effect: Effect);
fn apply_effect(&self, entity: EcsEntity, effect: Effect);
/// Build a non-player character
fn create_npc(
&mut self,
@ -71,7 +71,7 @@ pub trait StateExt {
}
impl StateExt for State {
fn apply_effect(&mut self, entity: EcsEntity, effect: Effect) {
fn apply_effect(&self, entity: EcsEntity, effect: Effect) {
match effect {
Effect::Health(change) => {
self.ecs()

View File

@ -1,9 +1,10 @@
use common::{
comp::{HealthSource, Object, PhysicsState, Pos, Vel},
comp::{HealthChange, HealthSource, Object, PhysicsState, Pos, Vel},
effect::Effect,
event::{EventBus, ServerEvent},
span,
state::DeltaTime,
Damage, DamageSource, Damages, Explosion, RadiusEffect,
Explosion, RadiusEffect,
};
use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage};
@ -49,16 +50,10 @@ impl<'a> System<'a> for Sys {
pos: pos.0,
explosion: Explosion {
effects: vec![
RadiusEffect::Damages(Damages::new(
Some(Damage {
source: DamageSource::Explosion,
value: 500.0,
}),
Some(Damage {
source: DamageSource::Explosion,
value: 500.0,
}),
)),
RadiusEffect::EntityEffect(Effect::Health(HealthChange {
amount: -500,
cause: HealthSource::Explosion { owner: *owner },
})),
RadiusEffect::TerrainDestruction(4.0),
],
radius: 12.0,
@ -79,16 +74,10 @@ impl<'a> System<'a> for Sys {
pos: pos.0,
explosion: Explosion {
effects: vec![
RadiusEffect::Damages(Damages::new(
Some(Damage {
source: DamageSource::Explosion,
value: 50.0,
}),
Some(Damage {
source: DamageSource::Explosion,
value: 50.0,
}),
)),
RadiusEffect::EntityEffect(Effect::Health(HealthChange {
amount: -50,
cause: HealthSource::Explosion { owner: *owner },
})),
RadiusEffect::TerrainDestruction(4.0),
],
radius: 12.0,

View File

@ -1195,7 +1195,7 @@ impl Hud {
let display_overhead_info =
(info.target_entity.map_or(false, |e| e == entity)
|| info.selected_entity.map_or(false, |s| s.0 == entity)
|| overhead::show_healthbar(health)
|| overhead::should_show_healthbar(health)
|| in_group)
&& dist_sqr
< (if in_group {

View File

@ -64,7 +64,7 @@ pub struct Info<'a> {
}
/// Determines whether to show the healthbar
pub fn show_healthbar(health: &Health) -> bool { health.current() != health.maximum() }
pub fn should_show_healthbar(health: &Health) -> bool { health.current() != health.maximum() }
/// ui widget containing everything that goes over a character's head
/// (Speech bubble, Name, Level, HP/energy bars, etc.)
@ -142,7 +142,7 @@ impl<'a> Ingameable for Overhead<'a> {
} else {
0
}
+ if show_healthbar(info.health) {
+ if should_show_healthbar(info.health) {
5 + if info.energy.is_some() { 1 } else { 0 }
} else {
0
@ -303,7 +303,7 @@ impl<'a> Widget for Overhead<'a> {
.parent(id)
.set(state.ids.name, ui);
if show_healthbar(health) {
if should_show_healthbar(health) {
// Show HP Bar
let hp_ani = (self.pulse * 4.0/* speed factor */).cos() * 0.5 + 1.0; //Animation timer
let crit_hp_color: Color = Color::Rgba(0.79, 0.19, 0.17, hp_ani);