4 Commits

51 changed files with 814 additions and 1340 deletions
Unified View
  1. +50
    -42
      Assets/GWConquest/Scripts/Battle.cs
  2. +12
    -9
      Assets/GWConquest/Scripts/BattleFlank.cs
  3. +13
    -13
      Assets/GWConquest/Scripts/BattleLog.cs
  4. +0
    -58
      Assets/GWConquest/Scripts/BoltEntityCache.cs
  5. +0
    -11
      Assets/GWConquest/Scripts/BoltEntityCache.cs.meta
  6. +0
    -240
      Assets/GWConquest/Scripts/BoltList.cs
  7. +0
    -11
      Assets/GWConquest/Scripts/BoltList.cs.meta
  8. +29
    -26
      Assets/GWConquest/Scripts/District.cs
  9. +19
    -15
      Assets/GWConquest/Scripts/DistrictFactory.cs
  10. +7
    -7
      Assets/GWConquest/Scripts/DistrictUpgrade.cs
  11. +0
    -119
      Assets/GWConquest/Scripts/EntityList.cs
  12. +269
    -236
      Assets/GWConquest/Scripts/Formation.cs
  13. +0
    -35
      Assets/GWConquest/Scripts/GWBoltBehaviour.cs
  14. +0
    -11
      Assets/GWConquest/Scripts/GWBoltBehaviour.cs.meta
  15. +0
    -5
      Assets/GWConquest/Scripts/GWNetworkArray.cs
  16. +0
    -11
      Assets/GWConquest/Scripts/GWNetworkArray.cs.meta
  17. +187
    -0
      Assets/GWConquest/Scripts/GWNetworkManager.cs
  18. +1
    -1
      Assets/GWConquest/Scripts/GWNetworkManager.cs.meta
  19. +18
    -31
      Assets/GWConquest/Scripts/GameManager.cs
  20. +0
    -69
      Assets/GWConquest/Scripts/GlobalCallbacks.cs
  21. +0
    -11
      Assets/GWConquest/Scripts/GlobalCallbacks.cs.meta
  22. +9
    -9
      Assets/GWConquest/Scripts/Inventory.cs
  23. +9
    -9
      Assets/GWConquest/Scripts/Planet.cs
  24. +3
    -3
      Assets/GWConquest/Scripts/PlanetConnection.cs
  25. +20
    -15
      Assets/GWConquest/Scripts/PlanetPlacement.cs
  26. +7
    -7
      Assets/GWConquest/Scripts/PlanetRegistry.cs
  27. +13
    -9
      Assets/GWConquest/Scripts/Player.cs
  28. +0
    -124
      Assets/GWConquest/Scripts/ServerCallbacks.cs
  29. +0
    -11
      Assets/GWConquest/Scripts/ServerCallbacks.cs.meta
  30. +4
    -4
      Assets/GWConquest/Scripts/SpawnAIUnits.cs
  31. +4
    -4
      Assets/GWConquest/Scripts/UI/BattleArmyPanel.cs
  32. +3
    -3
      Assets/GWConquest/Scripts/UI/BattleFlankUI.cs
  33. +3
    -3
      Assets/GWConquest/Scripts/UI/BattleUI.cs
  34. +2
    -2
      Assets/GWConquest/Scripts/UI/BattleUnitIcon.cs
  35. +1
    -1
      Assets/GWConquest/Scripts/UI/DebugUI.cs
  36. +4
    -4
      Assets/GWConquest/Scripts/UI/FormationIcon.cs
  37. +3
    -3
      Assets/GWConquest/Scripts/UI/FormationUI.cs
  38. +3
    -3
      Assets/GWConquest/Scripts/UI/GarrisonUI.cs
  39. +6
    -6
      Assets/GWConquest/Scripts/UI/IngameUI.cs
  40. +6
    -6
      Assets/GWConquest/Scripts/UI/ItemMoveTooltip.cs
  41. +15
    -19
      Assets/GWConquest/Scripts/UI/MainMenu.cs
  42. +4
    -3
      Assets/GWConquest/Scripts/UI/PauseMenu.cs
  43. +4
    -4
      Assets/GWConquest/Scripts/UI/PlanetViewUI.cs
  44. +2
    -15
      Assets/GWConquest/Scripts/UI/ProductionMenu.cs
  45. +2
    -2
      Assets/GWConquest/Scripts/UI/SelectFactionMenu.cs
  46. +4
    -4
      Assets/GWConquest/Scripts/UI/TransportUI.cs
  47. +2
    -2
      Assets/GWConquest/Scripts/UI/TransportUIItemIcon.cs
  48. +2
    -2
      Assets/GWConquest/Scripts/UI/TransportUIUnitIcon.cs
  49. +59
    -77
      Assets/GWConquest/Scripts/Unit.cs
  50. +11
    -11
      Assets/GWConquest/Scripts/UnitClass.cs
  51. +4
    -14
      Assets/GWConquest/Scripts/Zone.cs

+ 50
- 42
Assets/GWConquest/Scripts/Battle.cs View File

@ -1,8 +1,8 @@
using UnityEngine; using UnityEngine;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Photon.Bolt;
using Photon.Bolt.Utils;
using Unity.Netcode; using Unity.Netcode;
using Unity.Collections; using Unity.Collections;
@ -19,6 +19,8 @@ namespace GWConquest
private NetworkVariable<int> victorID; private NetworkVariable<int> victorID;
private NetworkVariable<float> preparingCooldown; private NetworkVariable<float> preparingCooldown;
public GameObject BattleFlankPrefab;
public IEnumerable<Formation> Formations public IEnumerable<Formation> Formations
{ {
get => formations.Select(r => r.GetBehaviour<Formation>()); get => formations.Select(r => r.GetBehaviour<Formation>());
@ -149,7 +151,9 @@ namespace GWConquest
private BattleFlank InstantiateNewFlank(int maxUnitCount) private BattleFlank InstantiateNewFlank(int maxUnitCount)
{ {
var go = BoltNetwork.Instantiate(BoltPrefabs.BattleFlank);
GameObject go = Instantiate(BattleFlankPrefab);
go.GetComponent<NetworkObject>().Spawn();
var flank = go.GetComponent<BattleFlank>(); var flank = go.GetComponent<BattleFlank>();
flank.Battle = this; flank.Battle = this;
flank.MaxUnitCount = maxUnitCount; flank.MaxUnitCount = maxUnitCount;
@ -181,7 +185,7 @@ namespace GWConquest
} }
} }
else { else {
BoltLog.Error("Battle has only one player!");
Debug.LogErrorFormat("Battle has only one player!");
} }
} }
@ -223,40 +227,43 @@ namespace GWConquest
public void FixedUpdate() public void FixedUpdate()
{ {
if(IsInPreparing)
if(IsServer)
{ {
PreparingCooldown -= BoltNetwork.FrameDeltaTime;
if(PreparingCooldown <= 0)
if(IsInPreparing)
{ {
PreparingCooldown = 0;
PreparingCooldown -= Time.fixedDeltaTime;
if(PreparingCooldown <= 0)
{
PreparingCooldown = 0;
}
} }
}
else if(!IsOver)
{
var gm = GameManager.Instance;
else if(!IsOver)
{
var gm = GameManager.Instance;
var players = AllPlayers;
var playerCount = players.Count();
var players = AllPlayers;
var playerCount = players.Count();
if(playerCount <= 1)
{
if(playerCount <= 0)
if(playerCount <= 1)
{ {
BoltLog.Info("No players in Battle {0}!", this);
if(playerCount <= 0)
{
Debug.LogFormat("No players in Battle {0}!", this);
}
else {
var finalPlayer = players.First();
Debug.LogFormat("Player {0} is only one left in Battle {1}!", finalPlayer, this);
}
Zone.CurrentBattle = null;
SetBattleOver();
//Destroy(gameObject);
} }
else {
var finalPlayer = players.First();
BoltLog.Info("Player {0} is only one left in Battle {1}!", finalPlayer, this);
}
Zone.CurrentBattle = null;
SetBattleOver();
//Destroy(gameObject);
SimulateTurn();
} }
SimulateTurn();
} }
@ -284,8 +291,7 @@ namespace GWConquest
foreach(var flank in AllFlanks.ToList()) foreach(var flank in AllFlanks.ToList())
{ {
BoltNetwork.Destroy(flank.gameObject);
Destroy(flank.gameObject);
flank.NetworkObject.Despawn();
} }
} }
@ -388,7 +394,7 @@ namespace GWConquest
private void SimulateUnitAction(UnitAction action) private void SimulateUnitAction(UnitAction action)
{ {
if(DebugUI.LogBattleEvents) if(DebugUI.LogBattleEvents)
BoltLog.Info("Simulating action {0} for unit {1} on flank {2}", action.ActionType, action.Unit, action.Unit.CurrentFlank);
Debug.LogFormat("Simulating action {0} for unit {1} on flank {2}", action.ActionType, action.Unit, action.Unit.CurrentFlank);
if(action.ActionType == UnitActionType.RevealSelf) if(action.ActionType == UnitActionType.RevealSelf)
{ {
@ -423,7 +429,7 @@ namespace GWConquest
return; return;
if(DebugUI.LogBattleEvents) if(DebugUI.LogBattleEvents)
BoltLog.Info("Revealing unit {0} from unit {1}", target, action.Unit);
Debug.LogFormat("Revealing unit {0} from unit {1}", target, action.Unit);
target.IncreaseRevealLevel(); target.IncreaseRevealLevel();
@ -435,7 +441,7 @@ namespace GWConquest
return; return;
if(DebugUI.LogBattleEvents) if(DebugUI.LogBattleEvents)
BoltLog.Info("Revealing unit {0} by itself", action.Unit);
Debug.LogFormat("Revealing unit {0} by itself", action.Unit);
action.Unit.IncreaseRevealLevel(); action.Unit.IncreaseRevealLevel();
} }
@ -479,7 +485,7 @@ namespace GWConquest
damage = 0; damage = 0;
if (DebugUI.LogBattleEvents) if (DebugUI.LogBattleEvents)
BoltLog.Info("Dealing {0} HP damage (armour modifier: {1}) to unit {2} from unit {3}", damage, modifier, target, action.Unit);
Debug.LogFormat("Dealing {0} HP damage (armour modifier: {1}) to unit {2} from unit {3}", damage, modifier, target, action.Unit);
bool isGlancingHit = damage == 0 || modifier < 1f; bool isGlancingHit = damage == 0 || modifier < 1f;
@ -497,7 +503,7 @@ namespace GWConquest
if (Check(GameManager.Instance.RevealChanceAttack)) if (Check(GameManager.Instance.RevealChanceAttack))
{ {
if (DebugUI.LogBattleEvents) if (DebugUI.LogBattleEvents)
BoltLog.Info("Revealing unit {0} as it attacked unit {1}", action.Unit, target);
Debug.LogFormat("Revealing unit {0} as it attacked unit {1}", action.Unit, target);
action.Unit.IncreaseRevealLevel(); action.Unit.IncreaseRevealLevel();
} }
} }
@ -636,18 +642,18 @@ namespace GWConquest
{ {
if(flank.Player != unit.Player) if(flank.Player != unit.Player)
{ {
BoltLog.Error("Tried to move unit {0} of player {1} to flank {2} of player {3}", unit, unit.Player, flank, flank.Player);
Debug.LogErrorFormat("Tried to move unit {0} of player {1} to flank {2} of player {3}", unit, unit.Player, flank, flank.Player);
} }
else if(flank.MaxUnitCount <= flankIndex) else if(flank.MaxUnitCount <= flankIndex)
{ {
BoltLog.Error("Tried to move unit {0} to flank index {1} on flank {2} with size {3}", unit, flankIndex, flank, flank.MaxUnitCount);
Debug.LogErrorFormat("Tried to move unit {0} to flank index {1} on flank {2} with size {3}", unit, flankIndex, flank, flank.MaxUnitCount);
} }
else if(flank.GetUnit(flankIndex) != null) else if(flank.GetUnit(flankIndex) != null)
{ {
BoltLog.Error("Tried to move unit {0} to flank index {1} on flank {2}, but it was already occupied by {3}", unit, flankIndex, flank, flank.GetUnit(flankIndex));
Debug.LogErrorFormat("Tried to move unit {0} to flank index {1} on flank {2}, but it was already occupied by {3}", unit, flankIndex, flank, flank.GetUnit(flankIndex));
} }
else { else {
BoltLog.Info("Moving unit {0} to flank index {1} on flank {2}", unit, flankIndex, flank);
Debug.LogFormat("Moving unit {0} to flank index {1} on flank {2}", unit, flankIndex, flank);
unit.BattleState = BattleUnitState.MovingToFlank; unit.BattleState = BattleUnitState.MovingToFlank;
float movement = unit.Class.Movement <= 0 ? 1f : unit.Class.Movement; float movement = unit.Class.Movement <= 0 ? 1f : unit.Class.Movement;
@ -664,7 +670,8 @@ namespace GWConquest
} }
} }
public void MoveUnitToFlankRpc(NetworkBehaviourReference unit, NetworkBehaviourReference flank, int flankIndex)
[ServerRpc]
public void MoveUnitToFlankServerRpc(NetworkBehaviourReference unit, NetworkBehaviourReference flank, int flankIndex)
{ {
MoveUnitToFlank(unit.GetBehaviour<Unit>(), flank.GetBehaviour<BattleFlank>(), flankIndex); MoveUnitToFlank(unit.GetBehaviour<Unit>(), flank.GetBehaviour<BattleFlank>(), flankIndex);
} }
@ -676,7 +683,8 @@ namespace GWConquest
unit.SetActionCooldown(GameManager.Instance.MoveToReserveCooldown / movement); unit.SetActionCooldown(GameManager.Instance.MoveToReserveCooldown / movement);
} }
public void MoveUnitToReserveRpc(NetworkBehaviourReference unit)
[ServerRpc]
public void MoveUnitToReserveServerRpc(NetworkBehaviourReference unit)
{ {
MoveUnitToReserve(unit.GetBehaviour<Unit>()); MoveUnitToReserve(unit.GetBehaviour<Unit>());
} }


+ 12
- 9
Assets/GWConquest/Scripts/BattleFlank.cs View File

@ -1,7 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
using Photon.Bolt;
using Unity.Netcode; using Unity.Netcode;
namespace GWConquest { namespace GWConquest {
@ -124,18 +124,21 @@ namespace GWConquest {
public void FixedUpdate() public void FixedUpdate()
{ {
for(int i = 0; i < MaxUnitCount; i++)
if(IsServer)
{ {
if(GetDeathCooldown(i) > 0)
for(int i = 0; i < MaxUnitCount; i++)
{ {
deathCooldowns[i] -= BoltNetwork.FrameDeltaTime;
if(GetDeathCooldown(i) <= 0)
if(GetDeathCooldown(i) > 0)
{ {
var unit = GetUnit(i);
if(unit != null)
deathCooldowns[i] -= Time.fixedDeltaTime;
if(GetDeathCooldown(i) <= 0)
{ {
unit.CurrentFlank = null;
SetUnit(i, null);
var unit = GetUnit(i);
if(unit != null)
{
unit.CurrentFlank = null;
SetUnit(i, null);
}
} }
} }
} }


+ 13
- 13
Assets/GWConquest/Scripts/BattleLog.cs View File

@ -1,7 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
using Photon.Bolt;
using System; using System;
namespace GWConquest namespace GWConquest
@ -12,27 +12,27 @@ namespace GWConquest
public struct BattleLogUnitEntry public struct BattleLogUnitEntry
{ {
public NetworkId Id;
public string ClassName;
public NullableNetworkBehaviourReference Id;
public ushort ClassID;
public int PlayerID; public int PlayerID;
public UnitClass UnitClass { public UnitClass UnitClass {
get => UnitClass.FromName(ClassName);
get => UnitClass.FromID(ClassID);
} }
public Unit Unit { public Unit Unit {
get => BoltNetwork.FindEntity(Id)?.GetComponent<Unit>();
get => Id.GetBehaviour<Unit>();
} }
} }
public struct BattleLogBattleEntry public struct BattleLogBattleEntry
{ {
public NetworkId Id;
public NullableNetworkBehaviourReference Id;
public string BattleName; public string BattleName;
public string PlanetName; public string PlanetName;
public Battle Battle { public Battle Battle {
get => BoltNetwork.FindEntity(Id)?.GetComponent<Battle>();
get => Id.GetBehaviour<Battle>();
} }
} }
@ -51,16 +51,16 @@ namespace GWConquest
public BattleLogEntry(Unit unit, BattleLogAction action, Unit target = null, Battle battle = null) public BattleLogEntry(Unit unit, BattleLogAction action, Unit target = null, Battle battle = null)
{ {
Unit = new BattleLogUnitEntry() { Unit = new BattleLogUnitEntry() {
Id = unit.entity.NetworkId,
ClassName = unit.state.UnitClass,
Id = unit,
ClassID = unit.Class.ID,
PlayerID = unit.Player.PlayerId PlayerID = unit.Player.PlayerId
}; };
Action = action; Action = action;
if(target != null) if(target != null)
{ {
Target = new BattleLogUnitEntry() { Target = new BattleLogUnitEntry() {
Id = target.entity.NetworkId,
ClassName = target.state.UnitClass,
Id = target,
ClassID = target.Class.ID,
PlayerID = target.Player.PlayerId PlayerID = target.Player.PlayerId
}; };
} }
@ -70,7 +70,7 @@ namespace GWConquest
if(battle != null) if(battle != null)
{ {
Battle = new BattleLogBattleEntry() { Battle = new BattleLogBattleEntry() {
Id = battle.entity.NetworkId,
Id = battle,
BattleName = battle.name, BattleName = battle.name,
PlanetName = battle.Zone.planet.name PlanetName = battle.Zone.planet.name
}; };
@ -91,7 +91,7 @@ namespace GWConquest
public IEnumerable<BattleLogEntry> GetEntriesForBattle(Battle battle) public IEnumerable<BattleLogEntry> GetEntriesForBattle(Battle battle)
{ {
return Entries.Where(e => e.Battle.Id == battle.entity.NetworkId);
return Entries.Where(e => e.Battle.Battle == battle);
} }
} }
} }

+ 0
- 58
Assets/GWConquest/Scripts/BoltEntityCache.cs View File

@ -1,58 +0,0 @@
using Photon.Bolt;
using UnityEngine;
using System.Collections.Generic;
namespace GWConquest
{
public static class BoltEntityCache
{
private static Dictionary<NetworkId, IEntityBehaviour> dictionary = new Dictionary<NetworkId, IEntityBehaviour>();
public static T Get<T>(NetworkId id) where T : class, IEntityBehaviour
{
if(id == default(NetworkId))
{
return null;
}
if(dictionary.ContainsKey(id))
{
var behaviour = dictionary[id];
if(behaviour.entity.NetworkId == id)
{
return behaviour as T;
}
}
var entity = BoltNetwork.FindEntity(id);
if(entity == null)
{
return null;
}
else {
var newBeh = entity.GetComponent<T>();
dictionary[id] = newBeh;
return newBeh;
}
}
public static NetworkId Set<T>(T behaviour) where T : class, IEntityBehaviour
{
if(behaviour == null)
{
return default(NetworkId);
}
else {
return behaviour.entity.NetworkId;
}
}
public static void ClearCache()
{
dictionary.Clear();
}
}
}

+ 0
- 11
Assets/GWConquest/Scripts/BoltEntityCache.cs.meta View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: c2f033f40a5a03e4ba66c6f9240d2043
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

+ 0
- 240
Assets/GWConquest/Scripts/BoltList.cs View File

@ -1,240 +0,0 @@
using Photon.Bolt;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UdpKit;
namespace GWConquest
{
public abstract class BoltList<T, TokenClass> : IList<T> where TokenClass : BoltListToken<T>, new()
{
private IState state;
private string propertyName;
public BoltList(IState _state, string _propertyName)
{
state = _state;
propertyName = _propertyName;
}
private TokenClass Token
{
get
{
TokenClass token = state.GetDynamic(propertyName) as TokenClass;
if (token == null)
{
return new TokenClass();
}
else
{
return token;
}
}
set => state.SetDynamic(propertyName, value);
}
public void FromToken(TokenClass token)
{
Token = token;
}
public T this[int index]
{
get => Token.entries[index];
set
{
Token.entries[index] = value;
Token = new TokenClass().SetEntries(Token.entries) as TokenClass;
}
}
public int Count => Token.entries.Length;
public bool IsReadOnly => false;
public void Add(T item)
{
if (!Contains(item))
{
Token = new TokenClass().SetEntries(Token.entries.Append(item)) as TokenClass;
}
}
public void Clear()
{
Token = new TokenClass();
}
public bool Contains(T item)
{
return Token.entries.Contains(item);
}
public void CopyTo(T[] array, int arrayIndex)
{
Token.entries.CopyTo(array, arrayIndex);
}
public IEnumerator<T> GetEnumerator()
{
return new GenericListEnumerator<T>(this);
}
public int IndexOf(T item)
{
return Array.IndexOf(Token.entries, item);
}
public void Insert(int index, T item)
{
List<T> list = Token.entries.ToList();
list.Insert(index, item);
Token = new TokenClass().SetEntries(list) as TokenClass;
}
public bool Remove(T item)
{
List<T> list = Token.entries.ToList();
if (list.Remove(item))
{
Token = new TokenClass().SetEntries(list) as TokenClass;
return true;
}
else return false;
}
public void RemoveAt(int index)
{
List<T> list = Token.entries.ToList();
list.RemoveAt(index);
Token = new TokenClass().SetEntries(list) as TokenClass;
}
IEnumerator IEnumerable.GetEnumerator()
{
return new GenericListEnumerator<T>(this);
}
public override string ToString()
{
return "BoltList " + Util.PrintEnumerable(this);
}
public void SetEntries(IEnumerable<T> entries)
{
Token = new TokenClass().SetEntries(entries) as TokenClass;
}
}
public abstract class BoltListToken<T> : IProtocolToken
{
public BoltListToken()
{
entries = new T[0];
}
public BoltListToken<T> SetEntries(IEnumerable<T> _entities)
{
entries = _entities.ToArray();
return this;
}
public T[] entries { get; private set; }
public void Read(UdpPacket packet)
{
//BoltLog.Info("Reading Bolt list...");
int count = packet.ReadInt();
entries = new T[count];
for (int i = 0; i < count; i++)
{
entries[i] = ReadEntry(packet);
}
//BoltLog.Info("Finished reading Bolt list {0}", this);
}
public void Write(UdpPacket packet)
{
//BoltLog.Info("Writing Bolt list...");
packet.WriteInt(entries.Length);
foreach (T e in entries)
{
WriteEntry(packet, e);
}
//BoltLog.Info("Finished writing Bolt list {0}", this);
}
public override string ToString()
{
return "BoltList " + Util.PrintEnumerable(entries);
}
public override bool Equals(object obj)
{
if(obj == null || !(obj is BoltListToken<T>))
return false;
var other = obj as BoltListToken<T>;
if(entries.Length != other.entries.Length)
return false;
for(int i = 0; i < entries.Length; i++)
{
if(entries[i] == null)
{
if(other.entries[i] != null)
return false;
}
else {
if(!entries[i].Equals(other.entries[i]))
return false;
}
}
return true;
}
public abstract T ReadEntry(UdpPacket packet);
public abstract void WriteEntry(UdpPacket packet, T entry);
}
public class ZoneListToken : BoltListToken<Zone> {
public override Zone ReadEntry(UdpPacket packet)
{
return Zone.GetFromId(packet.ReadInt());
}
public override void WriteEntry(UdpPacket packet, Zone entry)
{
packet.WriteInt(Zone.GetZoneId(entry));
}
}
public class ZoneList : BoltList<Zone, ZoneListToken>
{
public ZoneList(IState _state, string _propertyName) : base(_state, _propertyName) {}
}
public class StringListToken : BoltListToken<string> {
public override string ReadEntry(UdpPacket packet)
{
return packet.ReadString();
}
public override void WriteEntry(UdpPacket packet, string entry)
{
packet.WriteString(entry);
}
}
public class StringList : BoltList<string, StringListToken>
{
public StringList(IState _state, string _propertyName) : base(_state, _propertyName) {}
}
}

+ 0
- 11
Assets/GWConquest/Scripts/BoltList.cs.meta View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: fda8796fd8800ef46a1ae47fa4de74a7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

+ 29
- 26
Assets/GWConquest/Scripts/District.cs View File

@ -1,8 +1,8 @@
using UnityEngine; using UnityEngine;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Photon.Bolt;
using Photon.Bolt.Utils;
using Unity.Netcode; using Unity.Netcode;
using Unity.Collections; using Unity.Collections;
@ -63,7 +63,7 @@ namespace GWConquest
} }
else if(id >= Player.PlayerList.Count) else if(id >= Player.PlayerList.Count)
{ {
BoltLog.Warn("Tried accessing player {0} in player list of length {1}", id, Player.PlayerList.Count);
Debug.LogWarningFormat("Tried accessing player {0} in player list of length {1}", id, Player.PlayerList.Count);
return null; return null;
} }
else else
@ -103,7 +103,7 @@ namespace GWConquest
Inventory.StorageCapacity = StorageCapacity; Inventory.StorageCapacity = StorageCapacity;
storageCapacity.OnValueChanged += (prev, now) => Inventory.StorageCapacity = now; storageCapacity.OnValueChanged += (prev, now) => Inventory.StorageCapacity = now;
//BoltLog.Info("Setting storage capacity to {0}", StorageCapacity);
//Debug.LogFormat("Setting storage capacity to {0}", StorageCapacity);
AllDistricts.Add(this); AllDistricts.Add(this);
@ -277,15 +277,15 @@ namespace GWConquest
{ {
if(captureCooldown.Value >= GameManager.Instance.DistrictCaptureCooldown) if(captureCooldown.Value >= GameManager.Instance.DistrictCaptureCooldown)
{ {
BoltLog.Info($"Allegiance changed in district {this} to player {player}");
Debug.LogFormat($"Allegiance changed in district {this} to player {player}");
ControllingPlayer = player; ControllingPlayer = player;
} }
else { else {
if(captureCooldown.Value == 0) if(captureCooldown.Value == 0)
{ {
BoltLog.Info("Player {0} is the only player in district {1}, starting allegiance change...", player, this);
Debug.LogFormat("Player {0} is the only player in district {1}, starting allegiance change...", player, this);
} }
captureCooldown.Value += BoltNetwork.FrameDeltaTime;
captureCooldown.Value += Time.fixedDeltaTime;
} }
return; return;
} }
@ -298,31 +298,34 @@ namespace GWConquest
public void FixedUpdate() public void FixedUpdate()
{ {
CheckControllingChange();
if(ControllingPlayer != null)
if(IsServer)
{ {
string producingItem = ProducingItem;
CheckControllingChange();
bool producesCredits = DistrictType == DistrictType.Civil;
if(ControllingPlayer != null)
{
string producingItem = ProducingItem;
if(producingItem != null || producesCredits) {
if(itemProductionCooldown.Value <= 0f)
{
if(producingItem != null)
{
Inventory.AddItem(ItemRegistry.Instance.IDFromName(producingItem), 1);
}
bool producesCredits = DistrictType == DistrictType.Civil;
if(producesCredits)
if(producingItem != null || producesCredits) {
if(itemProductionCooldown.Value <= 0f)
{ {
ControllingPlayer.Credits++;
}
if(producingItem != null)
{
Inventory.AddItem(ItemRegistry.Instance.IDFromName(producingItem), 1);
}
itemProductionCooldown.Value = ProducingCooldown;
}
else {
itemProductionCooldown.Value -= Time.fixedDeltaTime;
if(producesCredits)
{
ControllingPlayer.Credits++;
}
itemProductionCooldown.Value = ProducingCooldown;
}
else {
itemProductionCooldown.Value -= Time.fixedDeltaTime;
}
} }
} }
} }


+ 19
- 15
Assets/GWConquest/Scripts/DistrictFactory.cs View File

@ -1,8 +1,8 @@
using UnityEngine; using UnityEngine;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Photon.Bolt;
using Photon.Bolt.Utils;
using Unity.Netcode; using Unity.Netcode;
using System; using System;
@ -43,6 +43,7 @@ namespace GWConquest
public bool StartsBroken = false; public bool StartsBroken = false;
public string[] SpecialUnits; public string[] SpecialUnits;
public int MaxQueueLength;
private District _district; private District _district;
public District District public District District
@ -118,7 +119,7 @@ namespace GWConquest
{ {
if(!District.CanBuild(buildable)) if(!District.CanBuild(buildable))
{ {
BoltLog.Error($"Could not build {buildable} in district {gameObject.name}");
Debug.LogErrorFormat($"Could not build {buildable} in district {gameObject.name}");
return; return;
} }
@ -144,7 +145,7 @@ namespace GWConquest
planetInv.RemoveItem(itemId, cost.Amount); planetInv.RemoveItem(itemId, cost.Amount);
} }
else { else {
BoltLog.Error("Error while building {0}: Item {1} x {2} not found in inventories", buildable, cost.Item, cost.Amount);
Debug.LogErrorFormat("Error while building {0}: Item {1} x {2} not found in inventories", buildable, cost.Item, cost.Amount);
} }
} }
} }
@ -152,19 +153,22 @@ namespace GWConquest
} }
int length = ProductionQueueLength; int length = ProductionQueueLength;
BoltLog.Info("Adding unit {0} to production queue on district {1}", buildable, gameObject.name);
productionQueue.Add(new ProductionQueueEntry() {
UnitClass = buildable.ID,
TimeProduced = 0f,
PlayerID = player.PlayerId,
IsUpgrade = buildable is DistrictUpgrade
});
if(length < MaxQueueLength)
{
Debug.LogFormat("Adding unit {0} to production queue on district {1}", buildable, gameObject.name);
productionQueue.Add(new ProductionQueueEntry() {
UnitClass = buildable.ID,
TimeProduced = 0f,
PlayerID = player.PlayerId,
IsUpgrade = buildable is DistrictUpgrade
});
}
} }
[ServerRpc] [ServerRpc]
public void AddProductionQueueEntryRpc(ushort buildableID, bool isUpgrade, NetworkBehaviourReference player)
public void AddProductionQueueEntryServerRpc(ushort buildableID, bool isUpgrade, NetworkBehaviourReference player)
{ {
IBuildable buildable = isUpgrade ? DistrictUpgrade.FromID(buildableID) : UnitClass.FromID(buildableID); IBuildable buildable = isUpgrade ? DistrictUpgrade.FromID(buildableID) : UnitClass.FromID(buildableID);
AddProductionQueueEntry(buildable, player.GetBehaviour<Player>()); AddProductionQueueEntry(buildable, player.GetBehaviour<Player>());
@ -188,11 +192,11 @@ namespace GWConquest
Zone zone = GetComponent<Zone>(); Zone zone = GetComponent<Zone>();
if(zone != null) if(zone != null)
{ {
Unit.SpawnUnit(zone, buildable as UnitClass, productionQueue[0].Player);
GWNetworkManager.Instance.SpawnUnit(zone, buildable as UnitClass, productionQueue[0].Player);
} }
else else
{ {
BoltLog.Error("No corresponding zone for factory {0}", gameObject.name);
Debug.LogErrorFormat("No corresponding zone for factory {0}", gameObject.name);
} }
} }
else if(buildable is DistrictUpgrade) else if(buildable is DistrictUpgrade)


+ 7
- 7
Assets/GWConquest/Scripts/DistrictUpgrade.cs View File

@ -1,4 +1,4 @@
using Photon.Bolt.Utils;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
@ -13,7 +13,7 @@ namespace GWConquest
public static void LoadRegistry() public static void LoadRegistry()
{ {
BoltLog.Info("Loading district upgrades...");
Debug.LogFormat("Loading district upgrades...");
List<DistrictUpgrade> upgradeList = new List<DistrictUpgrade>(); List<DistrictUpgrade> upgradeList = new List<DistrictUpgrade>();
UpgradeRegistry = new Dictionary<string, DistrictUpgrade>(); UpgradeRegistry = new Dictionary<string, DistrictUpgrade>();
@ -85,14 +85,14 @@ namespace GWConquest
} }
catch (Exception ex) catch (Exception ex)
{ {
BoltLog.Error("Could not parse district upgrade");
BoltLog.Exception(ex);
Debug.LogErrorFormat("Could not parse district upgrade");
Debug.LogException(ex);
} }
} }
Upgrades = upgradeList.ToArray(); Upgrades = upgradeList.ToArray();
BoltLog.Info("District upgrades loaded.");
Debug.LogFormat("District upgrades loaded.");
} }
public static DistrictUpgrade FromID(ushort id) public static DistrictUpgrade FromID(ushort id)
@ -119,7 +119,7 @@ namespace GWConquest
} }
if(Util.IsStringEmpty(name)) if(Util.IsStringEmpty(name))
{ {
BoltLog.Warn("DistrictUpgrade.FromName called with null name!");
Debug.LogWarningFormat("DistrictUpgrade.FromName called with null name!");
return null; return null;
} }
if (UpgradeRegistry.ContainsKey(name)) if (UpgradeRegistry.ContainsKey(name))
@ -128,7 +128,7 @@ namespace GWConquest
} }
else else
{ {
BoltLog.Warn("DistrictUpgrade {0} not in registry!", name);
Debug.LogWarningFormat("DistrictUpgrade {0} not in registry!", name);
return null; return null;
} }
} }


+ 0
- 119
Assets/GWConquest/Scripts/EntityList.cs View File

@ -1,119 +0,0 @@
using UdpKit;
using Photon.Bolt;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
using System;
namespace GWConquest
{
public class GenericListEnumerator<T> : IEnumerator<T>
{
private int position = -1;
private IList<T> list;
public GenericListEnumerator(IList<T> _list)
{
list = _list;
}
public T Current => list[position];
object IEnumerator.Current => list[position];
public void Dispose() { }
public bool MoveNext()
{
position++;
return position < list.Count;
}
public void Reset()
{
position = -1;
}
}
public class CachedBoltEntity
{
public NetworkId NetworkId { get; private set; }
private BoltEntity cachedEntity;
public CachedBoltEntity(NetworkId id)
{
NetworkId = id;
}
public CachedBoltEntity(BoltEntity e)
{
NetworkId = e.NetworkId;
cachedEntity = e;
}
public BoltEntity Entity
{
get
{
if (cachedEntity == null)
{
cachedEntity = BoltNetwork.FindEntity(NetworkId);
}
return cachedEntity;
}
}
public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
{
return false;
}
var other = obj as CachedBoltEntity;
return NetworkId == other.NetworkId;
}
public override int GetHashCode()
{
return NetworkId.PackedValue.GetHashCode();
}
public override string ToString()
{
return Entity?.ToString();
}
}
public class EntityListToken : BoltListToken<CachedBoltEntity>
{
public override CachedBoltEntity ReadEntry(UdpPacket packet)
{
var id = new NetworkId(packet.ReadULong());
return new CachedBoltEntity(id);
}
public override void WriteEntry(UdpPacket packet, CachedBoltEntity entry)
{
packet.WriteULong(entry.NetworkId.PackedValue);
}
}
public class EntityList : BoltList<CachedBoltEntity, EntityListToken>
{
public EntityList(IState _state, string _propertyName) : base(_state, _propertyName) { }
public void Add(BoltEntity e)
{
Add(new CachedBoltEntity(e));
}
public bool Remove(BoltEntity e)
{
return Remove(new CachedBoltEntity(e));
}
}
}

+ 269
- 236
Assets/GWConquest/Scripts/Formation.cs
File diff suppressed because it is too large
View File


+ 0
- 35
Assets/GWConquest/Scripts/GWBoltBehaviour.cs View File

@ -1,35 +0,0 @@
using Photon.Bolt;
namespace GWConquest {
public abstract class GWBoltBehaviour<T> : EntityBehaviour<T> where T : class, IState
{
private T _state = null;
public T State {
get {
/*if(_state == null)
{
_state = state;
}
return _state;*/
return state;
}
}
}
public abstract class GWBoltEntityListener<T> : EntityEventListener<T> where T : class, IState
{
private T _state = null;
public T State {
get {
/*if(_state == null)
{
_state = state;
}
return _state;*/
return state;
}
}
}
}

+ 0
- 11
Assets/GWConquest/Scripts/GWBoltBehaviour.cs.meta View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: f48b9c6bc6be7154e809c78208e38787
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

+ 0
- 5
Assets/GWConquest/Scripts/GWNetworkArray.cs View File

@ -1,5 +0,0 @@
using Unity.Netcode;
namespace GWConquest {
}

+ 0
- 11
Assets/GWConquest/Scripts/GWNetworkArray.cs.meta View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 5893ec9dc0d5802479ca61e4b13ac64f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

+ 187
- 0
Assets/GWConquest/Scripts/GWNetworkManager.cs View File

@ -0,0 +1,187 @@
using UnityEngine;
using Unity.Netcode;
using System.Linq;
namespace GWConquest {
public class GWNetworkManager : NetworkBehaviour
{
private static GWNetworkManager _instance;
public static GWNetworkManager Instance {
get {
if(_instance == null)
{
_instance = FindObjectOfType<GWNetworkManager>();
}
return _instance;
}
}
public GameObject UnitPrefab;
public GameObject FormationPrefab;
public GameObject BattlePrefab;
public override void OnNetworkSpawn()
{
NetworkManager.SceneManager.OnSceneEvent += OnSceneEvent;
base.OnNetworkSpawn();
}
private void OnSceneEvent(SceneEvent sceneEvent)
{
if(IsServer)
{
if(sceneEvent.SceneEventType == SceneEventType.LoadComplete)
{
if(sceneEvent.ClientId == NetworkManager.ServerClientId)
{
ServerSceneLoadCompleteLocal(sceneEvent.SceneName);
}
else {
ServerSceneLoadCompleteRemote(sceneEvent.ClientId);
}
GameManager.Instance.SceneLoadLocalDone(false);
}
}
else {
if(sceneEvent.SceneEventType == SceneEventType.LoadComplete)
{
ClientSceneLoadComplete();
GameManager.Instance.SceneLoadLocalDone(true);
}
}
}
public void ServerSceneLoadCompleteLocal(string scene)
{
if(scene != "GalaxyMap")
return;
PlanetPlacement.Instance.PlacePlanets();
foreach(Planet planet in FindObjectsOfType<Planet>())
{
planet.FinishSetup();
}
Player serverPlayer = NetworkManager.SpawnManager.GetLocalPlayerObject().GetComponent<Player>();
serverPlayer.SetFaction((ushort) GameManager.HostFactionIndex);
serverPlayer.AssignStartingPlanets();
GameManager.Instance.ServerSceneLoadLocalDone();
//foreach(GameObject go in FindObjectsOfType<GameObject>()) {
// go.SendMessage("OnSceneLoadLocalDone", SendMessageOptions.DontRequireReceiver);
//}
foreach(var spawner in FindObjectsOfType<SpawnAIUnits>())
{
spawner.SpawnUnits();
}
foreach(Zone z in Zone.AllZones)
{
z.CheckBattleStart();
}
Planet.SetupPlanetPathfinding();
GameManager.EntitiesLoaded = true;
GameOptions.ApplyOptions();
LoadingScreen.Dismiss();
Debug.Log("Server scene loading done.");
}
public void ServerSceneLoadCompleteRemote(ulong clientID)
{
Player clientPlayer = NetworkManager.SpawnManager.GetPlayerNetworkObject(clientID).GetComponent<Player>();
clientPlayer.SetFaction((ushort) ((GameManager.HostFactionIndex + 1) % 2));
clientPlayer.AssignStartingPlanets();
}
public void ClientSceneLoadComplete()
{
GameOptions.ApplyOptions();
}
[ServerRpc]
public void MoveItemServerRpc(NetworkBehaviourReference origin, NetworkBehaviourReference target, ushort itemID, int itemAmount)
{
NetworkBehaviour originBeh = origin.GetBehaviour();
NetworkBehaviour targetBeh = target.GetBehaviour();
if(originBeh is IHasInventory && targetBeh is IHasInventory)
{
IInventory originInv = (originBeh as IHasInventory).GetInventory();
IInventory targetInv = (targetBeh as IHasInventory).GetInventory();
Inventory.MoveItem(originInv, targetInv, itemID, itemAmount);
}
else {
Debug.LogError("One of the specified behaviours is not an inventory");
}
}
public Unit SpawnUnit(Zone zone, UnitClass uc, Player player)
{
Formation playerFormation = zone.Formations.FirstOrDefault(f => f.Player == player);
if (playerFormation == null)
{
playerFormation = SpawnFormation(zone, player);
}
GameObject go = Instantiate(UnitPrefab);
go.GetComponent<NetworkObject>().Spawn();
Unit unit = go.GetComponent<Unit>();
unit.InstantiateWithClass(uc);
unit.Formation = playerFormation;
playerFormation.AddUnit(unit);
Debug.LogFormat("Spawned unit {0} for player {1} in formation {2}", unit, player, playerFormation);
return unit;
}
[ServerRpc]
public void SpawnUnitServerRpc(int zoneID, ushort unitClassID, int playerID)
{
SpawnUnit(Zone.GetFromId(zoneID), UnitClass.FromID(unitClassID), Player.GetPlayerById(playerID));
}
public Formation SpawnFormation(Zone zone, Player player)
{
GameObject go = Instantiate(FormationPrefab);
go.GetComponent<NetworkObject>().Spawn();
Formation playerFormation = go.GetComponent<Formation>();
playerFormation.Initialize(zone, player);
return playerFormation;
}
public Battle SpawnBattle(Zone zone)
{
var go = Instantiate(BattlePrefab);
go.GetComponent<NetworkObject>().Spawn();
Battle battle = go.GetComponent<Battle>();
battle.Zone = zone;
foreach (Formation f in zone.Formations)
{
battle.AddFormation(f);
}
battle.Init();
Debug.LogFormat("Starting battle at zone {0}", this);
return battle;
}
}
}

Assets/GWConquest/Scripts/EntityList.cs.meta → Assets/GWConquest/Scripts/GWNetworkManager.cs.meta View File

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 38983f1af3b8f9446a9a71fc1d5ebfc7
guid: 1741c174eb1458047aa5ab35a3b0aec4
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

+ 18
- 31
Assets/GWConquest/Scripts/GameManager.cs View File

@ -1,7 +1,6 @@
using UnityEngine; using UnityEngine;
using System.Collections; using System.Collections;
using Photon.Bolt;
using Photon.Bolt.Utils;
using Unity.Netcode;
namespace GWConquest namespace GWConquest
{ {
@ -85,6 +84,8 @@ namespace GWConquest
public bool SpawnAIPlayer; public bool SpawnAIPlayer;
public GameObject PlayerPrefab;
public bool IsLoaded { get; private set; } = false; public bool IsLoaded { get; private set; } = false;
public float TimeScale = 1f; public float TimeScale = 1f;
@ -98,7 +99,7 @@ namespace GWConquest
_instance = FindObjectOfType<GameManager>(); _instance = FindObjectOfType<GameManager>();
if(_instance == null) if(_instance == null)
{ {
BoltLog.Warn("Found no Game Manager instance!");
Debug.LogWarningFormat("Found no Game Manager instance!");
} }
} }
return _instance; return _instance;
@ -118,21 +119,22 @@ namespace GWConquest
BattleLog.Instance = new BattleLog(); BattleLog.Instance = new BattleLog();
} }
public void SceneLoadLocalDone()
public void ServerSceneLoadLocalDone()
{ {
if(SpawnAIPlayer) if(SpawnAIPlayer)
{ {
BoltLog.Info("Spawning AI players...");
Debug.LogFormat("Spawning AI players...");
for(int i = 0; i < Factions.Length; i++) for(int i = 0; i < Factions.Length; i++)
{ {
var faction = Factions[i]; var faction = Factions[i];
if(faction.IsAI) if(faction.IsAI)
{ {
BoltEntity playerEntity = BoltNetwork.Instantiate(BoltPrefabs.Player);
IPlayerState playerState = playerEntity.GetState<IPlayerState>(); ;
playerState.IsAI = true;
playerState.FactionIndex = i;
playerEntity.GetComponent<Player>().AssignStartingPlanets();
GameObject go = Instantiate(PlayerPrefab);
go.GetComponent<NetworkObject>().Spawn();
Player player = go.GetComponent<Player>();
player.SetAI();
player.SetFaction((ushort) i);
player.AssignStartingPlanets();
} }
} }
@ -141,41 +143,27 @@ namespace GWConquest
IsLoaded = true; IsLoaded = true;
} }
public void FixedUpdate() {
if(Input.GetKeyDown(KeyCode.F1))
{
var ui = IngameUI.Instance.gameObject;
ui.SetActive(!ui.activeSelf);
}
}
public void SetEntitiesLoaded()
public void SceneLoadLocalDone(bool isClient)
{ {
StartCoroutine(EntitiesLoadedAsync());
}
private IEnumerator EntitiesLoadedAsync()
{
yield return new WaitForSecondsRealtime(1f);
yield return new WaitForFixedUpdate();
EntitiesLoaded = true; EntitiesLoaded = true;
if(BoltNetwork.IsClient)
if(isClient)
{ {
BoltLog.Info("Loading non-static planets on client...");
Debug.LogFormat("Loading non-static planets on client...");
InitPlanetsClient(); InitPlanetsClient();
} }
Planet.SetupPlanetPathfinding(); Planet.SetupPlanetPathfinding();
BoltLog.Info("Setup planet pathfinding.");
Debug.LogFormat("Setup planet pathfinding.");
Planet.UpdateVisibilityStatus(); Planet.UpdateVisibilityStatus();
BoltLog.Info("Entities loaded, Dismissing loading screen...");
Debug.LogFormat("Entities loaded, Dismissing loading screen...");
LoadingScreen.Dismiss(); LoadingScreen.Dismiss();
} }
private void InitPlanetsClient() private void InitPlanetsClient()
{ {
var allPlanets = FindObjectsOfType<Planet>(); var allPlanets = FindObjectsOfType<Planet>();
@ -212,7 +200,6 @@ namespace GWConquest
BattleLog.Instance = null; BattleLog.Instance = null;
BoltEntityCache.ClearCache();
District.AllDistricts.Clear(); District.AllDistricts.Clear();
Formation.AllFormations.Clear(); Formation.AllFormations.Clear();


+ 0
- 69
Assets/GWConquest/Scripts/GlobalCallbacks.cs View File

@ -1,69 +0,0 @@
using Photon.Bolt;
using Photon.Bolt.Utils;
using UdpKit;
using UnityEngine;
using System.Linq;
namespace GWConquest
{
[BoltGlobalBehaviour]
public class GlobalCallbacks : GlobalEventListener
{
public override void BoltStartBegin()
{
Debug.Log("Calling global callbacks...");
BoltNetwork.RegisterTokenClass<EntityListToken>();
BoltNetwork.RegisterTokenClass<ZoneListToken>();
BoltNetwork.RegisterTokenClass<InventoryToken>();
BoltNetwork.RegisterTokenClass<StringListToken>();
}
public override void SceneLoadLocalDone(string scene, IProtocolToken token)
{
//BoltLog.Info("scene load token: {0}", token);
GameOptions.ApplyOptions();
}
public override void SessionConnected(UdpSession session, IProtocolToken token)
{
BoltLog.Info("Session connected.");
}
public override void OnEvent(ServerConfigEvent evnt)
{
if(BoltNetwork.IsClient)
{
GameManager.InitialEntityCount = evnt.EntityCount;
BoltLog.Info("Initial entity count is {0}", GameManager.InitialEntityCount);
if(!GameManager.EntitiesLoaded && GameManager.InitialEntityCount <= BoltNetwork.Entities.Count())
{
BoltLog.Info("All entities retrieved!");
GameManager.Instance.SetEntitiesLoaded();
}
}
}
public override void EntityReceived(BoltEntity entity)
{
if(BoltNetwork.IsClient && !GameManager.EntitiesLoaded)
{
var ecount = BoltNetwork.Entities.Count();
if(ecount >= GameManager.InitialEntityCount)
{
BoltLog.Info("All entities retrieved!");
GameManager.Instance.SetEntitiesLoaded();
}
}
}
}
}

+ 0
- 11
Assets/GWConquest/Scripts/GlobalCallbacks.cs.meta View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 4cd2ea54c0e00384894169adbfdf6403
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

+ 9
- 9
Assets/GWConquest/Scripts/Inventory.cs View File

@ -1,6 +1,6 @@
using UdpKit; using UdpKit;
using Photon.Bolt;
using Photon.Bolt.Utils;
using System; using System;
using System.Linq; using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
@ -67,7 +67,7 @@ namespace GWConquest
var item = ItemRegistry.Instance.GetEntry(itemName); var item = ItemRegistry.Instance.GetEntry(itemName);
if(!item.Stackable && amount > 1) if(!item.Stackable && amount > 1)
{ {
BoltLog.Warn("Item {0} is not stackable to amount {1}", itemName, amount);
Debug.LogWarningFormat("Item {0} is not stackable to amount {1}", itemName, amount);
amount = 1; amount = 1;
} }
return new ItemStack { return new ItemStack {
@ -83,7 +83,7 @@ namespace GWConquest
var item = ItemRegistry.Instance.GetEntry(itemID); var item = ItemRegistry.Instance.GetEntry(itemID);
if(!item.Stackable && amount > 1) if(!item.Stackable && amount > 1)
{ {
BoltLog.Warn("Item {0} is not stackable to amount {1}", itemID, amount);
Debug.LogWarningFormat("Item {0} is not stackable to amount {1}", itemID, amount);
amount = 1; amount = 1;
} }
return new ItemStack { return new ItemStack {
@ -261,7 +261,7 @@ namespace GWConquest
if(amountToRemove > 0) if(amountToRemove > 0)
{ {
BoltLog.Error("Inventory Error: Did not remove enough items of type {0} (desired: {1}, left: {2})", item, amount, amountToRemove);
Debug.LogErrorFormat("Inventory Error: Did not remove enough items of type {0} (desired: {1}, left: {2})", item, amount, amountToRemove);
} }
return true; return true;
@ -335,12 +335,12 @@ namespace GWConquest
target.AddItem(itemID, itemAmount); target.AddItem(itemID, itemAmount);
} }
else { else {
BoltLog.Error("Could not move {0} of item {1} between inventories", itemAmount, itemID);
Debug.LogErrorFormat("Could not move {0} of item {1} between inventories", itemAmount, itemID);
} }
} }
else { else {
BoltLog.Error("One of the specified inventories is null");
Debug.LogErrorFormat("One of the specified inventories is null");
} }
} }
@ -386,7 +386,7 @@ namespace GWConquest
} }
} }
} }
BoltLog.Error("Could not add all items to combined inventory: item {0}, amount {1}, left {2}", item, amount, remainingAmount);
Debug.LogErrorFormat("Could not add all items to combined inventory: item {0}, amount {1}, left {2}", item, amount, remainingAmount);
return true; return true;
} }
else { else {
@ -414,7 +414,7 @@ namespace GWConquest
} }
} }
} }
BoltLog.Error("Could not remove all items from combined inventory: item {0}, amount {1}, left {2}", item, amount, remainingAmount);
Debug.LogErrorFormat("Could not remove all items from combined inventory: item {0}, amount {1}, left {2}", item, amount, remainingAmount);
return true; return true;
} }
else { else {


+ 9
- 9
Assets/GWConquest/Scripts/Planet.cs View File

@ -2,8 +2,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
using Photon.Bolt;
using Photon.Bolt.Utils;
using Unity.Netcode; using Unity.Netcode;
using Unity.Collections; using Unity.Collections;
@ -144,7 +144,7 @@ namespace GWConquest
public bool IsConnectedTo(Planet planet) public bool IsConnectedTo(Planet planet)
{ {
BoltLog.Info("Planet {0} has connections {1}", this, Util.PrintObject(connections));
Debug.LogFormat("Planet {0} has connections {1}", this, Util.PrintObject(connections));
if (connections == null) return false; if (connections == null) return false;
return connections.Exists(conn => (conn.planet1 == planet || conn.planet2 == planet)); return connections.Exists(conn => (conn.planet1 == planet || conn.planet2 == planet));
} }
@ -158,29 +158,29 @@ namespace GWConquest
/*if(BoltNetwork.IsClient) /*if(BoltNetwork.IsClient)
{ {
BoltLog.Info("Planet attached on client, name: {0}", State.PlanetName);
Debug.LogFormat("Planet attached on client, name: {0}", State.PlanetName);
State.AddCallback("SpaceZoneID", () => { State.AddCallback("SpaceZoneID", () => {
BoltLog.Info("Space zone id changed to {0} on client planet {1}, static: {2}", State.SpaceZoneID, State.PlanetName, PlanetStatic);
Debug.LogFormat("Space zone id changed to {0} on client planet {1}, static: {2}", State.SpaceZoneID, State.PlanetName, PlanetStatic);
var zone = GetMainZone(ZoneType.Space); var zone = GetMainZone(ZoneType.Space);
zone.SetZoneId(State.SpaceZoneID); zone.SetZoneId(State.SpaceZoneID);
zone.zoneType = ZoneType.Space; zone.zoneType = ZoneType.Space;
}); });
State.AddCallback("AttackZoneID", () => { State.AddCallback("AttackZoneID", () => {
BoltLog.Info("Attack zone id changed to {0} on client planet {1}, static: {2}", State.AttackZoneID, State.PlanetName, PlanetStatic);
Debug.LogFormat("Attack zone id changed to {0} on client planet {1}, static: {2}", State.AttackZoneID, State.PlanetName, PlanetStatic);
var zone = GetAttackZones(ZoneType.Ground)[0]; var zone = GetAttackZones(ZoneType.Ground)[0];
zone.SetZoneId(State.AttackZoneID); zone.SetZoneId(State.AttackZoneID);
zone.zoneType = ZoneType.Ground; zone.zoneType = ZoneType.Ground;
}); });
State.AddCallback("PlanetName", () => { State.AddCallback("PlanetName", () => {
BoltLog.Info("planet name changed to {0} on client planet, static: {1}", State.PlanetName, PlanetStatic);
Debug.LogFormat("planet name changed to {0} on client planet, static: {1}", State.PlanetName, PlanetStatic);
planetName = State.PlanetName; planetName = State.PlanetName;
}); });
State.AddCallback("ConnectedPlanets", () => { State.AddCallback("ConnectedPlanets", () => {
BoltLog.Info("Connected planets changed to {0} on client planet{1}, static: {2}", ConnectedPlanetsList, State.PlanetName, PlanetStatic);
Debug.LogFormat("Connected planets changed to {0} on client planet{1}, static: {2}", ConnectedPlanetsList, State.PlanetName, PlanetStatic);
}); });
}*/ }*/
@ -338,7 +338,7 @@ namespace GWConquest
{ {
formationsChangedSinceLastFrame = true; formationsChangedSinceLastFrame = true;
if(BoltNetwork.IsServer)
if(IsServer)
{ {
var currentPlayers = GetAllFormations(ZoneType.Space).Select(f => f.Player).Distinct(); var currentPlayers = GetAllFormations(ZoneType.Space).Select(f => f.Player).Distinct();
foreach(Player player in currentPlayers) foreach(Player player in currentPlayers)


+ 3
- 3
Assets/GWConquest/Scripts/PlanetConnection.cs View File

@ -1,8 +1,8 @@
using UnityEngine; using UnityEngine;
using System.Linq; using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using Photon.Bolt;
using Photon.Bolt.Utils;
namespace GWConquest namespace GWConquest
{ {
@ -241,7 +241,7 @@ namespace GWConquest
} }
else else
{ {
BoltLog.Info("Connecting planets {0} and {1}", planet1, planet2);
Debug.LogFormat("Connecting planets {0} and {1}", planet1, planet2);
if (!planet1.connections.Contains(this)) if (!planet1.connections.Contains(this))
{ {
planet1.connections.Add(this); planet1.connections.Add(this);


+ 20
- 15
Assets/GWConquest/Scripts/PlanetPlacement.cs View File

@ -2,8 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
using Photon.Bolt;
using Photon.Bolt.Utils;
using Unity.Netcode;
namespace GWConquest namespace GWConquest
@ -26,6 +25,10 @@ namespace GWConquest
public Transform PlanetConnectionParent; public Transform PlanetConnectionParent;
public GameObject[] PlanetPrefabs; public GameObject[] PlanetPrefabs;
public GameObject PlanetPrefab;
public GameObject DistrictPrefab;
public GameObject FactoryPrefab;
private string[] PlanetNames; private string[] PlanetNames;
public float MinPlanetDistance; public float MinPlanetDistance;
@ -110,7 +113,7 @@ namespace GWConquest
if(AvailableNames.Count == 0) if(AvailableNames.Count == 0)
{ {
AvailableNames.AddRange(PlanetNames); AvailableNames.AddRange(PlanetNames);
BoltLog.Info("Refilling planet name list...");
Debug.LogFormat("Refilling planet name list...");
} }
int i = Random.Range(0, AvailableNames.Count); int i = Random.Range(0, AvailableNames.Count);
string name = AvailableNames[i]; string name = AvailableNames[i];
@ -120,7 +123,8 @@ namespace GWConquest
public Planet PlacePlanet(Vector3 position, ref int nextZoneId) public Planet PlacePlanet(Vector3 position, ref int nextZoneId)
{ {
var planetGO = BoltNetwork.Instantiate(BoltPrefabs.Planet, position, Quaternion.identity);
var planetGO = Instantiate(PlanetPrefab, position, Quaternion.identity);
planetGO.GetComponent<NetworkObject>().Spawn();
var planet = planetGO.GetComponent<Planet>(); var planet = planetGO.GetComponent<Planet>();
var planetName = DrawName(); var planetName = DrawName();
@ -166,11 +170,11 @@ namespace GWConquest
public void SpawnDistrict(Planet planet, ref int nextZoneId) public void SpawnDistrict(Planet planet, ref int nextZoneId)
{ {
PrefabId prefabID;
GameObject prefab;
DistrictType type; DistrictType type;
if(Random.value <= districtSettings.FactoryChance) if(Random.value <= districtSettings.FactoryChance)
{ {
prefabID = BoltPrefabs.Factory;
prefab = FactoryPrefab;
int factoryType = Random.Range(0, 3); int factoryType = Random.Range(0, 3);
switch(factoryType) switch(factoryType)
{ {
@ -190,15 +194,15 @@ namespace GWConquest
} }
else if(Random.value <= districtSettings.FoodChance / (1f - districtSettings.FactoryChance)) else if(Random.value <= districtSettings.FoodChance / (1f - districtSettings.FactoryChance))
{ {
prefabID = BoltPrefabs.District;
prefab = DistrictPrefab;
type = DistrictType.Food; type = DistrictType.Food;
} }
else { else {
prefabID = BoltPrefabs.Factory;
prefab = FactoryPrefab;
type = DistrictType.Civil; type = DistrictType.Civil;
} }
BoltLog.Info("Spawning district of type {0} on planet {1}", type, planet.name);
Debug.LogFormat("Spawning district of type {0} on planet {1}", type, planet.name);
var point2D = Random.insideUnitCircle * districtSettings.MaxDistrictRadius; var point2D = Random.insideUnitCircle * districtSettings.MaxDistrictRadius;
@ -212,7 +216,8 @@ namespace GWConquest
districtPos += planet.transform.position; districtPos += planet.transform.position;
var go = BoltNetwork.Instantiate(prefabID, districtPos, Quaternion.identity);
var go = Instantiate(prefab, districtPos, Quaternion.identity);
go.GetComponent<NetworkObject>().Spawn();
go.transform.SetParent(planet.transform); go.transform.SetParent(planet.transform);
var district = go.GetComponent<District>(); var district = go.GetComponent<District>();
@ -391,13 +396,13 @@ namespace GWConquest
List<Planet> allPlanets = new List<Planet>(FindObjectsOfType<Planet>()); List<Planet> allPlanets = new List<Planet>(FindObjectsOfType<Planet>());
int origPlanetCount = allPlanets.Count; int origPlanetCount = allPlanets.Count;
BoltLog.Info("Static planets: {0}", origPlanetCount);
Debug.LogFormat("Static planets: {0}", origPlanetCount);
foreach(var conn in PreConnections) foreach(var conn in PreConnections)
{ {
float connLength = conn.GetLength(); float connLength = conn.GetLength();
int planetCount = Mathf.RoundToInt( Random.Range(connLength / MaxPlanetDistance, connLength / MinPlanetDistance) ) - 1; int planetCount = Mathf.RoundToInt( Random.Range(connLength / MaxPlanetDistance, connLength / MinPlanetDistance) ) - 1;
BoltLog.Info("Spawning {0} planets between {1} and {2}", planetCount, conn.planet1.PlanetName, conn.planet2.PlanetName);
Debug.LogFormat("Spawning {0} planets between {1} and {2}", planetCount, conn.planet1.PlanetName, conn.planet2.PlanetName);
Vector3 start = conn.planet1.transform.position; Vector3 start = conn.planet1.transform.position;
Vector3 dir = conn.planet2.transform.position - start; Vector3 dir = conn.planet2.transform.position - start;
@ -430,7 +435,7 @@ namespace GWConquest
PlacePlanetsSecondPassNew(allPlanets, spawnedConnections, ref nextZoneId); PlacePlanetsSecondPassNew(allPlanets, spawnedConnections, ref nextZoneId);
int finalPlanetCount = allPlanets.Count; int finalPlanetCount = allPlanets.Count;
BoltLog.Info("Additional planets: {0}", finalPlanetCount-origPlanetCount);
Debug.LogFormat("Additional planets: {0}", finalPlanetCount-origPlanetCount);
} }
private void PlacePlanetsSecondPass(List<Planet> allPlanets, List<PlanetConnection> spawnedConnections, ref int nextZoneId) private void PlacePlanetsSecondPass(List<Planet> allPlanets, List<PlanetConnection> spawnedConnections, ref int nextZoneId)
@ -484,7 +489,7 @@ namespace GWConquest
private void PlacePlanetsSecondPassNew(List<Planet> allPlanets, List<PlanetConnection> spawnedConnections, ref int nextZoneId) private void PlacePlanetsSecondPassNew(List<Planet> allPlanets, List<PlanetConnection> spawnedConnections, ref int nextZoneId)
{ {
int planetsToSpawn = Random.Range(Pass2New_MinPlanets, Pass2New_MaxPlanets); int planetsToSpawn = Random.Range(Pass2New_MinPlanets, Pass2New_MaxPlanets);
BoltLog.Info("Spawning {0} planets in second pass.", planetsToSpawn);
Debug.LogFormat("Spawning {0} planets in second pass.", planetsToSpawn);
Vector3 galaxyCenter = transform.position; Vector3 galaxyCenter = transform.position;
@ -577,7 +582,7 @@ namespace GWConquest
if(!hasSpawned) if(!hasSpawned)
{ {
BoltLog.Warn("Could not find a position to place the {0}th planet. Aborting.", i);
Debug.LogWarningFormat("Could not find a position to place the {0}th planet. Aborting.", i);
break; break;
} }
} }


+ 7
- 7
Assets/GWConquest/Scripts/PlanetRegistry.cs View File

@ -1,8 +1,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
using Photon.Bolt;
using Photon.Bolt.Utils;
namespace GWConquest namespace GWConquest
{ {
@ -47,7 +47,7 @@ namespace GWConquest
} }
else else
{ {
BoltLog.Warn("Planet {0} not found in planet map!", planetName);
Debug.LogWarningFormat("Planet {0} not found in planet map!", planetName);
return null; return null;
} }
} }
@ -61,7 +61,7 @@ namespace GWConquest
{ {
planetDataMap = new Dictionary<string, PlanetData>(); planetDataMap = new Dictionary<string, PlanetData>();
BoltLog.Info("Loading Planet Map...");
Debug.LogFormat("Loading Planet Map...");
TextAsset database = Resources.Load<TextAsset>("Database/Planets"); TextAsset database = Resources.Load<TextAsset>("Database/Planets");
CSVFile csv = CSVFile.ParseCSV(database.text); CSVFile csv = CSVFile.ParseCSV(database.text);
for(int i = 0; i < csv.Length; i++) for(int i = 0; i < csv.Length; i++)
@ -81,7 +81,7 @@ namespace GWConquest
HasShipyard = shipyard > 0, HasShipyard = shipyard > 0,
ShipyardRating = shipyard ShipyardRating = shipyard
}; };
BoltLog.Info("Loaded planet {0}", planet.Name);
Debug.LogFormat("Loaded planet {0}", planet.Name);
planetDataMap.Add(planet.Name, planet); planetDataMap.Add(planet.Name, planet);
} }
@ -261,8 +261,8 @@ namespace GWConquest
} }
catch(System.Exception ex) catch(System.Exception ex)
{ {
BoltLog.Warn("Failed to parse structure types: {0}", structureTypes);
BoltLog.Exception(ex);
Debug.LogWarningFormat("Failed to parse structure types: {0}", structureTypes);
Debug.LogException(ex);
return null; return null;
} }
} }


+ 13
- 9
Assets/GWConquest/Scripts/Player.cs View File

@ -1,8 +1,8 @@
using UnityEngine; using UnityEngine;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Photon.Bolt;
using Photon.Bolt.Utils;
using Unity.Netcode; using Unity.Netcode;
using Unity.Collections; using Unity.Collections;
@ -83,7 +83,17 @@ namespace GWConquest
public override void OnGainedOwnership() public override void OnGainedOwnership()
{ {
CurrentPlayer = this; CurrentPlayer = this;
BoltLog.Info("Current player is {0} with connection ID {1}", this, OwnerClientId);
Debug.LogFormat("Current player is {0} with connection ID {1}", this, OwnerClientId);
}
public void SetFaction(ushort ind)
{
factionIndex.Value = ind;
}
public void SetAI()
{
isAI.Value = true;
} }
public NetworkClient Client public NetworkClient Client
@ -161,12 +171,6 @@ namespace GWConquest
} }
} }
} }
[ServerRpc]
public void BuildUnit(int zoneID, ushort unitClassID)
{
Unit.SpawnUnit(Zone.GetFromId(zoneID), UnitClass.FromID(unitClassID), this);
}
} }
[System.Serializable] [System.Serializable]


+ 0
- 124
Assets/GWConquest/Scripts/ServerCallbacks.cs View File

@ -1,124 +0,0 @@
using System.Linq;
using UnityEngine;
using UdpKit;
using Photon.Bolt;
using Photon.Bolt.Utils;
using Unity.Netcode;
namespace GWConquest
{
[BoltGlobalBehaviour(BoltNetworkModes.Server)]
public class ServerCallbacks : NetworkBehaviour
{
private static ServerCallbacks _instance;
public static ServerCallbacks Instance {
get {
if(_instance == null)
{
_instance = FindObjectOfType<ServerCallbacks>();
}
return _instance;
}
}
public override void SceneLoadLocalDone(string scene, IProtocolToken token)
{
if(scene != "GalaxyMap")
return;
PlanetPlacement.Instance.PlacePlanets();
foreach(Planet planet in FindObjectsOfType<Planet>())
{
planet.FinishSetup();
}
BoltEntity playerEntity = BoltNetwork.Instantiate(BoltPrefabs.Player);
Debug.Log("Player entity instantiated");
IPlayerState playerState = playerEntity.GetState<IPlayerState>();
playerState.IsHost = true;
playerState.FactionIndex = GameManager.HostFactionIndex;
playerEntity.GetComponent<Player>().AssignStartingPlanets();
playerEntity.TakeControl();
GameManager.Instance.SceneLoadLocalDone();
//foreach(GameObject go in FindObjectsOfType<GameObject>()) {
// go.SendMessage("OnSceneLoadLocalDone", SendMessageOptions.DontRequireReceiver);
//}
foreach(var spawner in FindObjectsOfType<SpawnAIUnits>())
{
spawner.SpawnUnits();
}
foreach(Zone z in Zone.AllZones)
{
z.CheckBattleStart();
}
Planet.SetupPlanetPathfinding();
GameManager.EntitiesLoaded = true;
LoadingScreen.Dismiss();
BoltLog.Info("Server scene loading done.");
}
public override void SceneLoadRemoteDone(BoltConnection connection, IProtocolToken token)
{
BoltEntity playerEntity = BoltNetwork.Instantiate(BoltPrefabs.Player);
IPlayerState playerState = playerEntity.GetState<IPlayerState>();
playerState.ConnectionId = (int)connection.ConnectionId;
playerState.IsHost = false;
playerState.FactionIndex = (GameManager.HostFactionIndex + 1) % 2;
playerEntity.GetComponent<Player>().AssignStartingPlanets();
playerEntity.AssignControl(connection);
var ecount = BoltNetwork.Entities.Count();
var configEvnt = ServerConfigEvent.Create(connection);
configEvnt.EntityCount = ecount;
configEvnt.Send();
}
public override void ConnectRequest(UdpEndPoint endpoint, IProtocolToken token)
{
BoltLog.Info("Connect request recieved");
if(GameManager.EntitiesLoaded)
{
BoltLog.Info("Accepting connect request");
BoltNetwork.Accept(endpoint);
}
else {
BoltLog.Info("Refusing connect request");
BoltNetwork.Refuse(endpoint);
}
}
public override void Connected(BoltConnection connection)
{
BoltLog.Info("Client connected");
}
[ServerRpc]
public void MoveItemRpc(NetworkBehaviourReference origin, NetworkBehaviourReference target, ushort itemID, int itemAmount)
{
NetworkBehaviour originBeh = origin.GetBehaviour();
NetworkBehaviour targetBeh = target.GetBehaviour();
if(originBeh is IHasInventory && targetBeh is IHasInventory)
{
IInventory originInv = (originBeh as IHasInventory).GetInventory();
IInventory targetInv = (targetBeh as IHasInventory).GetInventory();
Inventory.MoveItem(originInv, targetInv, itemID, itemAmount);
}
else {
BoltLog.Error("One of the specified behaviours is not an inventory");
}
}
}
}

+ 0
- 11
Assets/GWConquest/Scripts/ServerCallbacks.cs.meta View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: b7ac2246de5adcc4eb245fff9adac55e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

+ 4
- 4
Assets/GWConquest/Scripts/SpawnAIUnits.cs View File

@ -1,7 +1,7 @@
using UnityEngine; using UnityEngine;
using System.Linq; using System.Linq;
using Photon.Bolt;
using Photon.Bolt.Utils;
namespace GWConquest { namespace GWConquest {
@ -16,14 +16,14 @@ namespace GWConquest {
public void SpawnUnits() public void SpawnUnits()
{ {
BoltLog.Info("Spawning AI units");
Debug.LogFormat("Spawning AI units");
Player player = Player.GetPlayerById(playerId); Player player = Player.GetPlayerById(playerId);
if(player != null) if(player != null)
{ {
for(int i = 0; i < unitCount; i++) for(int i = 0; i < unitCount; i++)
{ {
var unit = Unit.SpawnUnit(zone, UnitClass.FromName(unitName), player);
var unit = GWNetworkManager.Instance.SpawnUnit(zone, UnitClass.FromName(unitName), player);
if(assignAsLeader) if(assignAsLeader)
{ {
unit.Formation.HeroUnit = unit; unit.Formation.HeroUnit = unit;


+ 4
- 4
Assets/GWConquest/Scripts/UI/BattleArmyPanel.cs View File

@ -2,8 +2,8 @@ using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Photon.Bolt;
using Photon.Bolt.Utils;
namespace GWConquest { namespace GWConquest {
public class BattleArmyPanel : MonoBehaviour { public class BattleArmyPanel : MonoBehaviour {
@ -237,7 +237,7 @@ namespace GWConquest {
var fui = icon.GetComponentInParent<BattleFormationUI>(); var fui = icon.GetComponentInParent<BattleFormationUI>();
if(fui != null && target == fui.LeaderIcon) if(fui != null && target == fui.LeaderIcon)
{ {
icon.Unit.Formation.AssignLeaderRpc(icon.Unit);
icon.Unit.Formation.AssignLeaderServerRpc(icon.Unit);
} }
} }
else if(icon.Unit.BattleState == BattleUnitState.InReserve && icon.Unit.CanGoToFlank) else if(icon.Unit.BattleState == BattleUnitState.InReserve && icon.Unit.CanGoToFlank)
@ -250,7 +250,7 @@ namespace GWConquest {
if(flankUI.BattleFlank.GetUnit(flankIndex) == null) if(flankUI.BattleFlank.GetUnit(flankIndex) == null)
{ {
Battle.MoveUnitToFlankRpc(icon.Unit, flankUI.BattleFlank, flankIndex);
Battle.MoveUnitToFlankServerRpc(icon.Unit, flankUI.BattleFlank, flankIndex);
} }


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

@ -1,8 +1,8 @@
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using System.Linq; using System.Linq;
using Photon.Bolt;
using Photon.Bolt.Utils;
namespace GWConquest { namespace GWConquest {
@ -107,7 +107,7 @@ namespace GWConquest {
{ {
if(icon.Unit.BattleState == BattleUnitState.OnFlank) if(icon.Unit.BattleState == BattleUnitState.OnFlank)
{ {
battleUI.Battle.MoveUnitToReserveRpc(icon.Unit);
battleUI.Battle.MoveUnitToReserveServerRpc(icon.Unit);
} }
} }


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

@ -2,8 +2,8 @@ using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using System.Linq; using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using Photon.Bolt;
using Photon.Bolt.Utils;
namespace GWConquest namespace GWConquest
{ {
@ -480,7 +480,7 @@ namespace GWConquest
if (hasTarget) if (hasTarget)
{ {
SelectingTargetUnit.StartShellingRpc(flank);
SelectingTargetUnit.StartShellingServerRpc(flank);
} }
EndTargetSelection(); EndTargetSelection();


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

@ -1,8 +1,8 @@
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using System.Collections; using System.Collections;
using Photon.Bolt;
using Photon.Bolt.Utils;
namespace GWConquest { namespace GWConquest {
public class BattleUnitIcon : DragDropElement { public class BattleUnitIcon : DragDropElement {


+ 1
- 1
Assets/GWConquest/Scripts/UI/DebugUI.cs View File

@ -59,7 +59,7 @@ namespace GWConquest
for(int i = 0; i < amount; i++) for(int i = 0; i < amount; i++)
{ {
Unit.SpawnUnit(zone, uc, player);
GWNetworkManager.Instance.SpawnUnit(zone, uc, player);
} }
} }


+ 4
- 4
Assets/GWConquest/Scripts/UI/FormationIcon.cs View File

@ -3,8 +3,8 @@ using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
using UnityEngine.UI; using UnityEngine.UI;
using Photon.Bolt;
using Photon.Bolt.Utils;
namespace GWConquest { namespace GWConquest {
public class FormationIcon : DragDropElement, IUpdatable<Formation> public class FormationIcon : DragDropElement, IUpdatable<Formation>
@ -111,7 +111,7 @@ namespace GWConquest {
if (planet != null) if (planet != null)
{ {
CurrentFormation.TryMoveToPlanet(planet); CurrentFormation.TryMoveToPlanet(planet);
BoltLog.Info("Moving formation {0} to planet {1}", CurrentFormation.name, planet.name);
Debug.LogFormat("Moving formation {0} to planet {1}", CurrentFormation.name, planet.name);
break; break;
} }
} }
@ -123,7 +123,7 @@ namespace GWConquest {
if (RectTransformUtility.RectangleContainsScreenPoint(di.GetComponent<RectTransform>(), mousePos)) if (RectTransformUtility.RectangleContainsScreenPoint(di.GetComponent<RectTransform>(), mousePos))
{ {
CurrentFormation.TryMoveToZone(di.zone); CurrentFormation.TryMoveToZone(di.zone);
BoltLog.Info("Moving formation {0} to zone {1}", CurrentFormation.name, di.zone);
Debug.LogFormat("Moving formation {0} to zone {1}", CurrentFormation.name, di.zone);
break; break;
} }
} }


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

@ -2,8 +2,8 @@
using UnityEngine; using UnityEngine;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
using UnityEngine.UI; using UnityEngine.UI;
using Photon.Bolt;
using Photon.Bolt.Utils;
namespace GWConquest namespace GWConquest
{ {
@ -117,7 +117,7 @@ namespace GWConquest
if (planet != null) if (planet != null)
{ {
formation.TryMoveToPlanet(planet); formation.TryMoveToPlanet(planet);
BoltLog.Info("Moving formation {0} to planet {1}", formation.name, planet.name);
Debug.LogFormat("Moving formation {0} to planet {1}", formation.name, planet.name);
break; break;
} }
} }


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

@ -2,8 +2,8 @@
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using Photon.Bolt;
using Photon.Bolt.Utils;
namespace GWConquest namespace GWConquest
{ {
@ -70,7 +70,7 @@ namespace GWConquest
elementComp.Planet = obj as Planet; elementComp.Planet = obj as Planet;
} }
else { else {
BoltLog.Error("Displayed object is neither District or Formation: {0}", obj);
Debug.LogErrorFormat("Displayed object is neither District or Formation: {0}", obj);
} }


+ 6
- 6
Assets/GWConquest/Scripts/UI/IngameUI.cs View File

@ -2,8 +2,8 @@
using UnityEngine; using UnityEngine;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
using UnityEngine.UI; using UnityEngine.UI;
using Photon.Bolt;
using Photon.Bolt.Utils;
namespace GWConquest namespace GWConquest
{ {
@ -127,7 +127,7 @@ namespace GWConquest
{ {
Vector3 camPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector3 camPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
//BoltLog.Info("Raycasting with origin {0}; direction {1}", camPos, Camera.main.transform.forward);
//Debug.LogFormat("Raycasting with origin {0}; direction {1}", camPos, Camera.main.transform.forward);
Debug.DrawRay(camPos, Camera.main.transform.forward, Color.green, 5); Debug.DrawRay(camPos, Camera.main.transform.forward, Color.green, 5);
@ -137,7 +137,7 @@ namespace GWConquest
bool hasHit = false; bool hasHit = false;
foreach (RaycastResult result in list) foreach (RaycastResult result in list)
{ {
BoltLog.Info("Found game object {0}", result.gameObject);
Debug.LogFormat("Found game object {0}", result.gameObject);
Planet planet = result.gameObject.GetComponentInParent<Planet>(); Planet planet = result.gameObject.GetComponentInParent<Planet>();
if (planet != null) if (planet != null)
{ {
@ -145,7 +145,7 @@ namespace GWConquest
{ {
EnablePlanetView(planet); EnablePlanetView(planet);
BoltLog.Info("Enabling planet view on {0}", planet.gameObject);
Debug.LogFormat("Enabling planet view on {0}", planet.gameObject);
} }
else else
{ {
@ -153,7 +153,7 @@ namespace GWConquest
PlanetHud.SelectPlanet(planet); PlanetHud.SelectPlanet(planet);
BoltLog.Info("Selecting planet {0}", planet.gameObject);
Debug.LogFormat("Selecting planet {0}", planet.gameObject);
} }


+ 6
- 6
Assets/GWConquest/Scripts/UI/ItemMoveTooltip.cs View File

@ -2,8 +2,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using Photon.Bolt;
using Photon.Bolt.Utils;
using Unity.Netcode; using Unity.Netcode;
namespace GWConquest namespace GWConquest
@ -76,14 +76,14 @@ namespace GWConquest
{ {
NetworkBehaviour originBeh = Origin.Type == TransportUIElement.ObjectType.District ? Origin.District : Origin.Formation; NetworkBehaviour originBeh = Origin.Type == TransportUIElement.ObjectType.District ? Origin.District : Origin.Formation;
NetworkBehaviour targetBeh = Target.Type == TransportUIElement.ObjectType.District ? Target.District : Target.Formation; NetworkBehaviour targetBeh = Target.Type == TransportUIElement.ObjectType.District ? Target.District : Target.Formation;
ServerCallbacks.Instance.MoveItemRpc(originBeh, targetBeh, MovedItem.ItemName, current);
GWNetworkManager.Instance.MoveItemServerRpc(originBeh, targetBeh, MovedItem.ItemName, current);
} }
else { else {
BoltLog.Error("Amount {0} of item {1} is not transferable ({2})", current, MovedItem.ItemName, transferable);
Debug.LogErrorFormat("Amount {0} of item {1} is not transferable ({2})", current, MovedItem.ItemName, transferable);
} }
} }
else { else {
BoltLog.Error("Invalid amount: {0}", AmountField.text);
Debug.LogErrorFormat("Invalid amount: {0}", AmountField.text);
} }
Cancel(); Cancel();
@ -115,7 +115,7 @@ namespace GWConquest
} }
} }
else { else {
BoltLog.Error("bad string in input field: {0}", AmountField.text);
Debug.LogErrorFormat("bad string in input field: {0}", AmountField.text);
AmountField.text = ""; AmountField.text = "";
} }
} }


+ 15
- 19
Assets/GWConquest/Scripts/UI/MainMenu.cs View File

@ -1,17 +1,19 @@
using Photon.Bolt;
using Photon.Bolt.Utils;
using Photon.Bolt.Matchmaking;

using System; using System;
using UdpKit; using UdpKit;
using UnityEngine; using UnityEngine;
using Unity.Netcode;
namespace GWConquest namespace GWConquest
{ {
public class MainMenu : GlobalEventListener
public class MainMenu : MonoBehaviour
{ {
private void Start() { private void Start() {
GameOptions.ApplyOptions(); GameOptions.ApplyOptions();
NetworkManager.Singleton.OnServerStarted += ServerStartDone;
} }
public void StartServer(int hostFactionIndex) public void StartServer(int hostFactionIndex)
@ -22,41 +24,35 @@ namespace GWConquest
LoadingScreen.Show(); LoadingScreen.Show();
BoltLauncher.StartServer();
NetworkManager.Singleton.StartHost();
} }
public void StartClient() public void StartClient()
{ {
GameManager.ClearAllCaches(); GameManager.ClearAllCaches();
BoltLauncher.StartClient();
NetworkManager.Singleton.StartClient();
} }
public void CancelClient() public void CancelClient()
{ {
BoltLauncher.Shutdown();
NetworkManager.Singleton.Shutdown();
} }
public void Quit() { public void Quit() {
Application.Quit(); Application.Quit();
} }
public override void BoltStartDone()
public void ServerStartDone()
{ {
if(BoltNetwork.IsServer)
{
string matchName = Guid.NewGuid().ToString();
Debug.Log("Server start done");
BoltMatchmaking.CreateSession(
sessionID: matchName,
sceneToLoad: "GalaxyMap"
);
}
NetworkManager.Singleton.SceneManager.LoadScene("GalaxyMap", UnityEngine.SceneManagement.LoadSceneMode.Single);
} }
public override void SessionListUpdated(Map<Guid, UdpSession> sessionList)
/*public override void SessionListUpdated(Map<Guid, UdpSession> sessionList)
{ {
BoltLog.Info("Session list updated: {0} total sessions", sessionList.Count);
Debug.LogFormat("Session list updated: {0} total sessions", sessionList.Count);
foreach (var session in sessionList) foreach (var session in sessionList)
{ {
@ -69,6 +65,6 @@ namespace GWConquest
BoltMatchmaking.JoinSession(photonSession); BoltMatchmaking.JoinSession(photonSession);
} }
} }
}
}*/
} }
} }

+ 4
- 3
Assets/GWConquest/Scripts/UI/PauseMenu.cs View File

@ -1,6 +1,7 @@
using Photon.Bolt;

using UnityEngine; using UnityEngine;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
using Unity.Netcode;
namespace GWConquest namespace GWConquest
{ {
@ -8,13 +9,13 @@ namespace GWConquest
{ {
public void QuitToMainMenu() public void QuitToMainMenu()
{ {
BoltLauncher.Shutdown();
NetworkManager.Singleton.Shutdown();
SceneManager.LoadScene("MainMenu"); SceneManager.LoadScene("MainMenu");
} }
public void QuitToDesktop() public void QuitToDesktop()
{ {
BoltLauncher.Shutdown();
NetworkManager.Singleton.Shutdown();
Application.Quit(); Application.Quit();
} }
} }


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

@ -2,7 +2,7 @@
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using Photon.Bolt.Utils;
namespace GWConquest namespace GWConquest
{ {
@ -119,7 +119,7 @@ namespace GWConquest
public void SpawnLandingLine(Formation f) public void SpawnLandingLine(Formation f)
{ {
BoltLog.Info("Spawning landing line");
Debug.LogFormat("Spawning landing line");
if(f.CurrentTransition.OriginZone.planet == selectedPlanet) if(f.CurrentTransition.OriginZone.planet == selectedPlanet)
{ {
bool isLanding = f.MovementOriginFormation != null; bool isLanding = f.MovementOriginFormation != null;
@ -458,7 +458,7 @@ namespace GWConquest
public void SwitchPlanet(int dir) public void SwitchPlanet(int dir)
{ {
BoltLog.Info("Switching planets...");
Debug.LogFormat("Switching planets...");
var player = Player.CurrentPlayer; var player = Player.CurrentPlayer;
var planets = Planet.AllPlanets.Where(p => { var planets = Planet.AllPlanets.Where(p => {
return p.ControllingPlayer == player || return p.ControllingPlayer == player ||
@ -477,7 +477,7 @@ namespace GWConquest
nextInd -= planets.Count; nextInd -= planets.Count;
} }
BoltLog.Info("Switching to planet {0}", planets[nextInd].PlanetName);
Debug.LogFormat("Switching to planet {0}", planets[nextInd].PlanetName);
var ingameUI = GetComponentInParent<IngameUI>(); var ingameUI = GetComponentInParent<IngameUI>();
ingameUI.DisablePlanetView(); ingameUI.DisablePlanetView();


+ 2
- 15
Assets/GWConquest/Scripts/UI/ProductionMenu.cs View File

@ -2,7 +2,7 @@
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using Photon.Bolt;
namespace GWConquest namespace GWConquest
{ {
@ -130,20 +130,7 @@ namespace GWConquest
{ {
if(DebugUI.FreeBuild || buildable.BuildCost == null || factory.District.CanBuild(buildable)) if(DebugUI.FreeBuild || buildable.BuildCost == null || factory.District.CanBuild(buildable))
{ {
AddProductionEvent ev = AddProductionEvent.Create(GlobalTargets.OnlyServer);
ev.Factory = factory.entity;
if(buildable is UnitClass)
{
ev.UnitClass = (buildable as UnitClass).ShortName;
ev.IsUpgrade = false;
}
else if(buildable is DistrictUpgrade)
{
ev.UnitClass = (buildable as DistrictUpgrade).ShortName;
ev.IsUpgrade = true;
}
ev.Player = Player.CurrentPlayer.entity;
ev.Send();
factory.AddProductionQueueEntryServerRpc(buildable.ID, buildable is DistrictUpgrade, Player.CurrentPlayer);
} }
} }


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

@ -1,7 +1,7 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using Photon.Bolt.Utils;
namespace GWConquest namespace GWConquest
{ {
@ -25,7 +25,7 @@ namespace GWConquest
public void StartGame() public void StartGame()
{ {
BoltLog.Info("Starting game with faction {0}", FactionIndices[selected]);
Debug.LogFormat("Starting game with faction {0}", FactionIndices[selected]);
FindObjectOfType<MainMenu>().StartServer(FactionIndices[selected]); FindObjectOfType<MainMenu>().StartServer(FactionIndices[selected]);
} }
} }


+ 4
- 4
Assets/GWConquest/Scripts/UI/TransportUI.cs View File

@ -2,7 +2,7 @@
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using System.Linq; using System.Linq;
using Photon.Bolt.Utils;
namespace GWConquest namespace GWConquest
{ {
@ -140,7 +140,7 @@ namespace GWConquest
elementComp.Planet = obj as Planet; elementComp.Planet = obj as Planet;
} }
else { else {
BoltLog.Error("Displayed object is neither District or Formation: {0}", obj);
Debug.LogErrorFormat("Displayed object is neither District or Formation: {0}", obj);
} }
@ -166,7 +166,7 @@ namespace GWConquest
panel = SpacePanel; panel = SpacePanel;
} }
else { else {
BoltLog.Warn("UI Icon {0} not in any panel!", icon);
Debug.LogWarningFormat("UI Icon {0} not in any panel!", icon);
return; return;
} }
@ -185,7 +185,7 @@ namespace GWConquest
panel = SpacePanel; panel = SpacePanel;
} }
else { else {
BoltLog.Warn("UI Element {0} not in any panel!", element);
Debug.LogWarningFormat("UI Element {0} not in any panel!", element);
return; return;
} }
SelectFormationForPanel(panel, element); SelectFormationForPanel(panel, element);


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

@ -1,6 +1,6 @@
using UnityEngine.UI; using UnityEngine.UI;
using UnityEngine; using UnityEngine;
using Photon.Bolt.Utils;
namespace GWConquest { namespace GWConquest {
@ -65,7 +65,7 @@ namespace GWConquest {
return false; return false;
} }
else { else {
BoltLog.Info("No remaining space in target inventory!");
Debug.LogFormat("No remaining space in target inventory!");
} }
} }
} }


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

@ -1,6 +1,6 @@
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using Photon.Bolt;
namespace GWConquest namespace GWConquest
{ {
@ -41,7 +41,7 @@ namespace GWConquest
var LeaderIcon = ParentElement.DragTransform; var LeaderIcon = ParentElement.DragTransform;
if (RectTransformUtility.RectangleContainsScreenPoint(LeaderIcon, Input.mousePosition)) if (RectTransformUtility.RectangleContainsScreenPoint(LeaderIcon, Input.mousePosition))
{ {
ParentElement.Formation.AssignLeaderRpc(Unit);
ParentElement.Formation.AssignLeaderServerRpc(Unit);
} }
} }


+ 59
- 77
Assets/GWConquest/Scripts/Unit.cs View File

@ -1,7 +1,7 @@
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
using Photon.Bolt;
using Photon.Bolt.Utils;
using Unity.Netcode; using Unity.Netcode;
namespace GWConquest namespace GWConquest
@ -223,7 +223,7 @@ namespace GWConquest
Inventory.StorageCapacity = newClass.InventorySlots; Inventory.StorageCapacity = newClass.InventorySlots;
Equipment.StorageCapacity = newClass.EquipmentSlots; Equipment.StorageCapacity = newClass.EquipmentSlots;
if(IsOwner)
if(IsServer)
{ {
Fuel = newClass.FuelCapacity; Fuel = newClass.FuelCapacity;
Food = newClass.FoodCapacity; Food = newClass.FoodCapacity;
@ -253,26 +253,6 @@ namespace GWConquest
Morale = uc.Morale; Morale = uc.Morale;
} }
public static Unit SpawnUnit(Zone zone, UnitClass uc, Player player)
{
Formation playerFormation = zone.Formations.FirstOrDefault(f => f.Player == player);
if (playerFormation == null)
{
playerFormation = Formation.SpawnFormation(zone, player);
}
BoltEntity unitEntity = BoltNetwork.Instantiate(BoltPrefabs.Unit);
player.AssignControl(unitEntity);
Unit unit = unitEntity.GetComponent<Unit>();
unit.InstantiateWithClass(uc);
unit.Formation = playerFormation;
playerFormation.AddUnit(unit);
BoltLog.Info("Spawned unit {0} for player {1} in formation {2}", unit, player, playerFormation);
return unit;
}
public void TakeDamage(int damage, Unit attacker, bool isGlancingHit=false, WeaponStats weapon=null, WeaponType weaponType=WeaponType.Light) public void TakeDamage(int damage, Unit attacker, bool isGlancingHit=false, WeaponStats weapon=null, WeaponType weaponType=WeaponType.Light)
{ {
int remainingDamage = damage; int remainingDamage = damage;
@ -365,7 +345,7 @@ namespace GWConquest
{ {
animType = DamageAnimationType.GlancingHit; animType = DamageAnimationType.GlancingHit;
} }
PlayUnitDamageAnimation(weaponType, animType, attacker);
PlayUnitDamageAnimationClientRpc(weaponType, animType, attacker);
if(Hitpoints <= 0) if(Hitpoints <= 0)
{ {
@ -383,7 +363,7 @@ namespace GWConquest
} }
[ClientRpc] [ClientRpc]
public void PlayUnitDamageAnimation(WeaponType weaponType, DamageAnimationType animationType, NullableNetworkBehaviourReference attacker)
public void PlayUnitDamageAnimationClientRpc(WeaponType weaponType, DamageAnimationType animationType, NullableNetworkBehaviourReference attacker)
{ {
if(IconEnabled) if(IconEnabled)
{ {
@ -453,77 +433,79 @@ namespace GWConquest
public void FixedUpdate() public void FixedUpdate()
{ {
var battle = CurrentBattle;
if(!IsDead && battle != null && !battle.IsInPreparing)
if (IsServer)
{ {
if(BattleState == BattleUnitState.Arriving)
var battle = CurrentBattle;
if (!IsDead && battle != null && !battle.IsInPreparing)
{ {
if(!Formation.IsMoving)
if (BattleState == BattleUnitState.Arriving)
{ {
BattleState = BattleUnitState.InReserve;
}
}
if (ActionCooldown <= 0)
{
actionCooldown.Value = 0;
if (BattleState == BattleUnitState.MovingToFlank)
{
BattleState = BattleUnitState.OnFlank;
int requiredFuel = GetFuelCostForFlank();
if(requiredFuel <= TotalFuel)
if (!Formation.IsMoving)
{ {
ConsumeTotalFuel(requiredFuel);
BattleState = BattleUnitState.InReserve;
} }
} }
else if (BattleState == BattleUnitState.MovingToReserve)
if (ActionCooldown <= 0)
{ {
BattleState = BattleUnitState.InReserve;
CurrentFlank.RemoveUnit(this);
CurrentFlank = null;
actionCooldown.Value = 0;
if (BattleState == BattleUnitState.MovingToFlank)
{
BattleState = BattleUnitState.OnFlank;
int requiredFuel = GetFuelCostForFlank();
if(requiredFuel <= TotalFuel)
int requiredFuel = GetFuelCostForFlank();
if (requiredFuel <= TotalFuel)
{
ConsumeTotalFuel(requiredFuel);
}
}
else if (BattleState == BattleUnitState.MovingToReserve)
{ {
ConsumeTotalFuel(requiredFuel);
BattleState = BattleUnitState.InReserve;
CurrentFlank.RemoveUnit(this);
CurrentFlank = null;
int requiredFuel = GetFuelCostForFlank();
if (requiredFuel <= TotalFuel)
{
ConsumeTotalFuel(requiredFuel);
}
}
else if (BattleState == BattleUnitState.StartingShelling)
{
BattleState = BattleUnitState.Shelling;
}
else if (BattleState == BattleUnitState.StoppingShelling)
{
BattleState = BattleUnitState.InReserve;
FlankTarget = null;
} }
} }
else if(BattleState == BattleUnitState.StartingShelling)
{
BattleState = BattleUnitState.Shelling;
}
else if(BattleState == BattleUnitState.StoppingShelling)
else
{ {
BattleState = BattleUnitState.InReserve;
FlankTarget = null;
actionCooldown.Value -= Time.fixedDeltaTime;
} }
}
else
{
actionCooldown.Value -= Time.fixedDeltaTime;
}
if(ShieldsCooldown > 0)
{
ShieldsCooldown -= Time.fixedDeltaTime;
if(ShieldsCooldown <= 0)
if (ShieldsCooldown > 0)
{ {
ShieldsCooldown = 0;
ShieldsCooldown -= Time.fixedDeltaTime;
if (ShieldsCooldown <= 0)
{
ShieldsCooldown = 0;
}
} }
}
if(ShieldsCooldown == 0 && Shields < Class.Shields)
{
float regRate = Class.ShieldRegeneration / GameManager.Instance.BattleTurnLength;
Shields += regRate * BoltNetwork.FrameDeltaTime;
if(Shields > Class.Shields)
if (ShieldsCooldown == 0 && Shields < Class.Shields)
{ {
Shields = Class.Shields;
float regRate = Class.ShieldRegeneration / GameManager.Instance.BattleTurnLength;
Shields += regRate * Time.fixedDeltaTime;
if (Shields > Class.Shields)
{
Shields = Class.Shields;
}
} }
} }
} }
} }
//TODO shelling auch auf Flanke! //TODO shelling auch auf Flanke!
@ -561,7 +543,7 @@ namespace GWConquest
} }
[ServerRpc] [ServerRpc]
public void StartShellingRpc(NetworkBehaviourReference target)
public void StartShellingServerRpc(NetworkBehaviourReference target)
{ {
StartShelling(target.GetBehaviour<BattleFlank>()); StartShelling(target.GetBehaviour<BattleFlank>());
} }
@ -580,7 +562,7 @@ namespace GWConquest
if(Morale > 0 && !IsDead) if(Morale > 0 && !IsDead)
{ {
if(DebugUI.LogBattleEvents) if(DebugUI.LogBattleEvents)
BoltLog.Info("Unit {0} took {1} points of morale damage", this, moraleDamage);
Debug.LogFormat("Unit {0} took {1} points of morale damage", this, moraleDamage);
Morale -= moraleDamage; Morale -= moraleDamage;
if(Morale <= 0) if(Morale <= 0)
{ {


+ 11
- 11
Assets/GWConquest/Scripts/UnitClass.cs View File

@ -2,7 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
using Photon.Bolt.Utils;
namespace GWConquest namespace GWConquest
{ {
@ -21,7 +21,7 @@ namespace GWConquest
public static void LoadClassMap() public static void LoadClassMap()
{ {
BoltLog.Info("Loading unit classes...");
Debug.LogFormat("Loading unit classes...");
classMap = new Dictionary<string, UnitClass>(); classMap = new Dictionary<string, UnitClass>();
TextAsset shipsDatabase = Resources.Load<TextAsset>("Database/Ships"); TextAsset shipsDatabase = Resources.Load<TextAsset>("Database/Ships");
LoadDatabase(shipsDatabase, ZoneType.Space); LoadDatabase(shipsDatabase, ZoneType.Space);
@ -36,7 +36,7 @@ namespace GWConquest
classList.Sort((uc1, uc2) => uc1.ID - uc2.ID); classList.Sort((uc1, uc2) => uc1.ID - uc2.ID);
unitClasses = classList.ToArray(); unitClasses = classList.ToArray();
GameManager.Instance.UnitClasses = unitClasses; GameManager.Instance.UnitClasses = unitClasses;
BoltLog.Info("All unit classes loaded.");
Debug.LogFormat("All unit classes loaded.");
} }
private static void LoadDatabase(TextAsset asset, ZoneType zoneType, char delimiter=',') private static void LoadDatabase(TextAsset asset, ZoneType zoneType, char delimiter=',')
@ -55,7 +55,7 @@ namespace GWConquest
unitClass.FullName = data.GetString("Full Name"); unitClass.FullName = data.GetString("Full Name");
BoltLog.Info("Parsing unit class {0}", unitClass.ShortName);
Debug.LogFormat("Parsing unit class {0}", unitClass.ShortName);
unitClass.Hitpoints = data.GetInt("Hitpoints"); unitClass.Hitpoints = data.GetInt("Hitpoints");
@ -177,8 +177,8 @@ namespace GWConquest
} }
catch (Exception ex) catch (Exception ex)
{ {
BoltLog.Error("Could not parse unit class");
BoltLog.Exception(ex);
Debug.LogErrorFormat("Could not parse unit class");
Debug.LogException(ex);
} }
} }
@ -196,7 +196,7 @@ namespace GWConquest
var heroName = data.GetString("Name"); var heroName = data.GetString("Name");
BoltLog.Info("Parsing hero {0}", heroName);
Debug.LogFormat("Parsing hero {0}", heroName);
unitClass.ShortName = "Hero" + Util.RemoveSpecialCharacters(heroName); unitClass.ShortName = "Hero" + Util.RemoveSpecialCharacters(heroName);
unitClass.FullName = heroName; unitClass.FullName = heroName;
@ -266,8 +266,8 @@ namespace GWConquest
} }
catch(Exception ex) catch(Exception ex)
{ {
BoltLog.Error("Could not parse hero");
BoltLog.Exception(ex);
Debug.LogErrorFormat("Could not parse hero");
Debug.LogException(ex);
} }
} }
} }
@ -280,7 +280,7 @@ namespace GWConquest
} }
if(Util.IsStringEmpty(name)) if(Util.IsStringEmpty(name))
{ {
BoltLog.Warn("UnitClass.FromName called with null name!");
Debug.LogWarningFormat("UnitClass.FromName called with null name!");
return null; return null;
} }
if (classMap.ContainsKey(name)) if (classMap.ContainsKey(name))
@ -289,7 +289,7 @@ namespace GWConquest
} }
else else
{ {
BoltLog.Warn("Unit class {0} not in registry!", name);
Debug.LogWarningFormat("Unit class {0} not in registry!", name);
return null; return null;
} }
} }


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

@ -1,8 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using System.Linq; using System.Linq;
using Photon.Bolt;
using Photon.Bolt.Utils;
using Unity.Netcode;
namespace GWConquest namespace GWConquest
{ {
@ -111,7 +110,7 @@ namespace GWConquest
OnFormationChanged(formation); OnFormationChanged(formation);
if (BoltNetwork.IsServer)
if (NetworkManager.Singleton.IsServer)
{ {
if (CurrentBattle != null) if (CurrentBattle != null)
{ {
@ -132,16 +131,7 @@ namespace GWConquest
{ {
if (ShouldStartBattle()) if (ShouldStartBattle())
{ {
var battleEntity = BoltNetwork.Instantiate(BoltPrefabs.Battle);
CurrentBattle = battleEntity.GetComponent<Battle>();
CurrentBattle.Zone = this;
foreach (Formation f in Formations)
{
CurrentBattle.AddFormation(f);
}
CurrentBattle.Init();
BoltLog.Info("Starting battle at zone {0}", this);
GWNetworkManager.Instance.SpawnBattle(this);
} }
} }
@ -154,7 +144,7 @@ namespace GWConquest
{ {
OnFormationChanged(formation); OnFormationChanged(formation);
if (BoltNetwork.IsServer)
if (NetworkManager.Singleton.IsServer)
{ {
if (CurrentBattle != null) if (CurrentBattle != null)
{ {


Loading…
Cancel
Save