| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- using GadgetCore.API;
- using GadgetCore.Util;
- using HarmonyLib;
- using System.Collections;
- using System.Threading;
- using System.Windows.Threading;
- using UnityEngine;
- namespace MoreLights.Patches
- {
- [HarmonyPatch(typeof(KylockeStand))]
- [HarmonyPatch("Awake")]
- [HarmonyGadget("MoreLights")]
- public static class Patch_KylockeStand_Awake
- {
- [HarmonyPostfix]
- public static void Prefix(KylockeStand __instance)
- {
- __instance.StartCoroutine(StartUpdateLoop(__instance));
- }
- public static IEnumerator LightColorUpdateLoop(KylockeStand instance)
- {
- while (!Network.isServer && !Network.isClient)
- {
- yield return new WaitForSeconds(0f);
- }
- if (Network.isServer)
- {
- while (true)
- {
- yield return new WaitForSeconds(1f);
- if (instance.gameObject.activeSelf && Network.isServer)
- {
- instance.itemID = getItemIdFromIndex(colorIndex);
- instance.GetComponent<NetworkView>().RPC("Set", RPCMode.All, new object[]
- {
- new int[]{ instance.itemID, instance.cost }
- });
- }
- yield return new WaitForSeconds(9f);
- colorIndex = (colorIndex + 1) % 6;
- }
- }
- }
- private static IEnumerator StartUpdateLoop(KylockeStand instance)
- {
- if (instance.itemID == 2402)
- {
- instance.itemID = Core.itemWhiteLampId;
- foreach (var gadget in GadgetCore.API.Gadgets.ListAllEnabledGadgets())
- if (gadget.Info?.ModName == "ItemFrames")
- {
- instance.transform.localPosition += new Vector3(4, 0, 0);
- break;
- }
- }
- else if (instance.itemID == 2401)
- {
- colorIndex = Random.Range(0, 6);
- instance.StartCoroutine(LightColorUpdateLoop(instance));
- CoroutineManager newComponent = instance.gameObject.AddComponent<CoroutineManager>();
- newComponent.SetAction(new System.Action(() => { newComponent.StartCoroutine(LightColorUpdateLoop(instance)); }));
- }
- yield break;
- }
- private static int colorIndex = 0;
- private static int getItemIdFromIndex(int i)
- {
- switch (i)
- {
- case 0:
- return Core.itemYellowLampId;
- case 1:
- return Core.itemOrangeLampId;
- case 2:
- return 2402;
- case 3:
- return Core.itemPurpleLampId;
- case 4:
- return 2401;
- case 5:
- return Core.itemGreenLampId;
- }
- return 2401;
- }
- }
- }
|