* Impl. a usecase of a fight scenario
* Reset playermoves when necessary
This commit is contained in:
parent
fbe8dbde9d
commit
604001a365
@ -45,8 +45,8 @@ class MultiplayerNetwork{
|
||||
let encoder = JSONEncoder()
|
||||
let encoded = (try? encoder.encode(playerMoves))!
|
||||
sendDataToHost(data: encoded)
|
||||
DataService.sharedInstance.localPlayerMoves.removeAll()
|
||||
}
|
||||
DataService.sharedInstance.localPlayerMoves.removeAll()
|
||||
}
|
||||
|
||||
func sendHostIdentifier() {
|
||||
|
@ -54,7 +54,7 @@ class RoundCalculatorService {
|
||||
}
|
||||
playerMovesByBase.removeValue(forKey: playerName)
|
||||
}
|
||||
|
||||
|
||||
for (_, playerMoves) in playerMovesByBase {
|
||||
for playerMove in playerMoves {
|
||||
for base in currentSnapshotModel!.baseEntites {
|
||||
@ -84,11 +84,22 @@ class RoundCalculatorService {
|
||||
|
||||
for base in currentSnapshotModel!.baseEntites {
|
||||
if base.baseId == playerMoveWithMaxUnits.value.toBase {
|
||||
base.unitCount += playerMoveWithMaxUnits.value.unitCount
|
||||
if playerMoveWithMaxUnits.value.unitCount == 0 {
|
||||
base.ownership = nil
|
||||
if base.ownership == nil {
|
||||
base.unitCount += playerMoveWithMaxUnits.value.unitCount
|
||||
if playerMoveWithMaxUnits.value.unitCount == 0 {
|
||||
base.ownership = nil
|
||||
} else {
|
||||
base.ownership = playerMoveWithMaxUnits.key
|
||||
}
|
||||
} else {
|
||||
base.ownership = playerMoveWithMaxUnits.key
|
||||
if base.unitCount < playerMoveWithMaxUnits.value.unitCount {
|
||||
base.unitCount = playerMoveWithMaxUnits.value.unitCount - base.unitCount
|
||||
base.ownership = playerMoveWithMaxUnits.key
|
||||
} else if (base.unitCount == playerMoveWithMaxUnits.value.unitCount) {
|
||||
base.ownership = nil
|
||||
} else {
|
||||
base.unitCount -= playerMoveWithMaxUnits.value.unitCount
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -96,7 +107,9 @@ class RoundCalculatorService {
|
||||
baseSpecificMoves.removeValue(forKey: baseId)
|
||||
}
|
||||
allPlayerMoves.removeAll()
|
||||
DataService.sharedInstance.localPlayerMoves.removeAll()
|
||||
MultiplayerNetwork.sharedInstance.sendSnapshotModelToPlayers()
|
||||
DataService.sharedInstance.snapshotModel = currentSnapshotModel
|
||||
EntityManager.sharedInstance.updateSnapshotModel(snapshotModel: currentSnapshotModel!)
|
||||
os_log("Finished calculating Round", log: RoundCalculatorService.LOG, type: .info)
|
||||
}
|
||||
|
@ -26,13 +26,11 @@ class GameScene: SKScene{
|
||||
}
|
||||
|
||||
func initMap() {
|
||||
|
||||
if (DataService.sharedInstance.gameHost?.playerName == GKLocalPlayer.local.displayName) {
|
||||
let mapModel = MapFactory(scene: self, entityManager: EntityManager.sharedInstance).loadMap()
|
||||
MultiplayerNetwork.sharedInstance.sendMapModelToPlayers(mapModel: mapModel)
|
||||
DataService.sharedInstance.setSnapshotModel(snapshotModel: EntityManager.sharedInstance.getSnapshotModel())
|
||||
}
|
||||
|
||||
DataService.sharedInstance.setSnapshotModel(snapshotModel: EntityManager.sharedInstance.getSnapshotModel())
|
||||
}
|
||||
|
||||
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||
|
Loading…
Reference in New Issue
Block a user