Changed captured bases behavior so that they are not allowed to move units in same Round
Fixed Merge errors Fixed calculation on a specific fight scenario Fixed RoundTimer Fixed forced unwrap on boost nil object
This commit is contained in:
parent
96eb25de65
commit
9cd87c6bf5
@ -40,12 +40,12 @@ class Base: GKEntity{
|
|||||||
if ownershipPlayer == GKLocalPlayer.local {
|
if ownershipPlayer == GKLocalPlayer.local {
|
||||||
self.component(ofType: DefaultBaseComponent.self)?.labelNode.text = "\(unitCount)"
|
self.component(ofType: DefaultBaseComponent.self)?.labelNode.text = "\(unitCount)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func doPlayerMoveTypeToBase(base: Base, playerMoveType: PlayerMoveType, units: Int) -> [GKEntity]{
|
func doPlayerMoveTypeToBase(base: Base, playerMoveType: PlayerMoveType, units: Int) -> [GKEntity]{
|
||||||
|
if base.ownershipPlayer != GKLocalPlayer.local {
|
||||||
base.changeOwnership = true
|
base.changeOwnership = true
|
||||||
|
}
|
||||||
base.ownershipPlayer = self.ownershipPlayer
|
base.ownershipPlayer = self.ownershipPlayer
|
||||||
self.unitCount -= units
|
self.unitCount -= units
|
||||||
base.unitCount += units
|
base.unitCount += units
|
||||||
|
@ -117,7 +117,6 @@ class EntityManager {
|
|||||||
scene.addChild(fire)
|
scene.addChild(fire)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
base.changeOwnership = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -129,6 +128,7 @@ class EntityManager {
|
|||||||
let snapBase = self.getSnapshotBaseById(baseId: base.baseID, snapshotModel: snapshotModel)
|
let snapBase = self.getSnapshotBaseById(baseId: base.baseID, snapshotModel: snapshotModel)
|
||||||
var getOwnerBySnapBase: GKPlayer? = nil
|
var getOwnerBySnapBase: GKPlayer? = nil
|
||||||
base.unitCount = snapBase.unitCount
|
base.unitCount = snapBase.unitCount
|
||||||
|
base.changeOwnership = false
|
||||||
|
|
||||||
if snapBase.ownership != nil {
|
if snapBase.ownership != nil {
|
||||||
getOwnerBySnapBase = GameCenterManager.sharedInstance.getGKPlayerByUsername(displayName: snapBase.ownership!)
|
getOwnerBySnapBase = GameCenterManager.sharedInstance.getGKPlayerByUsername(displayName: snapBase.ownership!)
|
||||||
@ -142,7 +142,6 @@ class EntityManager {
|
|||||||
} else {
|
} else {
|
||||||
base.component(ofType: DefaultBaseComponent.self)?.labelNode.text = ""
|
base.component(ofType: DefaultBaseComponent.self)?.labelNode.text = ""
|
||||||
}
|
}
|
||||||
base.changeOwnership = true
|
|
||||||
base.ownershipPlayer = getOwnerBySnapBase
|
base.ownershipPlayer = getOwnerBySnapBase
|
||||||
if (entity.component(ofType: TeamComponent.self) != nil) {
|
if (entity.component(ofType: TeamComponent.self) != nil) {
|
||||||
entity.component(ofType: TeamComponent.self)!.change(to: getTeamByPlayer(playerName: snapBase.ownership!), to: getOwnerBySnapBase!)
|
entity.component(ofType: TeamComponent.self)!.change(to: getTeamByPlayer(playerName: snapBase.ownership!), to: getOwnerBySnapBase!)
|
||||||
|
@ -16,6 +16,7 @@ class RoundCalculatorService {
|
|||||||
let ATK_BOOST_MULTIPLICATOR = 1.1
|
let ATK_BOOST_MULTIPLICATOR = 1.1
|
||||||
let DEF_BOOST_MULTIPLICATOR = 1.1
|
let DEF_BOOST_MULTIPLICATOR = 1.1
|
||||||
|
|
||||||
|
var allPlayerMoves: [String: [PlayerMove]] = [:]
|
||||||
// TODO: Better data structure
|
// TODO: Better data structure
|
||||||
var boosts: [String: (Bool, Bool)] = [:] // First bool is atk boost, second is def boost
|
var boosts: [String: (Bool, Bool)] = [:] // First bool is atk boost, second is def boost
|
||||||
|
|
||||||
@ -61,7 +62,9 @@ class RoundCalculatorService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (baseId, playerMovesByBase) in baseSpecificMoves {
|
||||||
var combinePotentionalForces: [String: PlayerMove] = [:]
|
var combinePotentionalForces: [String: PlayerMove] = [:]
|
||||||
|
|
||||||
for playerMoves in playerMovesByBase {
|
for playerMoves in playerMovesByBase {
|
||||||
@ -122,13 +125,10 @@ class RoundCalculatorService {
|
|||||||
}
|
}
|
||||||
baseSpecificMoves.removeValue(forKey: baseId)
|
baseSpecificMoves.removeValue(forKey: baseId)
|
||||||
}
|
}
|
||||||
DataService.sharedInstance.localRoundData.localPlayerMoves.removeAll()
|
|
||||||
DataService.sharedInstance.localRoundData.hasAttackBoost = false
|
|
||||||
DataService.sharedInstance.localRoundData.hasDefenceBoost = false
|
|
||||||
var player1BaseCount = 0;
|
var player1BaseCount = 0;
|
||||||
var player2BaseCount = 0;
|
var player2BaseCount = 0;
|
||||||
let player1 = Array(allPlayerMoves)[0].key
|
let player1 = GameCenterManager.sharedInstance.hostingPlayer?.displayName
|
||||||
let player2 = Array(allPlayerMoves)[1].key
|
let player2 = GameCenterManager.sharedInstance.peerPlayer?.displayName
|
||||||
for baseEntry in currentSnapshotModel!.baseEntites {
|
for baseEntry in currentSnapshotModel!.baseEntites {
|
||||||
if baseEntry.ownership == player1 {
|
if baseEntry.ownership == player1 {
|
||||||
player1BaseCount += 1
|
player1BaseCount += 1
|
||||||
@ -138,14 +138,16 @@ class RoundCalculatorService {
|
|||||||
}
|
}
|
||||||
currentSnapshotModel?.baseEntites = currentSnapshotModel!.baseEntites.map { (BaseEntityModel) -> BaseEntityModel in
|
currentSnapshotModel?.baseEntites = currentSnapshotModel!.baseEntites.map { (BaseEntityModel) -> BaseEntityModel in
|
||||||
if BaseEntityModel.ownership == player1 {
|
if BaseEntityModel.ownership == player1 {
|
||||||
BaseEntityModel.unitCount += lround(Double(player1BaseCount / 2))
|
BaseEntityModel.unitCount += player1BaseCount
|
||||||
} else if BaseEntityModel.ownership == player2 {
|
} else if BaseEntityModel.ownership == player2 {
|
||||||
BaseEntityModel.unitCount += lround(Double(player2BaseCount / 2))
|
BaseEntityModel.unitCount += player2BaseCount
|
||||||
}
|
}
|
||||||
return BaseEntityModel
|
return BaseEntityModel
|
||||||
}
|
}
|
||||||
allPlayerMoves.removeAll()
|
allPlayerMoves.removeAll()
|
||||||
DataService.sharedInstance.localPlayerMoves.removeAll()
|
DataService.sharedInstance.localRoundData.localPlayerMoves.removeAll()
|
||||||
|
DataService.sharedInstance.localRoundData.hasAttackBoost = false
|
||||||
|
DataService.sharedInstance.localRoundData.hasDefenceBoost = false
|
||||||
MultiplayerNetwork.sharedInstance.sendSnapshotModelToPlayers()
|
MultiplayerNetwork.sharedInstance.sendSnapshotModelToPlayers()
|
||||||
DataService.sharedInstance.snapshotModel = currentSnapshotModel
|
DataService.sharedInstance.snapshotModel = currentSnapshotModel
|
||||||
entityManager.updateSnapshotModel(snapshotModel: currentSnapshotModel!)
|
entityManager.updateSnapshotModel(snapshotModel: currentSnapshotModel!)
|
||||||
@ -154,10 +156,6 @@ class RoundCalculatorService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func collectBaseSpecificMoves() -> [Int: [String: [PlayerMove]]] {
|
func collectBaseSpecificMoves() -> [Int: [String: [PlayerMove]]] {
|
||||||
|
|
||||||
var allPlayerMoves: [String: [PlayerMove]] = [:]
|
|
||||||
|
|
||||||
// collect moves from remote player
|
|
||||||
for playerMove in DataService.sharedInstance.remotePlayerMoves {
|
for playerMove in DataService.sharedInstance.remotePlayerMoves {
|
||||||
allPlayerMoves[playerMove.key] = playerMove.value.localPlayerMoves
|
allPlayerMoves[playerMove.key] = playerMove.value.localPlayerMoves
|
||||||
}
|
}
|
||||||
@ -166,13 +164,11 @@ class RoundCalculatorService {
|
|||||||
DataService.sharedInstance.localRoundData.hasAttackBoost,
|
DataService.sharedInstance.localRoundData.hasAttackBoost,
|
||||||
DataService.sharedInstance.localRoundData.hasDefenceBoost
|
DataService.sharedInstance.localRoundData.hasDefenceBoost
|
||||||
)
|
)
|
||||||
|
|
||||||
boosts[GameCenterManager.sharedInstance.peerPlayer!.displayName] = (
|
boosts[GameCenterManager.sharedInstance.peerPlayer!.displayName] = (
|
||||||
DataService.sharedInstance.remotePlayerMoves[GameCenterManager.sharedInstance.peerPlayer!.displayName]!.hasAttackBoost,
|
DataService.sharedInstance.remotePlayerMoves[GameCenterManager.sharedInstance.peerPlayer!.displayName]?.hasAttackBoost ?? false,
|
||||||
DataService.sharedInstance.remotePlayerMoves[GameCenterManager.sharedInstance.peerPlayer!.displayName]!.hasDefenceBoost
|
DataService.sharedInstance.remotePlayerMoves[GameCenterManager.sharedInstance.peerPlayer!.displayName]?.hasDefenceBoost ?? false
|
||||||
)
|
)
|
||||||
|
|
||||||
// collect moves from local player
|
|
||||||
allPlayerMoves[GKLocalPlayer.local.displayName] = DataService.sharedInstance.localRoundData.localPlayerMoves
|
allPlayerMoves[GKLocalPlayer.local.displayName] = DataService.sharedInstance.localRoundData.localPlayerMoves
|
||||||
|
|
||||||
var baseSpecificMoves: [Int: [String: [PlayerMove]]] = [:]
|
var baseSpecificMoves: [Int: [String: [PlayerMove]]] = [:]
|
||||||
@ -190,9 +186,7 @@ class RoundCalculatorService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DataService.sharedInstance.remotePlayerMoves.removeAll()
|
DataService.sharedInstance.remotePlayerMoves.removeAll()
|
||||||
|
|
||||||
return baseSpecificMoves
|
return baseSpecificMoves
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ class RoundTimer: Timer {
|
|||||||
if timeLeft == 0 {
|
if timeLeft == 0 {
|
||||||
RoundCalculatorService.sharedInstance.resetNumberOfAttacksAndFormats()
|
RoundCalculatorService.sharedInstance.resetNumberOfAttacksAndFormats()
|
||||||
if !MultiplayerNetwork.sharedInstance.isSending {
|
if !MultiplayerNetwork.sharedInstance.isSending {
|
||||||
MultiplayerNetwork.sharedInstance.sendPlayerMoves(playerMoves: DataService.sharedInstance.localPlayerMoves)
|
MultiplayerNetwork.sharedInstance.sendPlayerMoves(localRoundData: DataService.sharedInstance.localRoundData)
|
||||||
}
|
}
|
||||||
calculate = true
|
calculate = true
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,6 @@ class GameScene: SKScene{
|
|||||||
addBaseDetails(touchLocation: touchLocation, spriteNode: spriteNode, touches: touches, event: event, entity: entity)
|
addBaseDetails(touchLocation: touchLocation, spriteNode: spriteNode, touches: touches, event: event, entity: entity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
|
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||||
@ -68,9 +67,7 @@ class GameScene: SKScene{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
checkSlider()
|
checkSlider()
|
||||||
|
|
||||||
let bases = entityManager.getBasesByPlayer(for: GKLocalPlayer.local)
|
let bases = entityManager.getBasesByPlayer(for: GKLocalPlayer.local)
|
||||||
|
|
||||||
checkBases(bases: bases, touchLocation: touchLocation)
|
checkBases(bases: bases, touchLocation: touchLocation)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +90,6 @@ class GameScene: SKScene{
|
|||||||
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2),
|
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2),
|
||||||
gameScene: self,
|
gameScene: self,
|
||||||
currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, collisionBase: collisionBase))
|
currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, collisionBase: collisionBase))
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -142,6 +138,7 @@ class GameScene: SKScene{
|
|||||||
func checkBases(bases: Set<Base>, touchLocation: CGPoint){
|
func checkBases(bases: Set<Base>, touchLocation: CGPoint){
|
||||||
for base in bases {
|
for base in bases {
|
||||||
if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode {
|
if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode {
|
||||||
|
if !base.changeOwnership {
|
||||||
if !isMoveTouch {
|
if !isMoveTouch {
|
||||||
currentDraggedBase = base
|
currentDraggedBase = base
|
||||||
}
|
}
|
||||||
@ -151,6 +148,7 @@ class GameScene: SKScene{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func moveFireAndBase(base: Base, touchLocation: CGPoint){
|
func moveFireAndBase(base: Base, touchLocation: CGPoint){
|
||||||
base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = touchLocation
|
base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = touchLocation
|
||||||
|
Loading…
Reference in New Issue
Block a user