aboutsummaryrefslogtreecommitdiff
path: root/src/scalevalapokalypsi/Server/Server.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/scalevalapokalypsi/Server/Server.scala')
-rw-r--r--src/scalevalapokalypsi/Server/Server.scala24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/scalevalapokalypsi/Server/Server.scala b/src/scalevalapokalypsi/Server/Server.scala
index 609b581..bfb0893 100644
--- a/src/scalevalapokalypsi/Server/Server.scala
+++ b/src/scalevalapokalypsi/Server/Server.scala
@@ -3,7 +3,7 @@ package scalevalapokalypsi.Server
// TODO: TLS/SSL / import javax.net.ssl.SSLServerSocketFactory
-import scalevalapokalypsi.Model.Adventure
+import scalevalapokalypsi.Model.{Adventure, Event}
import scalevalapokalypsi.Model.Entities.Player
import scalevalapokalypsi.constants.*
import scalevalapokalypsi.utils.stringToByteArray
@@ -55,9 +55,9 @@ class Server(
this.makeClientsSing()
this.writeObservations()
if this.canExecuteTurns then
- this.clients.inRandomOrder(_.act())
- this.writeClientDataToClients()
- this.writeObservations()
+ this.clients.foreach(_.giveTurn())
+ //this.writeClientDataToClients()
+ //this.writeObservations()
this.clients.foreach(c =>
this.writeToClient(this.turnStartInfo(c), c)
)
@@ -100,12 +100,14 @@ class Server(
s"$timeLimit\r\n${this.turnStartInfo(c)}", c
)
- this.clients.foreach(c =>
- if c.player != playerEntity then
- c.player.foreach(_.observeString(
- s"${name.getOrElse("Unknown player")} joins the game.")
- )
- )
+ val joinEvent = c.player.map(p => Event(
+ Map.from(Vector((p, ""))),
+ s"${p.name} joins the game."
+ ))
+ joinEvent.foreach(ev => this.clients.foreach(cl =>
+ if cl != c then
+ cl.player.foreach(_.observe(ev))
+ ))
private def writeObservations(): Unit =
@@ -137,7 +139,7 @@ class Server(
// to the game after everyone
// left and everything is just
// as before!
- val allPlayersReady = this.clients.forall(_.isReadyToAct)
+ val allPlayersReady = this.clients.forall(_.hasActed)
val requirement3 = (allPlayersReady
|| currentTimeMillis() / 1000 >= previousTurn + timeLimit)
requirement1 && requirement2 && requirement3