diff --git a/Core/Game/Abilities/Essential/Scan.cs b/Core/Game/Abilities/Essential/Scan.cs index 47f0cf4b..93f770d5 100755 --- a/Core/Game/Abilities/Essential/Scan.cs +++ b/Core/Game/Abilities/Essential/Scan.cs @@ -505,7 +505,7 @@ public LSProjectile FireProjectile(string projCode, Vector3d projOffset, Vector3 public void Engage(LSAgent other) { - if (other != Agent) + if (other != Agent && other != null) { cachedTargetHealth = other.GetAbility(); if (cachedTargetHealth.IsNotNull()) @@ -593,8 +593,10 @@ protected override void OnExecute(Command com) isAttackMoving = false; LSAgent tempTarget; ushort targetValue = (ushort)target.Value; - AgentController.TryGetAgentInstance(targetValue, out tempTarget); - Engage(tempTarget); + if (AgentController.TryGetAgentInstance(targetValue, out tempTarget)) + Engage(tempTarget); + else + Debug.Log("nope"); } diff --git a/Core/Game/Agents/AgentController.cs b/Core/Game/Agents/AgentController.cs index 9bde7393..f5b0ff16 100755 --- a/Core/Game/Agents/AgentController.cs +++ b/Core/Game/Agents/AgentController.cs @@ -22,11 +22,12 @@ public sealed class AgentController public const int MaxAgents = 16384; private static readonly Dictionary CodeInterfacerMap = new Dictionary(); - public static IAgentData[] AgentData; + private static readonly Dictionary CodeTemplateMap = new Dictionary(); + public static IAgentData[] AgentData; public static Dictionary> TypeAgentsActive = new Dictionary>(); public static Dictionary> TypeAgents = new Dictionary>(); - + static Transform OrganizerObject; public static void Setup() { IAgentDataProvider database; @@ -38,7 +39,8 @@ public static void Setup() AgentCodes = new string[AgentData.Length]; CachedAgents = new Dictionary>(AgentData.Length); - + + OrganizerObject = LSUtility.CreateEmpty().transform; for (int i = 0; i < AgentData.Length; i++) { IAgentData interfacer = AgentData [i]; @@ -61,6 +63,19 @@ public static IAgentData GetAgentInterfacer(string agentCode) return AgentController.CodeInterfacerMap [agentCode]; } + public static LSAgent GetAgentTemplate(string agentCode) + { + LSAgent template; + if (!CodeTemplateMap.TryGetValue(agentCode, out template)) + { + template = GameObject.Instantiate(GetAgentSource(agentCode)); + CodeTemplateMap.Add(agentCode, template); + template.transform.parent = OrganizerObject.transform; + } + + return template; + } + public static ushort GetAgentCodeIndex(string agentCode) { return CodeIndexMap [agentCode]; @@ -417,10 +432,10 @@ public LSAgent CreateAgent(string agentCode, Vector2d position) { return CreateAgent(agentCode, position, Vector2d.right); } - public static GameObject GetTemplate(string agentCode) + public static LSAgent GetAgentSource(string agentCode) { IAgentData interfacer = AgentController.CodeInterfacerMap[agentCode]; - return interfacer.GetAgent().gameObject; + return interfacer.GetAgent(); } public LSAgent CreateAgent( string agentCode, @@ -451,7 +466,7 @@ Vector2d rotation { IAgentData interfacer = AgentController.CodeInterfacerMap [agentCode]; - curAgent = GameObject.Instantiate(interfacer.GetAgent().gameObject).GetComponent(); + curAgent = GameObject.Instantiate(AgentController.GetAgentTemplate(agentCode).gameObject).GetComponent(); curAgent.Setup(interfacer); diff --git a/Core/Utility/LSUtility.cs b/Core/Utility/LSUtility.cs index 0f91a97f..f2c75421 100755 --- a/Core/Utility/LSUtility.cs +++ b/Core/Utility/LSUtility.cs @@ -55,6 +55,14 @@ public static long GetRandomOne() return FixedMath.Create(GetRandom(), int.MaxValue); } + public static GameObject CreateEmpty() + { + GameObject go = GameObject.CreatePrimitive(PrimitiveType.Quad); + GameObject.Destroy(go.GetComponent()); + GameObject.Destroy(go.GetComponent()); + return go; + } + public static Vector2d GenerateRandomPointOnCircle(bool evenDistribution = false) {