Рабочий десайдер
This commit is contained in:
@@ -11,6 +11,7 @@ import java.util
|
||||
import scala.collection.JavaConverters.iterableAsScalaIterableConverter
|
||||
import scala.collection.immutable.HashSet
|
||||
import scala.concurrent.duration._
|
||||
import scala.util.Try
|
||||
|
||||
case class LobbyUser(name: String, actorRef: ActorRef)
|
||||
|
||||
@@ -43,13 +44,11 @@ class LobbieActor(hostUser: LobbyUser, deciderName: String) extends Actor with L
|
||||
|
||||
private var lobbyType: LobbyType = Last1()
|
||||
|
||||
private var isNecrons: Boolean = false
|
||||
|
||||
private var firstPlayerSelectedRaces: Option[SelectedRaces] = None
|
||||
private var secondPlayerSelectedRaces: Option[SelectedRaces] = None
|
||||
private var thirdPlayerSelectedRaces: Option[SelectedRaces] = None
|
||||
|
||||
|
||||
private val isSolo: Boolean = Try(config.getBoolean(s"deciders.$deciderName.isSolo")).getOrElse(false)
|
||||
private val mapsLobby: Set[DeciderMap] = {
|
||||
val configMaps = config.getList(s"deciders.$deciderName.maps").asScala
|
||||
configMaps.map(e => {
|
||||
@@ -67,7 +66,7 @@ class LobbieActor(hostUser: LobbyUser, deciderName: String) extends Actor with L
|
||||
status.toString(),
|
||||
playerTurn,
|
||||
lobbyType.toString(),
|
||||
isNecrons,
|
||||
isSolo,
|
||||
mapsLobby)),
|
||||
this.self)
|
||||
|
||||
@@ -79,6 +78,16 @@ class LobbieActor(hostUser: LobbyUser, deciderName: String) extends Actor with L
|
||||
// notify watchers
|
||||
logger.info(s"Ban map $mapName by ${sender.path.name}")
|
||||
|
||||
if (isSolo) {
|
||||
mapsLobby.find(p => p.map == mapName).foreach(m => m.isBanned = true)
|
||||
if (isFinish) {
|
||||
status = Finish()
|
||||
} else {
|
||||
status = Draft()
|
||||
}
|
||||
refreshAndBanMap(mapName)
|
||||
}
|
||||
|
||||
if (status == Draft()) {
|
||||
if ((playerTurn == 1 && sender == host.actorRef) ||
|
||||
(playerTurn == 2 && secondPlayer.exists(_.actorRef == sender))) {
|
||||
@@ -87,19 +96,10 @@ class LobbieActor(hostUser: LobbyUser, deciderName: String) extends Actor with L
|
||||
if (!map.isBanned) {
|
||||
map.isBanned = true
|
||||
if (playerTurn == 1) playerTurn = 2 else playerTurn = 1
|
||||
if (mapsLobby.count(_.isBanned == false) == 1 && lobbyType == Last1() ||
|
||||
mapsLobby.count(_.isBanned == false) == 3 && lobbyType == Last3() ||
|
||||
mapsLobby.count(_.isBanned == false) == 5 && lobbyType == Last5() ||
|
||||
mapsLobby.count(_.isBanned == false) == 7 && lobbyType == Last7()
|
||||
) {
|
||||
if (isFinish) {
|
||||
status = Finish()
|
||||
}
|
||||
users.foreach(_ ! RefreshLobbyInfo(getLobbyInfoResponse))
|
||||
|
||||
val senderName: String = if (sender == host.actorRef) {
|
||||
host.name
|
||||
} else secondPlayer.get.name
|
||||
users.foreach(_ ! SendBanMapMessage(BanMapMessage(senderName, mapName)))
|
||||
refreshAndBanMap(mapName)
|
||||
} else {
|
||||
logger.warn(s"User ban map $mapName, but map already banned")
|
||||
}
|
||||
@@ -227,9 +227,25 @@ class LobbieActor(hostUser: LobbyUser, deciderName: String) extends Actor with L
|
||||
status.toString(),
|
||||
playerTurn,
|
||||
lobbyType.toString(),
|
||||
isNecrons,
|
||||
isSolo,
|
||||
mapsLobby)
|
||||
}
|
||||
|
||||
private def isFinish: Boolean = {
|
||||
mapsLobby.count(_.isBanned == false) == 1 && lobbyType == Last1() ||
|
||||
mapsLobby.count(_.isBanned == false) == 3 && lobbyType == Last3() ||
|
||||
mapsLobby.count(_.isBanned == false) == 5 && lobbyType == Last5() ||
|
||||
mapsLobby.count(_.isBanned == false) == 7 && lobbyType == Last7()
|
||||
}
|
||||
|
||||
private def refreshAndBanMap(mapName: String): Unit = {
|
||||
val senderName: String = if (sender == host.actorRef) {
|
||||
host.name
|
||||
} else secondPlayer.get.name
|
||||
users.foreach(_ ! SendBanMapMessage(BanMapMessage(senderName, mapName)))
|
||||
users.foreach(_ ! RefreshLobbyInfo(getLobbyInfoResponse))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
case class BanMap(mapName: String)
|
||||
@@ -269,7 +285,7 @@ case class LobbyInfo(user1Info: UserInfo,
|
||||
status: String,
|
||||
playerTurn: BigDecimal,
|
||||
selectedType: String,
|
||||
isNecrons: Boolean,
|
||||
isSolo: Boolean,
|
||||
maps: Set[DeciderMap])
|
||||
|
||||
class LobbyStatus
|
||||
|
||||
Reference in New Issue
Block a user