Add atk and def boost to PlayerMove struct

This commit is contained in:
Marcel Schwarz 2020-05-31 19:04:58 +02:00
parent 0d20cc6716
commit 6b1d0eac12
3 changed files with 15 additions and 8 deletions

View File

@ -10,6 +10,8 @@ struct PlayerMove: Codable{
let fromBase: Int
let toBase: Int
var unitCount: Int
let hasDefenceBoost: Bool
let hasAttackBoost: Bool
}
class SnapshotModel: Codable {

View File

@ -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]
}

View File

@ -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