Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Core/Game/Abilities/Essential/Scan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Health>();
if (cachedTargetHealth.IsNotNull())
Expand Down Expand Up @@ -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");
}


Expand Down
27 changes: 21 additions & 6 deletions Core/Game/Agents/AgentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ public sealed class AgentController

public const int MaxAgents = 16384;
private static readonly Dictionary<string,IAgentData> CodeInterfacerMap = new Dictionary<string, IAgentData>();
public static IAgentData[] AgentData;
private static readonly Dictionary<string, LSAgent> CodeTemplateMap = new Dictionary<string, LSAgent>();
public static IAgentData[] AgentData;

public static Dictionary<ushort, FastList<bool>> TypeAgentsActive = new Dictionary<ushort, FastList<bool>>();
public static Dictionary<ushort, FastList<LSAgent>> TypeAgents = new Dictionary<ushort, FastList<LSAgent>>();

static Transform OrganizerObject;
public static void Setup()
{
IAgentDataProvider database;
Expand All @@ -38,7 +39,8 @@ public static void Setup()
AgentCodes = new string[AgentData.Length];

CachedAgents = new Dictionary<string,FastStack<LSAgent>>(AgentData.Length);


OrganizerObject = LSUtility.CreateEmpty().transform;
for (int i = 0; i < AgentData.Length; i++)
{
IAgentData interfacer = AgentData [i];
Expand All @@ -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];
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -451,7 +466,7 @@ Vector2d rotation
{
IAgentData interfacer = AgentController.CodeInterfacerMap [agentCode];

curAgent = GameObject.Instantiate(interfacer.GetAgent().gameObject).GetComponent<LSAgent>();
curAgent = GameObject.Instantiate(AgentController.GetAgentTemplate(agentCode).gameObject).GetComponent<LSAgent>();
curAgent.Setup(interfacer);


Expand Down
8 changes: 8 additions & 0 deletions Core/Utility/LSUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Collider>());
GameObject.Destroy(go.GetComponent<Renderer>());
return go;
}

public static Vector2d GenerateRandomPointOnCircle(bool evenDistribution = false)
{

Expand Down