using GadgetCore.API; using GadgetCore.Util; using ScrapYard.API; using System; using System.Reflection; using UnityEngine; namespace ScrapYard { public class ScrapYardGenerator { private static readonly Material materialaBackLight = new Material(Shader.Find("Unlit/Transparent")) { mainTexture = GadgetCoreAPI.LoadTexture2D("parallax.png") }; private static readonly Material materialaParalex0 = new Material(Shader.Find("Unlit/Transparent")) { mainTexture = GadgetCoreAPI.LoadTexture2D("bScrapYardbg0.png") }; private static readonly Material materialaParalex1 = new Material(Shader.Find("Unlit/Transparent")) { mainTexture = GadgetCoreAPI.LoadTexture2D("bScrapYardbg1.png") }; private static readonly Material materialaParalex2 = new Material(Shader.Find("Unlit/Transparent")) { mainTexture = GadgetCoreAPI.LoadTexture2D("bScrapYardbg2.png") }; private static readonly Material materialaParalex3 = new Material(Shader.Find("Unlit/Transparent")) { mainTexture = GadgetCoreAPI.LoadTexture2D("bScrapYardbg3.png") }; public static void GenarateTown(SpawnerScript s, int[] param) { try { s.backLights.SetActive(true); s.mainLight.SetActive(true); s.backLights.GetComponent().material = materialaBackLight; s.mainLight.GetComponentInChildren().color = new Color(0.05f, 0.05f, 0.05f, 0.1f); s.bg[0].GetComponent().material = materialaParalex0; s.bg[1].GetComponent().material = materialaParalex1; s.bg[2].GetComponent().material = materialaParalex2; s.bg[3].GetComponent().material = materialaParalex3; var chunks = s.GetFieldValue("chunks"); var num = 0; chunks[num] = (GameObject)UnityEngine.Object.Instantiate(Resources.Load("z/entrance"), new Vector3(224.5f, 0f, 5f), Quaternion.Euler(0f, 0f, 0f)); num++; chunks[num] = (GameObject)UnityEngine.Object.Instantiate(Resources.Load("z/ScrapYard/chunkBase"), new Vector3((float)(300 + 0 * 128), 0f, 5f), Quaternion.Euler(0f, 180f, 180f)); num++; int rowsNeeded = 0; foreach (var entry in ShopPlatform.ShopPlatforms) { rowsNeeded += entry.Value.GetRowsNeeded(); } int extensionAmount = System.Math.Max((rowsNeeded + 3) / 8, 0); for (int i = 0; i < extensionAmount; i++) { 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)); num++; } 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)); num++; chunks[num] = (GameObject)UnityEngine.Object.Instantiate(Resources.Load("z/exit"), new Vector3(375.5f, 0f, 5f), Quaternion.Euler(0f, 0f, 180f)); num++; if (Network.isServer) { chunks[num] = new GameObject("chunk"); var chunk = chunks[num].AddComponent(); PopulateTown(chunk); num++; } } catch (System.Exception e) { Core.logger.LogConsole(e); } } public static void PopulateTown(Chunk chunk) { var networkStuff = new GameObject[400]; chunk.SetFieldValue("networkStuff", networkStuff); chunk.GetFieldValue("networkStuff"); int temp = chunk.GetFieldValue("temp"); try { networkStuff[temp] = (GameObject)Network.Instantiate(Resources.Load("prop/ScrapYard/scrapYardShopBuilding"), new Vector3(250f, -6f + 0.118f, 0.3f), Quaternion.identity, 0); temp++; networkStuff[temp] = (GameObject)Network.Instantiate(Resources.Load("prop/ScrapYard/scrapYardMerchant"), new Vector3(255f, -6f - 0.118f * 12, 0.2f), Quaternion.identity, 0); temp++; networkStuff[temp] = (GameObject)Network.Instantiate(Resources.Load("npcStorage"), new Vector3(234.5f, -6.118f, 0.2f), Quaternion.identity, 0); temp++; networkStuff[temp] = (GameObject)Network.Instantiate(Resources.Load("npcStorage"), new Vector3(362f, -6.118f, 0.2f), Quaternion.identity, 0); temp++; networkStuff[temp] = (GameObject)Network.Instantiate(Resources.Load("npc2103"), new Vector3(366f, -6.118f, 0.2f), Quaternion.identity, 0); temp++; int rowNumber = -1; foreach (var platform in ShopPlatform.ShopPlatforms) { for (int i = 0; i < platform.Value.Entries.Count; i++) { ShopPlatformEntry entry = platform.Value.Entries[i]; if ((i % platform.Value.GetSpacesPerRow()) == 0) { rowNumber++; networkStuff[temp] = (GameObject)Network.Instantiate(Resources.Load("prop/ScrapYard/metalPlatform"), new Vector3(300, rowNumber * 8f, 0.4f), Quaternion.identity, 0); temp++; } var step = (i % platform.Value.GetSpacesPerRow()) / (float)(platform.Value.GetSpacesPerRow() - 1); if (entry.EntryType == ShopPlatformEntryType.Item) { 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); networkStuff[temp].GetComponent().StartCallSet(entry.Id, entry.Price, entry.Quantity, entry.CurrencyItemID); }else if (entry.EntryType == ShopPlatformEntryType.Chip) { networkStuff[temp] = (GameObject)Network.Instantiate((GameObject)Resources.Load("prop/ScrapYard/standchip"), new Vector3(300 - (40 / 2) + (step * 40), rowNumber * 8f + 0.5f - 0.05f, 0.2f), Quaternion.identity, 0); networkStuff[temp].GetComponent().StartCallSet(entry.Id, entry.Price, entry.CurrencyItemID); } temp++; } } networkStuff[temp] = (GameObject)Network.Instantiate((GameObject)Resources.Load("prop/ScrapYard/stand"), new Vector3(268.5f, -6.1175f - 1.45f, 0.2f), Quaternion.identity, 0); networkStuff[temp].GetComponent().StartCallSet(ItemRegistry.GetItemIDByRegistryName("ScrapYard:Scrap Trophy"), 9999, 1, 57); temp++; networkStuff[temp] = (GameObject)Network.Instantiate((GameObject)Resources.Load("prop/ScrapYard/stand"), new Vector3(272.5f, -6.1175f - 1.45f, 0.2f), Quaternion.identity, 0); networkStuff[temp].GetComponent().StartCallSet(57, 1, 9999, ItemRegistry.GetItemIDByRegistryName("ScrapYard:Scrap Trophy")); temp++; } catch (Exception e) { Core.logger.LogError(e); } GameScript.endPortal[3] = (GameObject)Network.Instantiate((GameObject)Resources.Load("portal"), new Vector3(226f, -6.118f, 0f), Quaternion.identity, 0); GameScript.endPortalUA[3] = GameScript.endPortal[3].transform.GetChild(0).gameObject; GameScript.endPortal[3].GetComponent().RPC("Activate", RPCMode.All, new object[0]); GameScript.endPortalUA[3].GetComponent().RPC("Set", RPCMode.AllBuffered, new object[] { 98, 0, 3 }); chunk.SetFieldValue("temp", temp); } } }