Пример #1
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
                        });
                    }
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Adds a brain to update asynchronously.
 /// </summary>
 /// <param name="brain">The rover brain to update.</param>
 internal void AddBrain(CreatureBrain brain)
 {
     if (brain.TryGetComponent(out Navigator nav))
     {
         // What PathProberSensor did
         nav.UpdateProbe(false);
     }
     brainsToUpdate.Add(new BrainPair(brain, nav));
 }
        public static int NamedCritters(string name)
        {
            int count = 0;

            foreach (object brain in Components.Brains)
            {
                CreatureBrain cmp = brain as CreatureBrain;
                if ((UnityEngine.Object)cmp != (UnityEngine.Object)null && cmp.name.Contains(name))
                {
                    count++;
                }
            }
            return(count);
        }
        public void LayEgg()
        {
            fertility.value = 0f;
            Vector3 position = base.smi.transform.GetPosition();

            position.z = Grid.GetLayerZ(Grid.SceneLayer.Ore);
            float num     = UnityEngine.Random.value;
            Tag   invalid = Tag.Invalid;

            foreach (BreedingChance breedingChance in breedingChances)
            {
                num -= breedingChance.weight;
                if (num <= 0f)
                {
                    invalid = breedingChance.egg;
                    break;
                }
            }
            if (GenericGameSettings.instance.acceleratedLifecycle)
            {
                float num2 = 0f;
                foreach (BreedingChance breedingChance2 in breedingChances)
                {
                    if (breedingChance2.weight > num2)
                    {
                        num2    = breedingChance2.weight;
                        invalid = breedingChance2.egg;
                    }
                }
            }
            Debug.Assert(invalid != Tag.Invalid, "Didn't pick an egg to lay. Weights weren't normalized?");
            GameObject prefab     = Assets.GetPrefab(invalid);
            GameObject gameObject = egg = Util.KInstantiate(prefab, position);
            SymbolOverrideController component = GetComponent <SymbolOverrideController>();
            string str = "egg01";

            IncubationMonitor.Def def        = prefab.GetDef <IncubationMonitor.Def>();
            CreatureBrain         component2 = Assets.GetPrefab(def.spawnedCreature).GetComponent <CreatureBrain>();

            if (!string.IsNullOrEmpty(component2.symbolPrefix))
            {
                str = component2.symbolPrefix + "egg01";
            }
            KAnim.Build.Symbol symbol = egg.GetComponent <KBatchedAnimController>().AnimFiles[0].GetData().build.GetSymbol(str);
            if (symbol != null)
            {
                component.AddSymbolOverride(targetEggSymbol, symbol, 0);
            }
            Trigger(1193600993, egg);
        }
    public override void PlaySound(AnimEventManager.EventPlayerData behaviour)
    {
        string        sound     = base.sound;
        CreatureBrain component = behaviour.GetComponent <CreatureBrain>();

        if ((Object)component != (Object)null && !string.IsNullOrEmpty(component.symbolPrefix))
        {
            string sound2 = GlobalAssets.GetSound(StringFormatter.Combine(component.symbolPrefix, base.name), false);
            if (!string.IsNullOrEmpty(sound2))
            {
                sound = sound2;
            }
        }
        PlaySound(behaviour, sound);
    }
    private string GetSelectedObjectCodexID()
    {
        string text = string.Empty;
        CellSelectionObject       component  = SelectTool.Instance.selected.GetComponent <CellSelectionObject>();
        BuildingUnderConstruction component2 = SelectTool.Instance.selected.GetComponent <BuildingUnderConstruction>();
        CreatureBrain             component3 = SelectTool.Instance.selected.GetComponent <CreatureBrain>();
        PlantableSeed             component4 = SelectTool.Instance.selected.GetComponent <PlantableSeed>();
        BudUprootedMonitor        component5 = SelectTool.Instance.selected.GetComponent <BudUprootedMonitor>();

        if ((UnityEngine.Object)component != (UnityEngine.Object)null)
        {
            text = CodexCache.FormatLinkID(component.element.id.ToString());
        }
        else if ((UnityEngine.Object)component2 != (UnityEngine.Object)null)
        {
            text = CodexCache.FormatLinkID(component2.Def.PrefabID);
        }
        else if ((UnityEngine.Object)component3 != (UnityEngine.Object)null)
        {
            text = CodexCache.FormatLinkID(SelectTool.Instance.selected.PrefabID().ToString());
            text = text.Replace("BABY", string.Empty);
        }
        else if ((UnityEngine.Object)component4 != (UnityEngine.Object)null)
        {
            text = CodexCache.FormatLinkID(SelectTool.Instance.selected.PrefabID().ToString());
            text = text.Replace("SEED", string.Empty);
        }
        else if ((UnityEngine.Object)component5 != (UnityEngine.Object)null)
        {
            if ((UnityEngine.Object)component5.parentObject.Get() != (UnityEngine.Object)null)
            {
                text = CodexCache.FormatLinkID(component5.parentObject.Get().PrefabID().ToString());
            }
            else if ((UnityEngine.Object)component5.GetComponent <TreeBud>() != (UnityEngine.Object)null)
            {
                text = CodexCache.FormatLinkID(component5.GetComponent <TreeBud>().buddingTrunk.Get().PrefabID().ToString());
            }
        }
        else
        {
            text = CodexCache.FormatLinkID(SelectTool.Instance.selected.PrefabID().ToString());
        }
        if (CodexCache.entries.ContainsKey(text) || CodexCache.FindSubEntry(text) != null)
        {
            return(text);
        }
        return(string.Empty);
    }
Пример #7
0
        public static int DomesticatedCritters()
        {
            int count = 0;

            foreach (object brain in Components.Brains)
            {
                CreatureBrain cmp = brain as CreatureBrain;
                if ((UnityEngine.Object)cmp != (UnityEngine.Object)null)
                {
                    if (!cmp.HasTag(GameTags.Creatures.Wild))
                    {
                        count++;
                    }
                }
            }
            return(count);
        }
Пример #8
0
    public static void AddCreatureBrain(GameObject prefab, ChoreTable.Builder chore_table, Tag species, string symbol_prefix)
    {
        CreatureBrain creatureBrain = prefab.AddOrGet <CreatureBrain>();

        creatureBrain.species      = species;
        creatureBrain.symbolPrefix = symbol_prefix;
        ChoreConsumer chore_consumer = prefab.AddOrGet <ChoreConsumer>();

        chore_consumer.choreTable = chore_table.CreateTable();
        KPrefabID kPrefabID = prefab.AddOrGet <KPrefabID>();

        kPrefabID.AddTag(GameTags.CreatureBrain, false);
        kPrefabID.instantiateFn += delegate(GameObject go)
        {
            go.GetComponent <ChoreConsumer>().choreTable = chore_consumer.choreTable;
        };
    }
        /************************************************************************************************************************/

        /// <summary>
        /// When a <see cref="Creature"/> enters this trigger, try to make it enter this state.
        /// </summary>
        private void OnTriggerEnter(Collider collider)
        {
            if (enabled)
            {
                return;
            }

            var creature = collider.GetComponent <Creature>();

            if (creature == null ||
                !creature.Idle.TryEnterState())
            {
                return;
            }

            _State         = State.Entering;
            _PreviousBrain = creature.Brain;
            Creature       = creature;
        }
        /// <summary>
        /// Gets the type of a critter.
        /// </summary>
        /// <param name="creature">The critter to query.</param>
        /// <returns>The critter type.</returns>
        public static CritterType GetCritterType(this CreatureBrain creature)
        {
            var go     = creature.gameObject;
            var result = CritterType.Wild;

            if (creature != null)
            {
                if (go.GetDef <RobotBatteryMonitor.Def>() != null)
                {
                    result = CritterType.Artificial;
                }
                else if (go.GetDef <WildnessMonitor.Def>() != null && !creature.HasTag(GameTags.
                                                                                       Creatures.Wild))
                {
                    result = CritterType.Tame;
                }
            }
            return(result);
        }
Пример #11
0
 /// <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>();
         // Create critter totals if not present
         if (!byType.TryGetValue(species, out CritterTotals totals))
         {
             byType.Add(species, totals = new CritterTotals());
             discovered = true;
         }
         totals.Total++;
         // Reserve wrangled, marked for attack, and trussed/bagged creatures
         if ((creature.GetComponent <Capturable>()?.IsMarkedForCapture ?? false) ||
             ((alignment?.targeted ?? false) && alignment.targetable) ||
             creature.HasTag(GameTags.Creatures.Bagged))
         {
             totals.Reserved++;
         }
     }
 }
Пример #12
0
 private void Start()
 {
     myBrain = this.gameObject.GetComponent <CreatureBrain>();
 }
 private void Start()
 {
     myBrain      = this.gameObject.GetComponent <CreatureBrain>();
     energyGained = 15f;
 }
 public static Tuple <Sprite, Color> GetUISprite(object item, string animName = "ui", bool centered = false)
 {
     if (item is Substance)
     {
         return(GetUISprite(ElementLoader.FindElementByHash((item as Substance).elementID), animName, centered));
     }
     if (item is Element)
     {
         if ((item as Element).IsSolid)
         {
             return(new Tuple <Sprite, Color>(GetUISpriteFromMultiObjectAnim((item as Element).substance.anim, animName, centered, string.Empty), Color.white));
         }
         if ((item as Element).IsLiquid)
         {
             return(new Tuple <Sprite, Color>(Assets.GetSprite("element_liquid"), (item as Element).substance.uiColour));
         }
         if ((item as Element).IsGas)
         {
             return(new Tuple <Sprite, Color>(Assets.GetSprite("element_gas"), (item as Element).substance.uiColour));
         }
         return(new Tuple <Sprite, Color>(null, Color.clear));
     }
     if (item is GameObject)
     {
         GameObject gameObject = item as GameObject;
         if (ElementLoader.GetElement(gameObject.PrefabID()) != null)
         {
             return(GetUISprite(ElementLoader.GetElement(gameObject.PrefabID()), animName, centered));
         }
         CreatureBrain component = gameObject.GetComponent <CreatureBrain>();
         if ((UnityEngine.Object)component != (UnityEngine.Object)null)
         {
             animName = component.symbolPrefix + "ui";
         }
         SpaceArtifact component2 = gameObject.GetComponent <SpaceArtifact>();
         if ((UnityEngine.Object)component2 != (UnityEngine.Object)null)
         {
             animName = component2.GetUIAnim();
         }
         if (gameObject.HasTag(GameTags.Egg))
         {
             IncubationMonitor.Def def = gameObject.GetDef <IncubationMonitor.Def>();
             if (def != null)
             {
                 GameObject prefab = Assets.GetPrefab(def.spawnedCreature);
                 if ((bool)prefab)
                 {
                     component = prefab.GetComponent <CreatureBrain>();
                     if ((bool)component && !string.IsNullOrEmpty(component.symbolPrefix))
                     {
                         animName = component.symbolPrefix + animName;
                     }
                 }
             }
         }
         KBatchedAnimController component3 = gameObject.GetComponent <KBatchedAnimController>();
         if ((bool)component3)
         {
             Sprite uISpriteFromMultiObjectAnim = GetUISpriteFromMultiObjectAnim(component3.AnimFiles[0], animName, centered, string.Empty);
             return(new Tuple <Sprite, Color>(uISpriteFromMultiObjectAnim, (!((UnityEngine.Object)uISpriteFromMultiObjectAnim != (UnityEngine.Object)null)) ? Color.clear : Color.white));
         }
         if ((UnityEngine.Object)gameObject.GetComponent <Building>() != (UnityEngine.Object)null)
         {
             Sprite uISprite = gameObject.GetComponent <Building>().Def.GetUISprite(animName, centered);
             return(new Tuple <Sprite, Color>(uISprite, (!((UnityEngine.Object)uISprite != (UnityEngine.Object)null)) ? Color.clear : Color.white));
         }
         Debug.LogWarningFormat("Can't get sprite for type {0} (no KBatchedAnimController)", item.ToString());
         return(null);
     }
     if (item is string)
     {
         if (Db.Get().Amounts.Exists(item as string))
         {
             Amount amount = Db.Get().Amounts.Get(item as string);
             return(new Tuple <Sprite, Color>(Assets.GetSprite(amount.uiSprite), Color.white));
         }
         if (Db.Get().Attributes.Exists(item as string))
         {
             Klei.AI.Attribute attribute = Db.Get().Attributes.Get(item as string);
             return(new Tuple <Sprite, Color>(Assets.GetSprite(attribute.uiSprite), Color.white));
         }
         return(GetUISprite((item as string).ToTag(), animName, centered));
     }
     if (item is Tag)
     {
         if (ElementLoader.GetElement((Tag)item) != null)
         {
             return(GetUISprite(ElementLoader.GetElement((Tag)item), animName, centered));
         }
         if ((UnityEngine.Object)Assets.GetPrefab((Tag)item) != (UnityEngine.Object)null)
         {
             return(GetUISprite(Assets.GetPrefab((Tag)item), animName, centered));
         }
         if ((UnityEngine.Object)Assets.GetSprite(((Tag)item).Name) != (UnityEngine.Object)null)
         {
             return(new Tuple <Sprite, Color>(Assets.GetSprite(((Tag)item).Name), Color.white));
         }
     }
     DebugUtil.DevAssertArgs(false, "Can't get sprite for type ", item.ToString());
     return(null);
 }
Пример #15
0
    private void ConfigureEntitySelector()
    {
        List <SelectorValue.SearchFilter> list = new List <SelectorValue.SearchFilter>();
        string name = UI.SANDBOXTOOLS.FILTERS.ENTITIES.FOOD;
        Func <object, bool> condition = delegate(object entity)
        {
            string idString = (entity as KPrefabID).PrefabID().ToString();
            return(!(entity as KPrefabID).HasTag(GameTags.Egg) && FOOD.FOOD_TYPES_LIST.Find((EdiblesManager.FoodInfo match) => match.Id == idString) != null);
        };
        Tuple <Sprite, Color> uISprite = Def.GetUISprite(Assets.GetPrefab("MushBar"), "ui", false);

        SelectorValue.SearchFilter item = new SelectorValue.SearchFilter(name, condition, null, uISprite);
        list.Add(item);
        name      = UI.SANDBOXTOOLS.FILTERS.ENTITIES.SPECIAL;
        condition = ((object entity) => (entity as KPrefabID).PrefabID().Name == MinionConfig.ID || (entity as KPrefabID).PrefabID().Name == DustCometConfig.ID || (entity as KPrefabID).PrefabID().Name == RockCometConfig.ID || (entity as KPrefabID).PrefabID().Name == IronCometConfig.ID);
        uISprite  = new Tuple <Sprite, Color>(Assets.GetSprite("ui_duplicant_portrait_placeholder"), Color.white);
        SelectorValue.SearchFilter item2 = new SelectorValue.SearchFilter(name, condition, null, uISprite);
        list.Add(item2);
        SelectorValue.SearchFilter searchFilter  = null;
        SelectorValue.SearchFilter searchFilter2 = null;
        name         = UI.SANDBOXTOOLS.FILTERS.ENTITIES.CREATURE;
        condition    = ((object entity) => false);
        uISprite     = Def.GetUISprite(Assets.GetPrefab("Hatch"), "ui", false);
        searchFilter = new SelectorValue.SearchFilter(name, condition, null, uISprite);
        list.Add(searchFilter);
        List <Tag> list2 = new List <Tag>();

        foreach (GameObject item7 in Assets.GetPrefabsWithTag("CreatureBrain".ToTag()))
        {
            CreatureBrain brain = item7.GetComponent <CreatureBrain>();
            if (!list2.Contains(brain.species))
            {
                Tuple <Sprite, Color> icon = new Tuple <Sprite, Color>(CodexCache.entries[brain.species.ToString().ToUpper()].icon, CodexCache.entries[brain.species.ToString().ToUpper()].iconColor);
                list2.Add(brain.species);
                string key = "STRINGS.CREATURES.FAMILY_PLURAL." + brain.species.ToString().ToUpper();
                SelectorValue.SearchFilter item3 = new SelectorValue.SearchFilter(Strings.Get(key), delegate(object entity)
                {
                    CreatureBrain component2 = Assets.GetPrefab((entity as KPrefabID).PrefabID()).GetComponent <CreatureBrain>();
                    return((entity as KPrefabID).HasTag("CreatureBrain".ToString()) && component2.species == brain.species);
                }, searchFilter, icon);
                list.Add(item3);
            }
        }
        searchFilter2 = new SelectorValue.SearchFilter(UI.SANDBOXTOOLS.FILTERS.ENTITIES.CREATURE_EGG, (object entity) => (entity as KPrefabID).HasTag(GameTags.Egg), searchFilter, Def.GetUISprite(Assets.GetPrefab("HatchEgg"), "ui", false));
        list.Add(searchFilter2);
        name      = UI.SANDBOXTOOLS.FILTERS.ENTITIES.EQUIPMENT;
        condition = delegate(object entity)
        {
            if ((UnityEngine.Object)(entity as KPrefabID).gameObject == (UnityEngine.Object)null)
            {
                return(false);
            }
            GameObject gameObject4 = (entity as KPrefabID).gameObject;
            if ((UnityEngine.Object)gameObject4 != (UnityEngine.Object)null)
            {
                return((UnityEngine.Object)gameObject4.GetComponent <Equippable>() != (UnityEngine.Object)null);
            }
            return(false);
        };
        uISprite = Def.GetUISprite(Assets.GetPrefab("Funky_Vest"), "ui", false);
        SelectorValue.SearchFilter item4 = new SelectorValue.SearchFilter(name, condition, null, uISprite);
        list.Add(item4);
        name      = UI.SANDBOXTOOLS.FILTERS.ENTITIES.PLANTS;
        condition = delegate(object entity)
        {
            if ((UnityEngine.Object)(entity as KPrefabID).gameObject == (UnityEngine.Object)null)
            {
                return(false);
            }
            GameObject gameObject3 = (entity as KPrefabID).gameObject;
            if ((UnityEngine.Object)gameObject3 != (UnityEngine.Object)null)
            {
                return((UnityEngine.Object)gameObject3.GetComponent <Harvestable>() != (UnityEngine.Object)null || (UnityEngine.Object)gameObject3.GetComponent <WiltCondition>() != (UnityEngine.Object)null);
            }
            return(false);
        };
        uISprite = Def.GetUISprite(Assets.GetPrefab("PrickleFlower"), "ui", false);
        SelectorValue.SearchFilter searchFilter3 = new SelectorValue.SearchFilter(name, condition, null, uISprite);
        list.Add(searchFilter3);
        SelectorValue.SearchFilter item5 = new SelectorValue.SearchFilter(UI.SANDBOXTOOLS.FILTERS.ENTITIES.SEEDS, delegate(object entity)
        {
            if ((UnityEngine.Object)(entity as KPrefabID).gameObject == (UnityEngine.Object)null)
            {
                return(false);
            }
            GameObject gameObject2 = (entity as KPrefabID).gameObject;
            if ((UnityEngine.Object)gameObject2 != (UnityEngine.Object)null)
            {
                return((UnityEngine.Object)gameObject2.GetComponent <PlantableSeed>() != (UnityEngine.Object)null);
            }
            return(false);
        }, searchFilter3, Def.GetUISprite(Assets.GetPrefab("PrickleFlowerSeed"), "ui", false));
        list.Add(item5);
        name      = UI.SANDBOXTOOLS.FILTERS.ENTITIES.INDUSTRIAL_PRODUCTS;
        condition = delegate(object entity)
        {
            if ((UnityEngine.Object)(entity as KPrefabID).gameObject == (UnityEngine.Object)null)
            {
                return(false);
            }
            GameObject gameObject = (entity as KPrefabID).gameObject;
            if ((UnityEngine.Object)gameObject != (UnityEngine.Object)null)
            {
                return(gameObject.HasTag(GameTags.IndustrialIngredient) || gameObject.HasTag(GameTags.IndustrialProduct) || gameObject.HasTag(GameTags.Medicine) || gameObject.HasTag(GameTags.MedicalSupplies));
            }
            return(false);
        };
        uISprite = Def.GetUISprite(Assets.GetPrefab("BasicCure"), "ui", false);
        SelectorValue.SearchFilter item6 = new SelectorValue.SearchFilter(name, condition, null, uISprite);
        list.Add(item6);
        List <KPrefabID> list3 = new List <KPrefabID>();

        foreach (KPrefabID prefab2 in Assets.Prefabs)
        {
            foreach (SelectorValue.SearchFilter item8 in list)
            {
                if (item8.condition(prefab2))
                {
                    list3.Add(prefab2);
                    break;
                }
            }
        }
        entitySelector = new SelectorValue(list3.ToArray(), delegate(object entity)
        {
            settings.SelectEntity(entity as KPrefabID);
        }, (object entity) => (entity as KPrefabID).GetProperName(), delegate(string filterString, object option)
        {
            if ((option as KPrefabID).GetProperName().ToUpper().Contains(filterString.ToUpper()))
            {
                return(true);
            }
            return(false);
        }, delegate(object entity)
        {
            GameObject prefab = Assets.GetPrefab((entity as KPrefabID).PrefabTag);
            if ((UnityEngine.Object)prefab != (UnityEngine.Object)null)
            {
                if (prefab.PrefabID() == (Tag)MinionConfig.ID)
                {
                    return(new Tuple <Sprite, Color>(Assets.GetSprite("ui_duplicant_portrait_placeholder"), Color.white));
                }
                KBatchedAnimController component = prefab.GetComponent <KBatchedAnimController>();
                if ((UnityEngine.Object)component != (UnityEngine.Object)null && component.AnimFiles.Length > 0)
                {
                    KAnimFile x = component.AnimFiles[0];
                    if ((UnityEngine.Object)x != (UnityEngine.Object)null)
                    {
                        return(Def.GetUISprite(prefab, "ui", false));
                    }
                }
            }
            return(null);
        }, list.ToArray());
    }