/// <summary> /// Fetches a tactic given its name. Defaults to the default tactic if name is not matching /// </summary> /// <param name="name">Tactic name</param> /// <returns>The tactic</returns> public static TargetSelectionTactic GetTactic(string name) { byte id = DefaultTacticID; if (NameToID.ContainsKey(name)) { id = NameToID[name]; } return(GetTactic(id)); }
private static void RegisterTacticDatas() { Type targetSelectionTacticDataType = typeof(TargetSelectionTactic); IEnumerable <Type> tacticDataTypes = Assembly.GetExecutingAssembly().GetTypes().Where(t => !t.IsAbstract && t.IsSubclassOf(targetSelectionTacticDataType)); foreach (var type in tacticDataTypes) { TargetSelectionTactic tactic = (TargetSelectionTactic)Activator.CreateInstance(type); int count = TacticDatas.Count; string name = tactic.Name; if (NameToID.ContainsKey(name)) { throw new Exception($"A {nameof(TargetSelectionTactic)} of name '{name}' has already been added!"); } if (count >= DefaultTacticID) { throw new Exception($"Data limit of {DefaultTacticID} reached!"); } TacticDatas.Add(tactic); DisplayNames.Add(tactic.DisplayName); Descriptions.Add(tactic.Description); string texture = tactic.Texture; Textures.Add(ModContent.GetTexture(texture)); OutlineTextures.Add(ModContent.GetTexture(texture + "_Outline")); SmallTextures.Add(ModContent.GetTexture(texture + "_Small")); byte id = (byte)count; Count++; TypeToID[type] = id; NameToID[name] = id; tactic.ID = id; } OrderedIds = new List <byte> { //First row GetTactic <ClosestEnemyToMinion>().ID, GetTactic <StrongestEnemy>().ID, GetTactic <LeastDamagedEnemy>().ID, GetTactic <SpreadOut>().ID, //Second row GetTactic <ClosestEnemyToPlayer>().ID, GetTactic <WeakestEnemy>().ID, GetTactic <MostDamagedEnemy>().ID, GetTactic <AttackGroups>().ID, }; }