Author | SHA1 | Message | Date |
---|---|---|---|
laurids | f6081ef965 | (WIP) Completely removed Bolt from Scripts | 1 year ago |
laurids | d7cbce23e6 | (WIP) deleted Photon imports | 1 year ago |
laurids | e12395b57f | Replaced logs | 1 year ago |
laurids | 253f3eaec7 | (WIP) Netcode Part 4: compiles! | 1 year ago |
@ -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(); | |||
} | |||
} | |||
} |
@ -1,11 +0,0 @@ | |||
fileFormatVersion: 2 | |||
guid: c2f033f40a5a03e4ba66c6f9240d2043 | |||
MonoImporter: | |||
externalObjects: {} | |||
serializedVersion: 2 | |||
defaultReferences: [] | |||
executionOrder: 0 | |||
icon: {instanceID: 0} | |||
userData: | |||
assetBundleName: | |||
assetBundleVariant: |
@ -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) {} | |||
} | |||
} |
@ -1,11 +0,0 @@ | |||
fileFormatVersion: 2 | |||
guid: fda8796fd8800ef46a1ae47fa4de74a7 | |||
MonoImporter: | |||
externalObjects: {} | |||
serializedVersion: 2 | |||
defaultReferences: [] | |||
executionOrder: 0 | |||
icon: {instanceID: 0} | |||
userData: | |||
assetBundleName: | |||
assetBundleVariant: |
@ -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)); | |||
} | |||
} | |||
} |
@ -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; | |||
} | |||
} | |||
} | |||
} |
@ -1,11 +0,0 @@ | |||
fileFormatVersion: 2 | |||
guid: f48b9c6bc6be7154e809c78208e38787 | |||
MonoImporter: | |||
externalObjects: {} | |||
serializedVersion: 2 | |||
defaultReferences: [] | |||
executionOrder: 0 | |||
icon: {instanceID: 0} | |||
userData: | |||
assetBundleName: | |||
assetBundleVariant: |
@ -1,5 +0,0 @@ | |||
using Unity.Netcode; | |||
namespace GWConquest { | |||
} |
@ -1,11 +0,0 @@ | |||
fileFormatVersion: 2 | |||
guid: 5893ec9dc0d5802479ca61e4b13ac64f | |||
MonoImporter: | |||
externalObjects: {} | |||
serializedVersion: 2 | |||
defaultReferences: [] | |||
executionOrder: 0 | |||
icon: {instanceID: 0} | |||
userData: | |||
assetBundleName: | |||
assetBundleVariant: |
@ -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; | |||
} | |||
} | |||
} |
@ -1,5 +1,5 @@ | |||
fileFormatVersion: 2 | |||
guid: 38983f1af3b8f9446a9a71fc1d5ebfc7 | |||
guid: 1741c174eb1458047aa5ab35a3b0aec4 | |||
MonoImporter: | |||
externalObjects: {} | |||
serializedVersion: 2 |
@ -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(); | |||
} | |||
} | |||
} | |||
} | |||
} |
@ -1,11 +0,0 @@ | |||
fileFormatVersion: 2 | |||
guid: 4cd2ea54c0e00384894169adbfdf6403 | |||
MonoImporter: | |||
externalObjects: {} | |||
serializedVersion: 2 | |||
defaultReferences: [] | |||
executionOrder: 0 | |||
icon: {instanceID: 0} | |||
userData: | |||
assetBundleName: | |||
assetBundleVariant: |
@ -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"); | |||
} | |||
} | |||
} | |||
} |
@ -1,11 +0,0 @@ | |||
fileFormatVersion: 2 | |||
guid: b7ac2246de5adcc4eb245fff9adac55e | |||
MonoImporter: | |||
externalObjects: {} | |||
serializedVersion: 2 | |||
defaultReferences: [] | |||
executionOrder: 0 | |||
icon: {instanceID: 0} | |||
userData: | |||
assetBundleName: | |||
assetBundleVariant: |