diff --git a/Assets/GWConquest/Scripts/BattleFlank.cs b/Assets/GWConquest/Scripts/BattleFlank.cs index 281056f..80e7ae1 100644 --- a/Assets/GWConquest/Scripts/BattleFlank.cs +++ b/Assets/GWConquest/Scripts/BattleFlank.cs @@ -12,8 +12,8 @@ namespace GWConquest { public BattleFlankUI CurrentUI; public Battle Battle { - get => State.Battle?.GetComponent(); - set => State.Battle = value?.entity; + get => BoltEntityCache.Get(State.Battle); + set => State.Battle = BoltEntityCache.Set(value); } public int FlankId { @@ -29,13 +29,13 @@ namespace GWConquest { } public BattleFlank OpposingFlank { - get => State.OpposingFlank?.GetComponent(); - set => State.OpposingFlank = value?.entity; + get => BoltEntityCache.Get(State.OpposingFlank); + set => State.OpposingFlank = BoltEntityCache.Set(value); } public Player Player { - get => State.Player?.GetComponent(); - set => State.Player = value?.entity; + get => BoltEntityCache.Get(State.Player); + set => State.Player = BoltEntityCache.Set(value); } public Unit GetUnit(int index) { diff --git a/Assets/GWConquest/Scripts/BoltEntityCache.cs b/Assets/GWConquest/Scripts/BoltEntityCache.cs new file mode 100644 index 0000000..a6b9f38 --- /dev/null +++ b/Assets/GWConquest/Scripts/BoltEntityCache.cs @@ -0,0 +1,53 @@ +using Bolt; +using UnityEngine; +using System.Collections.Generic; + +namespace GWConquest +{ + public static class BoltEntityCache + { + private static Dictionary dictionary = new Dictionary(); + + public static T Get(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(); + dictionary[id] = newBeh; + return newBeh; + } + + } + + public static NetworkId Set(T behaviour) where T : class, IEntityBehaviour + { + if(behaviour == null) + { + return default(NetworkId); + } + else { + return behaviour.entity.NetworkId; + } + } + } + + +} \ No newline at end of file diff --git a/Assets/GWConquest/Scripts/BoltEntityCache.cs.meta b/Assets/GWConquest/Scripts/BoltEntityCache.cs.meta new file mode 100644 index 0000000..a5d8dae --- /dev/null +++ b/Assets/GWConquest/Scripts/BoltEntityCache.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c2f033f40a5a03e4ba66c6f9240d2043 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/GWConquest/Scripts/Formation.cs b/Assets/GWConquest/Scripts/Formation.cs index 61ca237..2e10878 100644 --- a/Assets/GWConquest/Scripts/Formation.cs +++ b/Assets/GWConquest/Scripts/Formation.cs @@ -50,14 +50,8 @@ namespace GWConquest public Player Player { - get - { - return State.Player?.GetComponent(); - } - set - { - State.Player = value.entity; - } + get => BoltEntityCache.Get(State.Player); + set => State.Player = BoltEntityCache.Set(value); } public string FormationName @@ -96,8 +90,8 @@ namespace GWConquest public Unit HeroUnit { - get => State.HeroUnit?.GetComponent(); - set => State.HeroUnit = value.entity; + get => BoltEntityCache.Get(State.HeroUnit); + set => State.HeroUnit = BoltEntityCache.Set(value); } public IEnumerable AllItems @@ -113,13 +107,13 @@ namespace GWConquest public ZoneList PathQueue; public Formation MovementTargetFormation { - get => State.MovementTargetFormation?.GetComponent(); - set => State.MovementTargetFormation = value?.entity; + get => BoltEntityCache.Get(State.MovementTargetFormation); + set => State.MovementTargetFormation = BoltEntityCache.Set(value); } public Formation MovementOriginFormation { - get => State.MovementOriginFormation?.GetComponent(); - set => State.MovementOriginFormation = value?.entity; + get => BoltEntityCache.Get(State.MovementOriginFormation); + set => State.MovementOriginFormation = BoltEntityCache.Set(value); } public bool IsOnSpaceGroundTransition @@ -133,8 +127,8 @@ namespace GWConquest } public Formation ParentFormation { - get => State.ParentFormation?.GetComponent(); - set => State.ParentFormation = value?.entity; + get => BoltEntityCache.Get(State.ParentFormation); + set => State.ParentFormation = BoltEntityCache.Set(value); } public const float MoraleCap = 27 * 3 * 100; @@ -254,7 +248,7 @@ namespace GWConquest } if(evnt.TargetFormation != null) { - State.MovementTargetFormation = evnt.TargetFormation; + State.MovementTargetFormation = evnt.TargetFormation.NetworkId; } SetActionCooldown(GameManager.Instance.MovementStartingCooldown); diff --git a/Assets/GWConquest/Scripts/Unit.cs b/Assets/GWConquest/Scripts/Unit.cs index 13473fe..a67ce26 100644 --- a/Assets/GWConquest/Scripts/Unit.cs +++ b/Assets/GWConquest/Scripts/Unit.cs @@ -34,8 +34,8 @@ namespace GWConquest public Formation Formation { - get => State.Formation?.GetComponent(); - set => State.Formation = value.entity; + get => BoltEntityCache.Get(State.Formation); + set => State.Formation = BoltEntityCache.Set(value); } public int Hitpoints { @@ -288,7 +288,8 @@ namespace GWConquest public override void SimulateOwner() { - if(!IsDead && CurrentBattle != null && !CurrentBattle.IsInPreparing) + var battle = CurrentBattle; + if(!IsDead && battle != null && !battle.IsInPreparing) { if(BattleState == BattleUnitState.Arriving) { diff --git a/Assets/Photon/PhotonBolt/assemblies/bolt.user.dll b/Assets/Photon/PhotonBolt/assemblies/bolt.user.dll index 8ead9c6..13eb7c4 100644 Binary files a/Assets/Photon/PhotonBolt/assemblies/bolt.user.dll and b/Assets/Photon/PhotonBolt/assemblies/bolt.user.dll differ diff --git a/Assets/Photon/PhotonBolt/assemblies/bolt.user.dll.mdb b/Assets/Photon/PhotonBolt/assemblies/bolt.user.dll.mdb index 18a46bf..dd2c20c 100644 Binary files a/Assets/Photon/PhotonBolt/assemblies/bolt.user.dll.mdb and b/Assets/Photon/PhotonBolt/assemblies/bolt.user.dll.mdb differ diff --git a/Assets/Photon/PhotonBolt/project.json b/Assets/Photon/PhotonBolt/project.json index bdaff1a..cd47a74 100644 --- a/Assets/Photon/PhotonBolt/project.json +++ b/Assets/Photon/PhotonBolt/project.json @@ -65,7 +65,7 @@ "ReplicationMode": 1, "Priority": 1, "PropertyType": { - "$type": "Bolt.Compiler.PropertyTypeEntity, bolt.compiler" + "$type": "Bolt.Compiler.PropertyTypeNetworkId, bolt.compiler" }, "AssetSettings": { "$type": "Bolt.Compiler.PropertyStateSettings, bolt.compiler", @@ -116,7 +116,7 @@ "ReplicationMode": 1, "Priority": 1, "PropertyType": { - "$type": "Bolt.Compiler.PropertyTypeEntity, bolt.compiler" + "$type": "Bolt.Compiler.PropertyTypeNetworkId, bolt.compiler" }, "AssetSettings": { "$type": "Bolt.Compiler.PropertyStateSettings, bolt.compiler", @@ -133,7 +133,7 @@ "ReplicationMode": 1, "Priority": 1, "PropertyType": { - "$type": "Bolt.Compiler.PropertyTypeEntity, bolt.compiler" + "$type": "Bolt.Compiler.PropertyTypeNetworkId, bolt.compiler" }, "AssetSettings": { "$type": "Bolt.Compiler.PropertyStateSettings, bolt.compiler", @@ -203,7 +203,7 @@ "ReplicationMode": 1, "Priority": 1, "PropertyType": { - "$type": "Bolt.Compiler.PropertyTypeEntity, bolt.compiler" + "$type": "Bolt.Compiler.PropertyTypeNetworkId, bolt.compiler" }, "AssetSettings": { "$type": "Bolt.Compiler.PropertyStateSettings, bolt.compiler", @@ -220,7 +220,7 @@ "ReplicationMode": 1, "Priority": 1, "PropertyType": { - "$type": "Bolt.Compiler.PropertyTypeEntity, bolt.compiler" + "$type": "Bolt.Compiler.PropertyTypeNetworkId, bolt.compiler" }, "AssetSettings": { "$type": "Bolt.Compiler.PropertyStateSettings, bolt.compiler", @@ -254,7 +254,7 @@ "ReplicationMode": 1, "Priority": 1, "PropertyType": { - "$type": "Bolt.Compiler.PropertyTypeEntity, bolt.compiler" + "$type": "Bolt.Compiler.PropertyTypeNetworkId, bolt.compiler" }, "AssetSettings": { "$type": "Bolt.Compiler.PropertyStateSettings, bolt.compiler", @@ -881,7 +881,7 @@ "ReplicationMode": 1, "Priority": 1, "PropertyType": { - "$type": "Bolt.Compiler.PropertyTypeEntity, bolt.compiler" + "$type": "Bolt.Compiler.PropertyTypeNetworkId, bolt.compiler" }, "AssetSettings": { "$type": "Bolt.Compiler.PropertyStateSettings, bolt.compiler", @@ -1668,7 +1668,7 @@ "ReplicationMode": 1, "Priority": 1, "PropertyType": { - "$type": "Bolt.Compiler.PropertyTypeEntity, bolt.compiler" + "$type": "Bolt.Compiler.PropertyTypeNetworkId, bolt.compiler" }, "AssetSettings": { "$type": "Bolt.Compiler.PropertyStateSettings, bolt.compiler", @@ -1721,7 +1721,7 @@ "ReplicationMode": 1, "Priority": 1, "PropertyType": { - "$type": "Bolt.Compiler.PropertyTypeEntity, bolt.compiler" + "$type": "Bolt.Compiler.PropertyTypeNetworkId, bolt.compiler" }, "AssetSettings": { "$type": "Bolt.Compiler.PropertyStateSettings, bolt.compiler", @@ -1759,7 +1759,7 @@ "ReplicationMode": 1, "Priority": 1, "PropertyType": { - "$type": "Bolt.Compiler.PropertyTypeEntity, bolt.compiler" + "$type": "Bolt.Compiler.PropertyTypeNetworkId, bolt.compiler" }, "AssetSettings": { "$type": "Bolt.Compiler.PropertyStateSettings, bolt.compiler",