ScrapYard.cs 16 KB

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