Patch_KylockeStand_Awake.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using GadgetCore.API;
  2. using GadgetCore.Util;
  3. using HarmonyLib;
  4. using System.Collections;
  5. using System.Threading;
  6. using System.Windows.Threading;
  7. using UnityEngine;
  8. namespace ShipDecorations.Patches
  9. {
  10. [HarmonyPatch(typeof(KylockeStand))]
  11. [HarmonyPatch("Awake")]
  12. [HarmonyGadget("ShipDecorations")]
  13. public static class Patch_KylockeStand_Awake
  14. {
  15. [HarmonyPostfix]
  16. public static void Prefix(KylockeStand __instance)
  17. {
  18. __instance.StartCoroutine(StartUpdateLoop(__instance));
  19. }
  20. public static IEnumerator DecpStockUpdateLoop(KylockeStand instance)
  21. {
  22. while (!Network.isServer && !Network.isClient)
  23. {
  24. yield return new WaitForSeconds(0f);
  25. }
  26. if (Network.isServer)
  27. {
  28. while (true)
  29. {
  30. yield return new WaitForSeconds(1f);
  31. if (instance.gameObject.activeSelf && Network.isServer)
  32. {
  33. instance.itemID = Core.itemStoreList[colorIndex];
  34. instance.cost = Core.itemStorePriceList[instance.itemID];
  35. instance.GetComponent<NetworkView>().RPC("Set", RPCMode.All, new object[]
  36. {
  37. new int[]{ instance.itemID, instance.cost }
  38. });
  39. }
  40. yield return new WaitForSeconds(9f);
  41. colorIndex = (colorIndex + 1) % Core.itemStoreList.Count;
  42. }
  43. }
  44. }
  45. private static IEnumerator StartUpdateLoop(KylockeStand instance)
  46. {
  47. if (instance.itemID == Core.itemStoreList[0])
  48. {
  49. instance.StartCoroutine(DecpStockUpdateLoop(instance));
  50. CoroutineManager newComponent = instance.gameObject.AddComponent<CoroutineManager>();
  51. newComponent.SetAction(new System.Action(() => { newComponent.StartCoroutine(DecpStockUpdateLoop(instance)); }));
  52. }
  53. else if (instance.itemID == 2403)
  54. {
  55. while (!Network.isServer && !Network.isClient)
  56. {
  57. yield return new WaitForSeconds(0f);
  58. }
  59. if (Network.isServer)
  60. {
  61. var obj = ((GameObject)Network.Instantiate(Resources.Load("npc/buildStand"), new Vector3(-250f + 4 * 1, -5.99f, 0.19f), instance.transform.rotation, 0));
  62. obj.GetComponent<KylockeStand>().GetComponent<NetworkView>().RPC("Set", RPCMode.AllBuffered, new object[] { new int[] { Core.itemStoreList[0], 1000 } });
  63. obj.GetComponent<KylockeStand>().Awake();
  64. }
  65. }
  66. yield break;
  67. }
  68. private static int colorIndex = 0;
  69. }
  70. }