Browse Source

[2.0.3.9] GearModStackSize+ gear mod implementation

Zariteis 4 years ago
parent
commit
183972651a
3 changed files with 42 additions and 3 deletions
  1. 8 1
      Patches/Patch_GameScript_AddMod.cs
  2. 33 0
      Patches/Patch_GameScript_RefreshGearMods.cs
  3. 1 2
      Ships.cs

+ 8 - 1
Patches/Patch_GameScript_AddMod.cs

@@ -14,12 +14,19 @@ namespace Ships.Patches
 		[HarmonyPrefix]
     public static bool Prefix(GameScript __instance, int a, Item ___holdingItem, GameObject[] ___modObj, Item[] ___modSlot)
 		{
+			int n = 5;
+			int id = ___modSlot[0].id;
+			if (id > 0)
+				for (int i = 0; i < 3; i++)
+					if (___modSlot[0].aspect[i] > 0 && ___modSlot[0].aspect[i] == Core.itemOldTexMod.GetID())
+						n += ___modSlot[0].aspectLvl[i];
+
 			ItemInfo itemInfo = ItemRegistry.GetItem(___holdingItem.id);
 			if ((___holdingItem.id > 200 && ___holdingItem.id < 230) || (itemInfo != null && ((itemInfo.Type & ItemType.MOD) == (ItemType.MOD))))
 			{
 				if (___modSlot[0].id != 0)
 				{
-					if (___modSlot[0].aspectLvl[a] < 5)
+					if (___modSlot[0].aspectLvl[a] < 5 || (___modSlot[0].aspectLvl[a] < n && ___holdingItem.id != Core.itemOldTexMod.GetID()))
 					{
 						if (___modSlot[0].aspect[a] == ___holdingItem.id || ___modSlot[0].aspect[a] == 0)
 						{

+ 33 - 0
Patches/Patch_GameScript_RefreshGearMods.cs

@@ -0,0 +1,33 @@
+using GadgetCore.API;
+using HarmonyLib;
+using System.Reflection;
+using UnityEngine;
+
+namespace Ships.Patches
+{
+
+  [HarmonyPatch(typeof(GameScript))]
+  [HarmonyPatch("RefreshGearMods")]
+  [HarmonyGadget("Ships")]
+  public static class Patch_GameScript_RefreshGearMods
+  {
+    [HarmonyPostfix]
+    public static void Postfix(GameScript __instance, Item[] ___modSlot)
+    {
+      int n = 5;
+      int id = ___modSlot[0].id;
+      if (id > 0)
+        for (int i = 0; i < 3; i++)
+          if (___modSlot[0].aspect[i] > 0 && ___modSlot[0].aspect[i] == Core.itemOldTexMod.GetID())
+            n += ___modSlot[0].aspectLvl[i];
+      try
+      {
+        var text1Transform = GameObject.Find("Main Camera").transform.Find("menuMods").Find("txtName (1)");
+        var text2Transform = text1Transform.GetChild(0);
+        text1Transform.GetComponent<TextMesh>().text = "Mods can stack up to " + n + " times each";
+        text2Transform.GetComponent<TextMesh>().text = "Mods can stack up to " + n + " times each";
+      }
+      catch { }
+    }
+  }
+}

+ 1 - 2
Ships.cs

@@ -1,7 +1,6 @@
 using GadgetCore.API;
 using GadgetCore.Util;
 using RecipeMenuCore.API;
-using Ships.API;
 using System.Collections;
 using System.Reflection;
 using UnityEngine;
@@ -164,7 +163,7 @@ namespace Ships
          BodyTex: GadgetCoreAPI.LoadTexture2D("dOldTecDroidBase.png"), HeadTex: GadgetCoreAPI.LoadTexture2D("dOldTecDroidTop.png"));
       ItemRegistry.Singleton.Register(Core.itemOldTexDroid, "oldtecdroid");
 
-      Core.itemOldTexMod = new ItemInfo(ItemType.MOD, "ModStackSize+", "GEAR MOD\nAttach to weapons\nand armor in Mech City.", GadgetCoreAPI.LoadTexture2D("iOldTecMod.png"));
+      Core.itemOldTexMod = new ItemInfo(ItemType.MOD, "GearModStackSize+", "GEAR MOD\nAttach to weapons\nand armor in Mech City.", GadgetCoreAPI.LoadTexture2D("iOldTecMod.png"));
       ItemRegistry.Singleton.Register(Core.itemOldTexMod, "oldtecmod");
 
       var recipePage = new RecipePage(RecipePageType.UniversalCrafter, "Old Tec", GadgetCoreAPI.LoadTexture2D("recipesOldTec")).Register();