From 5321f2f18cb1a968778f7bc8ceaa13255bde586e Mon Sep 17 00:00:00 2001 From: metamuffin Date: Fri, 12 Dec 2025 15:40:14 +0100 Subject: environment_effect delay changes + doc entities --- server/src/entity/environment_effect.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'server/src/entity') diff --git a/server/src/entity/environment_effect.rs b/server/src/entity/environment_effect.rs index e50a65ff..fab6f47b 100644 --- a/server/src/entity/environment_effect.rs +++ b/server/src/entity/environment_effect.rs @@ -1,5 +1,3 @@ -use crate::random_float; - /* Hurry Curry! - a game about cooking Copyright (C) 2025 Hurry Curry! Contributors @@ -17,23 +15,24 @@ use crate::random_float; along with this program. If not, see . */ + use super::{Entity, EntityContext}; +use crate::random_gauss; use hurrycurry_data::entities::EnvironmentEffect; use hurrycurry_locale::TrError; use hurrycurry_protocol::PacketC; -use std::time::{Duration, Instant}; #[derive(Clone, Debug)] pub struct EnvironmentEffectController { config: EnvironmentEffect, - next_transition: Instant, + next_transition: f32, active: bool, } impl EnvironmentEffectController { pub fn new(config: EnvironmentEffect) -> Self { Self { - next_transition: Instant::now() + Duration::from_secs_f32(config.on), + next_transition: config.on, active: false, config, } @@ -41,15 +40,14 @@ impl EnvironmentEffectController { } impl Entity for EnvironmentEffectController { fn tick(&mut self, c: EntityContext) -> Result<(), TrError> { - if self.next_transition < Instant::now() { + self.next_transition -= c.dt; + if self.next_transition < 0. { if self.active { - self.next_transition += - Duration::from_secs_f32(self.config.on * (0.5 + random_float())); + self.next_transition += self.config.off + random_gauss() * self.config.off_stdev; self.active = false; c.game.environment_effects.remove(&self.config.name); } else { - self.next_transition += - Duration::from_secs_f32(self.config.off * (0.5 + random_float())); + self.next_transition += self.config.on + random_gauss() * self.config.on_stdev; self.active = true; c.game.environment_effects.insert(self.config.name.clone()); } -- cgit v1.3