Patch_Chunk_SpawnBiomeSlot.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 Subworlds.Patches
  9. {
  10. [HarmonyPatch(typeof(Chunk))]
  11. [HarmonyPatch("SpawnBiomeSlot")]
  12. [HarmonyGadget("SubworldCore")]
  13. public static class Patch_Chunk_SpawnBiomeSlot
  14. {
  15. [HarmonyPostfix]
  16. public static bool Prefix(Chunk __instance, int a, int i, int mid, ref GameObject[] ___spawnSpot, ref GameObject[] ___spawnSpotMid, ref GameObject[] ___networkStuff, ref int ___temp)
  17. {
  18. Transform transform;
  19. if (mid == 1)
  20. transform = ___spawnSpotMid[i].transform;
  21. else
  22. transform = ___spawnSpot[i].transform;
  23. int num = UnityEngine.Random.Range(0, 100);
  24. if (num < 30 && !Core.shipPorterPlaced && Core.planetHasPirates)
  25. {
  26. Core.shipPorterPlaced = true;
  27. if (a == 0 || a == 1 || a == 2 || a == 3 || a == 4 || a == 5)
  28. {
  29. var portal = (GameObject)Network.Instantiate((GameObject)Resources.Load("portal"), transform.position + new Vector3(-0.5f, 1.5f - 0.05f, 0.2f), Quaternion.identity, 0);
  30. portal.name = "portal/5/obj";
  31. var iUA = portal.transform.GetChild(0).gameObject;
  32. portal.GetComponent<NetworkView>().RPC("Activate", RPCMode.All, new object[0]);
  33. iUA.GetComponent<NetworkView>().RPC("Set", RPCMode.AllBuffered, new object[] { Core.shipPlanet.GetID(), 0, 5 });
  34. ___networkStuff[___temp] = portal;
  35. ___temp++;
  36. var crates = (GameObject)Network.Instantiate(Resources.Load("obj/Subworlds/BrokenCrates1"), transform.position + new Vector3(1.5f, 0, 0.2f), Quaternion.identity, 0);
  37. ___networkStuff[___temp] = crates;
  38. ___temp++;
  39. return false;
  40. }
  41. }
  42. if (num < 50 && !Core.meteorPorterPlaced && Core.planetHasMeteors)
  43. {
  44. Core.meteorPorterPlaced = true;
  45. if (a == 0 || a == 1 || a == 2 || a == 3 || a == 4 || a == 5)
  46. {
  47. var portal = (GameObject)Network.Instantiate((GameObject)Resources.Load("portal"), transform.position + new Vector3(0.5f, 1.5f - 0.05f, 0.2f), Quaternion.identity, 0);
  48. portal.name = "portal/6/obj";
  49. var iUA = portal.transform.GetChild(0).gameObject;
  50. portal.GetComponent<NetworkView>().RPC("Activate", RPCMode.All, new object[0]);
  51. iUA.GetComponent<NetworkView>().RPC("Set", RPCMode.AllBuffered, new object[] { Core.meteroidPlanet.GetID(), 0, 6 });
  52. ___networkStuff[___temp] = portal;
  53. ___temp++;
  54. var crates = (GameObject)Network.Instantiate(Resources.Load("obj/Subworlds/BrokenMeteor"), transform.position + new Vector3(-1.5f, 0 + 2.02f, 0.2f), Quaternion.identity, 0);
  55. ___networkStuff[___temp] = crates;
  56. ___temp++;
  57. return false;
  58. }
  59. }
  60. return true;
  61. }
  62. }
  63. }