ScrapYardGenerator.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using GadgetCore.API;
  2. using GadgetCore.Util;
  3. using ScrapYard.API;
  4. using System;
  5. using System.Reflection;
  6. using UnityEngine;
  7. namespace ScrapYard
  8. {
  9. public class ScrapYardGenerator
  10. {
  11. private static readonly Material materialaBackLight = new Material(Shader.Find("Unlit/Transparent")) { mainTexture = GadgetCoreAPI.LoadTexture2D("parallax.png") };
  12. private static readonly Material materialaParalex0 = new Material(Shader.Find("Unlit/Transparent")) { mainTexture = GadgetCoreAPI.LoadTexture2D("bScrapYardbg0.png") };
  13. private static readonly Material materialaParalex1 = new Material(Shader.Find("Unlit/Transparent")) { mainTexture = GadgetCoreAPI.LoadTexture2D("bScrapYardbg1.png") };
  14. private static readonly Material materialaParalex2 = new Material(Shader.Find("Unlit/Transparent")) { mainTexture = GadgetCoreAPI.LoadTexture2D("bScrapYardbg2.png") };
  15. private static readonly Material materialaParalex3 = new Material(Shader.Find("Unlit/Transparent")) { mainTexture = GadgetCoreAPI.LoadTexture2D("bScrapYardbg3.png") };
  16. public static void GenarateTown(SpawnerScript s, int[] param)
  17. {
  18. try
  19. {
  20. s.backLights.SetActive(true);
  21. s.mainLight.SetActive(true);
  22. s.backLights.GetComponent<Renderer>().material = materialaBackLight;
  23. s.mainLight.GetComponentInChildren<Light>().color = new Color(0.05f, 0.05f, 0.05f, 0.1f);
  24. s.bg[0].GetComponent<Renderer>().material = materialaParalex0;
  25. s.bg[1].GetComponent<Renderer>().material = materialaParalex1;
  26. s.bg[2].GetComponent<Renderer>().material = materialaParalex2;
  27. s.bg[3].GetComponent<Renderer>().material = materialaParalex3;
  28. var chunks = s.GetFieldValue<GameObject[]>("chunks");
  29. var num = 0;
  30. chunks[num] = (GameObject)UnityEngine.Object.Instantiate(Resources.Load("z/entrance"), new Vector3(224.5f, 0f, 5f), Quaternion.Euler(0f, 0f, 0f));
  31. num++;
  32. chunks[num] = (GameObject)UnityEngine.Object.Instantiate(Resources.Load("z/ScrapYard/chunkBase"), new Vector3((float)(300 + 0 * 128), 0f, 5f), Quaternion.Euler(0f, 180f, 180f));
  33. num++;
  34. int rowsNeeded = 0;
  35. foreach (var entry in ShopPlatform.ShopPlatforms)
  36. {
  37. rowsNeeded += entry.Value.GetRowsNeeded();
  38. }
  39. int extensionAmount = System.Math.Max((rowsNeeded + 3) / 8, 0);
  40. for (int i = 0; i < extensionAmount; i++)
  41. {
  42. chunks[num] = (GameObject)UnityEngine.Object.Instantiate(Resources.Load("z/ScrapYard/chunkExtension"), new Vector3((float)(300 + 0 * 128), 64 * (i + 1), 5f), Quaternion.Euler(0f, 180f, 180f));
  43. num++;
  44. }
  45. chunks[num] = (GameObject)UnityEngine.Object.Instantiate(Resources.Load("z/ScrapYard/chunkTop"), new Vector3((float)(300 + 0 * 128), 64 * (extensionAmount + 1), 5f), Quaternion.Euler(0f, 180f, 180f));
  46. num++;
  47. chunks[num] = (GameObject)UnityEngine.Object.Instantiate(Resources.Load("z/exit"), new Vector3(375.5f, 0f, 5f), Quaternion.Euler(0f, 0f, 180f));
  48. num++;
  49. if (Network.isServer)
  50. {
  51. chunks[num] = new GameObject("chunk");
  52. var chunk = chunks[num].AddComponent<Chunk>();
  53. PopulateTown(chunk);
  54. num++;
  55. }
  56. }
  57. catch (System.Exception e) { Core.logger.LogConsole(e); }
  58. }
  59. public static void PopulateTown(Chunk chunk)
  60. {
  61. var networkStuff = new GameObject[400];
  62. chunk.SetFieldValue("networkStuff", networkStuff);
  63. chunk.GetFieldValue<GameObject[]>("networkStuff");
  64. int temp = chunk.GetFieldValue<int>("temp");
  65. try
  66. {
  67. networkStuff[temp] = (GameObject)Network.Instantiate(Resources.Load("prop/ScrapYard/scrapYardShopBuilding"), new Vector3(250f, -6f + 0.118f, 0.3f), Quaternion.identity, 0);
  68. temp++;
  69. networkStuff[temp] = (GameObject)Network.Instantiate(Resources.Load("prop/ScrapYard/scrapYardMerchant"), new Vector3(255f, -6f - 0.118f * 12, 0.2f), Quaternion.identity, 0);
  70. temp++;
  71. networkStuff[temp] = (GameObject)Network.Instantiate(Resources.Load("npcStorage"), new Vector3(234.5f, -6.118f, 0.2f), Quaternion.identity, 0);
  72. temp++;
  73. networkStuff[temp] = (GameObject)Network.Instantiate(Resources.Load("npcStorage"), new Vector3(362f, -6.118f, 0.2f), Quaternion.identity, 0);
  74. temp++;
  75. networkStuff[temp] = (GameObject)Network.Instantiate(Resources.Load("npc2103"), new Vector3(366f, -6.118f, 0.2f), Quaternion.identity, 0);
  76. temp++;
  77. int rowNumber = -1;
  78. foreach (var platform in ShopPlatform.ShopPlatforms)
  79. {
  80. for (int i = 0; i < platform.Value.Entries.Count; i++)
  81. {
  82. ShopPlatformEntry entry = platform.Value.Entries[i];
  83. if ((i % platform.Value.GetSpacesPerRow()) == 0)
  84. {
  85. rowNumber++;
  86. networkStuff[temp] = (GameObject)Network.Instantiate(Resources.Load("prop/ScrapYard/metalPlatform"), new Vector3(300, rowNumber * 8f, 0.4f), Quaternion.identity, 0);
  87. temp++;
  88. }
  89. var step = (i % platform.Value.GetSpacesPerRow()) / (float)(platform.Value.GetSpacesPerRow() - 1);
  90. networkStuff[temp] = (GameObject)Network.Instantiate((GameObject)Resources.Load("prop/ScrapYard/stand"), new Vector3(300 - (40 / 2) + (step * 40), rowNumber * 8f + 0.5f - 0.05f, 0.2f), Quaternion.identity, 0);
  91. networkStuff[temp].GetComponent<ScrapYardShopStandScript>().StartCallSet(entry.ItemID, entry.Price, entry.Quantity, entry.CurrencyItemID);
  92. temp++;
  93. }
  94. }
  95. networkStuff[temp] = (GameObject)Network.Instantiate((GameObject)Resources.Load("prop/ScrapYard/stand"), new Vector3(268.5f, -6.1175f - 1.45f, 0.2f), Quaternion.identity, 0);
  96. networkStuff[temp].GetComponent<ScrapYardShopStandScript>().StartCallSet(ItemRegistry.GetItemIDByRegistryName("ScrapYard:Scrap Trophy"), 9999, 1, 57);
  97. temp++;
  98. networkStuff[temp] = (GameObject)Network.Instantiate((GameObject)Resources.Load("prop/ScrapYard/stand"), new Vector3(272.5f, -6.1175f - 1.45f, 0.2f), Quaternion.identity, 0);
  99. networkStuff[temp].GetComponent<ScrapYardShopStandScript>().StartCallSet(57, 1, 9999, ItemRegistry.GetItemIDByRegistryName("ScrapYard:Scrap Trophy"));
  100. temp++;
  101. }
  102. catch (Exception e) { Core.logger.LogError(e); }
  103. GameScript.endPortal[3] = (GameObject)Network.Instantiate((GameObject)Resources.Load("portal"), new Vector3(226f, -6.118f, 0f), Quaternion.identity, 0);
  104. GameScript.endPortalUA[3] = GameScript.endPortal[3].transform.GetChild(0).gameObject;
  105. GameScript.endPortal[3].GetComponent<NetworkView>().RPC("Activate", RPCMode.All, new object[0]);
  106. GameScript.endPortalUA[3].GetComponent<NetworkView>().RPC("Set", RPCMode.AllBuffered, new object[] { 98, 0, 3 });
  107. chunk.SetFieldValue("temp", temp);
  108. }
  109. }
  110. }