ImAxel0

Untitled

Jul 31st, 2023
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.64 KB | None | 0 0
  1. public class CustomRecipesFramework
  2. {
  3. public static bool AreRecipesLoaded = false;
  4.  
  5. private static void CreateRecipe(string recipeName, int obtaintedItemID, int[] ingredientIDs, int[] howManyXIngredient, CraftingRecipe.Type type, int howManyObtained = 1, WeaponMod weaponMod = null)
  6. {
  7. if (ingredientIDs.Length != howManyXIngredient.Length)
  8. return;
  9.  
  10. int howManyIngredients = ingredientIDs.Length;
  11.  
  12. CraftingRecipe craftingRecipe = new CraftingRecipe();
  13. //ResultingItem resultingItem = new ResultingItem();
  14. Il2CppSystem.Collections.Generic.List<ResultingItem> resultingItems = new Il2CppSystem.Collections.Generic.List<ResultingItem>();
  15.  
  16. // name of recipe
  17. craftingRecipe.name = recipeName;
  18.  
  19. // the obtained item ID
  20. //resultingItem.Id = obtaintedItemID;
  21.  
  22. // adding the item/s to the obtained item list & setting it to the recipe
  23. for (int i = 0; i < howManyObtained; i++)
  24. {
  25. ResultingItem resultingItem = new ResultingItem();
  26. resultingItem.Id = obtaintedItemID;
  27.  
  28. resultingItems.Add(resultingItem);
  29. }
  30. craftingRecipe._resultingItems = resultingItems;
  31.  
  32. // setting recipe parameters
  33. craftingRecipe._recipeType = type;
  34. craftingRecipe._forceNewItemInstance = false;
  35. craftingRecipe._weaponMod = weaponMod;
  36.  
  37. Il2CppSystem.Collections.Generic.List<CraftingIngredient> ingredients = new Il2CppSystem.Collections.Generic.List<CraftingIngredient>();
  38.  
  39. int currentPointedIngredient = 0;
  40. for (int i = 0; i < howManyIngredients; i++)
  41. {
  42. CraftingIngredient craftingIngredient = new CraftingIngredient();
  43.  
  44. craftingIngredient.Count = howManyXIngredient.ElementAt(currentPointedIngredient);
  45. craftingIngredient.ItemId = ingredientIDs.ElementAt(currentPointedIngredient);
  46. craftingIngredient.IsReusable = false;
  47.  
  48. ingredients.Add(craftingIngredient);
  49. currentPointedIngredient++;
  50. }
  51.  
  52. // adding ingredients to the final recipe
  53. craftingRecipe._ingredients = ingredients;
  54.  
  55. // Adding to game database
  56. CraftingSystem instance = CraftingSystem.Instance;
  57. if (!instance)
  58. return;
  59.  
  60. CraftingRecipeDatabase database = instance._recipeDatabase;
  61.  
  62. database._recipes.Add(craftingRecipe);
  63. }
  64.  
  65. public static void CreateNewRecipes()
  66. {
  67. CreateRecipe("RockRecipe", (int)ItemIDs.ItemID.Rock,
  68. new int[] { (int)ItemIDs.ItemID.SmallRocks },
  69. new int[] { 4 }, CraftingRecipe.Type.CraftNewItem);
  70.  
  71. CreateRecipe("BatteryRecipe", (int)ItemIDs.ItemID.Batteries,
  72. new int[] { (int)ItemIDs.ItemID.Coins, (int)ItemIDs.ItemID.CircuitBoard },
  73. new int[] { 5, 1 }, CraftingRecipe.Type.CraftNewItem);
  74.  
  75. CreateRecipe("C4BrickRecipe", (int)ItemIDs.ItemID.C4Brick,
  76. new int[] { (int)ItemIDs.ItemID.Coins, (int)ItemIDs.ItemID.PistolAmmo },
  77. new int[] { 20, 25 }, CraftingRecipe.Type.CraftNewItem);
  78.  
  79. CreateRecipe("CanOpenerRecipe", (int)ItemIDs.ItemID.CanOpener,
  80. new int[] { (int)ItemIDs.ItemID.Coins, (int)ItemIDs.ItemID.DuctTape, (int)ItemIDs.ItemID.Watch },
  81. new int[] { 15, 1, 2 }, CraftingRecipe.Type.CraftNewItem);
  82.  
  83. // better to create atleast 2 of them at time
  84. CreateRecipe("ClothRecipe", (int)ItemIDs.ItemID.Cloth,
  85. new int[] { (int)ItemIDs.ItemID.Cash, (int)ItemIDs.ItemID.Wire },
  86. new int[] { 5, 1 }, CraftingRecipe.Type.CraftNewItem);
  87.  
  88. CreateRecipe("DuctTapeRecipe", (int)ItemIDs.ItemID.DuctTape,
  89. new int[] { (int)ItemIDs.ItemID.Cash, (int)ItemIDs.ItemID.Rope },
  90. new int[] { 5, 1 }, CraftingRecipe.Type.CraftNewItem);
  91.  
  92. CreateRecipe("FragGrenade", (int)ItemIDs.ItemID.FragGrenade,
  93. new int[] { (int)ItemIDs.ItemID.Coins, (int)ItemIDs.ItemID.ShotgunSlugAmmo },
  94. new int[] { 30, 15 }, CraftingRecipe.Type.CraftNewItem);
  95.  
  96. CreateRecipe("MedsRecipe", (int)ItemIDs.ItemID.Meds,
  97. new int[] { (int)ItemIDs.ItemID.AloeVera },
  98. new int[] { 3 }, CraftingRecipe.Type.CraftNewItem);
  99.  
  100. MelonLogger.Msg("Custom recipes loaded");
  101. AreRecipesLoaded = true;
  102. }
  103. }
  104.  
Add Comment
Please, Sign In to add comment