summaryrefslogtreecommitdiff
path: root/server/src/entity/environment_effect.rs
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/entity/environment_effect.rs')
-rw-r--r--server/src/entity/environment_effect.rs38
1 files changed, 12 insertions, 26 deletions
diff --git a/server/src/entity/environment_effect.rs b/server/src/entity/environment_effect.rs
index f369bce4..8f54d29c 100644
--- a/server/src/entity/environment_effect.rs
+++ b/server/src/entity/environment_effect.rs
@@ -15,15 +15,11 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-use super::EntityT;
-use crate::game::Game;
+use super::{EntityContext, EntityT};
use hurrycurry_protocol::PacketC;
use rand::random;
use serde::{Deserialize, Serialize};
-use std::{
- collections::VecDeque,
- time::{Duration, Instant},
-};
+use std::time::{Duration, Instant};
#[derive(Clone, Debug, Deserialize, Serialize, Default)]
pub struct EnvironmentEffect {
@@ -54,26 +50,21 @@ impl EnvironmentEffectController {
}
}
impl EntityT for EnvironmentEffectController {
- fn tick(
- &mut self,
- game: &mut Game,
- packet_out: &mut VecDeque<PacketC>,
- _dt: f32,
- ) -> anyhow::Result<()> {
+ fn tick(&mut self, c: EntityContext) -> anyhow::Result<()> {
if self.next_transition < Instant::now() {
if self.active {
self.next_transition +=
Duration::from_secs_f32(self.config.on + (0.5 + random::<f32>()));
self.active = false;
- game.environment_effects.remove(&self.config.name);
+ c.game.environment_effects.remove(&self.config.name);
} else {
self.next_transition +=
Duration::from_secs_f32(self.config.off * (0.5 + random::<f32>()));
self.active = true;
- game.environment_effects.insert(self.config.name.clone());
+ c.game.environment_effects.insert(self.config.name.clone());
}
- packet_out.push_back(PacketC::Environment {
- effects: game.environment_effects.clone(),
+ c.packet_out.push_back(PacketC::Environment {
+ effects: c.game.environment_effects.clone(),
})
}
Ok(())
@@ -83,16 +74,11 @@ impl EntityT for EnvironmentEffectController {
#[derive(Debug, Clone)]
pub struct EnvironmentController(pub Vec<String>);
impl EntityT for EnvironmentController {
- fn tick(
- &mut self,
- game: &mut Game,
- packet_out: &mut VecDeque<PacketC>,
- _dt: f32,
- ) -> anyhow::Result<()> {
- if game.environment_effects.is_empty() {
- game.environment_effects.extend(self.0.clone());
- packet_out.push_back(PacketC::Environment {
- effects: game.environment_effects.clone(),
+ fn tick(&mut self, c: EntityContext) -> anyhow::Result<()> {
+ if c.game.environment_effects.is_empty() {
+ c.game.environment_effects.extend(self.0.clone());
+ c.packet_out.push_back(PacketC::Environment {
+ effects: c.game.environment_effects.clone(),
})
}
Ok(())