From c954ca4d1ec677a34a6d787a23f9d01396f7e585 Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Sun, 17 Nov 2024 17:06:56 +0200 Subject: Template for singing, WIP. * The line to sing is always the same. * The client recovers weirdly from singing before the next turn and my brain is currently too fried to figure out why --- src/scalevalapokalypsi/Server/Server.scala | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/scalevalapokalypsi/Server/Server.scala') diff --git a/src/scalevalapokalypsi/Server/Server.scala b/src/scalevalapokalypsi/Server/Server.scala index f18d5c0..db30283 100644 --- a/src/scalevalapokalypsi/Server/Server.scala +++ b/src/scalevalapokalypsi/Server/Server.scala @@ -52,6 +52,7 @@ class Server( this.readFromAll() this.clients.foreach(_.interpretData()) this.writeClientDataToClients() + this.makeClientsSing() this.writeObservations() if this.canExecuteTurns then this.clients.inRandomOrder(_.act()) @@ -68,7 +69,11 @@ class Server( ) startGameForClient(c) ) - else if this.adventure.isEmpty && !this.clients.isEmpty && this.clients.forall(_.isReadyForGameStart) then + else if + this.adventure.isEmpty && + !this.clients.isEmpty && + this.clients.forall(_.isReadyForGameStart) + then this.adventure = Some(Adventure(this.clients.names)) this.clients.foreach(startGameForClient(_)) this.previousTurn = currentTimeMillis() / 1000 @@ -97,7 +102,9 @@ class Server( this.clients.foreach(c => if c.player != playerEntity then - c.player.foreach(_.observe(s"${name.getOrElse("Unknown player")} joins the game.")) + c.player.foreach(_.observe( + s"${name.getOrElse("Unknown player")} joins the game.") + ) ) @@ -109,6 +116,16 @@ class Server( ) ) + private def makeClientsSing(): Unit = + this.clients.foreach(c => + if c.player.exists(_.isSinging) && !c.clientHasSong then + this.writeToClient( + s"${SING_INDICATOR}Esimerkkirivi laulettavaksi, lirulirulei\r\n", + c + ) + c.startSong() + ) + /** Helper function to determine if the next turn can be taken */ private def canExecuteTurns: Boolean = val requirement1 = this.adventure.isDefined -- cgit v1.2.3