ScrapYard.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. using GadgetCore.API;
  2. using ScrapYard.API;
  3. using System.Collections;
  4. using System.Reflection;
  5. using UnityEngine;
  6. using UnityEngine.SceneManagement;
  7. namespace ScrapYard
  8. {
  9. [Gadget("ScrapYard")]
  10. public class ScrapYard : Gadget<ScrapYard>
  11. {
  12. public const string MOD_VERSION = "1.0"; // Set this to the version of your mod.
  13. public const string CONFIG_VERSION = "1.0"; // Increment this whenever you change your mod's config file.
  14. protected override void LoadConfig()
  15. {
  16. Config.Load();
  17. string fileVersion = Config.ReadString("ConfigVersion", CONFIG_VERSION, comments: "The Config Version (not to be confused with mod version)");
  18. if (fileVersion != CONFIG_VERSION)
  19. {
  20. Config.Reset();
  21. Config.WriteString("ConfigVersion", CONFIG_VERSION, comments: "The Config Version (not to be confused with mod version)");
  22. }
  23. Config.Save();
  24. }
  25. public override string GetModDescription()
  26. {
  27. return "A mod that adds a scryp yard planet.";
  28. }
  29. protected override void Initialize()
  30. {
  31. Logger.Log("Scrap Yard v" + Info.Mod.Version);
  32. Core.logger = Logger;
  33. Texture2D texturePlanetIcon = GadgetCoreAPI.LoadTexture2D("planetScrapYard.png");
  34. Texture2D texturePlanetPrevIcon = GadgetCoreAPI.LoadTexture2D("planetScrapYardPrev.png");
  35. Texture2D texturePortalSign = GadgetCoreAPI.LoadTexture2D("signScrapYard.png");
  36. Texture2D textureBG = GadgetCoreAPI.LoadTexture2D("bgScrapYard.png");
  37. Texture2D textureBGExtension = GadgetCoreAPI.LoadTexture2D("bgScrapYardExtension.png");
  38. Texture2D textureBGTop = GadgetCoreAPI.LoadTexture2D("bgScrapYardTop.png");
  39. Texture2D textureParalex = GadgetCoreAPI.LoadTexture2D("parallax.png");
  40. Texture2D textureParalex0 = GadgetCoreAPI.LoadTexture2D("bScrapYardbg0.png");
  41. Texture2D textureParalex1 = GadgetCoreAPI.LoadTexture2D("bScrapYardbg1.png");
  42. Texture2D textureParalex2 = GadgetCoreAPI.LoadTexture2D("bScrapYardbg2.png");
  43. Texture2D textureParalex3 = GadgetCoreAPI.LoadTexture2D("bScrapYardbg3.png");
  44. Texture2D textureEntrance = GadgetCoreAPI.LoadTexture2D("entranceScrapYard.png");
  45. Texture2D textureSmallSide = GadgetCoreAPI.LoadTexture2D("sideSmallScrapYard.png");
  46. Texture2D textureBigSide = GadgetCoreAPI.LoadTexture2D("sideBigScrapYard.png");
  47. Texture2D textureMid0 = GadgetCoreAPI.LoadTexture2D("midScrapYardChunk0.png");
  48. Texture2D textureMid1 = GadgetCoreAPI.LoadTexture2D("midScrapYardChunk1.png");
  49. Texture2D textureScrapTrophy = GadgetCoreAPI.LoadTexture2D("iScrapTrophy.png");
  50. PlanetInfo scrapYardPlanet = new PlanetInfo(PlanetType.SPECIAL, "Scrap Yard", new GadgetCore.Util.Tuple<int, int>[] { new GadgetCore.Util.Tuple<int, int>(1, 100) });
  51. scrapYardPlanet.SetPortalInfo(texturePortalSign, texturePlanetPrevIcon, texturePlanetIcon);
  52. scrapYardPlanet.SetBackgroundInfo(textureParalex, textureParalex0, textureParalex1, textureParalex2, textureParalex3);
  53. scrapYardPlanet.SetTerrainInfo(textureEntrance, textureBG, textureMid0, textureMid1, textureBigSide, textureSmallSide);
  54. scrapYardPlanet.OnGenerateWorld += ScrapYardGenerator.GenarateTown;
  55. scrapYardPlanet.Register("Scrap Yard");
  56. scrapYardPlanet.PortalUses = -1;
  57. new ItemInfo(ItemType.GENERIC, "Scrap Trophy", "A rusty trophy.\nUsed for purchasing\nspecial items.", textureScrapTrophy).Register("Scrap Trophy");
  58. { // Scrap Yard Bulding
  59. var scrapYardShopBuilding = Object.Instantiate((GameObject)Resources.Load("prop/2501"));
  60. scrapYardShopBuilding.transform.localScale *= 8;
  61. Texture2D texture = GadgetCoreAPI.LoadTexture2D("shopStand.png");
  62. var renderer = scrapYardShopBuilding.GetComponentInChildren<Renderer>();
  63. renderer.material = new Material(Shader.Find("Unlit/Transparent"))
  64. {
  65. mainTexture = texture
  66. };
  67. GadgetCoreAPI.AddCustomResource("prop/ScrapYard/scrapYardShopBuilding", scrapYardShopBuilding);
  68. }
  69. { // Scrap Yard Shop Owner
  70. var scrapYardMerchant = Object.Instantiate((GameObject)Resources.Load("npc/perceval"));
  71. Texture2D textureBody = GadgetCoreAPI.LoadTexture2D("merchantBody.png");
  72. Texture2D textureHead = GadgetCoreAPI.LoadTexture2D("merchantHead.png");
  73. var gameObjectBody = scrapYardMerchant.transform.Find("e").Find("perceval").FindChild("Plane_002");
  74. var rendererBody = gameObjectBody.gameObject.GetComponentInChildren<Renderer>();
  75. rendererBody.material = new Material(Shader.Find("Unlit/Transparent"))
  76. {
  77. mainTexture = textureBody
  78. };
  79. var gameObjectHead = scrapYardMerchant.transform.Find("e").Find("perceval").FindChild("Plane");
  80. var rendererHead = gameObjectHead.gameObject.GetComponentInChildren<Renderer>();
  81. rendererHead.material = new Material(Shader.Find("Unlit/Transparent"))
  82. {
  83. mainTexture = textureHead
  84. };
  85. //scrapYardMerchant.layer = 0;
  86. scrapYardMerchant.transform.Find("e").rotation = Quaternion.Euler(0f, 180f, 0f);
  87. scrapYardMerchant.name = "scrapyardmerchant";
  88. Component.DestroyImmediate(scrapYardMerchant.GetComponent<npcTurnScript>());
  89. GadgetCoreAPI.AddCustomResource("prop/ScrapYard/scrapYardMerchant", scrapYardMerchant);
  90. TileInfo tile = new TileInfo(TileType.INTERACTIVE, null as Texture2D, new GameObject("scrapyardmerchant")).Register("scrapyardmerchant");
  91. tile.OnInteract += OnInteractMerchant;
  92. }
  93. { // Part Semicolider Platform
  94. var asset = GadgetCoreAPI.LoadAssetBundle("platform");
  95. var platform = UnityEngine.Object.Instantiate((GameObject)asset.LoadAsset("assets/resources/platform.prefab"));
  96. GadgetCoreAPI.AddCustomResource("prop/ScrapYard/component/platform", platform);
  97. }
  98. { // Bottom Chunk
  99. var gameObject = Object.Instantiate((GameObject)Resources.Load("z/chunk"));
  100. var rendererBody = gameObject.GetComponentInChildren<Renderer>();
  101. rendererBody.material = new Material(Shader.Find("Unlit/Transparent"))
  102. {
  103. mainTexture = textureBG
  104. };
  105. for (int i = 0; i < 6; i++)
  106. GameObject.DestroyImmediate(gameObject.transform.GetChild(0).gameObject);
  107. for (int i = 0; i < 16; i++)
  108. GameObject.DestroyImmediate(gameObject.transform.GetChild(1).gameObject);
  109. gameObject.transform.GetChild(0).GetChild(7).localScale += new Vector3(1.5f, 0, 0);
  110. GameObject.DestroyImmediate(gameObject.transform.GetChild(0).GetChild(5).gameObject);
  111. GameObject.DestroyImmediate(gameObject.transform.GetChild(0).GetChild(1).gameObject);
  112. Component.DestroyImmediate(gameObject.GetComponent<Chunk>());
  113. var platformComponent = Object.Instantiate((GameObject)Resources.Load("prop/ScrapYard/component/platform"));
  114. platformComponent.transform.SetParent(gameObject.transform);
  115. platformComponent.transform.localScale = new Vector3(0.5625f, 10, 1);
  116. platformComponent.transform.localPosition = new Vector3(0, 0.25f, 0);
  117. platformComponent.transform.localRotation = Quaternion.Euler(90, 0, 0);
  118. GadgetCoreAPI.AddCustomResource("z/ScrapYard/chunkBase", gameObject);
  119. }
  120. { // Extension Chunk
  121. var gameObject = Object.Instantiate((GameObject)Resources.Load("z/chunk"));
  122. var rendererBody = gameObject.GetComponentInChildren<Renderer>();
  123. rendererBody.material = new Material(Shader.Find("Unlit/Transparent"))
  124. {
  125. mainTexture = textureBGExtension
  126. };
  127. for (int i = 0; i < 6; i++)
  128. GameObject.DestroyImmediate(gameObject.transform.GetChild(0).gameObject);
  129. for (int i = 0; i < 16; i++)
  130. GameObject.DestroyImmediate(gameObject.transform.GetChild(1).gameObject);
  131. for (int i = 0; i < 6; i++)
  132. GameObject.DestroyImmediate(gameObject.transform.GetChild(0).GetChild(0).gameObject);
  133. gameObject.transform.GetChild(0).GetChild(0).localScale = new Vector3(0.4375f, 2, 1);
  134. gameObject.transform.GetChild(0).GetChild(0).localPosition = new Vector3(0.78125f, 0, 0);
  135. gameObject.transform.GetChild(0).GetChild(1).localScale = new Vector3(0.4375f, 2, 1);
  136. gameObject.transform.GetChild(0).GetChild(1).localPosition = new Vector3(-0.78125f, 0, 0);
  137. Component.DestroyImmediate(gameObject.GetComponent<Chunk>());
  138. GadgetCoreAPI.AddCustomResource("z/ScrapYard/chunkExtension", gameObject);
  139. }
  140. { // Top Chunk
  141. var gameObject = Object.Instantiate((GameObject)Resources.Load("z/chunk"));
  142. var rendererBody = gameObject.GetComponentInChildren<Renderer>();
  143. rendererBody.material = new Material(Shader.Find("Unlit/Transparent"))
  144. {
  145. mainTexture = textureBGTop
  146. };
  147. for (int i = 0; i < 6; i++)
  148. GameObject.DestroyImmediate(gameObject.transform.GetChild(0).gameObject);
  149. for (int i = 0; i < 16; i++)
  150. GameObject.DestroyImmediate(gameObject.transform.GetChild(1).gameObject);
  151. for (int i = 0; i < 5; i++)
  152. GameObject.DestroyImmediate(gameObject.transform.GetChild(0).GetChild(0).gameObject);
  153. gameObject.transform.GetChild(0).GetChild(0).localPosition = new Vector3(0.78125f, 0, 0);
  154. gameObject.transform.GetChild(0).GetChild(0).localScale = new Vector3(0.4375f, 2, 1);
  155. gameObject.transform.GetChild(0).GetChild(1).localPosition = new Vector3(-0.78125f, 0, 0);
  156. gameObject.transform.GetChild(0).GetChild(1).localScale = new Vector3(0.4375f, 2, 1);
  157. gameObject.transform.GetChild(0).GetChild(2).localPosition = new Vector3(0, 0.5f, 0);
  158. gameObject.transform.GetChild(0).GetChild(2).localScale = new Vector3(2f, 0.5f, 1);
  159. Component.DestroyImmediate(gameObject.GetComponent<Chunk>());
  160. GadgetCoreAPI.AddCustomResource("z/ScrapYard/chunkTop", gameObject);
  161. }
  162. { // Platform
  163. var gameObject = Object.Instantiate((GameObject)Resources.Load("prop/2501"));
  164. gameObject.transform.localScale = new Vector3(12, 2, 1);
  165. Texture2D texture = GadgetCoreAPI.LoadTexture2D("metalPlatform.png");
  166. var renderer = gameObject.GetComponentInChildren<Renderer>();
  167. renderer.material = new Material(Shader.Find("Unlit/Transparent"))
  168. {
  169. mainTexture = texture
  170. };
  171. var platformComponent = Object.Instantiate((GameObject)Resources.Load("prop/ScrapYard/component/platform"));
  172. platformComponent.transform.SetParent(gameObject.transform);
  173. platformComponent.transform.localScale = new Vector3(2, 2, 1);
  174. platformComponent.transform.localPosition = new Vector3(0, 0, 0);
  175. GadgetCoreAPI.AddCustomResource("prop/ScrapYard/metalPlatform", gameObject);
  176. }
  177. { // Shop Stand
  178. var asset = GadgetCoreAPI.LoadAssetBundle("scrapyardstand");
  179. var scrapYardStand = UnityEngine.Object.Instantiate((GameObject)asset.LoadAsset("assets/resources/scrapyardstand.prefab"));
  180. scrapYardStand.SetActive(false);
  181. scrapYardStand.AddComponent<ScrapYardShopStandScript>();
  182. scrapYardStand.name = "scrapyardstand";
  183. GadgetCoreAPI.AddCustomResource("prop/ScrapYard/stand", scrapYardStand);
  184. scrapYardStand.transform.GetChild(0).GetComponent<Renderer>().material = new Material(Shader.Find("Unlit/Transparent"))
  185. {
  186. mainTexture = GadgetCoreAPI.LoadTexture2D("scrapYardStand.png")
  187. };
  188. scrapYardStand.transform.GetChild(2).GetComponent<Renderer>().material = new Material(Shader.Find("Unlit/Transparent"))
  189. {
  190. mainTexture = GadgetCoreAPI.LoadTexture2D("scrapYardStandInfo.png")
  191. };
  192. TileInfo tile = new TileInfo(TileType.INTERACTIVE, null as Texture2D, new GameObject("scrapyardstand")).Register("scrapyardstand");
  193. tile.OnInteract += OnInteractStand;
  194. }
  195. // Setting up default shop platforms
  196. new ShopPlatform("Default Objects", ShopPlatformSpacingType.Near).Register();
  197. new ShopPlatform("Default Blocks", ShopPlatformSpacingType.Near).Register();
  198. new ShopPlatform("Default Walls", ShopPlatformSpacingType.Near).Register();
  199. ShopPlatform.DefaultBlocks.AddShopPlatformEntry(new ShopPlatformEntry(2000, 100));
  200. ShopPlatform.DefaultBlocks.AddShopPlatformEntry(new ShopPlatformEntry(2001, 100));
  201. ShopPlatform.DefaultBlocks.AddShopPlatformEntry(new ShopPlatformEntry(2002, 500));
  202. ShopPlatform.DefaultBlocks.AddShopPlatformEntry(new ShopPlatformEntry(2400, 7000));
  203. ShopPlatform.DefaultObjects.AddShopPlatformEntry(new ShopPlatformEntry(2100, 10));
  204. ShopPlatform.DefaultObjects.AddShopPlatformEntry(new ShopPlatformEntry(2101, 10));
  205. ShopPlatform.DefaultObjects.AddShopPlatformEntry(new ShopPlatformEntry(2102, 10));
  206. ShopPlatform.DefaultObjects.AddShopPlatformEntry(new ShopPlatformEntry(2103, 10));
  207. ShopPlatform.DefaultObjects.AddShopPlatformEntry(new ShopPlatformEntry(2104, 10));
  208. ShopPlatform.DefaultObjects.AddShopPlatformEntry(new ShopPlatformEntry(2105, 10));
  209. ShopPlatform.DefaultObjects.AddShopPlatformEntry(new ShopPlatformEntry(2106, 10));
  210. ShopPlatform.DefaultObjects.AddShopPlatformEntry(new ShopPlatformEntry(2107, 10));
  211. ShopPlatform.DefaultObjects.AddShopPlatformEntry(new ShopPlatformEntry(2108, 10));
  212. ShopPlatform.DefaultObjects.AddShopPlatformEntry(new ShopPlatformEntry(2403, 10));
  213. ShopPlatform.DefaultObjects.AddShopPlatformEntry(new ShopPlatformEntry(ItemRegistry.GetItemIDByRegistryName("Gadget Core:Crafter Block"), 10));
  214. ShopPlatform.DefaultObjects.AddShopPlatformEntry(new ShopPlatformEntry(2401, 1000));
  215. ShopPlatform.DefaultObjects.AddShopPlatformEntry(new ShopPlatformEntry(2402, 1000));
  216. ShopPlatform.DefaultWalls.AddShopPlatformEntry(new ShopPlatformEntry(2200, 50));
  217. SceneManager.sceneLoaded += OnSceneLoaded;
  218. }
  219. internal static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
  220. {
  221. if (scene.buildIndex == 1)
  222. {
  223. try
  224. {
  225. var storageMenu = GameObject.Find("Ship").transform.Find("SHIPPLACES").transform.Find("mech").localPosition = new Vector3(-130f, -5.23f, 0.6f);
  226. }
  227. catch (System.Exception e) { Core.logger.LogError(e.Message); }
  228. }
  229. }
  230. public static readonly FieldInfo canInteractField = typeof(PlayerScript).GetField("canInteract", BindingFlags.NonPublic | BindingFlags.Instance);
  231. public static readonly FieldInfo interactingField = typeof(PlayerScript).GetField("interacting", BindingFlags.NonPublic | BindingFlags.Instance);
  232. private IEnumerator OnInteractStand()
  233. {
  234. PlayerScript.curInteractObj.SendMessage("Request");
  235. canInteractField.SetValue(InstanceTracker.PlayerScript, true);
  236. interactingField.SetValue(InstanceTracker.PlayerScript, false);
  237. InstanceTracker.PlayerScript.w.SetActive(true);
  238. yield break;
  239. }
  240. public static readonly Material merchantPortraitMaterial = new Material(Shader.Find("Unlit/Transparent"))
  241. {
  242. mainTexture = GadgetCoreAPI.LoadTexture2D("merchantPortrait.png"),
  243. mainTextureScale = new Vector2(0.5f, 1)
  244. };
  245. public static readonly FieldInfo curAField = typeof(GameScript).GetField("curA", BindingFlags.NonPublic | BindingFlags.Instance);
  246. public static readonly FieldInfo curBField = typeof(GameScript).GetField("curB", BindingFlags.NonPublic | BindingFlags.Instance);
  247. public static readonly FieldInfo curCField = typeof(GameScript).GetField("curC", BindingFlags.NonPublic | BindingFlags.Instance);
  248. private IEnumerator OnInteractMerchant()
  249. {
  250. InstanceTracker.GameScript.hoverItem.SetActive(false);
  251. if (GameScript.inventoryOpen)
  252. {
  253. InstanceTracker.GameScript.inventoryMain.SetActive(false);
  254. GameScript.inventoryOpen = false;
  255. }
  256. InstanceTracker.GameScript.talkingPortrait.GetComponent<Renderer>().material = merchantPortraitMaterial;
  257. InstanceTracker.GameScript.txtTalkingName[0].text = "Ito";
  258. InstanceTracker.GameScript.txtTalkingName[1].text = InstanceTracker.GameScript.txtTalkingName[0].text;
  259. InstanceTracker.GameScript.StartCoroutine(InstanceTracker.GameScript.EnterTalking2());
  260. InstanceTracker.GameScript.menuTalking.SendMessage("Set", "Haz a look at my warez!!!");
  261. canInteractField.SetValue(InstanceTracker.PlayerScript, false);
  262. interactingField.SetValue(InstanceTracker.PlayerScript, false);
  263. curAField.SetValue(InstanceTracker.GameScript, -1);
  264. curBField.SetValue(InstanceTracker.GameScript, -1);
  265. curCField.SetValue(InstanceTracker.GameScript, -1);
  266. yield break;
  267. }
  268. }
  269. }