Send boosts with snapshot model, increase unit counts accordingly
This commit is contained in:
parent
6b1d0eac12
commit
a423942182
@ -10,8 +10,6 @@ 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 {
|
||||||
@ -26,11 +24,15 @@ class BaseEntityModel: Codable {
|
|||||||
let baseId: Int
|
let baseId: Int
|
||||||
var unitCount: Int
|
var unitCount: Int
|
||||||
var ownership: String?
|
var ownership: String?
|
||||||
|
var hasAttackBoost: Bool
|
||||||
|
var hasDefenceBoost: Bool
|
||||||
|
|
||||||
init(baseId: Int, unitCount: Int, ownership: String?) {
|
init(baseId: Int, unitCount: Int, ownership: String?, hasAttackBoost: Bool, hasDefenceBoost: Bool) {
|
||||||
self.baseId = baseId
|
self.baseId = baseId
|
||||||
self.unitCount = unitCount
|
self.unitCount = unitCount
|
||||||
self.ownership = ownership
|
self.ownership = ownership
|
||||||
|
self.hasAttackBoost = hasAttackBoost
|
||||||
|
self.hasDefenceBoost = hasDefenceBoost
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,9 +53,8 @@ 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]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,7 +249,15 @@ class EntityManager {
|
|||||||
|
|
||||||
for entity in bases {
|
for entity in bases {
|
||||||
let base = entity as! Base
|
let base = entity as! Base
|
||||||
snapBase.append(BaseEntityModel(baseId: base.baseID, unitCount: base.unitCount, ownership: base.ownershipPlayer?.displayName))
|
snapBase.append(
|
||||||
|
BaseEntityModel(
|
||||||
|
baseId: base.baseID,
|
||||||
|
unitCount: base.unitCount,
|
||||||
|
ownership: base.ownershipPlayer?.displayName,
|
||||||
|
hasAttackBoost: base.hasAttackBoost,
|
||||||
|
hasDefenceBoost: base.hasDefenseBoost
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return SnapshotModel(baseEntites: snapBase)
|
return SnapshotModel(baseEntites: snapBase)
|
||||||
|
@ -13,6 +13,9 @@ class RoundCalculatorService {
|
|||||||
static let sharedInstance = RoundCalculatorService()
|
static let sharedInstance = RoundCalculatorService()
|
||||||
static let LOG = OSLog.init(subsystem: "Round Calculator", category: "RoundCalculatorService")
|
static let LOG = OSLog.init(subsystem: "Round Calculator", category: "RoundCalculatorService")
|
||||||
|
|
||||||
|
let ATK_BOOST_MULTIPLICATOR = 1.1
|
||||||
|
let DEF_BOOST_MULTIPLICATOR = 1.1
|
||||||
|
|
||||||
var entityManager = EntityManager.gameEMInstance
|
var entityManager = EntityManager.gameEMInstance
|
||||||
|
|
||||||
var isCalculating = false
|
var isCalculating = false
|
||||||
@ -62,37 +65,38 @@ class RoundCalculatorService {
|
|||||||
combinePotentionalForces[playerMoves.key] = PlayerMove(
|
combinePotentionalForces[playerMoves.key] = PlayerMove(
|
||||||
fromBase: playerMoves.value[0].fromBase,
|
fromBase: playerMoves.value[0].fromBase,
|
||||||
toBase: playerMoves.value[0].toBase,
|
toBase: playerMoves.value[0].toBase,
|
||||||
unitCount: 0,
|
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 }
|
||||||
|
|
||||||
var playerMoveWithMaxUnits = sortedPotentionalCombinedForces[0]
|
var playerMoveWithMaxUnits = sortedPotentionalCombinedForces[0]
|
||||||
|
playerMoveWithMaxUnits.value.unitCount = Int(Double(playerMoveWithMaxUnits.value.unitCount) * ((currentSnapshotModel?.baseEntites[playerMoveWithMaxUnits.value.fromBase].hasAttackBoost)! ? ATK_BOOST_MULTIPLICATOR : 1))
|
||||||
if playerMovesByBase.count >= 2 {
|
if playerMovesByBase.count >= 2 {
|
||||||
let playerMoveWithSecMaxUnits = sortedPotentionalCombinedForces[1]
|
var playerMoveWithSecMaxUnits = sortedPotentionalCombinedForces[1]
|
||||||
playerMoveWithMaxUnits.value.unitCount -= playerMoveWithSecMaxUnits.value.unitCount
|
playerMoveWithSecMaxUnits.value.unitCount = Int(Double(playerMoveWithSecMaxUnits.value.unitCount) * ((currentSnapshotModel?.baseEntites[playerMoveWithSecMaxUnits.value.fromBase].hasAttackBoost)! ? ATK_BOOST_MULTIPLICATOR : 1))
|
||||||
|
playerMoveWithMaxUnits.value.unitCount -= playerMoveWithSecMaxUnits.value.unitCount // Apply Boost
|
||||||
}
|
}
|
||||||
|
|
||||||
for base in currentSnapshotModel!.baseEntites {
|
for base in currentSnapshotModel!.baseEntites {
|
||||||
if base.baseId == playerMoveWithMaxUnits.value.toBase {
|
if base.baseId == playerMoveWithMaxUnits.value.toBase {
|
||||||
|
base.unitCount = Int(Double(base.unitCount) * (base.hasDefenceBoost ? DEF_BOOST_MULTIPLICATOR : 1))
|
||||||
if base.ownership == nil {
|
if base.ownership == nil {
|
||||||
base.unitCount += playerMoveWithMaxUnits.value.unitCount
|
base.unitCount += playerMoveWithMaxUnits.value.unitCount // Apply Boost
|
||||||
base.ownership = playerMoveWithMaxUnits.value.unitCount == 0 ? nil : playerMoveWithMaxUnits.key
|
base.ownership = playerMoveWithMaxUnits.value.unitCount == 0 ? nil : 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 // Apply Boost
|
||||||
base.ownership = playerMoveWithMaxUnits.key
|
base.ownership = playerMoveWithMaxUnits.key
|
||||||
} else if (base.unitCount == playerMoveWithMaxUnits.value.unitCount) {
|
} else if (base.unitCount == playerMoveWithMaxUnits.value.unitCount) {
|
||||||
base.ownership = nil
|
base.ownership = nil
|
||||||
} else {
|
} else {
|
||||||
base.unitCount -= playerMoveWithMaxUnits.value.unitCount
|
base.unitCount -= playerMoveWithMaxUnits.value.unitCount // Apply Boost
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -126,7 +130,7 @@ class RoundCalculatorService {
|
|||||||
for playerMove in allPlayerMoves {
|
for playerMove in allPlayerMoves {
|
||||||
for move in playerMove.value {
|
for move in playerMove.value {
|
||||||
if baseSpecificMoves.keys.contains(move.toBase) {
|
if baseSpecificMoves.keys.contains(move.toBase) {
|
||||||
if (baseSpecificMoves[move.toBase]?.keys.contains(playerMove.key))!{
|
if (baseSpecificMoves[move.toBase]?.keys.contains(playerMove.key))! {
|
||||||
baseSpecificMoves[move.toBase]?[playerMove.key]?.append(move)
|
baseSpecificMoves[move.toBase]?[playerMove.key]?.append(move)
|
||||||
} else {
|
} else {
|
||||||
baseSpecificMoves[move.toBase]?.merge([playerMove.key: [move]]){(current, _) in current}
|
baseSpecificMoves[move.toBase]?.merge([playerMove.key: [move]]){(current, _) in current}
|
||||||
|
Loading…
Reference in New Issue
Block a user