| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using GadgetCore.API;
- using GadgetCore.Util;
- using HarmonyLib;
- using System.Collections;
- using System.Threading;
- using System.Windows.Threading;
- using UnityEngine;
- namespace ShipDecorations.Patches
- {
- [HarmonyPatch(typeof(KylockeStand))]
- [HarmonyPatch("Awake")]
- [HarmonyGadget("ShipDecorations")]
- public static class Patch_KylockeStand_Awake
- {
- [HarmonyPostfix]
- public static void Prefix(KylockeStand __instance)
- {
- __instance.StartCoroutine(StartUpdateLoop(__instance));
- }
- public static IEnumerator DecpStockUpdateLoop(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 = Core.itemStoreList[colorIndex];
- instance.cost = Core.itemStorePriceList[instance.itemID];
- instance.GetComponent<NetworkView>().RPC("Set", RPCMode.All, new object[]
- {
- new int[]{ instance.itemID, instance.cost }
- });
- }
- yield return new WaitForSeconds(9f);
- colorIndex = (colorIndex + 1) % Core.itemStoreList.Count;
- }
- }
- }
- private static IEnumerator StartUpdateLoop(KylockeStand instance)
- {
- if (instance.itemID == Core.itemStoreList[0])
- {
- instance.StartCoroutine(DecpStockUpdateLoop(instance));
- CoroutineManager newComponent = instance.gameObject.AddComponent<CoroutineManager>();
- newComponent.SetAction(new System.Action(() => { newComponent.StartCoroutine(DecpStockUpdateLoop(instance)); }));
- }
- else 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 + 4 * 1, -5.99f, 0.19f), instance.transform.rotation, 0));
- obj.GetComponent<KylockeStand>().GetComponent<NetworkView>().RPC("Set", RPCMode.AllBuffered, new object[] { new int[] { Core.itemStoreList[0], 1000 } });
- obj.GetComponent<KylockeStand>().Awake();
- }
- }
- yield break;
- }
- private static int colorIndex = 0;
- }
- }
|