/// <summary>
 /// Applied after OnSpawn runs.
 /// </summary>
 internal static void Postfix(WorldInventory __instance)
 {
     if (__instance != null)
     {
         __instance.gameObject.AddOrGet <BackgroundWorldInventory>();
     }
 }
Beispiel #2
0
 /// <summary>
 /// Updates all elements in the specified category.
 /// </summary>
 /// <param name="inv">The inventory of discovered elements.</param>
 /// <param name="category">The category to search.</param>
 /// <param name="overrideName">The name to override the category title</param>
 private void UpdateCategory(WorldInventory inv, Tag category,
                             string overrideName = null)
 {
     if (inv.TryGetDiscoveredResourcesFromTag(category, out HashSet <Tag> found) &&
         found.Count > 0)
     {
         // Attempt to add to type select control
         if (!children.TryGetValue(category, out TypeSelectCategory current))
         {
             current = new TypeSelectCategory(this, category, overrideName);
             children.Add(category, current);
             int        index = 1 + (children.IndexOfKey(category) << 1);
             GameObject header = current.Header, panel = current.ChildPanel;
             // Header goes in even indexes, panel goes in odds
             header.SetParent(childPanel);
             PUIElements.SetAnchors(header, PUIAnchoring.Stretch, PUIAnchoring.Stretch);
             header.transform.SetSiblingIndex(index);
             panel.SetParent(childPanel);
             PUIElements.SetAnchors(panel, PUIAnchoring.Stretch, PUIAnchoring.Stretch);
             panel.transform.SetSiblingIndex(index + 1);
         }
         foreach (var element in found)
         {
             current.TryAddType(element);
         }
     }
 }
    private void SpawnRows()
    {
        WorldInventory worldInventory = ClusterManager.Instance.GetWorld(ClusterManager.Instance.activeWorldId).worldInventory;

        allowDisplayCategories.Add(GameTags.MaterialCategories);
        allowDisplayCategories.Add(GameTags.CalorieCategories);
        allowDisplayCategories.Add(GameTags.UnitCategories);
        foreach (Tag materialCategory in GameTags.MaterialCategories)
        {
            SpawnCategoryRow(materialCategory, GameUtil.MeasureUnit.mass);
        }
        foreach (Tag calorieCategory in GameTags.CalorieCategories)
        {
            SpawnCategoryRow(calorieCategory, GameUtil.MeasureUnit.kcal);
        }
        foreach (Tag unitCategory in GameTags.UnitCategories)
        {
            SpawnCategoryRow(unitCategory, GameUtil.MeasureUnit.quantity);
        }
        List <Tag> list = new List <Tag>();

        foreach (KeyValuePair <Tag, GameObject> categoryRow in categoryRows)
        {
            list.Add(categoryRow.Key);
        }
        list.Sort((Tag a, Tag b) => a.ProperNameStripLink().CompareTo(b.ProperNameStripLink()));
        foreach (Tag item in list)
        {
            categoryRows[item].transform.SetAsLastSibling();
        }
    }
 /// <summary>
 /// Applied before Update runs.
 /// </summary>
 internal static bool Prefix(WorldInventory __instance)
 {
     // Only need to update the pinned resources panel
     if (__instance.TryGetComponent(out BackgroundWorldInventory bwi))
     {
         bwi.CheckRefresh(ref __instance.hasValidCount);
     }
     else
     {
         bwi = null;
     }
     return(bwi == null);
 }
        /// <summary>
        /// Applied before OnAddedFetchable runs.
        /// </summary>
        internal static bool Prefix(WorldInventory __instance, object data)
        {
            int cell, id;

            if (data is UnityEngine.GameObject gameObject && gameObject.TryGetComponent(
                    out Pickupable pickupable) && __instance.TryGetComponent(
                    out WorldContainer container) && Grid.IsValidCell(cell = pickupable.
                                                                             cachedCell) && (id = container.id) != ClusterManager.INVALID_WORLD_IDX &&
                Grid.WorldIdx[cell] == id && !gameObject.TryGetComponent(out Navigator _))
            {
                AddFetchable(pickupable, __instance.Inventory);
            }
            return(false);
        }
Beispiel #6
0
    public static GameObject ExtendEntityToFertileCreature(GameObject prefab, string eggId, string eggName, string eggDesc, string egg_anim, float egg_mass, string baby_id, float fertility_cycles, float incubation_cycles, List <FertilityMonitor.BreedingChance> egg_chances, int eggSortOrder = -1, bool is_ranchable = true, bool add_fish_overcrowding_monitor = false, bool add_fixed_capturable_monitor = true, float egg_anim_scale = 1f)
    {
        FertilityMonitor.Def def = prefab.AddOrGetDef <FertilityMonitor.Def>();
        def.baseFertileCycles = fertility_cycles;
        DebugUtil.DevAssert(eggSortOrder > -1, "Added a fertile creature without an egg sort order!");
        float      base_incubation_rate = 100f / (600f * incubation_cycles);
        GameObject gameObject           = EggConfig.CreateEgg(eggId, eggName, eggDesc, baby_id, egg_anim, egg_mass, eggSortOrder, base_incubation_rate);

        def.eggPrefab = new Tag(eggId);
        def.initialBreedingWeights = egg_chances;
        if (egg_anim_scale != 1f)
        {
            KBatchedAnimController component = gameObject.GetComponent <KBatchedAnimController>();
            component.animWidth  = egg_anim_scale;
            component.animHeight = egg_anim_scale;
        }
        KPrefabID egg_prefab_id = gameObject.GetComponent <KPrefabID>();
        SymbolOverrideController symbol_override_controller = SymbolOverrideControllerUtil.AddToPrefab(gameObject);
        string symbolPrefix = prefab.GetComponent <CreatureBrain>().symbolPrefix;

        if (!string.IsNullOrEmpty(symbolPrefix))
        {
            symbol_override_controller.ApplySymbolOverridesByAffix(Assets.GetAnim(egg_anim), symbolPrefix, null, 0);
        }
        KPrefabID creature_prefab_id = prefab.GetComponent <KPrefabID>();

        creature_prefab_id.prefabSpawnFn += delegate
        {
            WorldInventory.Instance.Discover(eggId.ToTag(), WorldInventory.GetCategoryForTags(egg_prefab_id.Tags));
            WorldInventory.Instance.Discover(baby_id.ToTag(), WorldInventory.GetCategoryForTags(creature_prefab_id.Tags));
        };
        if (is_ranchable)
        {
            prefab.AddOrGetDef <RanchableMonitor.Def>();
        }
        if (add_fixed_capturable_monitor)
        {
            prefab.AddOrGetDef <FixedCapturableMonitor.Def>();
        }
        if (add_fish_overcrowding_monitor)
        {
            gameObject.AddOrGetDef <FishOvercrowdingMonitor.Def>();
        }
        return(prefab);
    }
Beispiel #7
0
    public static GameObject CreateAndRegisterBaggedCreature(GameObject creature, bool must_stand_on_top_for_pickup, bool allow_mark_for_capture, bool use_gun_for_pickup = false)
    {
        KPrefabID creature_prefab_id = creature.GetComponent <KPrefabID>();

        creature_prefab_id.AddTag(GameTags.BagableCreature, false);
        Baggable baggable = creature.AddOrGet <Baggable>();

        baggable.mustStandOntopOfTrapForPickup = must_stand_on_top_for_pickup;
        baggable.useGunForPickup = use_gun_for_pickup;
        Capturable capturable = creature.AddOrGet <Capturable>();

        capturable.allowCapture           = allow_mark_for_capture;
        creature_prefab_id.prefabSpawnFn += delegate
        {
            WorldInventory.Instance.Discover(creature_prefab_id.PrefabTag, WorldInventory.GetCategoryForTags(creature_prefab_id.Tags));
        };
        return(creature);
    }
    /// Modifies critters as they are loaded
    /// missing parameters: is_baby, override_prefix, lifespan, diet_list
    /// babyId: only reveals material, actually object is defined in egg
    public static void PatchCritters(KPrefabID prefab, GameObject critter)
    {
        CritterContainer setting = CustomizeCritterState.StateManager.State.critter_settings.Find(s => s.id == critter.name);

        if (setting == null)
        {
            return;
        }

        Debug.Log("DEBUG HELLO 1");

        if (setting.name != null)
        {
            prefab.PrefabTag = TagManager.Create(setting.id, setting.name);
            critter.GetComponent <KSelectable>()?.SetName(setting.name);
            critter.AddOrGet <DecorProvider>().overrideName = setting.name;
        }

        Debug.Log("DEBUG HELLO 2");

        if (setting.desc != null)
        {
            critter.AddOrGet <InfoDescription>().description = setting.desc;
        }

        Debug.Log("DEBUG HELLO 3");

        if (setting.anim_file != null)
        {
            KBatchedAnimController kbatchedAnimController = critter.AddOrGet <KBatchedAnimController>();
            kbatchedAnimController.AnimFiles = new KAnimFile[] { Assets.GetAnim(setting.anim_file) };
            //kbatchedAnimController.sceneLayer = sceneLayer;
            //kbatchedAnimController.initialAnim = initialAnim;
        }

        Debug.Log("DEBUG HELLO 4");

        if (setting.is_baby != null)
        {
            Debug.Log(setting.id + ".is_baby: This cannot be changed on existing critters.");
        }

        Debug.Log("DEBUG HELLO 5");

        if (setting.traitId != null)
        {
            Modifiers modifiers = critter.AddOrGet <Modifiers>();
            if (setting.traitId != "")
            {
                modifiers.initialTraits = new string[] { setting.traitId }
            }
            ;
            else
            {
                modifiers.initialTraits = null;
            }
            //modifiers.initialAmounts.Add(Db.Get().Amounts.HitPoints.Id);
        }

        Debug.Log("DEBUG HELLO 6");

        if (setting.override_prefix != null)
        {
            Debug.Log(setting.id + ".override_prefix: This cannot be changed on existing critters.");
        }

        Debug.Log("DEBUG HELLO 7");

        if (setting.space_requirement != null)
        {
            critter.AddOrGetDef <OvercrowdingMonitor.Def>().spaceRequiredPerCreature = setting.space_requirement.Value;
        }

        Debug.Log("DEBUG HELLO 8");

        if (setting.lifespan != null)
        {
            Debug.Log(setting.id + ".lifespan: This value is not read from the game. It exists only as artifact. Use traits instead!");
            //trait.Add(new AttributeModifier(Db.Get().Amounts.Age.maxAttribute.Id, 150f, name, false, false, true));
        }

        Debug.Log("DEBUG HELLO 9");

        if (setting.mass != null)
        {
            critter.AddOrGet <PrimaryElement>().Mass = setting.mass.Value;
        }

        Debug.Log("DEBUG HELLO 10");

        if (setting.width != null || setting.height != null)
        {
            float          width          = setting.width ?? 1f;
            float          height         = setting.height ?? 1f;
            KBoxCollider2D kboxCollider2D = critter.AddOrGet <KBoxCollider2D>();
            kboxCollider2D.size = new Vector2f(width, height);
            float num = 0.5f * (float)((width + 1) % 2);
            kboxCollider2D.offset = new Vector2f(num, (float)height / 2f);
            critter.GetComponent <KBatchedAnimController>().Offset = new Vector3(num, 0f, 0f);
            critter.AddOrGet <OccupyArea>().OccupiedCellsOffsets   = EntityTemplates.GenerateOffsets((int)Math.Round(width, 0), (int)Math.Round(height, 0));
        }

        Debug.Log("DEBUG HELLO 11");

        if (setting.decor != null)
        {
            DecorProvider decorProvider = critter.AddOrGet <DecorProvider>();
            decorProvider.SetValues(setting.decor.Value);
        }

        Debug.Log("DEBUG HELLO 12");

        if (setting.navGridName != null)
        {
            critter.AddOrGet <Navigator>().NavGridName = setting.navGridName;
        }

        Debug.Log("DEBUG HELLO 13");

        if (setting.navi != null)
        {
            critter.AddOrGet <Navigator>().CurrentNavType = setting.navi.Value;
        }

        Debug.Log("DEBUG HELLO 14");

        if (setting.moveSpeed != null)
        {
            critter.AddOrGet <Navigator>().defaultSpeed = setting.moveSpeed.Value;
        }

        Debug.Log("DEBUG HELLO 15");

        if (setting.dropOnDeath != null)
        {
            critter.AddOrGet <Butcherable>().SetDrops(setting.dropOnDeath);
        }

        Debug.Log("DEBUG HELLO 16");

        if (setting.canDrown != null)
        {
            if (setting.canDrown.Value)
            {
                critter.AddOrGet <DrowningMonitor>();
            }
            else
            {
                critter.RemoveComponents <DrowningMonitor>();
            }
        }

        Debug.Log("DEBUG HELLO 17");

        if (setting.canCrushed != null)
        {
            if (setting.canCrushed.Value)
            {
                critter.AddOrGet <EntombVulnerable>();
            }
            else
            {
                critter.RemoveComponents <EntombVulnerable>();
            }
        }

        Debug.Log("DEBUG HELLO 18");

        if (setting.tempLowDeath != null)
        {
            critter.AddOrGet <TemperatureVulnerable>().internalTemperatureLethal_Low = setting.tempLowDeath.Value;
        }

        Debug.Log("DEBUG HELLO 19");

        if (setting.tempLowWarning != null)
        {
            critter.AddOrGet <TemperatureVulnerable>().internalTemperatureWarning_Low = setting.tempLowWarning.Value;
        }

        Debug.Log("DEBUG HELLO 20");

        if (setting.tempHighWarning != null)
        {
            critter.AddOrGet <TemperatureVulnerable>().internalTemperatureWarning_High = setting.tempHighWarning.Value;
        }

        Debug.Log("DEBUG HELLO 21");

        if (setting.tempHighDeath != null)
        {
            critter.AddOrGet <TemperatureVulnerable>().internalTemperatureLethal_High = setting.tempHighDeath.Value;
        }

        Debug.Log("DEBUG HELLO 22");

        if (setting.tempBorn != null)
        {
            critter.AddOrGet <PrimaryElement>().Temperature = setting.tempBorn.Value;
        }

        Debug.Log("DEBUG HELLO 23");

        if (setting.pickup_only_from_top != null)
        {
            critter.AddOrGet <Baggable>().mustStandOntopOfTrapForPickup = setting.pickup_only_from_top.Value;
        }

        Debug.Log("DEBUG HELLO 24");

        if (setting.pickup_allow_mark != null)
        {
            critter.AddOrGet <Capturable>().allowCapture = setting.pickup_allow_mark.Value;
        }

        Debug.Log("DEBUG HELLO 25");

        if (setting.pickup_use_gun != null)
        {
            critter.AddOrGet <Baggable>().useGunForPickup = setting.pickup_use_gun.Value;
        }

        Debug.Log("DEBUG HELLO 26");

        if (setting.tags != null)
        {
            prefab.ProcessTags(setting.tags);
        }

        Debug.Log("DEBUG HELLO 27");

        if (setting.species != null)
        {
            critter.AddOrGet <CreatureBrain>().species = setting.species;
        }

        Debug.Log("DEBUG HELLO 28");

        if (setting.attackValue != null)
        {
            if (setting.attackValue.Value > 0f)
            {
                critter.AddWeapon(setting.attackValue.Value, setting.attackValue.Value, AttackProperties.DamageType.Standard, AttackProperties.TargetType.Single, 1, 0f);
            }
            else
            {
                critter.RemoveComponents <Weapon>();
            }
        }

        Debug.Log("DEBUG HELLO 29");

        if (setting.chore_table != null)
        {
            ChoreConsumer chore_consumer = critter.AddOrGet <ChoreConsumer>();
            chore_consumer.choreTable = setting.chore_table.CreateTable();
            // prefab.instantiateFn += delegate(GameObject go) { go.GetComponent<ChoreConsumer>().choreTable = chore_consumer.choreTable; };
        }

        Debug.Log("DEBUG HELLO 30");

        if (setting.adultId != null)
        {
            critter.AddOrGetDef <BabyMonitor.Def>().adultPrefab = setting.adultId;
        }

        Debug.Log("DEBUG HELLO 31");

        if (setting.dropOnMature != null)
        {
            critter.AddOrGetDef <BabyMonitor.Def>().onGrowDropID = setting.dropOnMature;
        }

        Debug.Log("DEBUG HELLO 32");

        if (setting.fertility_cycles != null)
        {
            critter.AddOrGetDef <FertilityMonitor.Def>().baseFertileCycles = setting.fertility_cycles.Value;
        }

        Debug.Log("DEBUG HELLO 33");

        if (setting.egg_chances != null)
        {
            critter.AddOrGetDef <FertilityMonitor.Def>().initialBreedingWeights = setting.egg_chances;
        }

        Debug.Log("DEBUG HELLO 34");

        if (setting.is_ranchable != null)
        {
            if (setting.is_ranchable.Value)
            {
                critter.AddOrGetDef <RanchableMonitor.Def>();
            }
            else
            {
                critter.RemoveDef <RanchableMonitor.Def>();
            }
        }

        Debug.Log("DEBUG HELLO 35");

        if (setting.calories_per_KG != null)
        {
            critter.AddOrGetDef <CreatureCalorieMonitor.Def>();
        }

        Debug.Log("DEBUG HELLO 36");

        if (setting.min_poop_KG != null)
        {
            critter.AddOrGetDef <CreatureCalorieMonitor.Def>().minPoopSizeInCalories = setting.min_poop_KG.Value * setting.calories_per_KG ?? 1f;
        }

        Debug.Log("DEBUG HELLO 37");

        if (setting.diet_list != null)
        {
            //Diet diet = new Diet(setting.diet_list.ToArray());
            //critter.AddOrGetDef<CreatureCalorieMonitor.Def>().diet = diet;
            //critter.AddOrGetDef<SolidConsumerMonitor.Def>().diet = diet;
        }

        Debug.Log("DEBUG HELLO 38");

        if (setting.eggId != null)
        {
            critter.AddOrGetDef <FertilityMonitor.Def>().eggPrefab = setting.eggId;
            prefab.prefabSpawnFn += delegate(GameObject inst)
            {
                WorldInventory.Instance.Discover(setting.eggId.ToTag(), WorldInventory.GetCategoryForTags(egg_tags));
            };
        }

        Debug.Log("DEBUG HELLO 39");

        if (setting.babyId != null)
        {
            prefab.prefabSpawnFn += delegate(GameObject inst)
            {
                WorldInventory.Instance.Discover(setting.babyId.ToTag(), WorldInventory.GetCategoryForTags(prefab.Tags));
            };
        }

        Debug.Log("DEBUG HELLO 40");

        if (setting.light != null)
        {
            if (setting.light.color != Color.black)
            {
                Light2D light2D = critter.AddOrGet <Light2D>();
                if (setting.light.color != null)
                {
                    light2D.Color = setting.light.color.Value;
                }
                light2D.overlayColour = TUNING.LIGHT2D.LIGHTBUG_OVERLAYCOLOR;
                if (setting.light.range != null)
                {
                    light2D.Range = setting.light.range.Value;
                }
                light2D.Angle       = 0f;
                light2D.Direction   = TUNING.LIGHT2D.LIGHTBUG_DIRECTION;
                light2D.Offset      = TUNING.LIGHT2D.LIGHTBUG_OFFSET;
                light2D.shape       = LightShape.Circle;
                light2D.drawOverlay = true;
                if (setting.light.lux != null)
                {
                    light2D.Lux = setting.light.lux.Value;
                }
                critter.AddOrGet <LightSymbolTracker>().targetSymbol = "snapTo_light_locator";
                critter.AddOrGetDef <CreatureLightToggleController.Def>();
            }
            else
            {
                critter.RemoveComponents <Light2D>();
                critter.RemoveComponents <LightSymbolTracker>();
                critter.RemoveDef <CreatureLightToggleController.Def>();
            }
        }

        Debug.Log("DEBUG HELLO 41");

        if (setting.expulsion != null)  //works also with gasses/liquids/solids
        {
            ElementDropperMonitor.Def def_morb = critter.AddOrGetDef <ElementDropperMonitor.Def>();
            if (setting.expulsion.element != null)
            {
                def_morb.dirtyEmitElement = setting.expulsion.element.ToSimHash();
            }
            if (setting.expulsion.probability != null)
            {
                def_morb.dirtyProbabilityPercent = setting.expulsion.probability.Value;
            }
            if (setting.expulsion.cellTargetMass != null)
            {
                def_morb.dirtyCellToTargetMass = setting.expulsion.cellTargetMass.Value;
            }
            if (setting.expulsion.massPerDirt != null)
            {
                def_morb.dirtyMassPerDirty = setting.expulsion.massPerDirt.Value;
            }
            if (setting.expulsion.onDeath != null)
            {
                def_morb.dirtyMassReleaseOnDeath = setting.expulsion.onDeath.Value;
            }
            if (setting.expulsion.diseaseId != null)
            {
                def_morb.emitDiseaseIdx = Db.Get().Diseases.GetIndex(setting.expulsion.diseaseId);
            }
            if (setting.expulsion.diseaseAmount != null)
            {
                def_morb.emitDiseasePerKg = setting.expulsion.diseaseAmount.Value;
            }
        }

        Debug.Log("DEBUG HELLO 42");

        if (setting.scales != null)
        {
            ScaleGrowthMonitor.Def def_scale = critter.AddOrGetDef <ScaleGrowthMonitor.Def>();
            if (setting.scales.growthRate != null)
            {
                def_scale.defaultGrowthRate = setting.scales.growthRate.Value;
            }
            if (setting.scales.mass != null)
            {
                def_scale.dropMass = setting.scales.mass.Value;
            }
            if (setting.scales.drop != null)
            {
                def_scale.itemDroppedOnShear = setting.scales.drop;
            }
            if (setting.scales.levelCount != null)
            {
                def_scale.levelCount = setting.scales.levelCount.Value;
            }
            if (setting.scales.atmosphere != null)
            {
                def_scale.targetAtmosphere = setting.scales.atmosphere.ToSimHash();
            }
        }

        Debug.Log("DEBUG HELLO 43");
    }
    /// Creates new critters which were not already loaded by EntityLoad ...
    public static void CreateNewCritters()
    {
        foreach (var setting in CustomizeCritterState.StateManager.State.critter_settings)
        {
            if (setting?.id == null)
            {
                continue;
            }

            if (Assets.Prefabs.Find(a => a.gameObject?.name == setting.id) == null)
            {
                // configurations
                string             id                = setting.id;
                string             name              = setting.name ?? "Stone Hatch";
                string             desc              = setting.desc ?? "Stone Hatches excrete solid Coal as waste and enjoy burrowing into the ground.";
                string             anim_file         = setting.anim_file ?? "hatch_kanim";
                bool               is_baby           = setting.is_baby ?? false;
                string             traitId           = setting.traitId ?? "HatchHardBaseTrait";
                string             override_prefix   = setting.override_prefix;
                int                space_requirement = setting.space_requirement ?? HatchTuning.PEN_SIZE_PER_CREATURE;
                float              lifespan          = setting.lifespan ?? 100f;
                float              mass              = setting.mass ?? 100f;
                float              width             = setting.width ?? 1f;
                float              height            = setting.height ?? 1f;
                EffectorValues     decor             = setting.decor ?? TUNING.DECOR.BONUS.TIER0;
                string             navGridName       = setting.navGridName ?? (!is_baby ? "WalkerNavGrid1x1" : "WalkerBabyNavGrid");
                NavType            navi; Enum.TryParse(setting.navi, out navi);// ?? NavType.Floor;
                float              moveSpeed            = setting.moveSpeed ?? 2f;
                string[]           dropOnDeath          = setting.dropOnDeath ?? new string[] { "Meat", "Meat" };
                bool               canDrown             = setting.canDrown ?? true;
                bool               canCrushed           = setting.canCrushed ?? false;
                float              tempLowDeath         = setting.tempLowDeath ?? 243.15f;
                float              tempLowWarning       = setting.tempLowWarning ?? 283.15f;
                float              tempBorn             = setting.tempBorn ?? 293f;
                float              tempHighWarning      = setting.tempHighWarning ?? 293.15f;
                float              tempHighDeath        = setting.tempHighDeath ?? 343.15f;
                bool               pickup_only_from_top = setting.pickup_only_from_top ?? true;
                bool               pickup_allow_mark    = setting.pickup_allow_mark ?? true;
                bool               pickup_use_gun       = setting.pickup_use_gun ?? false;
                string[]           tags        = setting.tags ?? new string[] { GameTags.Creatures.Walker.ToString() };
                Tag                species     = setting.species ?? GameTags.Creatures.Species.HatchSpecies;
                float              attackValue = setting.attackValue ?? 1f;
                ChoreTable.Builder chore_table = setting.chore_table ?? new ChoreTable.Builder().Add(new DeathStates.Def(), true).Add(new AnimInterruptStates.Def(), true).Add(new ExitBurrowStates.Def(), !is_baby).Add(new PlayAnimsStates.Def(GameTags.Creatures.Burrowed, true, "idle_mound", STRINGS.CREATURES.STATUSITEMS.BURROWED.NAME, STRINGS.CREATURES.STATUSITEMS.BURROWED.TOOLTIP), !is_baby).Add(new GrowUpStates.Def(), true).Add(new TrappedStates.Def(), true).Add(new IncubatingStates.Def(), true).Add(new BaggedStates.Def(), true).Add(new FallStates.Def(), true).Add(new StunnedStates.Def(), true).Add(new DrowningStates.Def(), true).Add(new DebugGoToStates.Def(), true).Add(new FleeStates.Def(), true).Add(new AttackStates.Def(), !is_baby).PushInterruptGroup().Add(new CreatureSleepStates.Def(), true).Add(new FixedCaptureStates.Def(), true).Add(new RanchedStates.Def(), true).Add(new PlayAnimsStates.Def(GameTags.Creatures.WantsToEnterBurrow, false, "hide", STRINGS.CREATURES.STATUSITEMS.BURROWING.NAME, STRINGS.CREATURES.STATUSITEMS.BURROWING.TOOLTIP), !is_baby).Add(new LayEggStates.Def(), true).Add(new EatStates.Def(), true).Add(new PlayAnimsStates.Def(GameTags.Creatures.Poop, false, "poop", STRINGS.CREATURES.STATUSITEMS.EXPELLING_SOLID.NAME, STRINGS.CREATURES.STATUSITEMS.EXPELLING_SOLID.TOOLTIP), true).Add(new CallAdultStates.Def(), true).PopInterruptGroup().Add(new IdleStates.Def(), true);

                string adultId          = setting.adultId ?? "HatchHard";
                string eggId            = setting.eggId ?? "HatchHardEgg";
                string babyId           = setting.babyId ?? "HatchHardBaby";
                string dropOnMature     = setting.dropOnMature ?? null;
                float  fertility_cycles = setting.fertility_cycles ?? 60f;
                List <FertilityMonitor.BreedingChance> egg_chances = new List <FertilityMonitor.BreedingChance>();
                egg_chances.Add(BreedingChance("HatchHardEgg", 1f));
                bool is_ranchable = setting.is_ranchable ?? true;

                float            calories_per_KG = setting.calories_per_KG ?? (700000f / 140f);
                float            min_poop_KG     = setting.min_poop_KG ?? 25f;
                List <Diet.Info> diet_list       = setting.diet_list ?? BaseHatchConfig.HardRockDiet(SimHashes.Carbon.CreateTag(), calories_per_KG, TUNING.CREATURES.CONVERSION_EFFICIENCY.NORMAL, null, 0f);
                // end of configurations

                GameObject critter;
                critter = EntityTemplates.CreatePlacedEntity(id, name, desc, mass, Assets.GetAnim(anim_file), "idle_loop", Grid.SceneLayer.Creatures, (int)width, (int)height, decor, default(EffectorValues), SimHashes.Creature, null, tempBorn);
                EntityTemplates.ExtendEntityToBasicCreature(critter, FactionManager.FactionID.Pest, traitId, navGridName, navi, 32, moveSpeed, "Meat", 2, canDrown, canCrushed, tempLowWarning, tempHighWarning, tempLowDeath, tempHighDeath);
                critter.AddOrGet <Butcherable>().SetDrops(dropOnDeath);
                if (override_prefix != null)
                {
                    critter.AddOrGet <SymbolOverrideController>().ApplySymbolOverridesByAffix(Assets.GetAnim(anim_file), override_prefix, null, 0);
                }
                critter.AddOrGet <Trappable>();
                critter.AddOrGetDef <CreatureFallMonitor.Def>();
                critter.AddOrGetDef <BurrowMonitor.Def>();
                critter.AddOrGetDef <WorldSpawnableMonitor.Def>().adjustSpawnLocationCb = (int cell) => { return(cell); };//new Func<int, int>(BaseHatchConfig.AdjustSpawnLocationCB);
                critter.AddOrGetDef <ThreatMonitor.Def>().fleethresholdState            = Health.HealthState.Dead;
                if (attackValue > 0f)
                {
                    critter.AddWeapon(attackValue, attackValue, AttackProperties.DamageType.Standard, AttackProperties.TargetType.Single, 1, 0f);
                }
                EntityTemplates.CreateAndRegisterBaggedCreature(critter, pickup_only_from_top, pickup_allow_mark, pickup_use_gun);
                KPrefabID prefabID = critter.GetComponent <KPrefabID>();
                prefabID.ProcessTags(tags);
                prefabID.prefabInitFn += delegate(GameObject inst) { inst.GetAttributes().Add(Db.Get().Attributes.MaxUnderwaterTravelCost); };
                EntityTemplates.AddCreatureBrain(critter, chore_table, species, override_prefix);

                EntityTemplates.ExtendEntityToWildCreature(critter, space_requirement, lifespan);

                Diet diet = new Diet(diet_list.ToArray());
                CreatureCalorieMonitor.Def calorieMonitor = critter.AddOrGetDef <CreatureCalorieMonitor.Def>();
                calorieMonitor.diet = diet;
                calorieMonitor.minPoopSizeInCalories = calories_per_KG * min_poop_KG;
                critter.AddOrGetDef <SolidConsumerMonitor.Def>().diet = diet;

                if (is_baby)
                {
                    EntityTemplates.ExtendEntityToBeingABaby(critter, adultId, dropOnMature);
                }
                else
                {
                    FertilityMonitor.Def def = critter.AddOrGetDef <FertilityMonitor.Def>();
                    def.baseFertileCycles      = fertility_cycles;
                    def.eggPrefab              = new Tag(eggId);
                    def.initialBreedingWeights = egg_chances;
                    KPrefabID creature_prefab_id = critter.GetComponent <KPrefabID>();
                    creature_prefab_id.prefabSpawnFn += delegate(GameObject inst)
                    {
                        WorldInventory.Instance.Discover(eggId.ToTag(), WorldInventory.GetCategoryForTags(egg_tags));
                        WorldInventory.Instance.Discover(babyId.ToTag(), WorldInventory.GetCategoryForTags(creature_prefab_id.Tags));
                    };
                    if (is_ranchable)
                    {
                        critter.AddOrGetDef <RanchableMonitor.Def>();
                    }
                    critter.AddOrGetDef <FixedCapturableMonitor.Def>();
                }

                if (setting.scales != null)
                {
                    ScaleGrowthMonitor.Def def_scale = critter.AddOrGetDef <ScaleGrowthMonitor.Def>();
                    def_scale.defaultGrowthRate  = setting.scales.growthRate ?? (setting.scales.growthRate ?? (1f / DreckoConfig.SCALE_GROWTH_TIME_IN_CYCLES / 600f));
                    def_scale.dropMass           = setting.scales.mass ?? (DreckoConfig.FIBER_PER_CYCLE * DreckoConfig.SCALE_GROWTH_TIME_IN_CYCLES);
                    def_scale.itemDroppedOnShear = setting.scales.drop ?? "Dirt";
                    def_scale.levelCount         = setting.scales.levelCount ?? 6;
                    def_scale.targetAtmosphere   = (setting.scales.atmosphere ?? "Void").ToSimHash();
                }

                if (setting.expulsion != null)
                {
                    ElementDropperMonitor.Def def_morb = critter.AddOrGetDef <ElementDropperMonitor.Def>();
                    def_morb.dirtyEmitElement        = (setting.expulsion.element ?? "Dirt").ToSimHash();
                    def_morb.dirtyProbabilityPercent = setting.expulsion.probability ?? 25f;
                    def_morb.dirtyCellToTargetMass   = setting.expulsion.cellTargetMass ?? 1f;
                    def_morb.dirtyMassPerDirty       = setting.expulsion.massPerDirt ?? 0.2f;
                    def_morb.dirtyMassReleaseOnDeath = setting.expulsion.onDeath ?? 3f;
                    def_morb.emitDiseaseIdx          = Db.Get().Diseases.GetIndex(setting.expulsion.diseaseId ?? "");
                    def_morb.emitDiseasePerKg        = setting.expulsion.diseaseAmount ?? 0f;
                }

                if (setting.light != null)
                {
                    if (setting.light.color != Color.black)
                    {
                        Light2D light2D = critter.AddOrGet <Light2D>();
                        light2D.Color         = setting.light.color ?? Color.white;
                        light2D.overlayColour = TUNING.LIGHT2D.LIGHTBUG_OVERLAYCOLOR;
                        light2D.Range         = setting.light.range ?? 5f;
                        light2D.Angle         = 0f;
                        light2D.Direction     = TUNING.LIGHT2D.LIGHTBUG_DIRECTION;
                        light2D.Offset        = TUNING.LIGHT2D.LIGHTBUG_OFFSET;
                        light2D.shape         = LightShape.Circle;
                        light2D.drawOverlay   = true;
                        light2D.Lux           = setting.light.lux ?? 1800;
                        critter.AddOrGet <LightSymbolTracker>().targetSymbol = "snapTo_light_locator";
                        critter.AddOrGetDef <CreatureLightToggleController.Def>();
                    }
                }
            }
        }
    }
            public static bool Prefix(ref ResourceEntry __instance)
            {
                var cont = true;

                // check active modifiers
                var check = (Modifier)Traverse.Create(Global.Instance.GetInputManager().GetDefaultController()).Field("mActiveModifiers").GetValue();

                if (check == Modifier.Shift)
                {
                    cont = false;                     // don't execute original OnClick

                    Tag tag = (Tag)__instance.Resource;

                    if (favoritesCategoryHeader != null)
                    {
                        ResourceEntry resourceEntry = null;

                        HashSet <Tag> hashSet = null;
                        hashSet = WorldInventory.Instance.GetDiscoveredResourcesFromTag(favoritesCategoryHeader.ResourceCategoryTag);

                        if (hashSet.Contains(tag))
                        {
                            //Debug.Log("Toggle: Off");
                            // NOTE: removes resource tracking in Favorites category but still displays the button
                            hashSet.Remove(tag);

                            favoritesCategoryHeader.ResourcesDiscovered.TryGetValue(tag, out resourceEntry);

                            if (resourceEntry != null)
                            {
                                favoritesCategoryHeader.ResourcesDiscovered.Remove(tag);
                                resourceEntry.DeleteObject();
                                //resourceEntry.gameObject.SetActive(false);
                            }
                        }
                        else
                        {
                            //Debug.Log("Toggle: On");
                            // Activate the ResourceEntry
                            var discoverCat = Traverse.Create(WorldInventory.Instance).Method("DiscoverCategory", new[] { typeof(Tag), typeof(Tag) });
                            discoverCat.GetValue(favoritesCategoryHeader.ResourceCategoryTag, tag);

                            if (!favoritesCategoryHeader.ResourcesDiscovered.TryGetValue(tag, out resourceEntry))
                            {
                                List <Tag>    ts   = WorldInventory.Instance.GetPickupableTagsFromCategoryTag(tag);
                                HashSet <Tag> tags = new HashSet <Tag>(ts);
                                Tag           cat  = WorldInventory.GetCategoryForTags(tags);
                                //Debug.Log("[Favorites] <ResourceEntry_OnClick> cat: " + cat);

                                GameUtil.MeasureUnit measure = GameUtil.MeasureUnit.mass;
                                if (GameTags.CalorieCategories.Contains(cat))
                                {
                                    measure = GameUtil.MeasureUnit.kcal;
                                }
                                if (GameTags.UnitCategories.Contains(cat))
                                {
                                    measure = GameUtil.MeasureUnit.quantity;
                                }

                                //Debug.Log("[Favorites] <ResourceEntry_OnClick> measure: " + measure);
                                var newResourceEntry = Traverse.Create(favoritesCategoryHeader).Method("NewResourceEntry", new[] { typeof(Tag), typeof(GameUtil.MeasureUnit) });
                                resourceEntry = newResourceEntry.GetValue <ResourceEntry>(tag, measure);
                                favoritesCategoryHeader.ResourcesDiscovered.Add(tag, resourceEntry);
                            }

                            if (resourceEntry != null)                               // NOTE: might no longer need this
                            {
                                resourceEntry.gameObject.SetActive(true);
                            }
                        }
                    }
                }
                return(cont);                // if true: execute original OnClick
            }
 /// <summary>
 /// Applied after OnPrefabInit runs.
 /// </summary>
 internal static void Postfix(WorldInventory __instance)
 {
     __instance.gameObject.AddOrGet <CritterInventory>();
 }