Beispiel #1
0
    public static BuildingDef CreateBuildingDef(string id, int width, int height, string anim, int hitpoints, float construction_time, float[] construction_mass, string[] construction_materials, float melting_point, BuildLocationRule build_location_rule, EffectorValues decor, EffectorValues noise, float temperature_modification_mass_scale = 0.2f)
    {
        BuildingDef buildingDef = ScriptableObject.CreateInstance <BuildingDef>();

        buildingDef.PrefabID = id;
        buildingDef.InitDef();
        buildingDef.name = id;
        buildingDef.Mass = construction_mass;
        buildingDef.MassForTemperatureModification = construction_mass[0] * temperature_modification_mass_scale;
        buildingDef.WidthInCells     = width;
        buildingDef.HeightInCells    = height;
        buildingDef.HitPoints        = hitpoints;
        buildingDef.ConstructionTime = construction_time;
        buildingDef.SceneLayer       = Grid.SceneLayer.Building;
        buildingDef.MaterialCategory = construction_materials;
        buildingDef.BaseMeltingPoint = melting_point;
        switch (build_location_rule)
        {
        case BuildLocationRule.Anywhere:
        case BuildLocationRule.Tile:
        case BuildLocationRule.Conduit:
        case BuildLocationRule.LogicBridge:
        case BuildLocationRule.WireBridge:
            buildingDef.ContinuouslyCheckFoundation = false;
            break;

        default:
            buildingDef.ContinuouslyCheckFoundation = true;
            break;
        }
        buildingDef.BuildLocationRule = build_location_rule;
        buildingDef.ObjectLayer       = ObjectLayer.Building;
        buildingDef.AnimFiles         = new KAnimFile[1]
        {
            Assets.GetAnim(anim)
        };
        buildingDef.GenerateOffsets();
        buildingDef.BaseDecor                = (float)decor.amount;
        buildingDef.BaseDecorRadius          = (float)decor.radius;
        buildingDef.BaseNoisePollution       = noise.amount;
        buildingDef.BaseNoisePollutionRadius = noise.radius;
        return(buildingDef);
    }
Beispiel #2
0
    public override BuildingDef CreateBuildingDef()
    {
        string text  = "FlowerVaseHangingFancy";
        int    num   = 1;
        int    num2  = 2;
        string text2 = "flowervase_hanging_kanim";
        int    num3  = 10;
        float  num4  = 10f;

        float[]           tIER              = BUILDINGS.CONSTRUCTION_MASS_KG.TIER1;
        string[]          tRANSPARENTS      = MATERIALS.TRANSPARENTS;
        float             num5              = 800f;
        BuildLocationRule buildLocationRule = BuildLocationRule.OnCeiling;
        EffectorValues    nONE              = NOISE_POLLUTION.NONE;
        string            id     = text;
        int    width             = num;
        int    height            = num2;
        string anim              = text2;
        int    hitpoints         = num3;
        float  construction_time = num4;

        float[]           construction_mass      = tIER;
        string[]          construction_materials = tRANSPARENTS;
        float             melting_point          = num5;
        BuildLocationRule build_location_rule    = buildLocationRule;
        EffectorValues    decor = default(EffectorValues);
        EffectorValues    tIER2 = BUILDINGS.DECOR.BONUS.TIER1;

        decor.amount = tIER2.amount;
        EffectorValues tIER3 = BUILDINGS.DECOR.BONUS.TIER3;

        decor.radius = tIER3.radius;
        BuildingDef buildingDef = BuildingTemplates.CreateBuildingDef(id, width, height, anim, hitpoints, construction_time, construction_mass, construction_materials, melting_point, build_location_rule, decor, nONE, 0.2f);

        buildingDef.Floodable     = false;
        buildingDef.Overheatable  = false;
        buildingDef.ViewMode      = OverlayModes.Decor.ID;
        buildingDef.AudioCategory = "Glass";
        buildingDef.AudioSize     = "large";
        buildingDef.GenerateOffsets(1, 1);
        return(buildingDef);
    }
    public override BuildingDef CreateBuildingDef()
    {
        string id                = "FlowerVaseHanging";
        int    width             = 1;
        int    height            = 2;
        string anim              = "flowervase_hanging_basic_kanim";
        int    hitpoints         = 10;
        float  construction_time = 10f;

        float[]           tIER                = BUILDINGS.CONSTRUCTION_MASS_KG.TIER1;
        string[]          rAW_METALS          = MATERIALS.RAW_METALS;
        float             melting_point       = 800f;
        BuildLocationRule build_location_rule = BuildLocationRule.OnCeiling;
        EffectorValues    nONE                = NOISE_POLLUTION.NONE;
        BuildingDef       buildingDef         = BuildingTemplates.CreateBuildingDef(id, width, height, anim, hitpoints, construction_time, tIER, rAW_METALS, melting_point, build_location_rule, BUILDINGS.DECOR.NONE, nONE, 0.2f);

        buildingDef.Floodable     = false;
        buildingDef.Overheatable  = false;
        buildingDef.ViewMode      = OverlayModes.Decor.ID;
        buildingDef.AudioCategory = "Glass";
        buildingDef.AudioSize     = "large";
        buildingDef.GenerateOffsets(1, 1);
        return(buildingDef);
    }
Beispiel #4
0
        private static bool RegisterBuilding(BuildingConfigManager __instance, IBuildingConfig config, BuildingDef buildingDef)
        {
            //Debug.Log(config.CreateBuildingDef().PrefabID);
            if (!Helper.Config.Enabled)
            {
                return(true);
            }

            Helper.Log(" === [BuildingModifier] BuildingModifierMod_BuildingConfigManager_RegisterBuilding Prefix === ");

            //CreateBuildingDef
            //BuildingDef buildingDef = config.CreateBuildingDef();
            // Check if there is a config for the current building
            if (!Helper.Config.Modifiers.ContainsKey(buildingDef.PrefabID))
            {
                Helper.Log(" === [BuildingModifier] Ignoring: " + buildingDef.PrefabID);
                return(true);
            }

            Debug.Log(" === [BuildingModifier] Processing: " + buildingDef.PrefabID);

            Helper.Log(" === [BuildingModifier] CreateBuildingDef === ");
            Helper.Process(buildingDef, null);
            buildingDef.GenerateOffsets();  // Remake the offsets after modification


            // Create gameobject
            //configTable[config] = buildingDef;
            ((Dictionary <IBuildingConfig, BuildingDef>)configTableF.GetValue(__instance))[config] = buildingDef;
            //GameObject gameObject = Object.Instantiate(baseTemplate);
            GameObject gameObject = UnityEngine.Object.Instantiate((GameObject)baseTemplateF.GetValue(__instance));

            UnityEngine.Object.DontDestroyOnLoad(gameObject);
            gameObject.GetComponent <KPrefabID>().PrefabTag = buildingDef.Tag;
            gameObject.name = buildingDef.PrefabID + "Template";
            gameObject.GetComponent <Building>().Def = buildingDef;
            gameObject.GetComponent <OccupyArea>().OccupiedCellsOffsets = buildingDef.PlacementOffsets;
            if (buildingDef.Deprecated)
            {
                gameObject.GetComponent <KPrefabID>().AddTag(GameTags.DeprecatedContent);
            }

            //ConfigureBuildingTemplate
            config.ConfigureBuildingTemplate(gameObject, buildingDef.Tag);
            Helper.Log(" === [BuildingModifier] ConfigureBuildingTemplate === ");
            Helper.Process(buildingDef, gameObject);

            //ConfigureBuildingTemplate
            buildingDef.BuildingComplete = BuildingLoader.Instance.CreateBuildingComplete(gameObject, buildingDef);
            Helper.Log(" === [BuildingModifier] CreateBuildingComplete === ");
            Helper.Process(buildingDef, gameObject);

            bool flag = true;

            //for (int i = 0; i < NonBuildableBuildings.Length; i++)
            for (int i = 0; i < ((string[])NonBuildableBuildingsF.GetValue(__instance)).Length; i++)
            {
                //if (buildingDef.PrefabID == NonBuildableBuildings[i])
                if (buildingDef.PrefabID == ((string[])NonBuildableBuildingsF.GetValue(__instance))[i])
                {
                    flag = false;
                    break;
                }
            }

            // Previews
            if (flag)
            {
                buildingDef.BuildingUnderConstruction      = BuildingLoader.Instance.CreateBuildingUnderConstruction(buildingDef);
                buildingDef.BuildingUnderConstruction.name = BuildingConfigManager.GetUnderConstructionName(buildingDef.BuildingUnderConstruction.name);
                buildingDef.BuildingPreview       = BuildingLoader.Instance.CreateBuildingPreview(buildingDef);
                buildingDef.BuildingPreview.name += "Preview";
            }

            buildingDef.PostProcess();

            // Try to avoid errors if the gameobject doesn't have RequiereInputs

            /*
             * if (gameObject.GetComponent<RequireInputs>() == null)
             *  gameObject.AddOrGet<RequireInputs>();
             */

            //DoPostConfigureComplete
            config.DoPostConfigureComplete(buildingDef.BuildingComplete);
            Helper.Log(" === [BuildingModifier] DoPostConfigureComplete === ");
            Helper.Process(buildingDef, gameObject);

            // Previews
            if (flag)
            {
                config.DoPostConfigurePreview(buildingDef, buildingDef.BuildingPreview);
                Helper.Log(" === [BuildingModifier] CreateBuildingUnderConstruction === ");
                Helper.Process(buildingDef, gameObject);

                config.DoPostConfigureUnderConstruction(buildingDef.BuildingUnderConstruction);
                Helper.Log(" === [BuildingModifier] CreateBuildingPreview === ");
                Helper.Process(buildingDef, gameObject);
            }

            Assets.AddBuildingDef(buildingDef);

            return(false);
        }