Patch_ObjectScript_Die.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using GadgetCore.API;
  2. using HarmonyLib;
  3. using System.Collections;
  4. using UnityEngine;
  5. namespace MonsterNests.Patches
  6. {
  7. [HarmonyPatch(typeof(ObjectScript))]
  8. [HarmonyPatch("Die")]
  9. [HarmonyGadget("MonsterNests")]
  10. public static class Patch_ObjectScript_Die
  11. {
  12. [HarmonyPostfix]
  13. public static void Prefix(ObjectScript __instance, ref int ___id)
  14. {
  15. if (___id == Core.objectBugspotBig.GetID())
  16. {
  17. GameScript.cadetValue += 34;
  18. if (Network.isServer)
  19. {
  20. GadgetCoreAPI.CallCustomRPC(MonsterNests.RPCMonsterNestsShake, RPCMode.All, new object[] { 0 });
  21. __instance.StartCoroutine(SpawnMultiple(__instance.transform.position.x, __instance.transform.position.y, 10, 6, "e/wasp", 0.1f));
  22. }
  23. }
  24. if (___id == Core.objectBugTree.GetID())
  25. {
  26. GameScript.cadetValue += 34;
  27. if (Network.isServer)
  28. {
  29. GadgetCoreAPI.CallCustomRPC(MonsterNests.RPCMonsterNestsShake, RPCMode.All, new object[] { 0 });
  30. __instance.StartCoroutine(SpawnMultiple(__instance.transform.position.x, __instance.transform.position.y, 10, 3, "e/wasp", 0.2f));
  31. }
  32. }
  33. else if (___id == Core.objectSpikePlant.GetID())
  34. {
  35. GameScript.cadetValue += 34;
  36. if (Network.isServer)
  37. {
  38. GadgetCoreAPI.CallCustomRPC(MonsterNests.RPCMonsterNestsShake, RPCMode.All, new object[] { 0 });
  39. __instance.StartCoroutine(SpawnMultiple(__instance.transform.position.x, __instance.transform.position.y, 0, 12, "haz/vinegas", 0.1f));
  40. }
  41. }
  42. else if (___id == Core.objectSpikePlantCM.GetID())
  43. {
  44. GameScript.cadetValue += 34;
  45. if (Network.isServer)
  46. {
  47. GadgetCoreAPI.CallCustomRPC(MonsterNests.RPCMonsterNestsShake, RPCMode.All, new object[] { 0 });
  48. __instance.StartCoroutine(SpawnMultiple(__instance.transform.position.x, __instance.transform.position.y, 0, 6, "e/sliver", 0.3f));
  49. }
  50. }
  51. else if (___id == Core.objectSpiderEgg.GetID() || ___id == Core.objectSpiderEggCM.GetID())
  52. {
  53. GameScript.cadetValue += 34;
  54. if (Network.isServer)
  55. {
  56. GadgetCoreAPI.CallCustomRPC(MonsterNests.RPCMonsterNestsShake, RPCMode.All, new object[] { 0 });
  57. __instance.StartCoroutine(SpawnMultiple(__instance.transform.position.x, __instance.transform.position.y, 4, 10, "e/rockspider", 0.3f));
  58. }
  59. }
  60. else if (___id == Core.objectWizShroom.GetID() || ___id == Core.objectSpiderEggCM.GetID())
  61. {
  62. GameScript.cadetValue += 34;
  63. if (Network.isServer)
  64. {
  65. GadgetCoreAPI.CallCustomRPC(MonsterNests.RPCMonsterNestsShake, RPCMode.All, new object[] { 0 });
  66. Network.Instantiate(Resources.Load("e/Shroomwizard"), new Vector3(__instance.transform.position.x, __instance.transform.position.y + 5f, 0f), Quaternion.identity, 0);
  67. }
  68. }
  69. else if (___id == Core.objectGoldenShroom.GetID())
  70. {
  71. GameScript.cadetValue += 34;
  72. if (Network.isServer)
  73. {
  74. GadgetCoreAPI.CallCustomRPC(MonsterNests.RPCMonsterNestsShake, RPCMode.All, new object[] { 0 });
  75. Network.Instantiate(Resources.Load("e/MonsterNests/goldenShroom"), new Vector3(__instance.transform.position.x, __instance.transform.position.y + 1.1f, 0f), Quaternion.identity, 0);
  76. }
  77. }
  78. else if (___id == Core.objectAncientCrystal.GetID() || ___id == Core.objectAncientCrystalCM.GetID())
  79. {
  80. GameScript.cadetValue += 34;
  81. if (Network.isServer)
  82. {
  83. GadgetCoreAPI.CallCustomRPC(MonsterNests.RPCMonsterNestsShake, RPCMode.All, new object[] { 0 });
  84. Network.Instantiate(Resources.Load("e/golem"), new Vector3(__instance.transform.position.x, __instance.transform.position.y + 1.1f, 0f), Quaternion.identity, 0);
  85. }
  86. }
  87. else if (___id == Core.objectPlagueNest.GetID())
  88. {
  89. GameScript.cadetValue += 34;
  90. if (Network.isServer)
  91. {
  92. GadgetCoreAPI.CallCustomRPC(MonsterNests.RPCMonsterNestsShake, RPCMode.All, new object[] { 0 });
  93. //Network.Instantiate(Resources.Load("e/plaguebeast"), new Vector3(__instance.transform.position.x, __instance.transform.position.y + 1.1f, 0f), Quaternion.identity, 0);
  94. }
  95. }
  96. else if (___id == Core.objectFrozenWisp.GetID())
  97. {
  98. GameScript.cadetValue += 34;
  99. if (Network.isServer)
  100. {
  101. GadgetCoreAPI.CallCustomRPC(MonsterNests.RPCMonsterNestsShake, RPCMode.All, new object[] { 0 });
  102. __instance.StartCoroutine(SpawnMultiple(__instance.transform.position.x, __instance.transform.position.y, 5, 6, "e/wisp", 0.35f));
  103. }
  104. }
  105. else if (___id == Core.objectMolten.GetID())
  106. {
  107. GameScript.cadetValue += 34;
  108. if (Network.isServer)
  109. {
  110. GadgetCoreAPI.CallCustomRPC(MonsterNests.RPCMonsterNestsShake, RPCMode.All, new object[] { 0 });
  111. __instance.StartCoroutine(SpawnMultiple(__instance.transform.position.x, __instance.transform.position.y, 5, 6, "e/wyvern", 0.35f));
  112. }
  113. }
  114. }
  115. public static IEnumerator Shake()
  116. {
  117. Camera.main.GetComponent<Animation>().Play("shake");
  118. yield return new WaitForSeconds(1.0f);
  119. Camera.main.GetComponent<Animation>().Stop();
  120. Camera.main.transform.eulerAngles = new Vector3(0f, 0f, 0f);
  121. yield break;
  122. }
  123. private static IEnumerator SpawnMultiple(float xBase, float yBase, float range, int amount, string name, float speed)
  124. {
  125. for (int i = 0; i < amount; i++)
  126. {
  127. int x = 0;
  128. int y = 0;
  129. if (range > 0)
  130. {
  131. x = Random.Range(-1 * (int)(range * 10), (int)(range * 10));
  132. y = Random.Range(-1 * (int)(range * 10), (int)(range * 10));
  133. }
  134. Network.Instantiate(Resources.Load(name), new Vector3(xBase + x / 10f, yBase + 1.1f + y / 10f, 0f), Quaternion.identity, 0);
  135. yield return new WaitForSeconds(speed);
  136. }
  137. yield break;
  138. }
  139. }
  140. }