Browse Source

[CombatChipChest] [2.0.2.1] Use Awake creation of Market Stands

Zariteis 4 years ago
parent
commit
b22fab4d21

+ 8 - 1
CombatChipChest/CombatChipChest.cs

@@ -3,6 +3,7 @@ using GadgetCore.API;
 using System.Collections;
 using System;
 using UnityEngine.SceneManagement;
+using System.Reflection;
 
 namespace CombatChipChest
 {
@@ -50,7 +51,13 @@ namespace CombatChipChest
     {
       if (scene.buildIndex == 1)
       {
-        GadgetCoreAPI.CreateMarketStand(ItemRegistry.GetItem(Core.itemCombatChipChestId), new Vector2(-138f - 1 * 4, -7.49f), 100);
+        try
+        {
+          // GameObject obj = GadgetCoreAPI.CreateMarketStand(ItemRegistry.GetItem(Core.itemCombatChipChestId), new Vector2(-138f - 1 * 4, -7.49f), 100);
+          // // NetworkView network = obj.GetComponent<NetworkView>();
+          // // network.viewID = Network.AllocateViewID();
+        }
+        catch (Exception e) { Core.logger.LogConsole(e.Message); }
       }
     }
   }

+ 37 - 0
CombatChipChest/Patches/Patch_KylockeStand_Awake.cs

@@ -0,0 +1,37 @@
+using System;
+using System.Collections;
+using GadgetCore.API;
+using HarmonyLib;
+using UnityEngine;
+
+namespace CombatChipChest.Patches
+{
+  [HarmonyPatch(typeof(KylockeStand))]
+  [HarmonyPatch("Awake")]
+  [HarmonyGadget("CombatChipChest")]
+  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 + 8, -5.99f, 0.19f), instance.transform.rotation, 0));
+          obj.GetComponent<KylockeStand>().GetComponent<NetworkView>().RPC("Set", RPCMode.AllBuffered, new object[] { new int[] { Core.itemCombatChipChestId, 1000 } });
+        }
+      }
+      yield break;
+    }
+  }
+}

+ 42 - 0
CombatChipChest/Patches/Patch_KylockeStand_Set.cs

@@ -0,0 +1,42 @@
+using System;
+using System.Collections;
+using GadgetCore.API;
+using HarmonyLib;
+using UnityEngine;
+
+namespace CombatChipChest.Patches
+{
+	[HarmonyPatch(typeof(KylockeStand))]
+	[HarmonyPatch("Set")]
+	[HarmonyGadget("CombatChipChest")]
+	public static class Patch_KylockeStand_Set
+	{
+
+		[HarmonyPostfix]
+		public static bool Prefix(KylockeStand __instance, int[] p)
+		{
+			if (p[0] == Core.itemCombatChipChestId)
+			{
+				__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;
+		}
+	}
+}