/// <summary> /// Initializes NPCManager instance component from NPC faction's FactionSlot instance. /// </summary> /// <param name="npcType">The NPCTypeInfo instance that defines the NPC faction's type.</param> /// <param name="gameMgr">GameManager instance of currently active game.</param> /// <param name="factionMgr">FactionManager instance of the NPC faction.</param> public void Init(NPCTypeInfo npcType, GameManager gameMgr, FactionManager factionMgr) { this.NPCType = npcType; this.gameMgr = gameMgr; this.FactionMgr = factionMgr; //subscribe to event CustomEvents.FactionDefaultEntitiesInit += OnFactionDefaultEntitiesInit; }
//init the faction slot and update the faction attributes public void Init(string name, FactionTypeInfo typeInfo, Color color, bool playerControlled, int population, NPCTypeInfo npcType, FactionManager factionMgr, int factionID, GameManager gameMgr) { this.name = name; this.typeInfo = typeInfo; this.color = color; this.PlayerControlled = playerControlled; this.npcType = this.PlayerControlled ? null : npcType; Init(factionID, factionMgr, gameMgr); UpdateMaxPopulation(population, false); }
private static IEnumerable <NPCTypeInfo> npcTypes = null; //holds currently available NPCTypeInfo asset files. /// <summary> /// Gets the cached NPCTypeInfo assets in the project and refreshes the cache if necessary. /// </summary> /// <param name="requireTest">When true, a test will determine whether testNPCType is cached or not. If already cached, the cache will not be refreshed.</param> /// <param name="testNPCType">The NPCTypeInfo instance to test.</param> /// <returns>Diciontary instance where each key is the code cached NPCTypeInfo assets and each value is the actual asset instance that matches the key type</returns> public static Dictionary <string, NPCTypeInfo> GetNPCTypes(bool requireTest = false, NPCTypeInfo testNPCType = null) { //only refresh if.. if (npcTypes == null || //cache hasn't been assigned yet. (requireTest == true && !npcTypes.Contains(testNPCType))) //or test is required while test resource type is not in the cached list { CacheAssetFiles(out npcTypes, "t:NPCTypeInfo"); } return(npcTypes.ToDictionary(type => type == null ? "Unassigned" : type.GetCode())); }