Add atk and def boost to PlayerMove struct
This commit is contained in:
parent
0d20cc6716
commit
6b1d0eac12
@ -6,10 +6,12 @@
|
|||||||
// Copyright © 2020 SP2. All rights reserved.
|
// Copyright © 2020 SP2. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
struct PlayerMove: Codable{
|
struct PlayerMove: Codable {
|
||||||
let fromBase: Int
|
let fromBase: Int
|
||||||
let toBase: Int
|
let toBase: Int
|
||||||
var unitCount: Int
|
var unitCount: Int
|
||||||
|
let hasDefenceBoost: Bool
|
||||||
|
let hasAttackBoost: Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
class SnapshotModel: Codable {
|
class SnapshotModel: Codable {
|
||||||
|
@ -53,7 +53,9 @@ class Base: GKEntity{
|
|||||||
base.component(ofType: DefaultBaseComponent.self)?.labelNode.text = "\(base.unitCount)"
|
base.component(ofType: DefaultBaseComponent.self)?.labelNode.text = "\(base.unitCount)"
|
||||||
DataService.sharedInstance.addMove(playerMove: PlayerMove(fromBase: self.baseID,
|
DataService.sharedInstance.addMove(playerMove: PlayerMove(fromBase: self.baseID,
|
||||||
toBase: base.baseID,
|
toBase: base.baseID,
|
||||||
unitCount: units * playerMoveType.rawValue))
|
unitCount: units * playerMoveType.rawValue,
|
||||||
|
hasDefenceBoost: base.hasAttackBoost,
|
||||||
|
hasAttackBoost: base.hasDefenseBoost))
|
||||||
return [self, base]
|
return [self, base]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,11 +59,18 @@ class RoundCalculatorService {
|
|||||||
var combinePotentionalForces: [String: PlayerMove] = [:]
|
var combinePotentionalForces: [String: PlayerMove] = [:]
|
||||||
|
|
||||||
for playerMoves in playerMovesByBase {
|
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 {
|
for move in playerMoves.value {
|
||||||
combinePotentionalForces[playerMoves.key]!.unitCount += move.unitCount
|
combinePotentionalForces[playerMoves.key]!.unitCount += move.unitCount
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(combinePotentionalForces.count > 0) {
|
if(combinePotentionalForces.count > 0) {
|
||||||
let sortedPotentionalCombinedForces = combinePotentionalForces.sorted { $0.1.unitCount > $1.1.unitCount }
|
let sortedPotentionalCombinedForces = combinePotentionalForces.sorted { $0.1.unitCount > $1.1.unitCount }
|
||||||
|
|
||||||
@ -77,11 +84,7 @@ class RoundCalculatorService {
|
|||||||
if base.baseId == playerMoveWithMaxUnits.value.toBase {
|
if base.baseId == playerMoveWithMaxUnits.value.toBase {
|
||||||
if base.ownership == nil {
|
if base.ownership == nil {
|
||||||
base.unitCount += playerMoveWithMaxUnits.value.unitCount
|
base.unitCount += playerMoveWithMaxUnits.value.unitCount
|
||||||
if playerMoveWithMaxUnits.value.unitCount == 0 {
|
base.ownership = playerMoveWithMaxUnits.value.unitCount == 0 ? nil : playerMoveWithMaxUnits.key
|
||||||
base.ownership = nil
|
|
||||||
} else {
|
|
||||||
base.ownership = playerMoveWithMaxUnits.key
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if base.unitCount < playerMoveWithMaxUnits.value.unitCount {
|
if base.unitCount < playerMoveWithMaxUnits.value.unitCount {
|
||||||
base.unitCount = playerMoveWithMaxUnits.value.unitCount - base.unitCount
|
base.unitCount = playerMoveWithMaxUnits.value.unitCount - base.unitCount
|
||||||
|
Loading…
Reference in New Issue
Block a user