aboutsummaryrefslogtreecommitdiff
path: root/src/scalevalapokalypsi/Server/Server.scala
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2024-11-18 02:01:12 +0200
committerJoel Kronqvist <joel.kronqvist@iki.fi>2024-11-18 02:01:12 +0200
commitfe2543627bcec1ea0f7a429bede20ca293458ba9 (patch)
tree42c9630d65292c90bee37444fde14fcf99cc3ffe /src/scalevalapokalypsi/Server/Server.scala
parenta98f089035dbcc94c14c9cd6246c3150bee84241 (diff)
downloadscalevalapokalypsi-fe2543627bcec1ea0f7a429bede20ca293458ba9.tar.gz
scalevalapokalypsi-fe2543627bcec1ea0f7a429bede20ca293458ba9.zip
Major change! Changed Events to have multiple first persons & changed sending action results to clients using this. This improves code and made it easy to finally make arrival/leaving messages when going from one area to another!
This commit is too big indeed, and there are probably bugs. I'm annoyed we didn't set up unit testing during the course. I should've taken my time to set up IDEA myself for that. Now the bugs will just have to be fixed in future commits.
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