MonsterNests.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. using UnityEngine;
  2. using GadgetCore.API;
  3. using GadgetCore.Util;
  4. using GadgetCore.API.ConfigMenu;
  5. using MonsterNests.Scripts;
  6. namespace MonsterNests
  7. {
  8. [Gadget("MonsterNests", RequiredOnClients: true)]
  9. public class MonsterNests : Gadget<MonsterNests>
  10. {
  11. public const string MOD_VERSION = "1.0"; // Set this to the version of your mod.
  12. public const string CONFIG_VERSION = "1.0"; // Increment this whenever you change your mod's config file.
  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. }
  70. private void AlterObjectSpike(ObjectInfo info, Texture2D texture)
  71. {
  72. var obj = (GameObject)Resources.Load(info.ResourcePath);
  73. obj.name = "plant";
  74. var o = GameObject.Instantiate(obj.transform.GetChild(0).gameObject);
  75. o.transform.SetParent(obj.transform);
  76. o.transform.localPosition = obj.transform.GetChild(0).localPosition + new Vector3(0, 0.3125f * 1.5f, -1.05f);
  77. var haz = o.AddComponent<HazardScript>();
  78. haz.damage = 2;
  79. var box = o.AddComponent<BoxCollider>();
  80. box.size = new Vector3(1.25f, 1.25f, 4);
  81. box.isTrigger = true;
  82. obj.transform.GetChild(1).localPosition = new Vector3(0, 2.2f, 0);
  83. var ani = o.GetComponent<Animation>();
  84. ani.playAutomatically = true;
  85. AnimationClip clip = new AnimationClip
  86. {
  87. name = "plantSquish",
  88. wrapMode = WrapMode.Loop,
  89. legacy = true
  90. };
  91. 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)));
  92. 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)));
  93. ani.RemoveClip("shake_0");
  94. ani.AddClip(clip, "plantSquish");
  95. ani.clip = clip;
  96. o.GetComponent<Renderer>().material
  97. = new Material(o.GetComponent<Renderer>().material) { mainTexture = texture };
  98. GadgetCoreAPI.AddCustomResource(info.ResourcePath, obj);
  99. }
  100. private void AlterObjectAncientCrystal(ObjectInfo info, Texture2D texture)
  101. {
  102. var obj = (GameObject)Resources.Load(info.ResourcePath);
  103. obj.name = "plant";
  104. var o = GameObject.Instantiate(obj.transform.GetChild(0).gameObject);
  105. o.transform.SetParent(obj.transform);
  106. o.transform.localPosition = obj.transform.GetChild(0).localPosition + new Vector3(0, 0.3125f * 2f, 0);
  107. obj.transform.GetChild(1).localPosition = new Vector3(0, 2.2f, 0);
  108. var ani = o.GetComponent<Animation>();
  109. ani.playAutomatically = true;
  110. AnimationClip clip = new AnimationClip
  111. {
  112. name = "plantSquish",
  113. wrapMode = WrapMode.Loop,
  114. legacy = true
  115. };
  116. 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)));
  117. 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)));
  118. ani.RemoveClip("shake_0");
  119. ani.AddClip(clip, "plantSquish");
  120. ani.clip = clip;
  121. o.GetComponent<Renderer>().material
  122. = new Material(o.GetComponent<Renderer>().material) { mainTexture = texture };
  123. GadgetCoreAPI.AddCustomResource(info.ResourcePath, obj);
  124. }
  125. private void CreatGoldenShroom(string name, Texture2D textureHead, Texture2D textureBody)
  126. {
  127. GameObject gameObject = Object.Instantiate<GameObject>((GameObject)Resources.Load("e/shroomy1"));
  128. Renderer rendererHead = gameObject.transform.GetChild(0).GetChild(0).GetChild(1).GetComponentInChildren<Renderer>();
  129. rendererHead.material = new Material(Shader.Find("Unlit/Transparent"))
  130. {
  131. mainTexture = textureHead
  132. };
  133. Renderer rendererBody = gameObject.transform.GetChild(0).GetChild(0).GetChild(0).GetComponentInChildren<Renderer>();
  134. rendererBody.material = new Material(Shader.Find("Unlit/Transparent"))
  135. {
  136. mainTexture = textureBody
  137. };
  138. Component.DestroyImmediate(gameObject.GetComponent<RolandBall>());
  139. gameObject.AddComponent<GoldenShroomScript>();
  140. GadgetCoreAPI.AddCustomResource("e/MonsterNests/" + name, gameObject);
  141. }
  142. private void CreatGoldenShroomProjectile(string name, Texture2D texture)
  143. {
  144. GameObject gameObject = Object.Instantiate<GameObject>((GameObject)Resources.Load("proj/ballProj"));
  145. Renderer rendererHead = gameObject.transform.GetChild(0).GetComponentInChildren<Renderer>();
  146. rendererHead.material = new Material(Shader.Find("Unlit/Transparent"))
  147. {
  148. mainTexture = texture
  149. };
  150. Renderer rendererBody = gameObject.transform.GetChild(1).GetComponentInChildren<Renderer>();
  151. rendererBody.material = new Material(Shader.Find("Unlit/Transparent"))
  152. {
  153. mainTexture = texture
  154. };
  155. gameObject.GetComponent<HazardScript>().damage = 8;
  156. GadgetCoreAPI.AddCustomResource("proj/MonsterNests/" + name, gameObject);
  157. }
  158. }
  159. }