From 9d1c30cf9ef5a057c760da49b52312de4a5afc6a Mon Sep 17 00:00:00 2001 From: metamuffin Date: Wed, 18 Sep 2024 16:16:58 +0200 Subject: prevent multiple tutorials at once --- server/src/entity/bot.rs | 3 ++- server/src/entity/campaign.rs | 6 ++++++ server/src/entity/mod.rs | 4 ++-- server/src/entity/tutorial.rs | 10 +++++++++- 4 files changed, 19 insertions(+), 4 deletions(-) (limited to 'server/src/entity') diff --git a/server/src/entity/bot.rs b/server/src/entity/bot.rs index 6f39fab2..cd505c4f 100644 --- a/server/src/entity/bot.rs +++ b/server/src/entity/bot.rs @@ -21,6 +21,7 @@ use hurrycurry_bot::{BotAlgo, DynBotAlgo}; use hurrycurry_protocol::{PacketS, PlayerID}; use log::info; use rand::random; +use std::any::Any; pub type DynBotDriver = BotDriver; @@ -43,7 +44,7 @@ impl BotDriver { } } } -impl Entity for BotDriver { +impl Entity for BotDriver { fn finished(&self) -> bool { self.left } diff --git a/server/src/entity/campaign.rs b/server/src/entity/campaign.rs index 5d669a4d..2e45e650 100644 --- a/server/src/entity/campaign.rs +++ b/server/src/entity/campaign.rs @@ -123,6 +123,12 @@ impl GateCondition { o } GateCondition::Stars(map, thres) => { + // TODO what if the language wants map first? + // trm!( + // "s.campaign.condition.stars", + // s = thres.to_string(), + // s = map.to_string() + // ) format!("Reach at least {thres} stars in {map}") } } diff --git a/server/src/entity/mod.rs b/server/src/entity/mod.rs index 532031d5..aa565c83 100644 --- a/server/src/entity/mod.rs +++ b/server/src/entity/mod.rs @@ -40,7 +40,7 @@ use hurrycurry_protocol::{ use item_portal::ItemPortal; use player_portal::PlayerPortal; use serde::{Deserialize, Serialize}; -use std::collections::VecDeque; +use std::{any::Any, collections::VecDeque}; pub type DynEntity = Box; pub type Entities = Vec; @@ -55,7 +55,7 @@ pub struct EntityContext<'a> { pub dt: f32, } -pub trait Entity { +pub trait Entity: Any { fn tick(&mut self, _c: EntityContext<'_>) -> Result<()> { Ok(()) } diff --git a/server/src/entity/tutorial.rs b/server/src/entity/tutorial.rs index 9b2146d2..0d3d512d 100644 --- a/server/src/entity/tutorial.rs +++ b/server/src/entity/tutorial.rs @@ -8,7 +8,7 @@ use hurrycurry_protocol::{ use log::{debug, warn}; pub struct Tutorial { - player: PlayerID, + pub player: PlayerID, target: ItemIndex, current_hint: Option<(Option, Message)>, @@ -30,6 +30,14 @@ impl Entity for Tutorial { fn finished(&self) -> bool { self.delete_timer <= 0. } + fn destructor(&mut self, c: EntityContext<'_>) { + if let Some((position, _)) = self.current_hint { + c.packet_out.push_back(PacketC::ServerHint { + position, + message: None, + }); + } + } fn tick(&mut self, c: EntityContext<'_>) -> Result<()> { let mut hint = StepContext { ent: &c, -- cgit v1.2.3-70-g09d2