Exemple #1
0
        public static GameObject PlaceBlueprint()
        {
            GameObject obj = null;

            try
            {
                TheForest.Utils.LocalPlayer.Inventory.EquipPreviousWeapon();
                TheForest.Utils.LocalPlayer.FpCharacter.UnLockView();
                EditorVariables.isMenuOpened = false;
                obj = Core.Instantiate(EditorVariables.SelectedListItem.PrefabID, EditorVariables.pInteraction.GetLookAtPos(), out uint PlacedIndex);


                Blueprint     b = obj.AddComponent <Blueprint>();
                ItemRecipe    r = obj.AddComponent <ItemRecipe>();
                ItemVariables v = obj.AddComponent <ItemVariables>();
                v.blueprint       = b;
                v.Recipe          = r;
                v.ItemOnList      = EditorVariables.SelectedListItem;
                v.ItemOnListIndex = EditorVariables.SelectedListItemIndex;
                b.vars            = v;
                r.vars            = v;
                Dictionary <int, int> dict = new Dictionary <int, int>(EditorVariables.SelectedListItem.Ingredients);


                SerializableBluePrint bluePrint = new SerializableBluePrint();
                ModAPI.Console.Write(EditorVariables.SelectedListItem.Ingredients.Keys.Count + "---" + dict.Keys.Count);
                r.Ingredients = dict;

                bluePrint.Ingredients = dict;
                bluePrint.Built       = false;
                bluePrint.ListItemID  = EditorVariables.SelectedListItemIndex;

                EditorVariables.SerializableBlueprints.Add(PlacedIndex, bluePrint);
                v.SerializableBlueprint = bluePrint;
                v.Index = PlacedIndex;
            }
            catch (System.Exception ex)
            {
                ModAPI.Log.Write(ex.ToString());
            }
            return(obj);
        }
Exemple #2
0
        public static void LoadBlueprints()
        {
            try
            {
                string path = "Mods/Hazard's Mods/BuilderMenu/";

                if (GameSetup.IsSinglePlayer)
                {
                    path += "Singleplayer saves/";
                }
                else
                {
                    path += "Multiplayer saves/";
                }
                path += GameSetup.Slot.ToString();
                path += "/Blueprints.ass";

                if (File.Exists(path))
                {
                    ModAPI.Console.Write("Loading bp");
                    EditorVariables.SerializableBlueprints = new Dictionary <uint, SerializableBluePrint>();
                    BinaryReader buf  = new BinaryReader(new MemoryStream(File.ReadAllBytes(path)));
                    int          maxI = buf.ReadInt32();
                    for (int i = 0; i < maxI; i++)
                    {
                        uint key = buf.ReadUInt32();
                        SerializableBluePrint bp = new SerializableBluePrint();
                        bp.Built      = buf.ReadBoolean();
                        bp.ListItemID = buf.ReadInt32();
                        int b = buf.ReadInt32();
                        bp.Ingredients = new Dictionary <int, int>();
                        for (int a = 0; a < b; a++)
                        {
                            int x = buf.ReadInt32();
                            int y = buf.ReadInt32();
                            bp.Ingredients.Add(x, y);
                        }
                        EditorVariables.SerializableBlueprints.Add(key, bp);
                    }
                    buf.Close();


                    ModAPI.Console.Write("bp count " + EditorVariables.SerializableBlueprints.Count);
                    foreach (KeyValuePair <uint, SerializableBluePrint> pair in EditorVariables.SerializableBlueprints)
                    {
                        ModAPI.Console.Write("Doing foreach");
                        if (!pair.Value.Built)
                        {
                            GameObject obj = Core.placedBuildingGameObjects[pair.Key].PlacedGameObject;
                            ModAPI.Console.Write(obj.ToString() + obj.name);
                            Blueprint     b = obj.AddComponent <Blueprint>();
                            ItemRecipe    r = obj.AddComponent <ItemRecipe>();
                            ItemVariables v = obj.AddComponent <ItemVariables>();
                            b.Finished        = pair.Value.Built;
                            b.vars            = v;
                            r.vars            = v;
                            v.blueprint       = b;
                            v.Recipe          = r;
                            v.ItemOnList      = EditorVariables.Items[pair.Value.ListItemID];
                            v.ItemOnListIndex = pair.Value.ListItemID;
                            r.Ingredients     = pair.Value.Ingredients;
                            v.Index           = pair.Key;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ModAPI.Console.Write(e.ToString());
            }
        }