/// <summary>
 /// Adds a critter in the current world to the inventory.
 /// </summary>
 /// <param name="creature">The creature to add.</param>
 private void AddCritter(CreatureBrain creature)
 {
     if (counts.TryGetValue(creature.GetCritterType(), out CritterInventoryPerType
                            byType))
     {
         var  species = creature.PrefabID();
         var  alignment = creature.GetComponent <FactionAlignment>();
         bool targeted = false, targetable = false;
         // Create critter totals if not present
         if (!byType.TryGetValue(species, out CritterTotals totals))
         {
             byType.Add(species, totals = new CritterTotals());
             discovered = true;
         }
         totals.Total++;
         if (alignment != null)
         {
             targeted   = FACTION_TARGETED.Get(alignment);
             targetable = FACTION_TARGETABLE.Get(alignment);
         }
         // Reserve wrangled, marked for attack, and trussed/bagged creatures
         if ((creature.GetComponent <Capturable>()?.IsMarkedForCapture ?? false) ||
             (targeted && targetable) || creature.HasTag(GameTags.Creatures.Bagged))
         {
             totals.Reserved++;
         }
     }
 }
Beispiel #2
0
        private static void Action(Tag speciesTag, string name, Dictionary <string, CodexEntry> results)
        {
            List <GameObject> brains = Assets.GetPrefabsWithComponent <CreatureBrain>();
            CodexEntry        entry  = new CodexEntry("CREATURES", new List <ContentContainer>()
            {
                new ContentContainer(new List <ICodexWidget>()
                {
                    new CodexSpacer(),
                    new CodexSpacer()
                }, ContentContainer.ContentLayout.Vertical)
            }, name);

            entry.parentId = "CREATURES";
            CodexCache.AddEntry(speciesTag.ToString(), entry, null);
            results.Add(speciesTag.ToString(), entry);
            foreach (GameObject gameObject in brains)
            {
                if (gameObject.GetDef <BabyMonitor.Def>() == null)
                {
                    Sprite     sprite = null;
                    GameObject prefab = Assets.TryGetPrefab((gameObject.PrefabID().ToString() + "Baby"));
                    if (prefab != null)
                    {
                        sprite = Def.GetUISprite(prefab, "ui", false).first;
                    }
                    CreatureBrain component = gameObject.GetComponent <CreatureBrain>();
                    if (component.species == speciesTag)
                    {
                        List <ContentContainer> contentContainerList = new List <ContentContainer>();
                        string symbolPrefix = component.symbolPrefix;
                        Sprite first        = Def.GetUISprite(gameObject, symbolPrefix + "ui", false).first;
                        if ((bool)((UnityEngine.Object)sprite))
                        {
                            Traverse.Create(typeof(CodexEntryGenerator)).Method("GenerateImageContainers", new[] { typeof(Sprite[]), typeof(List <ContentContainer>), typeof(ContentContainer.ContentLayout) })
                            .GetValue(new Sprite[2]
                            {
                                first,
                                sprite
                            }, contentContainerList, ContentContainer.ContentLayout.Horizontal);
                        }
                        else
                        {
                            contentContainerList.Add(new ContentContainer(new List <ICodexWidget>()
                            {
                                new CodexImage(128, 128, first)
                            }, ContentContainer.ContentLayout.Vertical));
                        }

                        Traverse.Create(typeof(CodexEntryGenerator)).Method("GenerateCreatureDescriptionContainers", new[] { typeof(GameObject), typeof(List <ContentContainer>) }).GetValue(gameObject, contentContainerList);
                        entry.subEntries.Add(new SubEntry(component.PrefabID().ToString(), speciesTag.ToString(), contentContainerList, component.GetProperName())
                        {
                            icon      = first,
                            iconColor = UnityEngine.Color.white
                        });
                    }
                }
            }
        }