From 9e35f5ec3334d7b4488ca6b1c56b21e8c7835ec1 Mon Sep 17 00:00:00 2001 From: Ben Wallis Date: Fri, 20 Aug 2021 08:44:34 +0100 Subject: [PATCH] Explosions no longer change block colours within the radius of a safe zone. Doubled the radius of the safe zone in the /home town. --- CHANGELOG.md | 2 ++ server/src/events/entity_manipulation.rs | 45 +++++++++++++++++++++--- server/src/sys/terrain.rs | 4 ++- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b3379ab9f1..e1c44314a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Can now tilt glider while only wielding it - Experimental terrain persistence (see server documentation) - Add GPU filtering using WGPU_ADAPTER environment variable +- Explosions no longer change block colours within safe zones ### Changed @@ -53,6 +54,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Glider dimensions now depend on character height - Glider dimensions somewhat increased overall - Dungeon difficulty level starts at 1 instead of 0 +- The radius of the safe zone around the starting town has been doubled ### Removed diff --git a/server/src/events/entity_manipulation.rs b/server/src/events/entity_manipulation.rs index 5c90d6f24e..75074402df 100644 --- a/server/src/events/entity_manipulation.rs +++ b/server/src/events/entity_manipulation.rs @@ -4,9 +4,10 @@ use crate::{ agent::{Agent, AgentEvent, Sound, SoundKind}, biped_large, bird_large, quadruped_low, quadruped_medium, quadruped_small, skills::SkillGroupKind, - theropod, PhysicsState, + theropod, BuffKind, BuffSource, PhysicsState, }, rtsim::RtSim, + sys::terrain::SAFE_ZONE_RADIUS, Server, SpawnPoint, StateExt, }; use common::{ @@ -16,8 +17,9 @@ use common::{ self, aura, buff, chat::{KillSource, KillType}, inventory::item::MaterialStatManifest, - object, Alignment, Body, CharacterState, Energy, EnergyChange, Group, Health, HealthChange, - HealthSource, Inventory, Player, Poise, PoiseChange, PoiseSource, Pos, SkillSet, Stats, + object, Alignment, Auras, Body, CharacterState, Energy, EnergyChange, Group, Health, + HealthChange, HealthSource, Inventory, Player, Poise, PoiseChange, PoiseSource, Pos, + SkillSet, Stats, }, event::{EventBus, ServerEvent}, lottery::{LootSpec, Lottery}, @@ -741,11 +743,46 @@ pub fn handle_explosion(server: &Server, pos: Vec3, explosion: Explosion, o // TODO: Faster RNG? let mut rng = rand::thread_rng(); - for effect in explosion.effects { + 'effects: for effect in explosion.effects { match effect { RadiusEffect::TerrainDestruction(power) => { const RAYS: usize = 500; + let spatial_grid = ecs.read_resource::(); + let auras = ecs.read_storage::(); + let positions = ecs.read_storage::(); + + // Prevent block colour changes within the radius of a safe zone aura + if spatial_grid + .0 + .in_circle_aabr(pos.xy(), SAFE_ZONE_RADIUS) + .filter_map(|entity| { + auras + .get(entity) + .and_then(|entity_auras| { + positions.get(entity).map(|pos| (entity_auras, pos)) + }) + .and_then(|(entity_auras, pos)| { + entity_auras + .auras + .iter() + .find(|(_, aura)| { + matches!(aura.aura_kind, aura::AuraKind::Buff { + kind: BuffKind::Invulnerability, + source: BuffSource::World, + .. + }) + }) + .map(|(_, aura)| (*pos, aura.radius)) + }) + }) + .any(|(aura_pos, aura_radius)| { + pos.distance_squared(aura_pos.0) < aura_radius.powi(2) + }) + { + continue 'effects; + } + // Color terrain let mut touched_blocks = Vec::new(); let color_range = power * 2.7; diff --git a/server/src/sys/terrain.rs b/server/src/sys/terrain.rs index de9ad0a201..d91a7fecc0 100644 --- a/server/src/sys/terrain.rs +++ b/server/src/sys/terrain.rs @@ -36,6 +36,8 @@ pub(crate) struct LazyTerrainMessage { lazy_msg_hi: Option, } +pub const SAFE_ZONE_RADIUS: f32 = 200.0; + impl LazyTerrainMessage { #[allow(clippy::new_without_default)] pub(crate) fn new() -> Self { @@ -241,7 +243,7 @@ impl<'a> System<'a> for Sys { // Insert a safezone if chunk contains the spawn position if server_settings.safe_spawn && is_spawn_chunk(key, *spawn_point, &terrain) { server_emitter.emit(ServerEvent::CreateSafezone { - range: Some(100.0), + range: Some(SAFE_ZONE_RADIUS), pos: Pos(spawn_point.0), }); }