aboutsummaryrefslogtreecommitdiff
path: root/server/src/entity/environment_effect.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-12-12 15:40:14 +0100
committermetamuffin <metamuffin@disroot.org>2025-12-12 15:40:14 +0100
commit5321f2f18cb1a968778f7bc8ceaa13255bde586e (patch)
tree9a6594a214e290f3ca5daa20bf39f931b06d95dd /server/src/entity/environment_effect.rs
parent6c9e1480978e839692fa73f7e28639c3f95a36ee (diff)
downloadhurrycurry-5321f2f18cb1a968778f7bc8ceaa13255bde586e.tar
hurrycurry-5321f2f18cb1a968778f7bc8ceaa13255bde586e.tar.bz2
hurrycurry-5321f2f18cb1a968778f7bc8ceaa13255bde586e.tar.zst
environment_effect delay changes + doc entities
Diffstat (limited to 'server/src/entity/environment_effect.rs')
-rw-r--r--server/src/entity/environment_effect.rs18
1 files changed, 8 insertions, 10 deletions
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 <https://www.gnu.org/licenses/>.
*/
+
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());
}