Merge branch '69-globales-unit-wachstum' into 'development'
Resolve "Globales Unit Wachstum" Closes #69 See merge request marcel.schwarz/software-projekt-2!101
This commit is contained in:
commit
392f59108b
@ -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]{
|
||||||
base.changeOwnership = true
|
if base.ownershipPlayer != GKLocalPlayer.local {
|
||||||
|
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!)
|
||||||
@ -139,10 +139,9 @@ class EntityManager {
|
|||||||
if getOwnerBySnapBase != nil {
|
if getOwnerBySnapBase != nil {
|
||||||
if getOwnerBySnapBase == GKLocalPlayer.local {
|
if getOwnerBySnapBase == GKLocalPlayer.local {
|
||||||
base.component(ofType: DefaultBaseComponent.self)?.labelNode.text = "\(base.unitCount)"
|
base.component(ofType: DefaultBaseComponent.self)?.labelNode.text = "\(base.unitCount)"
|
||||||
}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,6 +125,26 @@ class RoundCalculatorService {
|
|||||||
}
|
}
|
||||||
baseSpecificMoves.removeValue(forKey: baseId)
|
baseSpecificMoves.removeValue(forKey: baseId)
|
||||||
}
|
}
|
||||||
|
var player1BaseCount = 0;
|
||||||
|
var player2BaseCount = 0;
|
||||||
|
let player1 = GameCenterManager.sharedInstance.hostingPlayer?.displayName
|
||||||
|
let player2 = GameCenterManager.sharedInstance.peerPlayer?.displayName
|
||||||
|
for baseEntry in currentSnapshotModel!.baseEntites {
|
||||||
|
if baseEntry.ownership == player1 {
|
||||||
|
player1BaseCount += 1
|
||||||
|
} else if baseEntry.ownership == player2 {
|
||||||
|
player2BaseCount += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
currentSnapshotModel?.baseEntites = currentSnapshotModel!.baseEntites.map { (BaseEntityModel) -> BaseEntityModel in
|
||||||
|
if BaseEntityModel.ownership == player1 {
|
||||||
|
BaseEntityModel.unitCount += player1BaseCount
|
||||||
|
} else if BaseEntityModel.ownership == player2 {
|
||||||
|
BaseEntityModel.unitCount += player2BaseCount
|
||||||
|
}
|
||||||
|
return BaseEntityModel
|
||||||
|
}
|
||||||
|
allPlayerMoves.removeAll()
|
||||||
DataService.sharedInstance.localRoundData.localPlayerMoves.removeAll()
|
DataService.sharedInstance.localRoundData.localPlayerMoves.removeAll()
|
||||||
DataService.sharedInstance.localRoundData.hasAttackBoost = false
|
DataService.sharedInstance.localRoundData.hasAttackBoost = false
|
||||||
DataService.sharedInstance.localRoundData.hasDefenceBoost = false
|
DataService.sharedInstance.localRoundData.hasDefenceBoost = false
|
||||||
@ -133,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
|
||||||
}
|
}
|
||||||
@ -145,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]]] = [:]
|
||||||
@ -169,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))
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -141,13 +137,15 @@ 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 !isMoveTouch {
|
if !base.changeOwnership {
|
||||||
currentDraggedBase = base
|
if !isMoveTouch {
|
||||||
|
currentDraggedBase = base
|
||||||
|
}
|
||||||
|
isMoveTouch = true
|
||||||
|
moveFireAndBase(base: base, touchLocation: touchLocation)
|
||||||
|
showNearestBases(base: base)
|
||||||
}
|
}
|
||||||
isMoveTouch = true
|
|
||||||
moveFireAndBase(base: base, touchLocation: touchLocation)
|
|
||||||
showNearestBases(base: base)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user