Browse Source

[PlatformBlock] [2.0.2.1] Use Old Market Stand Generation

Zariteis 4 years ago
parent
commit
938aa01d32

+ 37 - 0
PlatformBlock/Patches/Patch_KylockeStand_Awake.cs

@@ -0,0 +1,37 @@
+using System;
+using System.Collections;
+using GadgetCore.API;
+using HarmonyLib;
+using UnityEngine;
+
+namespace PlatformBlock.Patches
+{
+  [HarmonyPatch(typeof(KylockeStand))]
+  [HarmonyPatch("Awake")]
+  [HarmonyGadget("PlatformBlock")]
+  public static class Patch_KylockeStand_Awake
+  {
+    [HarmonyPrefix]
+    public static void Prefix(KylockeStand __instance)
+    {
+      __instance.StartCoroutine(Patch_KylockeStand_Awake.WaitAndCreate(__instance));
+    }
+
+    private static IEnumerator WaitAndCreate(KylockeStand instance)
+    {
+      if (instance.itemID == 2403)
+      {
+        while (!Network.isServer && !Network.isClient)
+        {
+          yield return new WaitForSeconds(0f);
+        }
+        if (Network.isServer)
+        {
+          var obj = ((GameObject)Network.Instantiate(Resources.Load("npc/buildStand"), new Vector3(-250f, -5.99f, 0.19f), instance.transform.rotation, 0));
+          obj.GetComponent<KylockeStand>().GetComponent<NetworkView>().RPC("Set", RPCMode.AllBuffered, new object[] { new int[] { Core.itemPlatformId, 1000 } });
+        }
+      }
+      yield break;
+    }
+  }
+}

+ 42 - 0
PlatformBlock/Patches/Patch_KylockeStand_Set.cs

@@ -0,0 +1,42 @@
+using System;
+using System.Collections;
+using GadgetCore.API;
+using HarmonyLib;
+using UnityEngine;
+
+namespace PlatformBlock.Patches
+{
+	[HarmonyPatch(typeof(KylockeStand))]
+	[HarmonyPatch("Set")]
+	[HarmonyGadget("PlatformBlock")]
+	public static class Patch_KylockeStand_Set
+	{
+
+		[HarmonyPostfix]
+		public static bool Prefix(KylockeStand __instance, int[] p)
+		{
+			if (p[0] == Core.itemPlatformId)
+			{
+				__instance.itemID = p[0];
+				__instance.cost = p[1];
+				__instance.icon.GetComponent<Renderer>().material = (Material)Resources.Load("i/i" + __instance.itemID.ToString());
+				__instance.txtCost[0].text = string.Empty + __instance.cost.ToString();
+				__instance.txtCost[1].text = __instance.txtCost[0].text;
+				__instance.txtName[0].text = string.Empty + ItemRegistry.GetItem(__instance.itemID).GetName();
+				__instance.txtName[1].text = __instance.txtName[0].text;
+				__instance.StartCoroutine(Patch_KylockeStand_Set.DoUpdatePlatformStand(__instance));
+				return false;
+			}
+			return true;
+		}
+
+		private static IEnumerator DoUpdatePlatformStand(KylockeStand instance)
+		{
+			instance.isBuild = true;
+			instance.isCredits = false;
+			instance.isTrophies = false;
+			instance.currency.GetComponent<Renderer>().material = (Material)Resources.Load("i/i57");
+			yield break;
+		}
+	}
+}

+ 1 - 1
PlatformBlock/PlatformBlock.cs

@@ -32,7 +32,7 @@ namespace PlatformBlock
     {
       if (scene.buildIndex == 1)
       {
-        GadgetCoreAPI.CreateMarketStand(ItemRegistry.GetItem(Core.itemPlatformId), new Vector2(-138f - 3 * 4, -7.49f), 500);
+        // GadgetCoreAPI.CreateMarketStand(ItemRegistry.GetItem(Core.itemPlatformId), new Vector2(-138f - 3 * 4, -7.49f), 500);
       }
     }
   }

+ 0 - 3
PlatformBlock/PlatformBlock.csproj

@@ -200,7 +200,4 @@
       <EmbedInteropTypes>false</EmbedInteropTypes>
     </Reference>
   </ItemGroup>
-  <ItemGroup>
-    <Folder Include="Patches\" />
-  </ItemGroup>
 </Project>