using GadgetCore.API; using GadgetCore.API.Dialog; using ScrapYard.API; using System.Collections; using System.Reflection; using UnityEngine; using UnityEngine.SceneManagement; namespace ScrapYard { [Gadget("ScrapYard", RequiredOnClients: true, GadgetVersionSpecificity: VersionSpecificity.NONBREAKING)] public class ScrapYard : Gadget { public const string MOD_VERSION = "1.7"; // Set this to the version of your mod. public const string CONFIG_VERSION = "1.0"; // Increment this whenever you change your mod's config file. protected override void LoadConfig() { Config.Load(); string fileVersion = Config.ReadString("ConfigVersion", CONFIG_VERSION, comments: "The Config Version (not to be confused with mod version)"); if (fileVersion != CONFIG_VERSION) { Config.Reset(); Config.WriteString("ConfigVersion", CONFIG_VERSION, comments: "The Config Version (not to be confused with mod version)"); } Config.Save(); } public override string GetModDescription() { return "A mod that adds a scryp yard planet."; } protected override void Initialize() { Logger.Log("Scrap Yard v" + Info.Mod.Version); Core.logger = Logger; Texture2D texturePlanetIcon = GadgetCoreAPI.LoadTexture2D("planetScrapYard.png"); Texture2D texturePlanetPrevIcon = GadgetCoreAPI.LoadTexture2D("planetScrapYardPrev.png"); Texture2D texturePortalSign = GadgetCoreAPI.LoadTexture2D("signScrapYard.png"); Texture2D textureBG = GadgetCoreAPI.LoadTexture2D("bgScrapYard.png"); Texture2D textureBGExtension = GadgetCoreAPI.LoadTexture2D("bgScrapYardExtension.png"); Texture2D textureBGTop = GadgetCoreAPI.LoadTexture2D("bgScrapYardTop.png"); Texture2D textureParalex = GadgetCoreAPI.LoadTexture2D("parallax.png"); Texture2D textureParalex0 = GadgetCoreAPI.LoadTexture2D("bScrapYardbg0.png"); Texture2D textureParalex1 = GadgetCoreAPI.LoadTexture2D("bScrapYardbg1.png"); Texture2D textureParalex2 = GadgetCoreAPI.LoadTexture2D("bScrapYardbg2.png"); Texture2D textureParalex3 = GadgetCoreAPI.LoadTexture2D("bScrapYardbg3.png"); Texture2D textureEntrance = GadgetCoreAPI.LoadTexture2D("entranceScrapYard.png"); Texture2D textureSmallSide = GadgetCoreAPI.LoadTexture2D("sideSmallScrapYard.png"); Texture2D textureBigSide = GadgetCoreAPI.LoadTexture2D("sideBigScrapYard.png"); Texture2D textureMid0 = GadgetCoreAPI.LoadTexture2D("midScrapYardChunk0.png"); Texture2D textureMid1 = GadgetCoreAPI.LoadTexture2D("midScrapYardChunk1.png"); Texture2D textureScrapTrophy = GadgetCoreAPI.LoadTexture2D("iScrapTrophy.png"); PlanetInfo scrapYardPlanet = new PlanetInfo(PlanetType.SPECIAL, "Scrap Yard", new GadgetCore.Util.Tuple[] { new GadgetCore.Util.Tuple(1, 100) }); scrapYardPlanet.SetPortalInfo(texturePortalSign, texturePlanetPrevIcon, texturePlanetIcon); scrapYardPlanet.SetBackgroundInfo(textureParalex, textureParalex0, textureParalex1, textureParalex2, textureParalex3); scrapYardPlanet.SetTerrainInfo(textureEntrance, textureBG, textureMid0, textureMid1, textureBigSide, textureSmallSide); scrapYardPlanet.OnGenerateWorld += ScrapYardGenerator.GenarateTown; scrapYardPlanet.Register("Scrap Yard"); scrapYardPlanet.PortalUses = -1; ItemInfo item = new ItemInfo(ItemType.GENERIC, "Scrap Trophy", "A rusty trophy.\nUsed for purchasing\nspecial items.", textureScrapTrophy); int itemID = ItemRegistry.Singleton.Register(item, "Scrap Trophy"); if (itemID == -1) throw new System.Exception("Could not register item " + "Scrap Trophy"); { // Scrap Yard Bulding var scrapYardShopBuilding = Object.Instantiate((GameObject)Resources.Load("prop/2501")); scrapYardShopBuilding.transform.localScale *= 8; Texture2D texture = GadgetCoreAPI.LoadTexture2D("shopStand.png"); var renderer = scrapYardShopBuilding.GetComponentInChildren(); renderer.material = new Material(Shader.Find("Unlit/Transparent")) { mainTexture = texture }; scrapYardShopBuilding.AddComponent(); GadgetCoreAPI.AddCustomResource("prop/ScrapYard/scrapYardShopBuilding", scrapYardShopBuilding); } { // Scrap Yard Shop Owner var scrapYardMerchant = Object.Instantiate((GameObject)Resources.Load("npc/perceval")); Texture2D textureBody = GadgetCoreAPI.LoadTexture2D("merchantBody.png"); Texture2D textureHead = GadgetCoreAPI.LoadTexture2D("merchantHead.png"); var gameObjectBody = scrapYardMerchant.transform.Find("e").Find("perceval").FindChild("Plane_002"); var rendererBody = gameObjectBody.gameObject.GetComponentInChildren(); rendererBody.material = new Material(Shader.Find("Unlit/Transparent")) { mainTexture = textureBody }; var gameObjectHead = scrapYardMerchant.transform.Find("e").Find("perceval").FindChild("Plane"); var rendererHead = gameObjectHead.gameObject.GetComponentInChildren(); rendererHead.material = new Material(Shader.Find("Unlit/Transparent")) { mainTexture = textureHead }; //scrapYardMerchant.layer = 0; scrapYardMerchant.transform.Find("e").rotation = Quaternion.Euler(0f, 180f, 0f); scrapYardMerchant.name = "scrapyardmerchant"; Component.DestroyImmediate(scrapYardMerchant.GetComponent()); GadgetCoreAPI.AddCustomResource("prop/ScrapYard/scrapYardMerchant", scrapYardMerchant); ItemInfo tileItem = new ItemInfo(ItemType.GENERIC, "scrapyardmerchant", "Degug item.", null as Texture2D).Register(); TileInfo tile = new TileInfo(TileType.INTERACTIVE, null as Texture2D, new GameObject("scrapyardmerchant"), tileItem); int tileID = TileRegistry.Singleton.Register(tile, "scrapyardmerchant"); if (tileID == -1) throw new System.Exception("Could not register Tile " + "scrapyardmerchant"); DialogChain dialogChain = new DialogChain(tileID, "Ito", merchantPortraitMaterial, (e) => true, new DialogMessage("Haz a look at my warez!!!")); dialogChain.RegisterDialogChain(); tile.OnInteract += tile.InitiateDialogRoutine; } { // Part Semicolider Platform var asset = GadgetCoreAPI.LoadAssetBundle("platform"); var platform = UnityEngine.Object.Instantiate((GameObject)asset.LoadAsset("assets/resources/platform.prefab")); GadgetCoreAPI.AddCustomResource("prop/ScrapYard/component/platform", platform); } { // Bottom Chunk var gameObject = Object.Instantiate((GameObject)Resources.Load("z/chunk")); var rendererBody = gameObject.GetComponentInChildren(); rendererBody.material = new Material(Shader.Find("Unlit/Transparent")) { mainTexture = textureBG }; for (int i = 0; i < 6; i++) GameObject.DestroyImmediate(gameObject.transform.GetChild(0).gameObject); for (int i = 0; i < 16; i++) GameObject.DestroyImmediate(gameObject.transform.GetChild(1).gameObject); gameObject.transform.GetChild(0).GetChild(7).localScale += new Vector3(1.5f, 0, 0); GameObject.DestroyImmediate(gameObject.transform.GetChild(0).GetChild(5).gameObject); GameObject.DestroyImmediate(gameObject.transform.GetChild(0).GetChild(1).gameObject); Component.DestroyImmediate(gameObject.GetComponent()); var platformComponent = Object.Instantiate((GameObject)Resources.Load("prop/ScrapYard/component/platform")); platformComponent.transform.SetParent(gameObject.transform); platformComponent.transform.localScale = new Vector3(0.5625f, 10, 1); platformComponent.transform.localPosition = new Vector3(0, 0.25f, 0); platformComponent.transform.localRotation = Quaternion.Euler(90, 0, 0); GadgetCoreAPI.AddCustomResource("z/ScrapYard/chunkBase", gameObject); } { // Extension Chunk var gameObject = Object.Instantiate((GameObject)Resources.Load("z/chunk")); var rendererBody = gameObject.GetComponentInChildren(); rendererBody.material = new Material(Shader.Find("Unlit/Transparent")) { mainTexture = textureBGExtension }; for (int i = 0; i < 6; i++) GameObject.DestroyImmediate(gameObject.transform.GetChild(0).gameObject); for (int i = 0; i < 16; i++) GameObject.DestroyImmediate(gameObject.transform.GetChild(1).gameObject); for (int i = 0; i < 6; i++) GameObject.DestroyImmediate(gameObject.transform.GetChild(0).GetChild(0).gameObject); gameObject.transform.GetChild(0).GetChild(0).localScale = new Vector3(0.4375f, 2, 1); gameObject.transform.GetChild(0).GetChild(0).localPosition = new Vector3(0.78125f, 0, 0); gameObject.transform.GetChild(0).GetChild(1).localScale = new Vector3(0.4375f, 2, 1); gameObject.transform.GetChild(0).GetChild(1).localPosition = new Vector3(-0.78125f, 0, 0); Component.DestroyImmediate(gameObject.GetComponent()); GadgetCoreAPI.AddCustomResource("z/ScrapYard/chunkExtension", gameObject); } { // Top Chunk var gameObject = Object.Instantiate((GameObject)Resources.Load("z/chunk")); var rendererBody = gameObject.GetComponentInChildren(); rendererBody.material = new Material(Shader.Find("Unlit/Transparent")) { mainTexture = textureBGTop }; for (int i = 0; i < 6; i++) GameObject.DestroyImmediate(gameObject.transform.GetChild(0).gameObject); for (int i = 0; i < 16; i++) GameObject.DestroyImmediate(gameObject.transform.GetChild(1).gameObject); for (int i = 0; i < 5; i++) GameObject.DestroyImmediate(gameObject.transform.GetChild(0).GetChild(0).gameObject); gameObject.transform.GetChild(0).GetChild(0).localPosition = new Vector3(0.78125f, 0, 0); gameObject.transform.GetChild(0).GetChild(0).localScale = new Vector3(0.4375f, 2, 1); gameObject.transform.GetChild(0).GetChild(1).localPosition = new Vector3(-0.78125f, 0, 0); gameObject.transform.GetChild(0).GetChild(1).localScale = new Vector3(0.4375f, 2, 1); gameObject.transform.GetChild(0).GetChild(2).localPosition = new Vector3(0, 0.5f, 0); gameObject.transform.GetChild(0).GetChild(2).localScale = new Vector3(2f, 0.5f, 1); Component.DestroyImmediate(gameObject.GetComponent()); GadgetCoreAPI.AddCustomResource("z/ScrapYard/chunkTop", gameObject); } { // Platform var gameObject = Object.Instantiate((GameObject)Resources.Load("prop/2501")); gameObject.transform.localScale = new Vector3(12, 2, 1); Texture2D texture = GadgetCoreAPI.LoadTexture2D("metalPlatform.png"); var renderer = gameObject.GetComponentInChildren(); renderer.material = new Material(Shader.Find("Unlit/Transparent")) { mainTexture = texture }; var platformComponent = Object.Instantiate((GameObject)Resources.Load("prop/ScrapYard/component/platform")); platformComponent.transform.SetParent(gameObject.transform); platformComponent.transform.localScale = new Vector3(2, 2, 1); platformComponent.transform.localPosition = new Vector3(0, 0, 0); GadgetCoreAPI.AddCustomResource("prop/ScrapYard/metalPlatform", gameObject); } var assetStand = GadgetCoreAPI.LoadAssetBundle("scrapyardstand"); { // Shop Stand var scrapYardStand = UnityEngine.Object.Instantiate((GameObject)assetStand.LoadAsset("assets/resources/scrapyardstand.prefab")); scrapYardStand.SetActive(false); scrapYardStand.AddComponent(); scrapYardStand.name = "scrapyardstand"; scrapYardStand.transform.GetChild(0).GetComponent().material = new Material(Shader.Find("Unlit/Transparent")) { mainTexture = GadgetCoreAPI.LoadTexture2D("scrapYardStand.png") }; scrapYardStand.transform.GetChild(2).GetComponent().material = new Material(Shader.Find("Unlit/Transparent")) { mainTexture = GadgetCoreAPI.LoadTexture2D("scrapYardStandInfo.png") }; GadgetCoreAPI.AddCustomResource("prop/ScrapYard/stand", scrapYardStand); ItemInfo tileItem = new ItemInfo(ItemType.GENERIC, "scrapyardstand", "Degug item.", null as Texture2D).Register(); TileInfo tile = new TileInfo(TileType.INTERACTIVE, null as Texture2D, new GameObject("scrapyardstand"), tileItem); int tileID = TileRegistry.Singleton.Register(tile, "scrapyardstand"); if (tileID == -1) throw new System.Exception("Could not register Tile " + "scrapyardstand"); tile.OnInteract += OnInteractStand; } { // Shop Stand Chip var scrapYardStand = UnityEngine.Object.Instantiate((GameObject)assetStand.LoadAsset("assets/resources/scrapyardstand.prefab")); scrapYardStand.SetActive(false); scrapYardStand.AddComponent(); scrapYardStand.name = "scrapyardstandchip"; scrapYardStand.transform.GetChild(0).GetComponent().material = new Material(Shader.Find("Unlit/Transparent")) { mainTexture = GadgetCoreAPI.LoadTexture2D("scrapYardStandChip.png") }; scrapYardStand.transform.GetChild(2).GetComponent().material = new Material(Shader.Find("Unlit/Transparent")) { mainTexture = GadgetCoreAPI.LoadTexture2D("scrapYardStandInfo.png") }; GadgetCoreAPI.AddCustomResource("prop/ScrapYard/standchip", scrapYardStand); ItemInfo tileItem = new ItemInfo(ItemType.GENERIC, "scrapyardstandchip", "Degug item.", null as Texture2D).Register(); TileInfo tile = new TileInfo(TileType.INTERACTIVE, null as Texture2D, new GameObject("scrapyardstandchip"), tileItem); int tileID = TileRegistry.Singleton.Register(tile, "scrapyardstandchip"); if (tileID == -1) throw new System.Exception("Could not register Tile " + "scrapyardstandchip"); tile.OnInteract += OnInteractStand; } ShopPlatform.Reset(); // Setting up default shop platforms new ShopPlatform("Default Objects", ShopPlatformSpacingType.Near).Register("DefaultObjects"); new ShopPlatform("Default Blocks", ShopPlatformSpacingType.Near).Register("DefaultBlocks"); new ShopPlatform("Default Walls", ShopPlatformSpacingType.Near).Register("DefaultWalls"); ShopPlatform.DefaultBlocks.AddShopPlatformEntry(new ShopPlatformEntry(2000, 100)); ShopPlatform.DefaultBlocks.AddShopPlatformEntry(new ShopPlatformEntry(2001, 100)); ShopPlatform.DefaultBlocks.AddShopPlatformEntry(new ShopPlatformEntry(2002, 500)); ShopPlatform.DefaultBlocks.AddShopPlatformEntry(new ShopPlatformEntry(2400, 7000)); ShopPlatform.DefaultObjects.AddShopPlatformEntry(new ShopPlatformEntry(2100, 10)); ShopPlatform.DefaultObjects.AddShopPlatformEntry(new ShopPlatformEntry(2101, 10)); ShopPlatform.DefaultObjects.AddShopPlatformEntry(new ShopPlatformEntry(2102, 10)); ShopPlatform.DefaultObjects.AddShopPlatformEntry(new ShopPlatformEntry(2103, 10)); ShopPlatform.DefaultObjects.AddShopPlatformEntry(new ShopPlatformEntry(2104, 10)); ShopPlatform.DefaultObjects.AddShopPlatformEntry(new ShopPlatformEntry(2105, 10)); ShopPlatform.DefaultObjects.AddShopPlatformEntry(new ShopPlatformEntry(2106, 10)); ShopPlatform.DefaultObjects.AddShopPlatformEntry(new ShopPlatformEntry(2107, 10)); ShopPlatform.DefaultObjects.AddShopPlatformEntry(new ShopPlatformEntry(2108, 10)); ShopPlatform.DefaultObjects.AddShopPlatformEntry(new ShopPlatformEntry(2403, 10)); ShopPlatform.DefaultObjects.AddShopPlatformEntry(new ShopPlatformEntry(ItemRegistry.GetItemIDByRegistryName("Gadget Core:Crafter Block"), 10)); ShopPlatform.DefaultObjects.AddShopPlatformEntry(new ShopPlatformEntry(2401, 1000)); ShopPlatform.DefaultObjects.AddShopPlatformEntry(new ShopPlatformEntry(2402, 1000)); ShopPlatform.DefaultWalls.AddShopPlatformEntry(new ShopPlatformEntry(2200, 50)); SceneManager.sceneLoaded += OnSceneLoaded; } internal static void OnSceneLoaded(Scene scene, LoadSceneMode mode) { if (scene.buildIndex == 1) { try { var storageMenu = GameObject.Find("Ship").transform.Find("SHIPPLACES").transform.Find("mech").localPosition = new Vector3(-130f, -5.23f, 0.6f); } catch (System.Exception e) { Core.logger.LogError(e.Message); } } } public static readonly FieldInfo canInteractField = typeof(PlayerScript).GetField("canInteract", BindingFlags.NonPublic | BindingFlags.Instance); public static readonly FieldInfo interactingField = typeof(PlayerScript).GetField("interacting", BindingFlags.NonPublic | BindingFlags.Instance); private IEnumerator OnInteractStand() { try { PlayerScript.curInteractObj.SendMessage("Request"); canInteractField.SetValue(InstanceTracker.PlayerScript, true); interactingField.SetValue(InstanceTracker.PlayerScript, false); InstanceTracker.PlayerScript.w.SetActive(true); } catch (System.Exception e) { Core.logger.Log(e); } yield break; } public static readonly Material merchantPortraitMaterial = new Material(Shader.Find("Unlit/Transparent")) { mainTexture = GadgetCoreAPI.LoadTexture2D("merchantPortrait.png"), mainTextureScale = new Vector2(0.5f, 1) }; } }