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