From 2ac82e5159d249eee3494d7e8077b42a0060294f Mon Sep 17 00:00:00 2001 From: Aldin Duraki Date: Wed, 20 May 2020 01:41:48 +0200 Subject: [PATCH] * Minor fixes * Open up calculator service --- GoldWars/GoldWars.xcodeproj/project.pbxproj | 4 --- .../GoldWars/Components/TimerComponent.swift | 1 + GoldWars/GoldWars/MultiplayerNetwork.swift | 1 + .../GoldWars/RoundCalculatorService.swift | 34 ++++++++++--------- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/GoldWars/GoldWars.xcodeproj/project.pbxproj b/GoldWars/GoldWars.xcodeproj/project.pbxproj index bc36494..58ae06f 100644 --- a/GoldWars/GoldWars.xcodeproj/project.pbxproj +++ b/GoldWars/GoldWars.xcodeproj/project.pbxproj @@ -21,7 +21,6 @@ 3EBD242C245D8044003CECE7 /* GameCenterHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EBD242B245D8044003CECE7 /* GameCenterHelper.swift */; }; 3EBD242E245D9332003CECE7 /* Team.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EBD242D245D9332003CECE7 /* Team.swift */; }; 3F745DF0246F48FC00CE7375 /* PlayerMoveType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F745DEF246F48FC00CE7375 /* PlayerMoveType.swift */; }; - 3FE19DB3246C690B004827AB /* RoundSimulatorService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FE19DB2246C690B004827AB /* RoundSimulatorService.swift */; }; 3FE19DB5246C7A22004827AB /* RoundCalculatorService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FE19DB4246C7A22004827AB /* RoundCalculatorService.swift */; }; 9E04AFAF245E2B73002D5CFC /* AttackActionComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E04AFAE245E2B73002D5CFC /* AttackActionComponent.swift */; }; 9E11FF79245CD81100EED3BE /* Fire.sks in Resources */ = {isa = PBXBuildFile; fileRef = 9E11FF77245CD81100EED3BE /* Fire.sks */; }; @@ -92,7 +91,6 @@ 3EBD242B245D8044003CECE7 /* GameCenterHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameCenterHelper.swift; sourceTree = ""; }; 3EBD242D245D9332003CECE7 /* Team.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Team.swift; sourceTree = ""; }; 3F745DEF246F48FC00CE7375 /* PlayerMoveType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerMoveType.swift; sourceTree = ""; }; - 3FE19DB2246C690B004827AB /* RoundSimulatorService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoundSimulatorService.swift; sourceTree = ""; }; 3FE19DB4246C7A22004827AB /* RoundCalculatorService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoundCalculatorService.swift; sourceTree = ""; }; 9E04AFAE245E2B73002D5CFC /* AttackActionComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttackActionComponent.swift; sourceTree = ""; }; 9E11FF77245CD81100EED3BE /* Fire.sks */ = {isa = PBXFileReference; lastKnownFileType = file.sks; path = Fire.sks; sourceTree = ""; }; @@ -283,7 +281,6 @@ children = ( 110360DC244B101A008610AF /* Main.storyboard */, 110360E1244B101B008610AF /* LaunchScreen.storyboard */, - 3FE19DB2246C690B004827AB /* RoundSimulatorService.swift */, ); path = Storyboards; sourceTree = ""; @@ -421,7 +418,6 @@ 9E04AFAF245E2B73002D5CFC /* AttackActionComponent.swift in Sources */, 110360D9244B101A008610AF /* GameScene.swift in Sources */, C04783F024685995004961FB /* SettingsScene.swift in Sources */, - 3FE19DB3246C690B004827AB /* RoundSimulatorService.swift in Sources */, 116060F7245C57D2004E5A36 /* EntityManager.swift in Sources */, C064E9AA246C114C0022B228 /* LabelComponent.swift in Sources */, 3EBD242E245D9332003CECE7 /* Team.swift in Sources */, diff --git a/GoldWars/GoldWars/Components/TimerComponent.swift b/GoldWars/GoldWars/Components/TimerComponent.swift index 0ed4e63..52c51b6 100644 --- a/GoldWars/GoldWars/Components/TimerComponent.swift +++ b/GoldWars/GoldWars/Components/TimerComponent.swift @@ -26,6 +26,7 @@ class TimerComponent: GKComponent { func startWithDuration(duration: TimeInterval){ endTime = Date().addingTimeInterval(duration) + RoundCalculatorService.sharedInstance.isCalculating = false } func timeLeft() -> Int { diff --git a/GoldWars/GoldWars/MultiplayerNetwork.swift b/GoldWars/GoldWars/MultiplayerNetwork.swift index 32926d2..7ffbc37 100644 --- a/GoldWars/GoldWars/MultiplayerNetwork.swift +++ b/GoldWars/GoldWars/MultiplayerNetwork.swift @@ -46,6 +46,7 @@ class MultiplayerNetwork{ let encoded = (try? encoder.encode(playerMoves))! sendDataToHost(data: encoded) } + DataService.sharedInstance.localPlayerMoves.removeAll() } func sendHostIdentifier() { diff --git a/GoldWars/GoldWars/RoundCalculatorService.swift b/GoldWars/GoldWars/RoundCalculatorService.swift index 4b92575..3704ec8 100644 --- a/GoldWars/GoldWars/RoundCalculatorService.swift +++ b/GoldWars/GoldWars/RoundCalculatorService.swift @@ -73,27 +73,29 @@ class RoundCalculatorService { combinePotentionalForces[playerMoves.key]!.unitCount += move.unitCount } } - - let sortedPotentionalCombinedForces = combinePotentionalForces.sorted { $0.1.unitCount > $1.1.unitCount } - - var playerMoveWithMaxUnits = sortedPotentionalCombinedForces[0] - if playerMovesByBase.count >= 2 { - let playerMoveWithSecMaxUnits = sortedPotentionalCombinedForces[1] - playerMoveWithMaxUnits.value.unitCount -= playerMoveWithSecMaxUnits.value.unitCount - } - - for base in currentSnapshotModel!.baseEntites { - if base.baseId == playerMoveWithMaxUnits.value.toBase { - base.unitCount += playerMoveWithMaxUnits.value.unitCount - if playerMoveWithMaxUnits.value.unitCount == 0 { - base.ownership = nil - } else { - base.ownership = playerMoveWithMaxUnits.key + if(combinePotentionalForces.count > 0) { + let sortedPotentionalCombinedForces = combinePotentionalForces.sorted { $0.1.unitCount > $1.1.unitCount } + + var playerMoveWithMaxUnits = sortedPotentionalCombinedForces[0] + if playerMovesByBase.count >= 2 { + let playerMoveWithSecMaxUnits = sortedPotentionalCombinedForces[1] + playerMoveWithMaxUnits.value.unitCount -= playerMoveWithSecMaxUnits.value.unitCount + } + + for base in currentSnapshotModel!.baseEntites { + if base.baseId == playerMoveWithMaxUnits.value.toBase { + base.unitCount += playerMoveWithMaxUnits.value.unitCount + if playerMoveWithMaxUnits.value.unitCount == 0 { + base.ownership = nil + } else { + base.ownership = playerMoveWithMaxUnits.key + } } } } baseSpecificMoves.removeValue(forKey: baseId) } + allPlayerMoves.removeAll() MultiplayerNetwork.sharedInstance.sendSnapshotModelToPlayers() EntityManager.sharedInstance.updateSnapshotModel(snapshotModel: currentSnapshotModel!) os_log("Finished calculating Round", log: RoundCalculatorService.LOG, type: .info)