diff --git a/GoldWars/GoldWars/RoundCalculatorService.swift b/GoldWars/GoldWars/RoundCalculatorService.swift index c8ac29b..6397894 100644 --- a/GoldWars/GoldWars/RoundCalculatorService.swift +++ b/GoldWars/GoldWars/RoundCalculatorService.swift @@ -125,6 +125,27 @@ class RoundCalculatorService { DataService.sharedInstance.localRoundData.localPlayerMoves.removeAll() DataService.sharedInstance.localRoundData.hasAttackBoost = false DataService.sharedInstance.localRoundData.hasDefenceBoost = false + var player1BaseCount = 0; + var player2BaseCount = 0; + let player1 = Array(allPlayerMoves)[0].key + let player2 = Array(allPlayerMoves)[1].key + for baseEntry in currentSnapshotModel!.baseEntites { + if baseEntry.ownership == player1 { + player1BaseCount += 1 + } else if baseEntry.ownership == player2 { + player2BaseCount += 1 + } + } + currentSnapshotModel?.baseEntites = currentSnapshotModel!.baseEntites.map { (BaseEntityModel) -> BaseEntityModel in + if BaseEntityModel.ownership == player1 { + BaseEntityModel.unitCount += lround(Double(player1BaseCount / 2)) + } else if BaseEntityModel.ownership == player2 { + BaseEntityModel.unitCount += lround(Double(player2BaseCount / 2)) + } + return BaseEntityModel + } + allPlayerMoves.removeAll() + DataService.sharedInstance.localPlayerMoves.removeAll() MultiplayerNetwork.sharedInstance.sendSnapshotModelToPlayers() DataService.sharedInstance.snapshotModel = currentSnapshotModel entityManager.updateSnapshotModel(snapshotModel: currentSnapshotModel!)