示例#1
0
    public static GameObject CreateArtifact(string id, string name, string desc, string initial_anim, string ui_anim, ArtifactTier artifact_tier, PostInitFn postInitFn = null, SimHashes element = SimHashes.Creature)
    {
        GameObject gameObject = EntityTemplates.CreateLooseEntity("artifact_" + id.ToLower(), name, desc, 25f, true, Assets.GetAnim("artifacts_kanim"), initial_anim, Grid.SceneLayer.Ore, EntityTemplates.CollisionShape.RECTANGLE, 1f, 1f, true, SORTORDER.BUILDINGELEMENTS, element, new List <Tag>
        {
            GameTags.MiscPickupable
        });
        OccupyArea occupyArea = gameObject.AddOrGet <OccupyArea>();

        occupyArea.OccupiedCellsOffsets = EntityTemplates.GenerateOffsets(1, 1);
        DecorProvider decorProvider = gameObject.AddOrGet <DecorProvider>();

        decorProvider.SetValues(artifact_tier.decorValues);
        decorProvider.overrideName = gameObject.name;
        SpaceArtifact spaceArtifact = gameObject.AddOrGet <SpaceArtifact>();

        spaceArtifact.SetUIAnim(ui_anim);
        spaceArtifact.SetArtifactTier(artifact_tier);
        gameObject.AddOrGet <KSelectable>();
        gameObject.GetComponent <KBatchedAnimController>().initialMode = KAnim.PlayMode.Loop;
        postInitFn?.Invoke(gameObject);
        KPrefabID component = gameObject.GetComponent <KPrefabID>();

        component.AddTag(GameTags.PedestalDisplayable, false);
        component.AddTag(GameTags.Artifact, false);
        return(gameObject);
    }
示例#2
0
    public GameObject CreatePrefab()
    {
        int            num        = 1;
        int            height     = 1;
        string         id         = "PropLadder";
        string         name       = STRINGS.BUILDINGS.PREFABS.PROPLADDER.NAME;
        string         desc       = STRINGS.BUILDINGS.PREFABS.PROPLADDER.DESC;
        float          mass       = 50f;
        int            width      = num;
        GameObject     gameObject = EntityTemplates.CreatePlacedEntity(id, name, desc, mass, Assets.GetAnim("ladder_poi_kanim"), "off", Grid.SceneLayer.Building, width, height, TUNING.BUILDINGS.DECOR.BONUS.TIER0, NOISE_POLLUTION.NOISY.TIER0, SimHashes.Creature, null, 293f);
        PrimaryElement component  = gameObject.GetComponent <PrimaryElement>();

        component.SetElement(SimHashes.Polypropylene);
        component.Temperature = 294.15f;
        Ladder ladder = gameObject.AddOrGet <Ladder>();

        ladder.upwardsMovementSpeedMultiplier   = 1.5f;
        ladder.downwardsMovementSpeedMultiplier = 1.5f;
        gameObject.AddOrGet <AnimTileable>();
        OccupyArea obj = gameObject.AddOrGet <OccupyArea>();

        Object.DestroyImmediate(obj);
        obj = gameObject.AddOrGet <OccupyArea>();
        obj.OccupiedCellsOffsets = EntityTemplates.GenerateOffsets(num, height);
        obj.objectLayers         = new ObjectLayer[1]
        {
            ObjectLayer.Building
        };
        return(gameObject);
    }
示例#3
0
        public GameObject CreatePrefab()
        {
            GameObject gameObject = EntityTemplates.CreateLooseEntity(
                id: ID,
                name: STRINGS.ITEMS.INDUSTRIAL_PRODUCTS.SKELETON.NAME,
                desc: STRINGS.ITEMS.INDUSTRIAL_PRODUCTS.SKELETON.DESC,
                mass: MASS,
                unitMass: true,
                anim: Assets.GetAnim("bones_kanim"),
                initialAnim: "object",
                sceneLayer: Grid.SceneLayer.Ore,
                collisionShape: EntityTemplates.CollisionShape.RECTANGLE,
                width: 0.9f,
                height: 0.8f,
                isPickupable: true,
                sortOrder: 0,
                element: SimHashes.Creature,
                additionalTags: new List <Tag> {
                GameTags.IndustrialIngredient, GameTags.Organics
            });

            gameObject.AddOrGet <SimpleMassStatusItem>();
            gameObject.AddOrGet <OccupyArea>().OccupiedCellsOffsets = EntityTemplates.GenerateOffsets(1, 1);
            DecorProvider decorProvider = gameObject.AddOrGet <DecorProvider>();

            decorProvider.baseDecor  = TUNING.DUPLICANTSTATS.CLOTHING.DECOR_MODIFICATION.BASIC;
            decorProvider.baseRadius = 3f;
            gameObject.AddOrGetDef <EffectLineOfSight.Def>().effectName = DeathPatches.OBSERVED_ROTTEN_CORPSE;
            gameObject.AddOrGet <Skeleton>();
            ConfigureRecipes();
            return(gameObject);
        }
示例#4
0
        public GameObject CreatePrefab()
        {
            var go = EntityTemplates.CreateLooseEntity(
                id: ID,
                name: STRINGS.ITEMS.MASSIVE_HEATSINK_CORE.NAME,
                desc: STRINGS.ITEMS.MASSIVE_HEATSINK_CORE.DESC,
                mass: MASS,
                unitMass: true,
                anim: Assets.GetAnim("massiveheatsink_core_kanim"),
                initialAnim: "idle_crystal",
                sceneLayer: Grid.SceneLayer.Ore,
                collisionShape: EntityTemplates.CollisionShape.RECTANGLE,
                width: 1f,
                height: 1f,
                isPickupable: true,
                sortOrder: SORTORDER.BUILDINGELEMENTS,
                element: SimHashes.Unobtanium,
                additionalTags: new List <Tag> {
                GameTags.IndustrialIngredient,
                GameTags.PedestalDisplayable,
                GameTags.Artifact,
            });

            // это частично спокировано из ArtifactConfig.CreateArtifact, надо поглядывать если что то поменяют
            var occupyArea = go.AddOrGet <OccupyArea>();

            occupyArea.OccupiedCellsOffsets = EntityTemplates.GenerateOffsets(1, 1);
            var decorProvider = go.AddOrGet <DecorProvider>();

            decorProvider.SetValues(TIER_CORE.decorValues);
            decorProvider.overrideName = STRINGS.ITEMS.MASSIVE_HEATSINK_CORE.NAME;
            var spaceArtifact = go.AddOrGet <SpaceArtifact>();

            spaceArtifact.SetUIAnim("ui_crystal");
            spaceArtifact.SetArtifactTier(TIER_CORE);
            spaceArtifact.uniqueAnimNameFragment = "idle_crystal";
            spaceArtifact.artifactType           = ArtifactType.Any;
            go.AddOrGet <KSelectable>();
            go.GetComponent <KBatchedAnimController>().initialMode = KAnim.PlayMode.Loop;

            var pe = go.GetComponent <PrimaryElement>();

            pe.Mass        = MASS;
            pe.Temperature = TEMPERATURE;

            // добавляем в список артифактов только в ваниле, воизбежание непредвиденных последствий на длц
            if (DlcManager.IsPureVanilla())
            {
                ArtifactConfig.artifactItems[ArtifactType.Any].Add(go.name);
            }
            return(go);
        }
示例#5
0
        public GameObject CreatePrefab()
        {
            const float X      = 0.5f * ((WIDTH + 1) % 2);
            var         prefab = MooConfig.CreateMoo(ID, MooReproductionStrings.CREATURES.
                                                     SPECIES.MOO.BABY.NAME, MooReproductionStrings.CREATURES.SPECIES.MOO.BABY.DESC,
                                                     "gassy_moo_kanim", true);
            // Resize to 1x1
            var collider = prefab.GetComponent <KBoxCollider2D>();

            collider.size   = new Vector2f(WIDTH, HEIGHT);
            collider.offset = new Vector2f(X, HEIGHT * 0.5f);
            var kbac = prefab.GetComponent <KBatchedAnimController>();

            kbac.Offset     = new Vector3(X, 0f, 0f);
            kbac.animScale *= 0.5f;
            var occupyArea = prefab.AddOrGet <OccupyArea>();

            occupyArea.OccupiedCellsOffsets = EntityTemplates.GenerateOffsets(WIDTH, HEIGHT);
            EntityTemplates.ExtendEntityToBeingABaby(prefab, MooConfig.ID, null, false, 5.0f);
            // Reduce to 1kg meat for baby
            var butcherable = prefab.GetComponent <Butcherable>();

            if (butcherable != null)
            {
                butcherable.SetDrops(new string[] { MeatConfig.ID });
            }
            MooReproductionPatches.UpdateMooChores(prefab);
            // Babies should not be ranchable or auto wrangled, but there is no RemoveDef
            // function...
            var smc = prefab.GetComponent <StateMachineController>();

            if (smc != null && smc.defHandle.IsValid())
            {
                var defs = smc.cmpdef?.defs;
                if (defs != null)
                {
                    defs.Remove(smc.GetDef <RanchableMonitor.Def>());
                    defs.Remove(smc.GetDef <FixedCapturableMonitor.Def>());
                }
            }
            return(prefab);
        }
    /// 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");
    }