/// <summary> /// Populates a list of the creatures matching the critter type specified. /// </summary> /// <param name="totals">The location where the quantity of creatures will be stored.</param> /// <param name="type">The critter type to match.</param> public static CritterTotals FindCreatures(IDictionary <Tag, CritterTotals> totals, CritterType type) { if (totals == null) { throw new ArgumentNullException("totals"); } var all = new CritterTotals(); IterateCreatures((creature) => { var species = creature.PrefabID(); var go = creature.gameObject; if (type.Matches(creature)) { var alignment = go.GetComponent <FactionAlignment>(); // Create critter totals if not present if (!totals.TryGetValue(species, out CritterTotals total)) { total = new CritterTotals(); totals.Add(species, total); } total.Total++; all.Total++; // Reserve wrangled, marked for attack, and trussed/bagged creatures if ((go.GetComponent <Capturable>()?.IsMarkedForCapture ?? false) || ((alignment?.targeted ?? false) && alignment.targetable) || creature.HasTag(GameTags.Creatures.Bagged)) { total.Reserved++; all.Reserved++; } } }); return(all); }
/// <summary> /// Applied after OnClick runs. /// </summary> /// <param name="__instance">The current resource entry.</param> /// <param name="___selectionIdx">The current selection index.</param> internal static void Postfix(ResourceEntry __instance, ref int ___selectionIdx) { var info = __instance.gameObject.GetComponentSafe <CritterResourceInfo>(); if (info != null) { var creaturesOfType = ListPool <CreatureBrain, ResourceCategoryHeader> . Allocate(); CritterType type = info.CritterType; var species = __instance.Resource; // Get a list of creatures that match this type CritterInventoryUtils.IterateCreatures((creature) => { if (creature.PrefabID() == species && type.Matches(creature)) { creaturesOfType.Add(creature); } }); int count = creaturesOfType.Count; if (count > 0) { // Rotate through valid indexes // Select the object and center it PUtil.CenterAndSelect(creaturesOfType[___selectionIdx++ % count]); } creaturesOfType.Recycle(); } }
/// <summary> /// Applied after Hover runs. /// </summary> /// <param name="__instance">The current resource entry.</param> /// <param name="is_hovering">true if the user is hovering, or false otherwise</param> /// <param name="___HighlightColor">The highlight color from the instance.</param> internal static void Postfix(ResourceEntry __instance, bool is_hovering, Color ___HighlightColor) { var info = __instance.gameObject.GetComponent<CritterResourceInfo>(); if (info != null) { var hlc = ___HighlightColor; CritterType type = info.CritterType; Tag species = __instance.Resource; CritterInventoryUtils.IterateCreatures((creature) => { if (creature.PrefabID() == species && type.Matches(creature)) PUtil.HighlightEntity(creature, is_hovering ? hlc : Color.black); }); } }
/// <summary> /// Applied after Hover runs. /// </summary> /// <param name="__instance">The current resource category header.</param> /// <param name="is_hovering">true if the user is hovering, or false otherwise.</param> /// <param name="___highlightColour">The highlight color from the instance.</param> internal static void Postfix(ResourceCategoryHeader __instance, bool is_hovering, Color ___highlightColour) { var info = __instance.gameObject.GetComponent<CritterResourceInfo>(); if (info != null) { CritterType type = info.CritterType; // It is a creature header, highlight all matching CritterInventoryUtils.IterateCreatures((creature) => { if (type.Matches(creature)) PUtil.HighlightEntity(creature, is_hovering ? ___highlightColour : Color.black); }); } }