From 6b1d0eac1258ddbda4e379dca0e275b9ec2cf6dc Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Sun, 31 May 2020 19:04:58 +0200 Subject: [PATCH] Add atk and def boost to PlayerMove struct --- GoldWars/GoldWars/DataService.swift | 4 +++- GoldWars/GoldWars/Entities/Base.swift | 4 +++- GoldWars/GoldWars/RoundCalculatorService.swift | 15 +++++++++------ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/GoldWars/GoldWars/DataService.swift b/GoldWars/GoldWars/DataService.swift index cba4f4d..f3a5591 100644 --- a/GoldWars/GoldWars/DataService.swift +++ b/GoldWars/GoldWars/DataService.swift @@ -6,10 +6,12 @@ // Copyright © 2020 SP2. All rights reserved. // -struct PlayerMove: Codable{ +struct PlayerMove: Codable { let fromBase: Int let toBase: Int var unitCount: Int + let hasDefenceBoost: Bool + let hasAttackBoost: Bool } class SnapshotModel: Codable { diff --git a/GoldWars/GoldWars/Entities/Base.swift b/GoldWars/GoldWars/Entities/Base.swift index 947a6c2..2611b78 100644 --- a/GoldWars/GoldWars/Entities/Base.swift +++ b/GoldWars/GoldWars/Entities/Base.swift @@ -53,7 +53,9 @@ class Base: GKEntity{ base.component(ofType: DefaultBaseComponent.self)?.labelNode.text = "\(base.unitCount)" DataService.sharedInstance.addMove(playerMove: PlayerMove(fromBase: self.baseID, toBase: base.baseID, - unitCount: units * playerMoveType.rawValue)) + unitCount: units * playerMoveType.rawValue, + hasDefenceBoost: base.hasAttackBoost, + hasAttackBoost: base.hasDefenseBoost)) return [self, base] } diff --git a/GoldWars/GoldWars/RoundCalculatorService.swift b/GoldWars/GoldWars/RoundCalculatorService.swift index d495681..2a75942 100644 --- a/GoldWars/GoldWars/RoundCalculatorService.swift +++ b/GoldWars/GoldWars/RoundCalculatorService.swift @@ -59,11 +59,18 @@ class RoundCalculatorService { var combinePotentionalForces: [String: PlayerMove] = [:] for playerMoves in playerMovesByBase { - combinePotentionalForces[playerMoves.key] = PlayerMove(fromBase: playerMoves.value[0].fromBase, toBase: playerMoves.value[0].toBase, unitCount: 0) + combinePotentionalForces[playerMoves.key] = PlayerMove( + fromBase: playerMoves.value[0].fromBase, + toBase: playerMoves.value[0].toBase, + unitCount: 0, + hasDefenceBoost: playerMoves.value[0].hasDefenceBoost, + hasAttackBoost: playerMoves.value[0].hasDefenceBoost + ) for move in playerMoves.value { combinePotentionalForces[playerMoves.key]!.unitCount += move.unitCount } } + if(combinePotentionalForces.count > 0) { let sortedPotentionalCombinedForces = combinePotentionalForces.sorted { $0.1.unitCount > $1.1.unitCount } @@ -77,11 +84,7 @@ class RoundCalculatorService { if base.baseId == playerMoveWithMaxUnits.value.toBase { if base.ownership == nil { base.unitCount += playerMoveWithMaxUnits.value.unitCount - if playerMoveWithMaxUnits.value.unitCount == 0 { - base.ownership = nil - } else { - base.ownership = playerMoveWithMaxUnits.key - } + base.ownership = playerMoveWithMaxUnits.value.unitCount == 0 ? nil : playerMoveWithMaxUnits.key } else { if base.unitCount < playerMoveWithMaxUnits.value.unitCount { base.unitCount = playerMoveWithMaxUnits.value.unitCount - base.unitCount