Exemplo n.º 1
0
        private static RecipeData GetPieceRecipeByName(string name)
        {
            GameObject go = GetPieces().Find(g => Utils.GetPrefabName(g) == name);

            if (go == null)
            {
                Dbgl($"Item {name} not found!");
                return(null);
            }
            Piece piece = go.GetComponent <Piece>();

            if (piece == null)
            {
                Dbgl("Item data not found!");
                return(null);
            }
            var data = new RecipeData()
            {
                name            = name,
                amount          = 1,
                craftingStation = piece.m_craftingStation?.m_name ?? "",
                minStationLevel = 1,
            };

            foreach (Piece.Requirement req in piece.m_resources)
            {
                data.reqs.Add($"{Utils.GetPrefabName(req.m_resItem.gameObject)}:{req.m_amount}:{req.m_amountPerLevel}:{req.m_recover}");
            }

            return(data);
        }
Exemplo n.º 2
0
        private static void SetPieceRecipeData(RecipeData data)
        {
            GameObject go = GetPieces().Find(g => Utils.GetPrefabName(g) == data.name);

            if (go == null)
            {
                Dbgl($"Item {data.name} not found!");
                return;
            }
            if (go.GetComponent <Piece>() == null)
            {
                Dbgl($"Item data for {data.name} not found!");
                return;
            }

            go.GetComponent <Piece>().m_craftingStation = GetCraftingStation(data.craftingStation);
            List <Piece.Requirement> reqs = new List <Piece.Requirement>();

            foreach (string req in data.reqs)
            {
                string[] parts = req.Split(':');
                reqs.Add(new Piece.Requirement()
                {
                    m_resItem = ObjectDB.instance.GetItemPrefab(parts[0]).GetComponent <ItemDrop>(), m_amount = int.Parse(parts[1]), m_amountPerLevel = int.Parse(parts[2]), m_recover = parts[3].ToLower() == "true"
                });
            }
            go.GetComponent <Piece>().m_resources = reqs.ToArray();
        }
Exemplo n.º 3
0
        private static void GetRecipeDataFromFiles()
        {
            CheckModFolder();

            recipeDatas.Clear();

            foreach (string file in Directory.GetFiles(assetPath, "*.json"))
            {
                RecipeData data = JsonUtility.FromJson <RecipeData>(File.ReadAllText(file));
                recipeDatas.Add(data);
            }
        }
Exemplo n.º 4
0
        private static void SetPieceRecipeData(RecipeData data)
        {
            GameObject go = GetPieces().Find(g => Utils.GetPrefabName(g) == data.name);

            if (go == null)
            {
                Dbgl($"Item {data.name} not found!");
                return;
            }
            if (go.GetComponent <Piece>() == null)
            {
                Dbgl($"Item data for {data.name} not found!");
                return;
            }

            if (data.disabled)
            {
                Dbgl($"Removing recipe for {data.name} from the game");

                ItemDrop hammer = ObjectDB.instance.GetItemPrefab("Hammer")?.GetComponent <ItemDrop>();
                if (hammer && hammer.m_itemData.m_shared.m_buildPieces.m_pieces.Contains(go))
                {
                    hammer.m_itemData.m_shared.m_buildPieces.m_pieces.Remove(go);
                    return;
                }
                ItemDrop hoe = ObjectDB.instance.GetItemPrefab("Hoe")?.GetComponent <ItemDrop>();
                if (hoe && hoe.m_itemData.m_shared.m_buildPieces.m_pieces.Contains(go))
                {
                    hoe.m_itemData.m_shared.m_buildPieces.m_pieces.Remove(go);
                    return;
                }
            }

            go.GetComponent <Piece>().m_craftingStation = GetCraftingStation(data.craftingStation);
            List <Piece.Requirement> reqs = new List <Piece.Requirement>();

            foreach (string req in data.reqs)
            {
                string[] parts = req.Split(':');
                reqs.Add(new Piece.Requirement()
                {
                    m_resItem = ObjectDB.instance.GetItemPrefab(parts[0]).GetComponent <ItemDrop>(), m_amount = int.Parse(parts[1]), m_amountPerLevel = int.Parse(parts[2]), m_recover = parts[3].ToLower() == "true"
                });
            }
            go.GetComponent <Piece>().m_resources = reqs.ToArray();
        }
Exemplo n.º 5
0
        private static void SetRecipeData(RecipeData data)
        {
            GameObject go = ObjectDB.instance.GetItemPrefab(data.name);

            if (go == null)
            {
                SetPieceRecipeData(data);
                return;
            }
            if (go.GetComponent <ItemDrop>() == null)
            {
                Dbgl($"Item data for {data.name} not found!");
                return;
            }

            for (int i = ObjectDB.instance.m_recipes.Count - 1; i > 0; i--)
            {
                if (ObjectDB.instance.m_recipes[i].m_item?.m_itemData.m_shared.m_name == go.GetComponent <ItemDrop>().m_itemData.m_shared.m_name)
                {
                    if (data.disabled)
                    {
                        Dbgl($"Removing recipe for {data.name} from the game");
                        ObjectDB.instance.m_recipes.RemoveAt(i);
                        return;
                    }

                    ObjectDB.instance.m_recipes[i].m_amount          = data.amount;
                    ObjectDB.instance.m_recipes[i].m_minStationLevel = data.minStationLevel;
                    ObjectDB.instance.m_recipes[i].m_craftingStation = GetCraftingStation(data.craftingStation);
                    List <Piece.Requirement> reqs = new List <Piece.Requirement>();
                    foreach (string req in data.reqs)
                    {
                        string[] parts = req.Split(':');
                        reqs.Add(new Piece.Requirement()
                        {
                            m_resItem = ObjectDB.instance.GetItemPrefab(parts[0]).GetComponent <ItemDrop>(), m_amount = int.Parse(parts[1]), m_amountPerLevel = int.Parse(parts[2]), m_recover = parts[3].ToLower() == "true"
                        });
                    }
                    ObjectDB.instance.m_recipes[i].m_resources = reqs.ToArray();
                    return;
                }
            }
        }
Exemplo n.º 6
0
        private static RecipeData GetRecipeDataByName(string name)
        {
            GameObject go = ObjectDB.instance.GetItemPrefab(name);

            if (go == null)
            {
                return(GetPieceRecipeByName(name));
            }


            ItemDrop.ItemData item = go.GetComponent <ItemDrop>().m_itemData;
            if (item == null)
            {
                Dbgl("Item data not found!");
                return(null);
            }
            Recipe recipe = ObjectDB.instance.GetRecipe(item);

            if (!recipe)
            {
                Dbgl("Recipe not found!");
                return(null);
            }

            var data = new RecipeData()
            {
                name            = name,
                amount          = recipe.m_amount,
                craftingStation = recipe.m_craftingStation?.m_name ?? "",
                minStationLevel = recipe.m_minStationLevel,
            };

            foreach (Piece.Requirement req in recipe.m_resources)
            {
                data.reqs.Add($"{Utils.GetPrefabName(req.m_resItem.gameObject)}:{req.m_amount}:{req.m_amountPerLevel}:{req.m_recover}");
            }

            return(data);
        }
Exemplo n.º 7
0
            static bool Prefix(Console __instance)
            {
                if (!modEnabled.Value)
                {
                    return(true);
                }

                string text = __instance.m_input.text;

                if (text.ToLower().Equals($"{typeof(BepInExPlugin).Namespace.ToLower()} reset"))
                {
                    context.Config.Reload();
                    context.Config.Save();
                    Traverse.Create(__instance).Method("AddString", new object[] { text }).GetValue();
                    Traverse.Create(__instance).Method("AddString", new object[] { $"{context.Info.Metadata.Name} config reloaded" }).GetValue();
                    return(false);
                }
                else if (text.ToLower().Equals($"{typeof(BepInExPlugin).Namespace.ToLower()} reload"))
                {
                    GetRecipeDataFromFiles();
                    if (ObjectDB.instance)
                    {
                        LoadAllRecipeData(true);
                    }
                    Traverse.Create(__instance).Method("AddString", new object[] { text }).GetValue();
                    Traverse.Create(__instance).Method("AddString", new object[] { $"{context.Info.Metadata.Name} reloaded recipes from files" }).GetValue();
                    return(false);
                }
                else if (text.ToLower().StartsWith($"{typeof(BepInExPlugin).Namespace.ToLower()} save "))
                {
                    var        t         = text.Split(' ');
                    string     file      = t[t.Length - 1];
                    RecipeData armorData = GetRecipeDataByName(file);
                    if (armorData == null)
                    {
                        return(false);
                    }
                    CheckModFolder();
                    File.WriteAllText(Path.Combine(assetPath, armorData.name + ".json"), JsonUtility.ToJson(armorData));
                    Traverse.Create(__instance).Method("AddString", new object[] { text }).GetValue();
                    Traverse.Create(__instance).Method("AddString", new object[] { $"{context.Info.Metadata.Name} saved recipe data to {file}.json" }).GetValue();
                    return(false);
                }
                else if (text.ToLower().StartsWith($"{typeof(BepInExPlugin).Namespace.ToLower()} dump "))
                {
                    var        t          = text.Split(' ');
                    string     recipe     = t[t.Length - 1];
                    RecipeData recipeData = GetRecipeDataByName(recipe);
                    if (recipeData == null)
                    {
                        return(false);
                    }
                    Dbgl(JsonUtility.ToJson(recipeData));
                    Traverse.Create(__instance).Method("AddString", new object[] { text }).GetValue();
                    Traverse.Create(__instance).Method("AddString", new object[] { $"{context.Info.Metadata.Name} dumped {recipe}" }).GetValue();
                    return(false);
                }
                else if (text.ToLower().StartsWith($"{typeof(BepInExPlugin).Namespace.ToLower()}"))
                {
                    string output = $"{context.Info.Metadata.Name} reset\r\n"
                                    + $"{context.Info.Metadata.Name} reload\r\n"
                                    + $"{context.Info.Metadata.Name} dump <ItemName>\r\n"
                                    + $"{context.Info.Metadata.Name} save <ItemName>";

                    Traverse.Create(__instance).Method("AddString", new object[] { text }).GetValue();
                    Traverse.Create(__instance).Method("AddString", new object[] { output }).GetValue();
                    return(false);
                }
                return(true);
            }