private void Start() { SetAllInactive(); bool canAddNPCs = true; foreach (GameObject gameObject in firstActNpcs) { NpcComponent npc = gameObject.GetComponent <NpcComponent>(); if (npc.startsMission && canAddNPCs) { //if the level is completed then go on to check the next npcs if (OptionManager.GetIntIfExists(npc.missionComponent.targetSceneName) != int.MinValue && OptionManager.GetIntIfExists(npc.missionComponent.targetSceneName) == 1) { break; } else { Debug.Log("Set first act visible"); SetActActive(firstActNpcs); canAddNPCs = false; } } } foreach (GameObject gameObject in secondActNpcs) { NpcComponent npc = gameObject.GetComponent <NpcComponent>(); if (npc.startsMission && canAddNPCs) { //if the level is completed then go on to check the next npcs if (OptionManager.GetIntIfExists(npc.missionComponent.targetSceneName) != int.MinValue || OptionManager.GetIntIfExists(npc.missionComponent.targetSceneName) == 1) { break; } else { Debug.Log("Set second act visible"); SetActActive(secondActNpcs); canAddNPCs = false; } } } foreach (GameObject gameObject in thirdActNpcs) { NpcComponent npc = gameObject.GetComponent <NpcComponent>(); if (npc.startsMission && canAddNPCs) { //if the level is completed then go on to check the next npcs if (OptionManager.GetIntIfExists(npc.missionComponent.targetSceneName) != int.MinValue || OptionManager.GetIntIfExists(npc.missionComponent.targetSceneName) == 1) { break; } else { Debug.Log("Set third act visible"); SetActActive(thirdActNpcs); canAddNPCs = false; } } } }
// TODO : replace definition id with an INpcDefinition interface? public IEntityHandle Create(string name, int definitionId) { var handle = Entities.Create($"Npc: {name}"); var ent = handle.Get(); var id = GetId(); if (id == InvalidId) { return(null); } var vision = new VisionComponent(ent); ent.Components.Add(vision); ent.Components.Add <IVisionComponent>(vision); ent.Components.Add(new MovementActionComponent(ent)); ent.Components.Add(new TileMovementComponent(ent)); ent.Components.Add(new FlagAccumulatorComponent(ent)); ent.Components.Add(new MarkedForDeathBroadcasterComponent(ent)); // TODO : set npc health according to it's definition when creating the npc. var health = new HealthComponent(ent); ent.Components.Add(health); ent.Components.Add <IHealthComponent>(health); var npc = new NpcComponent(ent, (short)definitionId.Clamp(0, short.MaxValue), (short)id.Clamp(0, short.MaxValue), DestroyCallback); ent.Components.Add(npc); ent.Components.Add <INpcComponent>(npc); Debug.Assert(InstanceLookup[id] == null); InstanceLookup[id] = handle; ent.SendMessage(NotificationMessage.Initialize); return(handle); }
private void DestroyCallback(NpcComponent npc) { Log.Normal(this, $"Freeing npc slot {npc.InstanceId} named {npc.Parent.Name}"); InstanceLookup[npc.InstanceId] = null; }