Browse Source

Distrikte einnehmen

bolt_update
laurids 3 years ago
parent
commit
36f072bfec
6 changed files with 77 additions and 36 deletions
  1. +20
    -0
      Assets/GWConquest/Scripts/Battle.cs
  2. +36
    -16
      Assets/GWConquest/Scripts/District.cs
  3. +14
    -4
      Assets/GWConquest/Scripts/Planet.cs
  4. +2
    -3
      Assets/GWConquest/Scripts/UI/BalanceUI.cs
  5. +0
    -2
      Assets/GWConquest/Scripts/UI/DistrictIcon.cs
  6. +5
    -11
      Assets/GWConquest/Scripts/UI/PlanetViewUI.cs

+ 20
- 0
Assets/GWConquest/Scripts/Battle.cs View File

@ -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();
}


+ 36
- 16
Assets/GWConquest/Scripts/District.cs View File

@ -1,9 +1,13 @@
using UnityEngine;
using System.Collections.Generic;
using System.Linq;
namespace GWConquest
{
public class District : GWBoltBehaviour<IDistrictState>
{
public static List<District> AllDistricts = new List<District>();
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;
}
}
}
}


+ 14
- 4
Assets/GWConquest/Scripts/Planet.cs View File

@ -155,12 +155,12 @@ namespace GWConquest
public IEnumerable<Formation> GetAllFormations(ZoneType zoneType)
{
List<Formation> list = new List<Formation>();
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<Formation> GetAllFormations(ZoneType zoneType, Player player)
{
@ -205,6 +205,16 @@ namespace GWConquest
}
}
public bool IsPlanetContested {
get {
var districts = GetComponentsInChildren<District>();
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


+ 2
- 3
Assets/GWConquest/Scripts/UI/BalanceUI.cs View File

@ -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<District>();
if(d != null && d.ControllingPlayer == currentPlayer)
if(d.ControllingPlayer == currentPlayer)
{
totalFood += d.Inventory.GetItemAmount("Food");
totalSupplies += d.Inventory.GetItemAmount("Supplies");


+ 0
- 2
Assets/GWConquest/Scripts/UI/DistrictIcon.cs View File

@ -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);


+ 5
- 11
Assets/GWConquest/Scripts/UI/PlanetViewUI.cs View File

@ -119,21 +119,15 @@ namespace GWConquest
UpdateGroundIndicator();
UpdateSpaceIndicator();
var districts = selectedPlanet.GetComponentsInChildren<District>();
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()


Loading…
Cancel
Save