From 604001a36555f65c75f63a86436d3d556b4c541e Mon Sep 17 00:00:00 2001 From: Aldin Duraki Date: Wed, 20 May 2020 22:14:29 +0200 Subject: [PATCH 1/9] * Impl. a usecase of a fight scenario * Reset playermoves when necessary --- GoldWars/GoldWars/MultiplayerNetwork.swift | 2 +- .../GoldWars/RoundCalculatorService.swift | 23 +++++++++++++++---- GoldWars/GoldWars/Scenes/GameScene.swift | 4 +--- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/GoldWars/GoldWars/MultiplayerNetwork.swift b/GoldWars/GoldWars/MultiplayerNetwork.swift index 34cbccd..5cf2937 100644 --- a/GoldWars/GoldWars/MultiplayerNetwork.swift +++ b/GoldWars/GoldWars/MultiplayerNetwork.swift @@ -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() { diff --git a/GoldWars/GoldWars/RoundCalculatorService.swift b/GoldWars/GoldWars/RoundCalculatorService.swift index 3704ec8..fb403ac 100644 --- a/GoldWars/GoldWars/RoundCalculatorService.swift +++ b/GoldWars/GoldWars/RoundCalculatorService.swift @@ -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) } diff --git a/GoldWars/GoldWars/Scenes/GameScene.swift b/GoldWars/GoldWars/Scenes/GameScene.swift index 58a3d9d..be67b35 100644 --- a/GoldWars/GoldWars/Scenes/GameScene.swift +++ b/GoldWars/GoldWars/Scenes/GameScene.swift @@ -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, with event: UIEvent?) { From 458d50e4b3d40e188ddfad2996191d7ccad993ba Mon Sep 17 00:00:00 2001 From: Aldin Duraki Date: Wed, 20 May 2020 22:59:32 +0200 Subject: [PATCH 2/9] FIXME solved by extending the TeamComponent behavior --- .../GoldWars/Components/TeamComponent.swift | 27 ++++++++---- .../GoldWars/Entities/EntityManager.swift | 42 ++++++++++--------- 2 files changed, 40 insertions(+), 29 deletions(-) diff --git a/GoldWars/GoldWars/Components/TeamComponent.swift b/GoldWars/GoldWars/Components/TeamComponent.swift index db67deb..7fee0ae 100644 --- a/GoldWars/GoldWars/Components/TeamComponent.swift +++ b/GoldWars/GoldWars/Components/TeamComponent.swift @@ -14,7 +14,7 @@ class TeamComponent: GKComponent { var team: Team var player: GKPlayer let fire: SKEmitterNode - + init(team: Team, player: GKPlayer, position: CGPoint) { fire = SKEmitterNode(fileNamed: "Fire")! fire.zPosition = -1 @@ -22,21 +22,30 @@ class TeamComponent: GKComponent { fire.name = "fire" fire.particleColorSequence = nil fire.particleColorBlendFactor = 1.0 - - switch team { - case .team1: fire.particleColor = SKColor.red - case .team2: fire.particleColor = SKColor.purple - case .team3: fire.particleColor = SKColor.green - case .team4: fire.particleColor = SKColor.gray - } - + self.team = team self.player = player super.init() + fire.particleColor = getColor(by: team) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } + + func getColor(by team: Team) -> SKColor { + switch team { + case .team1: return SKColor.red + case .team2: return SKColor.purple + case .team3: return SKColor.green + case .team4: return SKColor.gray + } + } + + func change(to team: Team, to player: GKPlayer) -> Void { + self.team = team + self.player = player + self.fire.particleColor = getColor(by: team) + } } diff --git a/GoldWars/GoldWars/Entities/EntityManager.swift b/GoldWars/GoldWars/Entities/EntityManager.swift index cbeb114..264a064 100644 --- a/GoldWars/GoldWars/Entities/EntityManager.swift +++ b/GoldWars/GoldWars/Entities/EntityManager.swift @@ -119,17 +119,18 @@ class EntityManager { let base = (entity as! Base) if base.changeOwnership { - //FIX-ME: Find a way to update the Component without deleting it upfront - //TODO: outsource component handling to a generic function - //base.removeComponent(ofType: TeamComponent.self) - base.addComponent(TeamComponent( - team: (entities[0] as! Base).component(ofType: TeamComponent.self)!.team, - player: (entities[0] as! Base).component(ofType: TeamComponent.self)!.player, - position: (base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position)! + if (entity.component(ofType: TeamComponent.self) != nil) { + entity.component(ofType: TeamComponent.self)!.change(to: (entities[0] as! Base).component(ofType: TeamComponent.self)!.team, to: (entities[0] as! Base).component(ofType: TeamComponent.self)!.player) + } else { + base.addComponent(TeamComponent( + team: (entities[0] as! Base).component(ofType: TeamComponent.self)!.team, + player: (entities[0] as! Base).component(ofType: TeamComponent.self)!.player, + position: (base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position)! + ) ) - ) - if let fire = entity.component(ofType: TeamComponent.self)?.fire{ - scene.addChild(fire) + if let fire = entity.component(ofType: TeamComponent.self)?.fire{ + scene.addChild(fire) + } } base.changeOwnership = false } @@ -150,17 +151,18 @@ class EntityManager { if getOwnerBySnapBase != nil { base.changeOwnership = true base.ownershipPlayer = getOwnerBySnapBase - //FIX-ME: Find a way to update the Component without deleting it upfront - //TODO: outsource component handling to a generic function - //entity.removeComponent(ofType: TeamComponent.self) - entity.addComponent(TeamComponent( - team: getTeamByPlayer(playerName: snapBase.ownership!), - player: getOwnerBySnapBase!, - position: (entity.component(ofType: DefaultBaseComponent.self)?.spriteNode.position)! + if (entity.component(ofType: TeamComponent.self) != nil) { + entity.component(ofType: TeamComponent.self)!.change(to: getTeamByPlayer(playerName: snapBase.ownership!), to: getOwnerBySnapBase!) + } else { + entity.addComponent(TeamComponent( + team: getTeamByPlayer(playerName: snapBase.ownership!), + player: getOwnerBySnapBase!, + position: (entity.component(ofType: DefaultBaseComponent.self)?.spriteNode.position)! + ) ) - ) - if let fire = entity.component(ofType: TeamComponent.self)?.fire{ - scene.addChild(fire) + if let fire = entity.component(ofType: TeamComponent.self)?.fire{ + scene.addChild(fire) + } } } } From 5f7b12c28c79b8862982b2db68d020db9dee0a97 Mon Sep 17 00:00:00 2001 From: Aldin Duraki Date: Wed, 20 May 2020 23:20:05 +0200 Subject: [PATCH 3/9] * Changed slider behavior to not take MAX and 0 value as unit counts to send --- GoldWars/GoldWars/Components/AtkBoostSkillComponent.swift | 3 +-- GoldWars/GoldWars/Scenes/GameScene.swift | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/GoldWars/GoldWars/Components/AtkBoostSkillComponent.swift b/GoldWars/GoldWars/Components/AtkBoostSkillComponent.swift index 3f2e1c3..8829c19 100644 --- a/GoldWars/GoldWars/Components/AtkBoostSkillComponent.swift +++ b/GoldWars/GoldWars/Components/AtkBoostSkillComponent.swift @@ -25,8 +25,7 @@ class AtkBoostSkillComponent: GKComponent{ }else { base.unitType = .Attack } - } - }) + }}) super.init() } diff --git a/GoldWars/GoldWars/Scenes/GameScene.swift b/GoldWars/GoldWars/Scenes/GameScene.swift index be67b35..e4cf1a2 100644 --- a/GoldWars/GoldWars/Scenes/GameScene.swift +++ b/GoldWars/GoldWars/Scenes/GameScene.swift @@ -114,6 +114,13 @@ class GameScene: SKScene{ for e in EntityManager.sharedInstance.entities{ if let body = e.component(ofType: ModalContentComponent.self)?.body{ GameScene.sendUnits = ((e.component(ofType: SliderComponent.self)?.sliderNode.getValue ?? 0) * CGFloat((e as! Modal).unitCount)).rounded(.up) + + //TODO: refactor this quick and dirty fix + if GameScene.sendUnits == 0 { + GameScene.sendUnits = 1 + } else if Int(GameScene.sendUnits) == currentDraggedBase?.unitCount { + GameScene.sendUnits -= 1 + } body.text = "Schicke \(GameScene.sendUnits) Einheiten " } } From a8c42fa0b0eee0172491c95e2390a51578d516d8 Mon Sep 17 00:00:00 2001 From: Aldin Duraki Date: Wed, 20 May 2020 23:36:48 +0200 Subject: [PATCH 4/9] Fix slider min max unit values --- GoldWars/GoldWars/Entities/Modal.swift | 1 + GoldWars/GoldWars/Scenes/GameScene.swift | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/GoldWars/GoldWars/Entities/Modal.swift b/GoldWars/GoldWars/Entities/Modal.swift index c01999e..489aed4 100644 --- a/GoldWars/GoldWars/Entities/Modal.swift +++ b/GoldWars/GoldWars/Entities/Modal.swift @@ -58,6 +58,7 @@ class Modal: GKEntity{ for base in currentDraggedBase!.adjacencyList { if base == collisionBase { EntityManager.sharedInstance.update((currentDraggedBase?.doPlayerMoveTypeToBase(base: base, playerMoveType: PlayerMoveType.AtkMove, units: Int(GameScene.sendUnits)))!) + GameScene.sendUnits = 0 } } } diff --git a/GoldWars/GoldWars/Scenes/GameScene.swift b/GoldWars/GoldWars/Scenes/GameScene.swift index e4cf1a2..31eec3b 100644 --- a/GoldWars/GoldWars/Scenes/GameScene.swift +++ b/GoldWars/GoldWars/Scenes/GameScene.swift @@ -93,6 +93,7 @@ class GameScene: SKScene{ base: entity as! Base, anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), gameScene: self, currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, collisionBase: collisionBase)) + } } } @@ -106,6 +107,8 @@ class GameScene: SKScene{ base: currentDraggedBase!, anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), gameScene: self, currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, collisionBase: collisionBase)) + GameScene.sendUnits = CGFloat(currentDraggedBase!.unitCount / 2) + } } } @@ -115,7 +118,7 @@ class GameScene: SKScene{ if let body = e.component(ofType: ModalContentComponent.self)?.body{ GameScene.sendUnits = ((e.component(ofType: SliderComponent.self)?.sliderNode.getValue ?? 0) * CGFloat((e as! Modal).unitCount)).rounded(.up) - //TODO: refactor this quick and dirty fix + //TODO: quick fix chauntalle die olle mach augen auf if GameScene.sendUnits == 0 { GameScene.sendUnits = 1 } else if Int(GameScene.sendUnits) == currentDraggedBase?.unitCount { From 5df7fd3dac3dd18225dbf556448c8898f81b6d8e Mon Sep 17 00:00:00 2001 From: Aldin Duraki Date: Wed, 20 May 2020 23:46:40 +0200 Subject: [PATCH 5/9] TEST: playermoves not synched in same second --- GoldWars/GoldWars/Components/TimerComponent.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GoldWars/GoldWars/Components/TimerComponent.swift b/GoldWars/GoldWars/Components/TimerComponent.swift index 52c51b6..c91785c 100644 --- a/GoldWars/GoldWars/Components/TimerComponent.swift +++ b/GoldWars/GoldWars/Components/TimerComponent.swift @@ -31,7 +31,7 @@ class TimerComponent: GKComponent { func timeLeft() -> Int { let remainingSeconds = Int(endTime.timeIntervalSince(Date())) - if(remainingSeconds < 0 ){ + if(remainingSeconds < 0 && DataService.sharedInstance.didReceiveAllData()){ startWithDuration(duration: duration) } return remainingSeconds From ad44ba8302147eedacffaf940c4191ab8ad2c423 Mon Sep 17 00:00:00 2001 From: Aldin Duraki Date: Thu, 21 May 2020 00:29:19 +0200 Subject: [PATCH 6/9] Synching players timer since playermoves would not register before calculating --- .../GoldWars/Components/TimerComponent.swift | 17 +++++++++++++---- GoldWars/GoldWars/Entities/EntityManager.swift | 4 ++++ GoldWars/GoldWars/MatchmakingHelper.swift | 1 + GoldWars/GoldWars/RoundCalculatorService.swift | 2 ++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/GoldWars/GoldWars/Components/TimerComponent.swift b/GoldWars/GoldWars/Components/TimerComponent.swift index c91785c..3d2579c 100644 --- a/GoldWars/GoldWars/Components/TimerComponent.swift +++ b/GoldWars/GoldWars/Components/TimerComponent.swift @@ -13,6 +13,7 @@ class TimerComponent: GKComponent { let labelNode :SKLabelNode var endTime :Date! var duration :Double + var isRunning = false init(text: String, anchorPoint: CGPoint, duration: TimeInterval) { self.labelNode = SKLabelNode(text: text) @@ -25,16 +26,24 @@ class TimerComponent: GKComponent { } func startWithDuration(duration: TimeInterval){ + isRunning = true endTime = Date().addingTimeInterval(duration) RoundCalculatorService.sharedInstance.isCalculating = false } func timeLeft() -> Int { - let remainingSeconds = Int(endTime.timeIntervalSince(Date())) - if(remainingSeconds < 0 && DataService.sharedInstance.didReceiveAllData()){ - startWithDuration(duration: duration) + if isRunning { + let remainingSeconds = Int(endTime.timeIntervalSince(Date())) + if(remainingSeconds == 0) { + isRunning = false + } + return remainingSeconds } - return remainingSeconds + + // if(remainingSeconds < 0){ + // startWithDuration(duration: duration) + // } + return 0 } func isFinished() -> Bool { diff --git a/GoldWars/GoldWars/Entities/EntityManager.swift b/GoldWars/GoldWars/Entities/EntityManager.swift index 264a064..f18dcf4 100644 --- a/GoldWars/GoldWars/Entities/EntityManager.swift +++ b/GoldWars/GoldWars/Entities/EntityManager.swift @@ -259,4 +259,8 @@ class EntityManager { return SnapshotModel(baseEntites: snapBase) } + + func getTimer() -> TimerComponent { + return entities.filter{$0 is HUD}[0].component(ofType: TimerComponent.self)! + } } diff --git a/GoldWars/GoldWars/MatchmakingHelper.swift b/GoldWars/GoldWars/MatchmakingHelper.swift index 5e09ed6..60dc5d2 100644 --- a/GoldWars/GoldWars/MatchmakingHelper.swift +++ b/GoldWars/GoldWars/MatchmakingHelper.swift @@ -120,6 +120,7 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe if let snapshotModel = try? jsonDecoder.decode(SnapshotModel.self, from: data) { DataService.sharedInstance.snapshotModel = snapshotModel EntityManager.sharedInstance.updateSnapshotModel(snapshotModel: snapshotModel) + EntityManager.sharedInstance.getTimer().startWithDuration(duration: 31) } if let mapModel = try? jsonDecoder.decode(MapGenerationModel.self, from: data) { diff --git a/GoldWars/GoldWars/RoundCalculatorService.swift b/GoldWars/GoldWars/RoundCalculatorService.swift index fb403ac..b9186c6 100644 --- a/GoldWars/GoldWars/RoundCalculatorService.swift +++ b/GoldWars/GoldWars/RoundCalculatorService.swift @@ -111,6 +111,8 @@ class RoundCalculatorService { MultiplayerNetwork.sharedInstance.sendSnapshotModelToPlayers() DataService.sharedInstance.snapshotModel = currentSnapshotModel EntityManager.sharedInstance.updateSnapshotModel(snapshotModel: currentSnapshotModel!) + sleep(1) + EntityManager.sharedInstance.getTimer().startWithDuration(duration: 31) os_log("Finished calculating Round", log: RoundCalculatorService.LOG, type: .info) } From 9fd34d9a6cb0fd36f5728c689a21bbdfce4f792c Mon Sep 17 00:00:00 2001 From: Aldin Duraki Date: Thu, 21 May 2020 02:44:38 +0200 Subject: [PATCH 7/9] Minor fixes --- GoldWars/GoldWars/Entities/Base.swift | 5 +- .../GoldWars/Entities/EntityManager.swift | 9 ++-- .../GoldWars/RoundCalculatorService.swift | 1 - GoldWars/GoldWars/Scenes/GameScene.swift | 48 ++++++++++--------- 4 files changed, 33 insertions(+), 30 deletions(-) diff --git a/GoldWars/GoldWars/Entities/Base.swift b/GoldWars/GoldWars/Entities/Base.swift index 4f695c9..0749085 100644 --- a/GoldWars/GoldWars/Entities/Base.swift +++ b/GoldWars/GoldWars/Entities/Base.swift @@ -31,9 +31,10 @@ class Base: GKEntity{ self.position = position super.init() - addComponent(DefaultBaseComponent(texture: SKTexture(imageNamed: "Base"), position: position)) + let spritePos = position + addComponent(DefaultBaseComponent(texture: SKTexture(imageNamed: "Base"), position: spritePos)) if(team != nil && player != nil){ - addComponent(TeamComponent(team: team!, player: player!, position: position)) + addComponent(TeamComponent(team: team!, player: player!, position: spritePos)) self.unitCount = 500 } } diff --git a/GoldWars/GoldWars/Entities/EntityManager.swift b/GoldWars/GoldWars/Entities/EntityManager.swift index f18dcf4..3cfafa7 100644 --- a/GoldWars/GoldWars/Entities/EntityManager.swift +++ b/GoldWars/GoldWars/Entities/EntityManager.swift @@ -43,10 +43,10 @@ class EntityManager { scene.addChild(modal.header) scene.addChild(modal.body) scene.addChild(modal.footer) + isModal = true } if let skillButtonNode = entity.component(ofType: AtkBoostSkillComponent.self)?.skillButtonNode { scene.addChild(skillButtonNode) - isModal = true } if let skillButtonNode = entity.component(ofType: DefBoostSkillComponent.self)?.skillButtonNode { scene.addChild(skillButtonNode) @@ -60,7 +60,6 @@ class EntityManager { } if let buttonNode = entity.component(ofType: ButtonComponent.self)?.buttonNode { scene.addChild(buttonNode) - isModal = true } if let nodes = entity.component(ofType: BackgroundComponent.self)?.nodes { for node in nodes { @@ -76,7 +75,6 @@ class EntityManager { } if let cancelBtnNode = entity.component(ofType: CancelBtnComponent.self)?.cancelBtnNode { scene.addChild(cancelBtnNode) - isModal = true } if let node = entity.component(ofType: SpinningLogoComponent.self)?.node { scene.addChild(node) @@ -97,6 +95,7 @@ class EntityManager { modal.header.removeFromParent() modal.body.removeFromParent() modal.footer.removeFromParent() + isModal = false } if let sliderNode = entity.component(ofType: SliderComponent.self)?.sliderNode { sliderNode.sliderKnob.removeFromParent() @@ -104,11 +103,9 @@ class EntityManager { } if let modalButton = entity.component(ofType: ButtonComponent.self) { modalButton.buttonNode.removeFromParent() - isModal = false } if let cancelBtnNode = entity.component(ofType: CancelBtnComponent.self)?.cancelBtnNode { cancelBtnNode.removeFromParent() - isModal = false } entities.remove(entity) } @@ -147,6 +144,8 @@ class EntityManager { if snapBase.ownership != nil { getOwnerBySnapBase = MatchmakingHelper.sharedInstance.getGKPlayerByUsername(displayName: snapBase.ownership!) + } else { + entity.removeComponent(ofType: TeamComponent.self) } if getOwnerBySnapBase != nil { base.changeOwnership = true diff --git a/GoldWars/GoldWars/RoundCalculatorService.swift b/GoldWars/GoldWars/RoundCalculatorService.swift index b9186c6..a07fa2f 100644 --- a/GoldWars/GoldWars/RoundCalculatorService.swift +++ b/GoldWars/GoldWars/RoundCalculatorService.swift @@ -111,7 +111,6 @@ class RoundCalculatorService { MultiplayerNetwork.sharedInstance.sendSnapshotModelToPlayers() DataService.sharedInstance.snapshotModel = currentSnapshotModel EntityManager.sharedInstance.updateSnapshotModel(snapshotModel: currentSnapshotModel!) - sleep(1) EntityManager.sharedInstance.getTimer().startWithDuration(duration: 31) os_log("Finished calculating Round", log: RoundCalculatorService.LOG, type: .info) } diff --git a/GoldWars/GoldWars/Scenes/GameScene.swift b/GoldWars/GoldWars/Scenes/GameScene.swift index 31eec3b..962fe46 100644 --- a/GoldWars/GoldWars/Scenes/GameScene.swift +++ b/GoldWars/GoldWars/Scenes/GameScene.swift @@ -13,7 +13,6 @@ import GameKit class GameScene: SKScene{ var isMoveTouch = false - var currentDraggedBasePos = CGPoint() var currentDraggedBase : Base? static var sendUnits: CGFloat = 0 var collisionBase: Base? @@ -42,8 +41,8 @@ class GameScene: SKScene{ if isMoveTouch{ isMoveTouch = false - currentDraggedBase!.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = currentDraggedBasePos - currentDraggedBase!.component(ofType: TeamComponent.self)?.fire.position = currentDraggedBasePos + currentDraggedBase!.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = currentDraggedBase!.position + currentDraggedBase!.component(ofType: TeamComponent.self)?.fire.position = currentDraggedBase!.position addAttackDetails(touchLocation: touchLocation) } @@ -51,6 +50,7 @@ class GameScene: SKScene{ for entity in EntityManager.sharedInstance.entities { let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode + //FIXME: this is confusing addBaseDetails(touchLocation: touchLocation, spriteNode: spriteNode, touches: touches, event: event, entity: entity) } } @@ -83,17 +83,20 @@ class GameScene: SKScene{ func addBaseDetails(touchLocation: CGPoint, spriteNode: SKNode?, touches: Set, event: UIEvent?, entity: GKEntity){ if atPoint(touchLocation) == spriteNode && !EntityManager.sharedInstance.isModal { spriteNode?.touchesBegan(touches, with: event) - if !EntityManager.sharedInstance.isModal { - for child in self.children { - if(child.name != "fire"){ - child.alpha = 0.3 + if let baseEntity = entity as? Base { + if baseEntity.ownershipPlayer == GKLocalPlayer.local { + for child in self.children { + if(child.name != "fire"){ + child.alpha = 0.3 + } } + EntityManager.sharedInstance.add(Modal(modaltype: .BaseDetails, + base: entity as! Base, + anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), + gameScene: self, + currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, collisionBase: collisionBase)) + } - EntityManager.sharedInstance.add(Modal(modaltype: .BaseDetails, - base: entity as! Base, - anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), - gameScene: self, currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, collisionBase: collisionBase)) - } } } @@ -103,12 +106,13 @@ class GameScene: SKScene{ if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode { collisionBase = base // TODO: change interaction based on collision instead of touchlocation - EntityManager.sharedInstance.add(Modal(modaltype: .BaseAttack, - base: currentDraggedBase!, - anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), - gameScene: self, currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, collisionBase: collisionBase)) - GameScene.sendUnits = CGFloat(currentDraggedBase!.unitCount / 2) - + if currentDraggedBase!.unitCount > 1 { + EntityManager.sharedInstance.add(Modal(modaltype: .BaseAttack, + base: currentDraggedBase!, + anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), + gameScene: self, currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, collisionBase: collisionBase)) + GameScene.sendUnits = CGFloat(currentDraggedBase!.unitCount / 2) + } } } } @@ -118,7 +122,7 @@ class GameScene: SKScene{ if let body = e.component(ofType: ModalContentComponent.self)?.body{ GameScene.sendUnits = ((e.component(ofType: SliderComponent.self)?.sliderNode.getValue ?? 0) * CGFloat((e as! Modal).unitCount)).rounded(.up) - //TODO: quick fix chauntalle die olle mach augen auf + //TODO: refactor this quick and dirty fix if GameScene.sendUnits == 0 { GameScene.sendUnits = 1 } else if Int(GameScene.sendUnits) == currentDraggedBase?.unitCount { @@ -131,9 +135,9 @@ class GameScene: SKScene{ func checkBases(bases: Set, touchLocation: CGPoint){ for base in bases { - if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode{ if !isMoveTouch { - currentDraggedBasePos = base.component(ofType: DefaultBaseComponent.self)!.spriteNode.position - currentDraggedBase = base + if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode{ + if !isMoveTouch { + currentDraggedBase = base } isMoveTouch = true moveFireAndBase(base: base, touchLocation: touchLocation) From 8e22f02c7a02caa0f6b1e3705ee4d317c2624963 Mon Sep 17 00:00:00 2001 From: Aldin Duraki Date: Thu, 21 May 2020 03:18:07 +0200 Subject: [PATCH 8/9] * Impl. debugging move on MapGeneration * Changed fire particle with master designer niko von jochim --- GoldWars/GoldWars/Partikels/Fire.sks | Bin 7975 -> 7929 bytes GoldWars/GoldWars/Scenes/GameScene.swift | 3 +++ 2 files changed, 3 insertions(+) diff --git a/GoldWars/GoldWars/Partikels/Fire.sks b/GoldWars/GoldWars/Partikels/Fire.sks index f25e78f0519eda7cf34d37d2aaf74a2bb8d5574a..1f31d2ee246501b8f420929f38872eb5d147ae58 100644 GIT binary patch delta 2264 zcmZux4Rln+6~1?O-<$X5En(%fW#4-clPrXU1k7ePi3vZ81S~coh#N=rO(@F&;~JK+QP5cb0XI0Q%G z7#xRd@HyOoui$IA4d1~XxC{5--)KTJ)Sv~e_zN6}4jhC@n1X5O!iRAbj>X?#9!|n3 zSdKodz}e`>N}PjFB33tjzAsb;bNHQA5a6_w&uW+pHBie}0hq^W#G}&Qy$^z18i1z_ z?a0apjqt3YRnDmo7IXaoFk>CX1MmWuya-F79A1W3U>Ucy+&H-sUWF#gRe#U7r4ZOT z%yiE(-g66#;TWUF-<`#mOmsvg01nTdHEWt9GRfgN5nVdQgvJ=S!}I5@1G@RrF~$>a zAOl^Du)Yjf9G}2!1_c)DI2h64gNe2X;OGSsI8P5>AP-`E_%6|u)sPQsxW{W@T{uok zBpaX^TA(#NQHpi9KwEKvcarZ(e?_npHo==*cQd>NZx=9h3@XTbAYU<;F5 zU~71Tl$0D%d>6JgGo=F}2H%4n{KzBq_2mt%eA5<{w!{13TarE04!fXjMuB%+pduKk zt1Yi@=rFF@4SSkdOjLI->?K21oZdBYUPYp|~;Aof?{P6QY8~NHth26Q(vgQ{$YAj3^Kgr+M=V{m%p!)cacz zcyWHRT-2DB8aFI$(ODEAA4Mc6p^OyP!8%l?mIVVf{`qCLer17L9{aqyx#f{OPpk{C zQ2OUQ#GGu9kwokRdp2PV_C*^$fc@BDHk75ZVQe^yIg7uQ+vuu{bMuxNWg?UCxVU^KR zBbZQTOKnUWp5{z^h{@l+ZE}b;m!=FJ3Bku>2hT|-5KumtVNxXvh(cD zh3mZF-|I=CWRO6G1V{xZGrws*Y(8baY`$qRTVgD#CDG!s6k94R)s~Ru zB}=Pio8^GzjOCK$j$jdDg%rUR67q!#;VFR$D}>F$9^trfR=6PC76nlk-Qo!GF>$gu zORN!@_>$Npt`WD0yTlV>r`Rpt5WgcPl1P$>ljM+*WIQP#kCSP{N2*DX{FXdJ7Lw=5 z60(%MOqP-5WF=`LVe&`v8d*culJ#T*X(3xl=pFJd*-mzlcCw4?CLfZ0ZFCz zA}J(2C%quOC~cA6lXgh$(thcvbW-Y+zL0K7Kgyy^WLfSf$ID3}IayAZU2=vzR?d~j z$&bpD>ZBL1)r3I*a<~ zY+6aHXn)^XNH ztrM(MtR>c2R-bjYwbH)BzSn--e%gNCe%bz|{g#TVtXkC=)uyVdt`1bw)k1Z?xF&`#V Olw)m__fj+HKmG?Kad7Ma delta 2263 zcmZ7#3v^V)_1^uwnK!c}D}greJw8h|#1InLkllnRBw#=f1s5bpASfY$4Qvca3@a5v z+~KE|gEV#R2Z1IbA$$}mVvAN9B8NW(gn$S=B5GBrQoxd05T&zkQE6w++nj+Dq${ELA9hR;7JK5EB`^F-%s zU>vNK$^0G~BUYM1)4_VKnt+Z2D{__B(?%upw6g3VHQ3%m-i75NJXJrP(i zuUO)0Q#`L3UJ+_DY>h0Tso|*Nc6hx>@RJaA_y+t@nvATiEnTo)UfN>Zo$zLfGr?c@ z@Kd4EvdX}y;LK34x~jBxK@04Jx1jAYf8me3lV?&&`mo4#A1J?fo? zW6FC>rY6xnX8jf%S|1Jac;VR5bAzE!pw?eKEAXMy34ev7a14&ayKn+d z%0xQh6r6_l;0(MEXW^V2;|}-$&YQRqK9cwo+4E23>41xHskkH<*`yxjUz&xzEDL)j zB3Q5fvHMriyU>JvN?o=$-IeXF?}UGwnqN!FjmSGJC45&)giY8xA;!2J?UCps?33#< z(_NYMW*%ro+tk9blLAkNo~jM3M=P`y*ZF*dvVG|;U;Ph3it0S+t_)B8X;fhxGUVvM zZWsrR(1`JqOG3f9fq5m)?j^yhP#`jmC*9`}LqvbGjCc?1+JN0L0efIi{E0{r14V`y zBnFGP)2N}22KJIZdt)Ezt1r4DJNc@9_lmSmOhUI5Bx8R}ndC1VGwM+Z3JRP=q>2GM z${l`3Sk49xz%<$Dg6hiZ+QORBnKFlgX6t|C#1hTGL2`yn?t09Cwo~Z26FL)a;1G04 zY0;cuDDZ#>M7l^jiAgfL4^x~LG2rf(4#nKqOUFmDw2_JOsdr0kHOR*1gta)=#b1Y<8Q|X4q0~BW=aDfNidAv2BH|)wbQ% zVLNI2$ad4N*j@GvyU*^o2ki6gOY9By&GxtLhwW$VAK0%eMCq+$hn3;VSfx-YQ>v9E z$_gc-tWmZoZz@NW)5^!n73Bu8kyMgKvdA!!M;;;*$V4)Y%p!Bid=e&$$x^bMtRfBM zMe-8)4QV9Jq=jrC8_8z!3fW4wk?mv$*+tsP0dj~OAxFt^a)NY{)8q^}Oa4awPQss& zi{u*l7wIBjlN;n4@-4YdDP`0_<7fhP(R7+abLstbI2}bFrc-Ds4bm$5bGnSKq`##v z)3vmbHq#cmj~=7P=?Qv{eoQ~7S5-yrrs}F&O;%IX!D^m5T76I*uTD@WswL_SwN#y{ zR;o{`;jp?#J*vL1o>woa*VS8$vjod(Qd!DUe4Qw6T#I~?k*=uYk+spQ|gX{!5&n~eq*kyKwTX;ObhbM3sPvXgZAoub- zUcmjlh?npXujAnczLvN0Hol2(;X8Oc@8Em*UcR3njiq5K1(mxtM!HYBK?^vUFb{nW%{%FFZJK)TlLrV1NyuAdHr*}OTT4M zqo>iwa2ZKPvXNp8HZqMY!)N3exyD4J+*oEb8*RomW0%oxbQqV7o4xwUA1Rl`62n*< K!{5VR?*9VN;C1-` diff --git a/GoldWars/GoldWars/Scenes/GameScene.swift b/GoldWars/GoldWars/Scenes/GameScene.swift index 962fe46..8a967a0 100644 --- a/GoldWars/GoldWars/Scenes/GameScene.swift +++ b/GoldWars/GoldWars/Scenes/GameScene.swift @@ -30,6 +30,9 @@ class GameScene: SKScene{ MultiplayerNetwork.sharedInstance.sendMapModelToPlayers(mapModel: mapModel) DataService.sharedInstance.setSnapshotModel(snapshotModel: EntityManager.sharedInstance.getSnapshotModel()) } + if CommandLine.arguments.contains("--no-matchmaking") { + MapFactory(scene: self, entityManager: EntityManager.sharedInstance).loadMap() + } } override func touchesEnded(_ touches: Set, with event: UIEvent?) { From 841bda9d9b30c5ff75b9cdb7a1a6a32883b9c520 Mon Sep 17 00:00:00 2001 From: Aldin Duraki Date: Thu, 21 May 2020 15:48:32 +0200 Subject: [PATCH 9/9] Readded sleep --- GoldWars/GoldWars/RoundCalculatorService.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/GoldWars/GoldWars/RoundCalculatorService.swift b/GoldWars/GoldWars/RoundCalculatorService.swift index a07fa2f..b9186c6 100644 --- a/GoldWars/GoldWars/RoundCalculatorService.swift +++ b/GoldWars/GoldWars/RoundCalculatorService.swift @@ -111,6 +111,7 @@ class RoundCalculatorService { MultiplayerNetwork.sharedInstance.sendSnapshotModelToPlayers() DataService.sharedInstance.snapshotModel = currentSnapshotModel EntityManager.sharedInstance.updateSnapshotModel(snapshotModel: currentSnapshotModel!) + sleep(1) EntityManager.sharedInstance.getTimer().startWithDuration(duration: 31) os_log("Finished calculating Round", log: RoundCalculatorService.LOG, type: .info) }