Browse Source

[RecipeMenuCore] [2.0.3.6] Universal Crafter

Zariteis 4 years ago
parent
commit
5c832c5d06

+ 9 - 1
RecipeMenuCore/API/RecipePage.cs

@@ -67,6 +67,9 @@ namespace RecipeMenuCore.API
         case RecipePageType.UltimateForge:
           Core.pageUltimateForgeInfoList.Add(this);
           break;
+        case RecipePageType.UniversalCrafter:
+          Core.pageUniversalCrafterInfoList.Add(this);
+          break;
       }
       return this;
     }
@@ -150,6 +153,11 @@ namespace RecipeMenuCore.API
     /// <summary>
     /// This recipe is for the Ultimate Forge.
     /// </summary>
-    UltimateForge
+    UltimateForge,
+
+    /// <summary>
+    /// This recipe is for the Gadget Core Universal Crafter.
+    /// </summary>
+    UniversalCrafter
   }
 }

+ 1 - 0
RecipeMenuCore/Core.cs

@@ -10,6 +10,7 @@ namespace RecipeMenuCore
     internal static List<RecipePage> pageGearForgeInfoList = new List<RecipePage>();
     internal static List<RecipePage> pageAlchemyStationInfoList = new List<RecipePage>();
     internal static List<RecipePage> pageUltimateForgeInfoList = new List<RecipePage>();
+    internal static List<RecipePage> pageUniversalCrafterInfoList = new List<RecipePage>();
 
     internal static RecipePage[] pageGearForgeInfoListVanilla = new RecipePage[6];
     internal static RecipePage[] pageAlchemyStationInfoListVanilla = new RecipePage[2];

+ 26 - 0
RecipeMenuCore/Patches/Patch_CraftMenuInfo_AllowQuickCrafting.cs

@@ -0,0 +1,26 @@
+using HarmonyLib;
+using GadgetCore.API;
+using UnityEngine;
+using System.Collections;
+using System.Reflection;
+using System.Collections.Generic;
+
+namespace RecipeMenuCore.Patches
+{
+  [HarmonyPatch(typeof(CraftMenuInfo))]
+  [HarmonyPatch("AllowQuickCrafting")]
+  [HarmonyGadget("RecipeMenuCore")]
+  public static class Patch_CraftMenuInfo_AllowQuickCrafting
+  {
+    [HarmonyPrefix]
+    public static bool Prefix(CraftMenuInfo __instance, ref bool __result)
+    {
+      if(__instance.GetRegistryName() == "Gadget Core:Crafter Menu")
+      {
+        __result = Core.pageUniversalCrafterInfoList.Count > 0;
+        return false;
+      }
+      return true;
+    }
+  }
+}

+ 6 - 1
RecipeMenuCore/Patches/Patch_GameScript_HoverRecipeSelect.cs

@@ -21,10 +21,13 @@ namespace RecipeMenuCore.Patches
       if (!Core.settingUseDialog)
         return true;
 
-      if (___craftType == 0 || ___craftType == 1)
+      if (___craftType == 0 || ___craftType == 1 || ___craftType == MenuRegistry.Singleton["Gadget Core:Crafter Menu"].GetID())
       {
         if (id >= 12 || ___recipeLock[id].active)
+        {
+          ___hoverItem.SetActive(false);
           return false;
+        }
       }
       var item = new Item(GetItemId(__instance, id, ___craftType, ___curRecipePage), 1, 0, 0, 0, new int[3], new int[3]);
       var itemInfo = ItemRegistry.GetItem(item.id);
@@ -126,6 +129,8 @@ namespace RecipeMenuCore.Patches
         return Core.pageAlchemyStationInfoList[curRecipePage - 2].GetRecipePageEntries()[index].ItemIdBase;
       else if (craftType == 2 && curRecipePage >= 6)
         return Core.pageUltimateForgeInfoList[curRecipePage - 6].GetRecipePageEntries()[index].ItemIdBase;
+      else if (craftType == MenuRegistry.Singleton["Gadget Core:Crafter Menu"].GetID())
+        return Core.pageUniversalCrafterInfoList[curRecipePage].GetRecipePageEntries()[index].ItemIdBase;
 
       else if (craftType == 0 && curRecipePage < 6 && Core.pageGearForgeInfoListVanilla[curRecipePage] != null)
         return Core.pageGearForgeInfoListVanilla[curRecipePage].GetRecipePageEntries()[index].ItemIdBase;

+ 9 - 12
RecipeMenuCore/Patches/Patch_GameScript_RecipeDown.cs

@@ -14,18 +14,15 @@ namespace RecipeMenuCore.Patches
     public static bool Prefix(GameScript __instance, int ___craftType, ref int ___curRecipePage)
     {
       int pages = 1;
-      switch (___craftType)
-      {
-        case 0:
-          pages = 6 + Core.pageGearForgeInfoList.Count;
-          break;
-        case 1:
-          pages = 2 + Core.pageAlchemyStationInfoList.Count;
-          break;
-        case 2:
-          pages = 6 + Core.pageUltimateForgeInfoList.Count;
-          break;
-      }
+      if (___craftType == 0)
+        pages = 6 + Core.pageGearForgeInfoList.Count;
+      else if (___craftType == 1)
+        pages = 2 + Core.pageAlchemyStationInfoList.Count;
+      else if (___craftType == 2)
+        pages = 6 + Core.pageUltimateForgeInfoList.Count;
+      else if (___craftType == MenuRegistry.Singleton["Gadget Core:Crafter Menu"].GetID())
+        pages = Core.pageUniversalCrafterInfoList.Count;
+
       ___curRecipePage = (___curRecipePage + pages - 1) % pages;
       __instance.RefreshRecipe();
       return false;

+ 9 - 12
RecipeMenuCore/Patches/Patch_GameScript_RecipeUp.cs

@@ -14,18 +14,15 @@ namespace RecipeMenuCore.Patches
     public static bool Prefix(GameScript __instance, int ___craftType, ref int ___curRecipePage)
     {
       int pages = 1;
-      switch (___craftType)
-      {
-        case 0:
-          pages = 6 + Core.pageGearForgeInfoList.Count;
-          break;
-        case 1:
-          pages = 2 + Core.pageAlchemyStationInfoList.Count;
-          break;
-        case 2:
-          pages = 6 + Core.pageUltimateForgeInfoList.Count;
-          break;
-      }
+      if (___craftType == 0)
+        pages = 6 + Core.pageGearForgeInfoList.Count;
+      else if (___craftType == 1)
+        pages = 2 + Core.pageAlchemyStationInfoList.Count;
+      else if (___craftType == 2)
+        pages = 6 + Core.pageUltimateForgeInfoList.Count;
+      else if (___craftType == MenuRegistry.Singleton["Gadget Core:Crafter Menu"].GetID())
+        pages = Core.pageUniversalCrafterInfoList.Count;
+
       ___curRecipePage = (___curRecipePage + 1) % pages;
       __instance.RefreshRecipe();
       return false;

+ 14 - 1
RecipeMenuCore/Patches/Patch_GameScript_RefreshRecipe.cs

@@ -28,13 +28,19 @@ namespace RecipeMenuCore.Patches
         __instance.txtRecipeName[0].text = string.Empty + __instance.GetRecipeName2(___curRecipePage);
         __instance.txtRecipeUnlocked[0].text = "Page " + (___curRecipePage + 1) + "/" + (6 + Core.pageUltimateForgeInfoList.Count);
       }
+      else if (___craftType == MenuRegistry.Singleton["Gadget Core:Crafter Menu"].GetID())
+      {
+        __instance.txtRecipeName[0].text = string.Empty + __instance.GetRecipeName2(___curRecipePage);
+        __instance.txtRecipeUnlocked[0].text = "Page " + (___curRecipePage + 1) + "/" + (Core.pageUniversalCrafterInfoList.Count);
+      }
       __instance.txtRecipeUnlocked[0].gameObject.GetComponent<Animation>().Play();
       __instance.txtRecipeName[0].gameObject.GetComponent<Animation>().Play();
       __instance.txtRecipeName[1].text = __instance.txtRecipeName[0].text;
       __instance.txtRecipeUnlocked[1].text = __instance.txtRecipeUnlocked[0].text;
       if ((___craftType != 0 || (___curRecipePage <= 5 && Core.pageGearForgeInfoListVanilla[___curRecipePage] == null))
         && (___craftType != 1 || (___curRecipePage <= 1 && Core.pageAlchemyStationInfoListVanilla[___curRecipePage] == null))
-        && (___craftType != 2 || (___curRecipePage <= 5 && Core.pageUltimateForgeInfoListVanilla[___curRecipePage] == null)))
+        && (___craftType != 2 || (___curRecipePage <= 5 && Core.pageUltimateForgeInfoListVanilla[___curRecipePage] == null))
+        && (___craftType != MenuRegistry.Singleton["Gadget Core:Crafter Menu"].GetID()))
       {
         __instance.menuRecipe.GetComponent<Renderer>().material = (Material)Resources.Load(string.Concat(new object[] { "mat/r", ___curRecipePage, "t", ___craftType }));
       }
@@ -61,6 +67,13 @@ namespace RecipeMenuCore.Patches
           __instance.txtRecipeName[1].text = __instance.txtRecipeName[0].text;
           __instance.menuRecipe.GetComponent<Renderer>().material = page.Mat;
         }
+        else if (___craftType == MenuRegistry.Singleton["Gadget Core:Crafter Menu"].GetID())
+        {
+          var page = Core.pageUniversalCrafterInfoList[___curRecipePage];
+          __instance.txtRecipeName[0].text = page.Title;
+          __instance.txtRecipeName[1].text = __instance.txtRecipeName[0].text;
+          __instance.menuRecipe.GetComponent<Renderer>().material = page.Mat;
+        }
       }
       __instance.RefreshRecipeUnlock();
       return false;

+ 24 - 1
RecipeMenuCore/Patches/Patch_GameScript_RefreshRecipeUnlock.cs

@@ -16,7 +16,7 @@ namespace RecipeMenuCore.Patches
     public static bool Prefix(GameScript __instance, int ___craftType, int ___curRecipePage, GameObject ___ultLocksObj, GameObject ___recipeButtons,
       GameObject[] ___recipeLock, GameObject[] ___ultLocks, int[,] ___ultLocksUnlocked)
     {
-      if (___craftType == 0 || ___craftType == 1)
+      if (___craftType == 0 || ___craftType == 1 || ___craftType == MenuRegistry.Singleton["Gadget Core:Crafter Menu"].GetID())
       {
         for (int i = 0; i < 12; i++)
         {
@@ -123,6 +123,29 @@ namespace RecipeMenuCore.Patches
         }
         return false;
       }
+      else if (___craftType == MenuRegistry.Singleton["Gadget Core:Crafter Menu"].GetID())
+      {
+        ___ultLocksObj.SetActive(false);
+        ___recipeButtons.SetActive(true);
+        var page = Core.pageUniversalCrafterInfoList[___curRecipePage];
+        for (int i = 0; i < 12; i++)
+        {
+          if (page.GetRecipePageEntries().Length > i)
+          {
+            int itemID = page.GetRecipePageEntries()[i].ItemIdBase;
+            if (((CraftMenuInfo)MenuRegistry.Singleton["Gadget Core:Crafter Menu"]).IsRecipeUnlocked(itemID))
+              ___recipeLock[i].SetActive(false);
+            else
+              ___recipeLock[i].SetActive(true);
+          }
+          else
+          {
+            ___recipeLock[i].SetActive(false);
+            ___recipeButtons.transform.GetChild(i).gameObject.SetActive(false);
+          }
+        }
+        return false;
+      }
       return true;
     }
   }

+ 21 - 1
RecipeMenuCore/Patches/Patch_GameScript_Update.cs

@@ -46,6 +46,11 @@ namespace RecipeMenuCore.Patches
                   {
                     acted = true;
                   }
+                  else if (___craftType == MenuRegistry.Singleton["Gadget Core:Crafter Menu"].GetID())
+                  {
+                    __instance.StartCoroutine(QuickCraft(__instance, ___curRecipePage, slotID, ___craftType, ___inventory, ___craft));
+                    acted = true;
+                  }
                 }
               }
             }
@@ -97,7 +102,22 @@ namespace RecipeMenuCore.Patches
                 price.Add(itemID);
             }
           }
-          if (craftingItemID == 0 || !__instance.RecipeCraftedAlready(craftingItemID, 0))
+          else if (___craftType == MenuRegistry.Singleton["Gadget Core:Crafter Menu"].GetID())
+          {
+            var recipePageEntry = Core.pageUniversalCrafterInfoList[___curRecipePage].GetRecipePageEntries()[slot];
+            craftingItemID = recipePageEntry.ItemIdBase;
+            craftingItemAmount = recipePageEntry.MinAmount + Random.Range(0, 1 + recipePageEntry.MaxBonusAmount);
+            for (int i = 0; i < recipePageEntry.ItemIdExtension.Length; i++)
+            {
+              var itemID = recipePageEntry.ItemIdExtension[i];
+              if (itemID > 0)
+                price.Add(itemID);
+            }
+          }
+          if (craftingItemID == 0 
+            || !(___craftType == MenuRegistry.Singleton["Gadget Core:Crafter Menu"].GetID()
+            ? ((CraftMenuInfo)MenuRegistry.Singleton["Gadget Core:Crafter Menu"]).IsRecipeUnlocked(craftingItemID)
+            : __instance.RecipeCraftedAlready(craftingItemID, 0) ))
           {
             yield break;
           }

+ 1 - 1
RecipeMenuCore/RecipeMenuCore.cs

@@ -11,7 +11,7 @@ namespace RecipeMenuCore
   [Gadget("RecipeMenuCore", RequiredOnClients: false)]
   public class RecipeMenuCore : Gadget<RecipeMenuCore>
   {
-    public const string MOD_VERSION = "1.4"; // Set this to the version of your mod.
+    public const string MOD_VERSION = "1.5"; // Set this to the version of your mod.
     public const string CONFIG_VERSION = "1.0"; // Increment this whenever you change your mod's config file.
 
     protected override void LoadConfig()