diff options
Diffstat (limited to 'src/scalevalapokalypsi/Server/Client.scala')
-rw-r--r-- | src/scalevalapokalypsi/Server/Client.scala | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/src/scalevalapokalypsi/Server/Client.scala b/src/scalevalapokalypsi/Server/Client.scala index 1af83bf..17c3777 100644 --- a/src/scalevalapokalypsi/Server/Client.scala +++ b/src/scalevalapokalypsi/Server/Client.scala @@ -18,6 +18,7 @@ class Client(val socket: Socket): private var protocolIsIntact = true private var name: Option[String] = None private var nextAction: Option[Action] = None + private var turnUsed = false private var singStartTime: Option[Long] = None def clientHasSong = this.singStartTime.isDefined @@ -114,16 +115,13 @@ class Client(val socket: Socket): None /** Makes the client play its turn */ - def act(): Unit = - this.nextAction.foreach(a => this.addDataToSend( - s"$ACTION_BLOCKING_INDICATOR${this.executeAction(a)}" - )) - this.nextAction = None + def giveTurn(): Unit = + this.turnUsed = false /** Checks whether the client has chosen its next action * * @return whether the client is ready to act */ - def isReadyToAct: Boolean = this.nextAction.isDefined + def hasActed: Boolean = this.turnUsed /** Causes the client to interpret the data it has received */ def interpretData(): Unit = @@ -154,12 +152,31 @@ class Client(val socket: Socket): true case WaitingForGameStart => true case InGame => - this.bufferAction(Action(line)) + this.executeLine(line) true /** Buffers the action for execution or executes it immediately if it * doesn't take a turn */ - private def bufferAction(action: Action) = + private def executeLine(line: String) = + if !this.turnUsed then + this.singStartTime match + case Some(t) => + val timePassed = currentTimeMillis()/1000 - t + this.player.foreach(_.applySingEffect( + 1 / max(5, timePassed) * 5 + )) + this.singStartTime = None + case None => + val action = Action(line) + val takesATurn = this.character.exists(p => action.execute(p)) + if takesATurn then + this.addDataToSend(s"$ACTION_BLOCKING_INDICATOR") + this.turnUsed = true + + /* + val takesATurn = this.character.exists(action.execute(_)) + if takesATurn then + this.addDataToSend(s"$ACTION_BLOCKING_INDICATOR") if ( this.nextAction.isEmpty && this.player.exists(action.takesATurnFor(_)) @@ -170,19 +187,13 @@ class Client(val socket: Socket): case Some(t) => val timePassed = currentTimeMillis()/1000 - t this.player.foreach(_.applySingEffect( - 5 / max(5, timePassed) + 1 / max(5, timePassed) * 5 )) this.singStartTime = None case None => this.addDataToSend( s"$ACTION_NONBLOCKING_INDICATOR${this.executeAction(action)}" - ) - - /** Executes the specified action and returns its description */ - private def executeAction(action: Action): String = - this.character.flatMap(action.execute(_)) match - case Some(s) => s - case None => "You can't do that" + )*/ end Client |