From d05364708b86f354ab49dfb0f23975f9e7c90ced Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Tue, 23 Jun 2020 20:52:27 +0200 Subject: [PATCH 1/2] Use player move type to update unit count label --- GoldWars/GoldWars/Entities/Base.swift | 4 +++- GoldWars/GoldWars/Entities/Modal.swift | 3 ++- GoldWars/GoldWars/Scenes/GameScene.swift | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/GoldWars/GoldWars/Entities/Base.swift b/GoldWars/GoldWars/Entities/Base.swift index 8f14a8b..87c6f8b 100644 --- a/GoldWars/GoldWars/Entities/Base.swift +++ b/GoldWars/GoldWars/Entities/Base.swift @@ -49,9 +49,11 @@ class Base: GKEntity{ self.unitCount -= units base.unitCount += units self.component(ofType: TeamComponent.self)?.unitcountLabel.text = "\(self.unitCount)" - if base.ownershipPlayer == GKLocalPlayer.local { + + if playerMoveType == .TxnMove { base.component(ofType: TeamComponent.self)?.unitcountLabel.text = "\(base.unitCount)" } + base.ownershipPlayer = self.ownershipPlayer DataService.sharedInstance.addMove(playerMove: PlayerMove(fromBase: self.baseID, toBase: base.baseID, diff --git a/GoldWars/GoldWars/Entities/Modal.swift b/GoldWars/GoldWars/Entities/Modal.swift index 7dcce67..412e736 100644 --- a/GoldWars/GoldWars/Entities/Modal.swift +++ b/GoldWars/GoldWars/Entities/Modal.swift @@ -109,10 +109,11 @@ class Modal: GKEntity{ } func sendUnits(currentDraggedBase: Base?, touchLocation: CGPoint, gameScene: GameScene, collisionBase: Base?){ + let moveType: PlayerMoveType = self.type == ModalType.BaseAttack ? .AtkMove : .TxnMove for base in currentDraggedBase!.adjacencyList { if base == collisionBase { RoundCalculatorService.sharedInstance.increaseMoveCounter(ownBase: currentDraggedBase?.ownershipPlayer == base.ownershipPlayer) - entityManager.update((currentDraggedBase?.doPlayerMoveTypeToBase(base: base, playerMoveType: PlayerMoveType.AtkMove, units: Int(GameScene.sendUnits)))!) + entityManager.update((currentDraggedBase?.doPlayerMoveTypeToBase(base: base, playerMoveType: moveType, units: Int(GameScene.sendUnits)))!) GameScene.sendUnits = 0 } } diff --git a/GoldWars/GoldWars/Scenes/GameScene.swift b/GoldWars/GoldWars/Scenes/GameScene.swift index 812e3fc..f4f431b 100644 --- a/GoldWars/GoldWars/Scenes/GameScene.swift +++ b/GoldWars/GoldWars/Scenes/GameScene.swift @@ -264,7 +264,7 @@ class GameScene: SKScene{ } func isAttackMove() -> Bool { - return collisionBase?.ownershipPlayer != currentDraggedBase?.ownershipPlayer + return collisionBase?.ownershipPlayer != currentDraggedBase?.ownershipPlayer && !(collisionBase?.changeOwnership ?? false) } @objc func pauseGame() -> Void { From 13bc1b46d5183824929b16e198ef1946c554e5fd Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Tue, 23 Jun 2020 20:52:55 +0200 Subject: [PATCH 2/2] Update base label only when was not empty before --- GoldWars/GoldWars/Entities/Base.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GoldWars/GoldWars/Entities/Base.swift b/GoldWars/GoldWars/Entities/Base.swift index 87c6f8b..ba1bbdc 100644 --- a/GoldWars/GoldWars/Entities/Base.swift +++ b/GoldWars/GoldWars/Entities/Base.swift @@ -50,7 +50,7 @@ class Base: GKEntity{ base.unitCount += units self.component(ofType: TeamComponent.self)?.unitcountLabel.text = "\(self.unitCount)" - if playerMoveType == .TxnMove { + if base.component(ofType: TeamComponent.self)?.unitcountLabel.text != "" { base.component(ofType: TeamComponent.self)?.unitcountLabel.text = "\(base.unitCount)" }