Merge branch 'blood_particle_fix' into 'master'

Fixed blood particles showing on projectile hit for bodies not supposed to bleed from gameplay perspective

See merge request veloren/veloren!3290
This commit is contained in:
Ben Wallis 2022-03-20 15:45:50 +00:00
commit a8601bc76e
2 changed files with 32 additions and 5 deletions

View File

@ -225,6 +225,13 @@ impl Body {
pub fn is_campfire(&self) -> bool { matches!(self, Body::Object(object::Body::CampfireLit)) }
pub fn bleeds(&self) -> bool {
!matches!(
self,
Body::Object(_) | Body::Ship(_) | Body::ItemDrop(_) | Body::Golem(_)
)
}
/// Average density of the body
// Units are based on kg/m³
pub fn density(&self) -> Density {

View File

@ -18,12 +18,13 @@ use common::{
spiral::Spiral2d,
states::{self, utils::StageSection},
terrain::{Block, TerrainChunk, TerrainGrid},
uid::UidAllocator,
vol::{ReadVol, RectRasterableVol, SizedVol},
};
use common_base::span;
use hashbrown::HashMap;
use rand::prelude::*;
use specs::{Join, WorldExt};
use specs::{saveload::MarkerAllocator, Join, WorldExt};
use std::{
f32::consts::{PI, TAU},
time::Duration,
@ -218,10 +219,29 @@ impl ParticleMgr {
},
Outcome::ProjectileHit { pos, target, .. } => {
if target.is_some() {
self.particles.resize_with(self.particles.len() + 30, || {
Particle::new(Duration::from_millis(250), time, ParticleMode::Blood, *pos)
});
}
let ecs = scene_data.state.ecs();
if target
.and_then(|target| {
ecs.read_resource::<UidAllocator>()
.retrieve_entity_internal(target.0)
})
.and_then(|entity| {
ecs.read_storage::<Body>()
.get(entity)
.map(|body| body.bleeds())
})
.unwrap_or(false)
{
self.particles.resize_with(self.particles.len() + 30, || {
Particle::new(
Duration::from_millis(250),
time,
ParticleMode::Blood,
*pos,
)
})
};
};
},
Outcome::Block { pos, parry, .. } => {
if *parry {