diff --git a/GoldWars/GoldWars/Entities/EntityManager.swift b/GoldWars/GoldWars/Entities/EntityManager.swift index 05b9f14..161d3b4 100644 --- a/GoldWars/GoldWars/Entities/EntityManager.swift +++ b/GoldWars/GoldWars/Entities/EntityManager.swift @@ -8,6 +8,7 @@ import SpriteKit import GameplayKit +import GameKit class EntityManager { @@ -92,13 +93,22 @@ class EntityManager { let base = (entity as! Base) if base.changeOwnerShip { - base.addComponent(TeamComponent(team: (entities[0] as! Base).component(ofType: TeamComponent.self)!.team, position: (base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position)!)) + base.addComponent( + TeamComponent( + team: (entities[0] as! Base).component(ofType: TeamComponent.self)!.team, + position: (base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position)!, + player: (entities[0] as! Base).component(ofType: TeamComponent.self)!.player)) base.changeOwnerShip = false scene.addChild(base.component(ofType: TeamComponent.self)!.fire) } } } + + func getBaseByPlayer(for player: GKPlayer) -> Set { + return entities.filter{$0 is Base && ($0 as! Base).component(ofType: TeamComponent.self)?.player == player } as! Set + } + func getBaseByTeam(for team: Team) -> GKEntity? { for entity in entities { if let teamComponent = entity.component(ofType: TeamComponent.self),