MonsterNests.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. using GadgetCore.API;
  2. using GadgetCore.API.ConfigMenu;
  3. using MonsterNests.Scripts;
  4. using UnityEngine;
  5. namespace MonsterNests
  6. {
  7. [Gadget("MonsterNests", RequiredOnClients: true)]
  8. public class MonsterNests : Gadget<MonsterNests>
  9. {
  10. public const string MOD_VERSION = "1.0"; // Set this to the version of your mod.
  11. public const string CONFIG_VERSION = "1.0"; // Increment this whenever you change your mod's config file.
  12. public const string RPCMonsterNestsShake = "MonsterNestsShake";
  13. protected override void LoadConfig()
  14. {
  15. Config.Load();
  16. string fileVersion = Config.ReadString("ConfigVersion", CONFIG_VERSION, comments: "The Config Version (not to be confused with mod version)");
  17. if (fileVersion != CONFIG_VERSION)
  18. {
  19. Config.Reset();
  20. Config.WriteString("ConfigVersion", CONFIG_VERSION, comments: "The Config Version (not to be confused with mod version)");
  21. }
  22. Config.Reset();
  23. Config.Save();
  24. }
  25. public override IGadgetConfigMenu GetConfigMenu() { return null; }
  26. public override string GetModDescription()
  27. {
  28. return "A mod that adds some rare dangerous harvestables.";
  29. }
  30. protected override void Initialize()
  31. {
  32. Logger.Log("Monster Nests v" + Info.Mod.Version);
  33. Core.logger = Logger;
  34. Texture2D textureBugspotBig = GadgetCoreAPI.LoadTexture2D("objects/bugspotBig.png");
  35. Texture2D textureBugTree = GadgetCoreAPI.LoadTexture2D("objects/bugTree.png");
  36. Texture2D textureSpikePlant = GadgetCoreAPI.LoadTexture2D("objects/spikePlant.png");
  37. Texture2D textureSpikePlantTop = GadgetCoreAPI.LoadTexture2D("objects/spikePlantTop.png");
  38. Texture2D textureSpikePlantCM = GadgetCoreAPI.LoadTexture2D("objects/spikePlantCM.png");
  39. Texture2D textureSpikePlantCMTop = GadgetCoreAPI.LoadTexture2D("objects/spikePlantCMTop.png");
  40. Texture2D textureSpiderEgg = GadgetCoreAPI.LoadTexture2D("objects/spiderEgg.png");
  41. Texture2D textureSpiderEggCM = GadgetCoreAPI.LoadTexture2D("objects/spiderEggCM.png");
  42. Texture2D textureGoldenShroom = GadgetCoreAPI.LoadTexture2D("objects/goldenShroom.png");
  43. Texture2D textureWizShroom = GadgetCoreAPI.LoadTexture2D("objects/wizShroom.png");
  44. Texture2D textureAncientCrystal = GadgetCoreAPI.LoadTexture2D("objects/ancientCrystal.png");
  45. Texture2D textureAncientCrystalCMTop = GadgetCoreAPI.LoadTexture2D("objects/ancientCrystalCMTop.png");
  46. Texture2D textureAncientCrystalTop = GadgetCoreAPI.LoadTexture2D("objects/ancientCrystalTop.png");
  47. Texture2D texturePlagueNest = GadgetCoreAPI.LoadTexture2D("objects/plagueNest.png");
  48. Texture2D textureFrozenWisp = GadgetCoreAPI.LoadTexture2D("objects/frozenWisp.png");
  49. Texture2D textureMolten = GadgetCoreAPI.LoadTexture2D("objects/molten.png");
  50. Core.objectBugspotBig = new ObjectInfo(ObjectType.BUGSPOT, new Item(31, 1, 0, 0, 0, new int[3], new int[3]), 16, textureBugspotBig).Register("bugspotBig");
  51. Core.objectBugTree = new ObjectInfo(ObjectType.TREE, new Item(11, 1, 0, 0, 0, new int[3], new int[3]), 16, textureBugTree).Register("bugTree");
  52. Core.objectSpikePlant = new ObjectInfo(ObjectType.PLANT, new Item(11, 1, 0, 0, 0, new int[3], new int[3]), 16, textureSpikePlant).Register("spikePlant");
  53. Core.objectSpikePlantCM = new ObjectInfo(ObjectType.PLANT, new Item(11, 1, 0, 0, 0, new int[3], new int[3]), 16, textureSpikePlantCM).Register("spikePlantCM");
  54. Core.objectSpiderEgg = new ObjectInfo(ObjectType.ORE, new Item(2, 1, 0, 0, 0, new int[3], new int[3]), 16, textureSpiderEgg).Register("spiderEgg");
  55. Core.objectSpiderEggCM = new ObjectInfo(ObjectType.ORE, new Item(2, 1, 0, 0, 0, new int[3], new int[3]), 16, textureSpiderEggCM).Register("spiderEggCM");
  56. Core.objectGoldenShroom = new ObjectInfo(ObjectType.PLANT, new Item(12, 1, 0, 0, 0, new int[3], new int[3]), 16, textureGoldenShroom).Register("goldenShroom");
  57. Core.objectWizShroom = new ObjectInfo(ObjectType.PLANT, new Item(12, 1, 0, 0, 0, new int[3], new int[3]), 16, textureWizShroom).Register("wizShroom");
  58. Core.objectAncientCrystal = new ObjectInfo(ObjectType.ORE, new Item(57, 1, 0, 0, 0, new int[3], new int[3]), 106, textureAncientCrystal).Register("ancientCrystal");
  59. Core.objectAncientCrystalCM = new ObjectInfo(ObjectType.ORE, new Item(57, 1, 0, 0, 0, new int[3], new int[3]), 106, textureAncientCrystal).Register("ancientCrystalCM");
  60. Core.objectPlagueNest = new ObjectInfo(ObjectType.TREE, new Item(51, 1, 0, 0, 0, new int[3], new int[3]), 106, texturePlagueNest).Register("plagueNest");
  61. Core.objectFrozenWisp = new ObjectInfo(ObjectType.ORE, new Item(3, 1, 0, 0, 0, new int[3], new int[3]), 16, textureFrozenWisp).Register("frozenWisp");
  62. Core.objectMolten = new ObjectInfo(ObjectType.ORE, new Item(5, 1, 0, 0, 0, new int[3], new int[3]), 16, textureMolten).Register("molten");
  63. CreatGoldenShroom("goldenShroom", GadgetCoreAPI.LoadTexture2D("entity/goldenShroomHead.png"), GadgetCoreAPI.LoadTexture2D("entity/goldenShroomTop.png"));
  64. CreatGoldenShroomProjectile("goldenShroom", GadgetCoreAPI.LoadTexture2D("projectiles/goldenShroom.png"));
  65. AlterObjectSpike(Core.objectSpikePlant, textureSpikePlantTop);
  66. AlterObjectSpike(Core.objectSpikePlantCM, textureSpikePlantCMTop);
  67. AlterObjectAncientCrystal(Core.objectAncientCrystal, textureAncientCrystalTop);
  68. AlterObjectAncientCrystal(Core.objectAncientCrystalCM, textureAncientCrystalCMTop);
  69. GadgetCoreAPI.RegisterCustomRPC(RPCMonsterNestsShake, (e) =>
  70. {
  71. InstanceTracker.GameScript.StartCoroutine(Patches.Patch_ObjectScript_Die.Shake());
  72. });
  73. }
  74. private void AlterObjectSpike(ObjectInfo info, Texture2D texture)
  75. {
  76. var obj = (GameObject)Resources.Load(info.ResourcePath);
  77. obj.name = "plant";
  78. var o = GameObject.Instantiate(obj.transform.GetChild(0).gameObject);
  79. o.transform.SetParent(obj.transform);
  80. o.transform.localPosition = obj.transform.GetChild(0).localPosition + new Vector3(0, 0.3125f * 1.5f, -1.05f);
  81. var haz = o.AddComponent<HazardScript>();
  82. haz.damage = 2;
  83. var box = o.AddComponent<BoxCollider>();
  84. box.size = new Vector3(1.25f, 1.25f, 4);
  85. box.isTrigger = true;
  86. obj.transform.GetChild(1).localPosition = new Vector3(0, 2.2f, 0);
  87. var ani = o.GetComponent<Animation>();
  88. ani.playAutomatically = true;
  89. AnimationClip clip = new AnimationClip
  90. {
  91. name = "plantSquish",
  92. wrapMode = WrapMode.Loop,
  93. legacy = true
  94. };
  95. clip.SetCurve("", typeof(Transform), "m_LocalScale.x", new AnimationCurve(new Keyframe(0f, 1.9f, 0f, 0f), new Keyframe(0.371f, 2.1f, 0f, 0f), new Keyframe(1f, 1.9f, 0f, 0f)));
  96. clip.SetCurve("", typeof(Transform), "m_LocalScale.y", new AnimationCurve(new Keyframe(0f, 2.1f, 0f, 0f), new Keyframe(0.442f, 1.9f, 0f, 0f), new Keyframe(1f, 2.1f, 0f, 0f)));
  97. ani.RemoveClip("shake_0");
  98. ani.AddClip(clip, "plantSquish");
  99. ani.clip = clip;
  100. o.GetComponent<Renderer>().material
  101. = new Material(o.GetComponent<Renderer>().material) { mainTexture = texture };
  102. GadgetCoreAPI.AddCustomResource(info.ResourcePath, obj);
  103. }
  104. private void AlterObjectAncientCrystal(ObjectInfo info, Texture2D texture)
  105. {
  106. var obj = (GameObject)Resources.Load(info.ResourcePath);
  107. obj.name = "plant";
  108. var o = GameObject.Instantiate(obj.transform.GetChild(0).gameObject);
  109. o.transform.SetParent(obj.transform);
  110. o.transform.localPosition = obj.transform.GetChild(0).localPosition + new Vector3(0, 0.3125f * 2f, 0);
  111. obj.transform.GetChild(1).localPosition = new Vector3(0, 2.2f, 0);
  112. var ani = o.GetComponent<Animation>();
  113. ani.playAutomatically = true;
  114. AnimationClip clip = new AnimationClip
  115. {
  116. name = "plantSquish",
  117. wrapMode = WrapMode.Loop,
  118. legacy = true
  119. };
  120. clip.SetCurve("", typeof(Transform), "m_LocalScale.x", new AnimationCurve(new Keyframe(0f, 1.8f, 0f, 0f), new Keyframe(0.171f, 2.1f, 0f, 0f), new Keyframe(0.5f, 1.8f, 0f, 0f)));
  121. clip.SetCurve("", typeof(Transform), "m_LocalScale.y", new AnimationCurve(new Keyframe(0f, 2.1f, 0f, 0f), new Keyframe(0.142f, 1.8f, 0f, 0f), new Keyframe(0.5f, 2.1f, 0f, 0f)));
  122. ani.RemoveClip("shake_0");
  123. ani.AddClip(clip, "plantSquish");
  124. ani.clip = clip;
  125. o.GetComponent<Renderer>().material
  126. = new Material(o.GetComponent<Renderer>().material) { mainTexture = texture };
  127. GadgetCoreAPI.AddCustomResource(info.ResourcePath, obj);
  128. }
  129. private void CreatGoldenShroom(string name, Texture2D textureHead, Texture2D textureBody)
  130. {
  131. GameObject gameObject = Object.Instantiate<GameObject>((GameObject)Resources.Load("e/shroomy1"));
  132. Renderer rendererHead = gameObject.transform.GetChild(0).GetChild(0).GetChild(1).GetComponentInChildren<Renderer>();
  133. rendererHead.material = new Material(Shader.Find("Unlit/Transparent"))
  134. {
  135. mainTexture = textureHead
  136. };
  137. Renderer rendererBody = gameObject.transform.GetChild(0).GetChild(0).GetChild(0).GetComponentInChildren<Renderer>();
  138. rendererBody.material = new Material(Shader.Find("Unlit/Transparent"))
  139. {
  140. mainTexture = textureBody
  141. };
  142. Component.DestroyImmediate(gameObject.GetComponent<RolandBall>());
  143. gameObject.AddComponent<GoldenShroomScript>();
  144. GadgetCoreAPI.AddCustomResource("e/MonsterNests/" + name, gameObject);
  145. }
  146. private void CreatGoldenShroomProjectile(string name, Texture2D texture)
  147. {
  148. GameObject gameObject = Object.Instantiate<GameObject>((GameObject)Resources.Load("proj/ballProj"));
  149. Renderer rendererHead = gameObject.transform.GetChild(0).GetComponentInChildren<Renderer>();
  150. rendererHead.material = new Material(Shader.Find("Unlit/Transparent"))
  151. {
  152. mainTexture = texture
  153. };
  154. Renderer rendererBody = gameObject.transform.GetChild(1).GetComponentInChildren<Renderer>();
  155. rendererBody.material = new Material(Shader.Find("Unlit/Transparent"))
  156. {
  157. mainTexture = texture
  158. };
  159. gameObject.GetComponent<HazardScript>().damage = 8;
  160. GadgetCoreAPI.AddCustomResource("proj/MonsterNests/" + name, gameObject);
  161. }
  162. }
  163. }