ShipDecorations.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using UnityEngine;
  2. using GadgetCore.API;
  3. using UnityEngine.SceneManagement;
  4. using System.Reflection;
  5. using GadgetCore.API.ConfigMenu;
  6. namespace ShipDecorations
  7. {
  8. [Gadget("ShipDecorations")]
  9. public class ShipDecorations : Gadget<ShipDecorations>
  10. {
  11. public const string MOD_VERSION = "1.0"; // Set this to the version of your mod.
  12. public const string CONFIG_VERSION = "1.0"; // Increment this whenever you change your mod's config file.
  13. public override IGadgetConfigMenu GetConfigMenu() { return null; }
  14. public override string GetModDescription()
  15. {
  16. return "A mod that adds some more ship decorations.";
  17. }
  18. protected override void Initialize()
  19. {
  20. Logger.Log("Ship Decorations v" + Info.Mod.Version);
  21. Core.logger = Logger;
  22. AddToList(ItemUtil.CreatePlacableDecoItem("cBed.png", "iBed.png", "Bed"), 1000);
  23. AddToList(ItemUtil.CreatePlacableDecoItem("cTree5Plant.png", "iTree5Plant.png", "Tree Plant"), 2000);
  24. AddToList(ItemUtil.CreatePlacableDecoItem("cPlant0Plant.png", "iPlant0Plant.png", "Bush Plant"), 2000);
  25. AddToList(ItemUtil.CreatePlacableDecoItem("cTreantHeadPlant.png", "iTreantHeadPlant.png", "Treant Plant"), 10000);
  26. AddToList(ItemUtil.CreatePlacableSlideDoorItem("cDoor.png", "cDoorOpen.png", "iDoor.png", "Door"), 5000);
  27. SceneManager.sceneLoaded += OnSceneLoaded;
  28. }
  29. internal static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
  30. {
  31. if (scene.buildIndex == 1)
  32. {
  33. var i = GadgetCoreAPI.CreateMarketStand(ItemRegistry.GetItem(Core.itemStoreList[0]), new Vector2(-138f - 2 * 4, -7.49f), 1000);
  34. call(i.GetComponent<KylockeStand>(), "Awake");
  35. }
  36. }
  37. private static object call<T>(T __instance, string meth, object[] o = null)
  38. {
  39. MethodInfo dynMethod = __instance.GetType().GetMethod(meth, BindingFlags.NonPublic | BindingFlags.Instance);
  40. return dynMethod.Invoke(__instance, o ?? new object[0]);
  41. }
  42. private void AddToList(int id, int price)
  43. {
  44. Core.itemStoreList.Add(id);
  45. Core.itemStorePriceList.Add(id, price);
  46. }
  47. }
  48. }