From 36f072bfec69f9a44ed66174c52e80fd20becc95 Mon Sep 17 00:00:00 2001 From: laurids Date: Wed, 13 Jan 2021 16:58:34 +0100 Subject: [PATCH] Distrikte einnehmen --- Assets/GWConquest/Scripts/Battle.cs | 20 ++++++++ Assets/GWConquest/Scripts/District.cs | 52 ++++++++++++++------ Assets/GWConquest/Scripts/Planet.cs | 18 +++++-- Assets/GWConquest/Scripts/UI/BalanceUI.cs | 5 +- Assets/GWConquest/Scripts/UI/DistrictIcon.cs | 2 - Assets/GWConquest/Scripts/UI/PlanetViewUI.cs | 16 ++---- 6 files changed, 77 insertions(+), 36 deletions(-) diff --git a/Assets/GWConquest/Scripts/Battle.cs b/Assets/GWConquest/Scripts/Battle.cs index c9877d9..a1dd5c5 100644 --- a/Assets/GWConquest/Scripts/Battle.cs +++ b/Assets/GWConquest/Scripts/Battle.cs @@ -134,6 +134,26 @@ namespace GWConquest var gm = GameManager.Instance; + var players = AllPlayers; + var playerCount = players.Count(); + + if(playerCount <= 1) + { + if(playerCount <= 0) + { + BoltLog.Info("No players in Battle {0}!", this); + } + else { + var finalPlayer = players.First(); + BoltLog.Info("Player {0} is only one left in Battle {1}!", finalPlayer, this); + } + + Zone.CurrentBattle = null; + + Destroy(gameObject); + + } + SimulateTurn(); } diff --git a/Assets/GWConquest/Scripts/District.cs b/Assets/GWConquest/Scripts/District.cs index 3157867..cff2bf1 100644 --- a/Assets/GWConquest/Scripts/District.cs +++ b/Assets/GWConquest/Scripts/District.cs @@ -1,9 +1,13 @@ using UnityEngine; +using System.Collections.Generic; +using System.Linq; namespace GWConquest { public class District : GWBoltBehaviour { + public static List AllDistricts = new List(); + public Sprite DefaultSprite; public string DistrictName; @@ -52,6 +56,8 @@ namespace GWConquest Inventory = new Inventory(State, "Inventory"); Inventory.StorageCapacity = StorageCapacity; State.ControllingPlayerId = -1; + + AllDistricts.Add(this); } public void Initialize(Planet _planet) @@ -110,27 +116,41 @@ namespace GWConquest public override void SimulateOwner() { - string producingItem = ProducingItem; + var allPlayers = Zone.Formations.Select(f => f.Player).Distinct(); + if(allPlayers.Count() == 1) + { + var player = allPlayers.First(); + if(player != ControllingPlayer) + { + BoltLog.Info("Player {0} is the only player in district {1}, changing allegiance", player, this); + ControllingPlayer = player; + } + } - bool producesCredits = DistrictType == DistrictType.Civil && ControllingPlayer != null; + if(ControllingPlayer != null) + { + string producingItem = ProducingItem; - if(producingItem != null || producesCredits) { - if(State.ItemProductionCooldown <= 0f) - { - if(producingItem != null) - { - Inventory.AddItem(producingItem, 1); - } + bool producesCredits = DistrictType == DistrictType.Civil; - if(producesCredits) + if(producingItem != null || producesCredits) { + if(State.ItemProductionCooldown <= 0f) { - ControllingPlayer.Credits++; - } + if(producingItem != null) + { + Inventory.AddItem(producingItem, 1); + } - State.ItemProductionCooldown = ProducingCooldown; - } - else { - State.ItemProductionCooldown -= BoltNetwork.FrameDeltaTime; + if(producesCredits) + { + ControllingPlayer.Credits++; + } + + State.ItemProductionCooldown = ProducingCooldown; + } + else { + State.ItemProductionCooldown -= BoltNetwork.FrameDeltaTime; + } } } } diff --git a/Assets/GWConquest/Scripts/Planet.cs b/Assets/GWConquest/Scripts/Planet.cs index 9784c63..321a5c6 100644 --- a/Assets/GWConquest/Scripts/Planet.cs +++ b/Assets/GWConquest/Scripts/Planet.cs @@ -155,12 +155,12 @@ namespace GWConquest public IEnumerable GetAllFormations(ZoneType zoneType) { - List list = new List(); - foreach (Zone zone in GetZones(zoneType)) + var formations = GetZones(zoneType).SelectMany(z => z.Formations); + if(zoneType == ZoneType.Ground) { - list.AddRange(zone.Formations); + formations = formations.Concat(InTransitFormations); } - return list; + return formations; } public IEnumerable GetAllFormations(ZoneType zoneType, Player player) { @@ -205,6 +205,16 @@ namespace GWConquest } } + public bool IsPlanetContested { + get { + var districts = GetComponentsInChildren(); + var districtPlayers = districts.Select(d => d.ControllingPlayer); + var formationPlayers = GetAllFormations(ZoneType.Ground).Select(f => f.Player); + var allPlayers = districtPlayers.Concat(formationPlayers); + return allPlayers.Distinct().Count() > 1; + } + } + #if UNITY_EDITOR diff --git a/Assets/GWConquest/Scripts/UI/BalanceUI.cs b/Assets/GWConquest/Scripts/UI/BalanceUI.cs index 8f4d412..27d6819 100644 --- a/Assets/GWConquest/Scripts/UI/BalanceUI.cs +++ b/Assets/GWConquest/Scripts/UI/BalanceUI.cs @@ -22,10 +22,9 @@ namespace GWConquest int totalSupplies = 0; int totalFuel = 0; - foreach(Zone z in Zone.AllZones) + foreach(var d in District.AllDistricts) { - District d = z.GetComponent(); - if(d != null && d.ControllingPlayer == currentPlayer) + if(d.ControllingPlayer == currentPlayer) { totalFood += d.Inventory.GetItemAmount("Food"); totalSupplies += d.Inventory.GetItemAmount("Supplies"); diff --git a/Assets/GWConquest/Scripts/UI/DistrictIcon.cs b/Assets/GWConquest/Scripts/UI/DistrictIcon.cs index a548f63..ed9d80c 100644 --- a/Assets/GWConquest/Scripts/UI/DistrictIcon.cs +++ b/Assets/GWConquest/Scripts/UI/DistrictIcon.cs @@ -83,8 +83,6 @@ namespace GWConquest if (enemyStrength > 0f) { Player enemyPlayer = formations.FirstOrDefault(f => f.Player != Player.CurrentPlayer)?.Player; - Debug.Log(enemyPlayer); - EnemyIndicator.gameObject.SetActive(true); EnemyIndicatorMask.enabled = true; EnemyIndicator.UpdateContinuous(enemyStrength, enemyPlayer?.Color); diff --git a/Assets/GWConquest/Scripts/UI/PlanetViewUI.cs b/Assets/GWConquest/Scripts/UI/PlanetViewUI.cs index f24c5f0..d9358d6 100644 --- a/Assets/GWConquest/Scripts/UI/PlanetViewUI.cs +++ b/Assets/GWConquest/Scripts/UI/PlanetViewUI.cs @@ -119,21 +119,15 @@ namespace GWConquest UpdateGroundIndicator(); UpdateSpaceIndicator(); - var districts = selectedPlanet.GetComponentsInChildren(); - var districtPlayers = districts.Select((d,i) => d.ControllingPlayer); - Debug.LogFormat("District players: {0}", string.Join(",", districtPlayers)); - var formationPlayers = selectedPlanet.GetAllFormations(ZoneType.Ground).Select((f,i) => f.Player); - Debug.LogFormat("Formation players: {0}", string.Join(",", formationPlayers)); - var allPlayers = districtPlayers.Concat(formationPlayers); - Debug.LogFormat("All players: {0}", string.Join(",", allPlayers)); - bool isPlanetContested = allPlayers.Distinct().Count() > 1; + FleetIcons.SetZone(selectedPlanet.GetMainZone(ZoneType.Space)); + } + private void FixedUpdate() + { foreach(DistrictIcon icon in districtIcons) { - icon.UpdateIndicator(isPlanetContested); + icon.UpdateIndicator(selectedPlanet.IsPlanetContested); } - - FleetIcons.SetZone(selectedPlanet.GetMainZone(ZoneType.Space)); } private void PlanetFormationsChanged()