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/commands.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'server/src/commands.rs') diff --git a/server/src/commands.rs b/server/src/commands.rs index 8e6f32c7..f5792a22 100644 --- a/server/src/commands.rs +++ b/server/src/commands.rs @@ -239,7 +239,18 @@ impl Server { .data .get_item_by_name(&item) .ok_or(anyhow!("unknown item"))?; - // TODO prevent too many (> 1) tutorials for this player + #[cfg(not(test))] // TODO rust-analyser does not undestand trait upcasting + if self + .entities + .iter() + .find(|e| { + ::downcast_ref::(e.as_ref()) + .map_or(false, |t| t.player == player) + }) + .is_some() + { + bail!("Tutorial already running") + } self.entities.push(Box::new(Tutorial::new(player, item))); } Command::TranslateMessage { -- cgit v1.2.3-70-g09d2