Patch_KylockeStand_Awake.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 MultiplayerClientSpawn.Patches
  9. {
  10. [HarmonyPatch(typeof(KylockeStand))]
  11. [HarmonyPatch("Awake")]
  12. [HarmonyGadget("MultiplayerClientSpawn")]
  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 LightColorUpdateLoop(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 = getItemIdFromIndex(colorIndex);
  34. instance.GetComponent<NetworkView>().RPC("Set", RPCMode.All, new object[]
  35. {
  36. new int[]{ instance.itemID, instance.cost }
  37. });
  38. }
  39. yield return new WaitForSeconds(9f);
  40. colorIndex = (colorIndex + 1) % 2;
  41. }
  42. }
  43. }
  44. private static IEnumerator StartUpdateLoop(KylockeStand instance)
  45. {
  46. if (instance.itemID == 2403)
  47. {
  48. instance.StartCoroutine(LightColorUpdateLoop(instance));
  49. CoroutineManager newComponent = instance.gameObject.AddComponent<CoroutineManager>();
  50. newComponent.SetAction(new System.Action(() => { newComponent.StartCoroutine(LightColorUpdateLoop(instance)); }));
  51. }
  52. yield break;
  53. }
  54. private static int colorIndex = 0;
  55. private static int getItemIdFromIndex(int i)
  56. {
  57. switch (i)
  58. {
  59. case 0:
  60. return 2403;
  61. case 1:
  62. return Core.itemSpawnId;
  63. }
  64. return 2403;
  65. }
  66. }
  67. }