mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Addressed comments.
This commit is contained in:
parent
be2f376176
commit
e34f5f09e9
@ -120,10 +120,10 @@ impl Component for Health {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct Dying {
|
pub struct Dead {
|
||||||
pub cause: HealthSource,
|
pub cause: HealthSource,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Component for Dying {
|
impl Component for Dead {
|
||||||
type Storage = IdvStorage<Self>;
|
type Storage = IdvStorage<Self>;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::combat::Damages;
|
use crate::{combat::Damages, effect::Effect};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
@ -12,4 +12,5 @@ pub struct Explosion {
|
|||||||
pub enum RadiusEffect {
|
pub enum RadiusEffect {
|
||||||
Damages(Damages),
|
Damages(Damages),
|
||||||
TerrainDestruction(f32),
|
TerrainDestruction(f32),
|
||||||
|
EntityEffect(Effect),
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ use chrono::{NaiveTime, Timelike};
|
|||||||
use common::{
|
use common::{
|
||||||
cmd::{ChatCommand, CHAT_COMMANDS, CHAT_SHORTCUTS},
|
cmd::{ChatCommand, CHAT_COMMANDS, CHAT_SHORTCUTS},
|
||||||
comp::{self, ChatType, Item, LightEmitter, WaypointArea},
|
comp::{self, ChatType, Item, LightEmitter, WaypointArea},
|
||||||
|
effect::Effect,
|
||||||
event::{EventBus, ServerEvent},
|
event::{EventBus, ServerEvent},
|
||||||
msg::{DisconnectReason, Notification, PlayerListUpdate, ServerGeneral},
|
msg::{DisconnectReason, Notification, PlayerListUpdate, ServerGeneral},
|
||||||
npc::{self, get_npc_name},
|
npc::{self, get_npc_name},
|
||||||
@ -18,7 +19,7 @@ use common::{
|
|||||||
terrain::{Block, BlockKind, SpriteKind, TerrainChunkSize},
|
terrain::{Block, BlockKind, SpriteKind, TerrainChunkSize},
|
||||||
util::Dir,
|
util::Dir,
|
||||||
vol::RectVolSize,
|
vol::RectVolSize,
|
||||||
Damage, DamageSource, Damages, Explosion, LoadoutBuilder, RadiusEffect,
|
Explosion, LoadoutBuilder, RadiusEffect,
|
||||||
};
|
};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use specs::{Builder, Entity as EcsEntity, Join, WorldExt};
|
use specs::{Builder, Entity as EcsEntity, Join, WorldExt};
|
||||||
@ -1157,16 +1158,10 @@ fn handle_explosion(
|
|||||||
pos: pos.0,
|
pos: pos.0,
|
||||||
explosion: Explosion {
|
explosion: Explosion {
|
||||||
effects: vec![
|
effects: vec![
|
||||||
RadiusEffect::Damages(Damages::new(
|
RadiusEffect::EntityEffect(Effect::Health(comp::HealthChange {
|
||||||
Some(Damage {
|
amount: (-100.0 * power) as i32,
|
||||||
source: DamageSource::Explosion,
|
cause: comp::HealthSource::Explosion { owner: None },
|
||||||
value: 100.0 * power,
|
})),
|
||||||
}),
|
|
||||||
Some(Damage {
|
|
||||||
source: DamageSource::Explosion,
|
|
||||||
value: 100.0 * power,
|
|
||||||
}),
|
|
||||||
)),
|
|
||||||
RadiusEffect::TerrainDestruction(power),
|
RadiusEffect::TerrainDestruction(power),
|
||||||
],
|
],
|
||||||
radius: 3.0 * power,
|
radius: 3.0 * power,
|
||||||
|
@ -516,15 +516,10 @@ pub fn handle_explosion(
|
|||||||
|
|
||||||
// Add an outcome
|
// Add an outcome
|
||||||
// Uses radius as outcome power, makes negative if explosion has healing effect
|
// Uses radius as outcome power, makes negative if explosion has healing effect
|
||||||
#[allow(clippy::blocks_in_if_conditions)]
|
|
||||||
let outcome_power = explosion.radius
|
let outcome_power = explosion.radius
|
||||||
* if explosion.effects.iter().any(|e| {
|
* if explosion.effects.iter().any(
|
||||||
if let RadiusEffect::Damages(d) = e {
|
|e| matches!(e, RadiusEffect::Damages(d) if d.contains_damage(DamageSource::Healing)),
|
||||||
d.contains_damage(DamageSource::Healing)
|
) {
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}) {
|
|
||||||
-1.0
|
-1.0
|
||||||
} else {
|
} else {
|
||||||
1.0
|
1.0
|
||||||
@ -672,6 +667,16 @@ pub fn handle_explosion(
|
|||||||
.cast();
|
.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ use vek::*;
|
|||||||
|
|
||||||
pub trait StateExt {
|
pub trait StateExt {
|
||||||
/// Updates a component associated with the entity based on the `Effect`
|
/// 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
|
/// Build a non-player character
|
||||||
fn create_npc(
|
fn create_npc(
|
||||||
&mut self,
|
&mut self,
|
||||||
@ -71,7 +71,7 @@ pub trait StateExt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl StateExt for State {
|
impl StateExt for State {
|
||||||
fn apply_effect(&mut self, entity: EcsEntity, effect: Effect) {
|
fn apply_effect(&self, entity: EcsEntity, effect: Effect) {
|
||||||
match effect {
|
match effect {
|
||||||
Effect::Health(change) => {
|
Effect::Health(change) => {
|
||||||
self.ecs()
|
self.ecs()
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
use common::{
|
use common::{
|
||||||
comp::{HealthSource, Object, PhysicsState, Pos, Vel},
|
comp::{HealthChange, HealthSource, Object, PhysicsState, Pos, Vel},
|
||||||
|
effect::Effect,
|
||||||
event::{EventBus, ServerEvent},
|
event::{EventBus, ServerEvent},
|
||||||
span,
|
span,
|
||||||
state::DeltaTime,
|
state::DeltaTime,
|
||||||
Damage, DamageSource, Damages, Explosion, RadiusEffect,
|
Explosion, RadiusEffect,
|
||||||
};
|
};
|
||||||
use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage};
|
use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage};
|
||||||
|
|
||||||
@ -49,16 +50,10 @@ impl<'a> System<'a> for Sys {
|
|||||||
pos: pos.0,
|
pos: pos.0,
|
||||||
explosion: Explosion {
|
explosion: Explosion {
|
||||||
effects: vec![
|
effects: vec![
|
||||||
RadiusEffect::Damages(Damages::new(
|
RadiusEffect::EntityEffect(Effect::Health(HealthChange {
|
||||||
Some(Damage {
|
amount: -500,
|
||||||
source: DamageSource::Explosion,
|
cause: HealthSource::Explosion { owner: *owner },
|
||||||
value: 500.0,
|
})),
|
||||||
}),
|
|
||||||
Some(Damage {
|
|
||||||
source: DamageSource::Explosion,
|
|
||||||
value: 500.0,
|
|
||||||
}),
|
|
||||||
)),
|
|
||||||
RadiusEffect::TerrainDestruction(4.0),
|
RadiusEffect::TerrainDestruction(4.0),
|
||||||
],
|
],
|
||||||
radius: 12.0,
|
radius: 12.0,
|
||||||
@ -79,16 +74,10 @@ impl<'a> System<'a> for Sys {
|
|||||||
pos: pos.0,
|
pos: pos.0,
|
||||||
explosion: Explosion {
|
explosion: Explosion {
|
||||||
effects: vec![
|
effects: vec![
|
||||||
RadiusEffect::Damages(Damages::new(
|
RadiusEffect::EntityEffect(Effect::Health(HealthChange {
|
||||||
Some(Damage {
|
amount: -50,
|
||||||
source: DamageSource::Explosion,
|
cause: HealthSource::Explosion { owner: *owner },
|
||||||
value: 50.0,
|
})),
|
||||||
}),
|
|
||||||
Some(Damage {
|
|
||||||
source: DamageSource::Explosion,
|
|
||||||
value: 50.0,
|
|
||||||
}),
|
|
||||||
)),
|
|
||||||
RadiusEffect::TerrainDestruction(4.0),
|
RadiusEffect::TerrainDestruction(4.0),
|
||||||
],
|
],
|
||||||
radius: 12.0,
|
radius: 12.0,
|
||||||
|
@ -1195,7 +1195,7 @@ impl Hud {
|
|||||||
let display_overhead_info =
|
let display_overhead_info =
|
||||||
(info.target_entity.map_or(false, |e| e == entity)
|
(info.target_entity.map_or(false, |e| e == entity)
|
||||||
|| info.selected_entity.map_or(false, |s| s.0 == entity)
|
|| info.selected_entity.map_or(false, |s| s.0 == entity)
|
||||||
|| overhead::show_healthbar(health)
|
|| overhead::should_show_healthbar(health)
|
||||||
|| in_group)
|
|| in_group)
|
||||||
&& dist_sqr
|
&& dist_sqr
|
||||||
< (if in_group {
|
< (if in_group {
|
||||||
|
@ -64,7 +64,7 @@ pub struct Info<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Determines whether to show the healthbar
|
/// 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
|
/// ui widget containing everything that goes over a character's head
|
||||||
/// (Speech bubble, Name, Level, HP/energy bars, etc.)
|
/// (Speech bubble, Name, Level, HP/energy bars, etc.)
|
||||||
@ -142,7 +142,7 @@ impl<'a> Ingameable for Overhead<'a> {
|
|||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
+ if show_healthbar(info.health) {
|
+ if should_show_healthbar(info.health) {
|
||||||
5 + if info.energy.is_some() { 1 } else { 0 }
|
5 + if info.energy.is_some() { 1 } else { 0 }
|
||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
@ -303,7 +303,7 @@ impl<'a> Widget for Overhead<'a> {
|
|||||||
.parent(id)
|
.parent(id)
|
||||||
.set(state.ids.name, ui);
|
.set(state.ids.name, ui);
|
||||||
|
|
||||||
if show_healthbar(health) {
|
if should_show_healthbar(health) {
|
||||||
// Show HP Bar
|
// Show HP Bar
|
||||||
let hp_ani = (self.pulse * 4.0/* speed factor */).cos() * 0.5 + 1.0; //Animation timer
|
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);
|
let crit_hp_color: Color = Color::Rgba(0.79, 0.19, 0.17, hp_ani);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user