예제 #1
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);
    }
    /// 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>();
                    }
                }
            }
        }
    }