OldChestScript.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using GadgetCore.API;
  2. using System.Collections;
  3. using UnityEngine;
  4. namespace Subworlds.Scripts
  5. {
  6. public class OldChestScript : MonoBehaviour
  7. {
  8. private static int[] dropsLoot = new int[] { 1, 2, 3, 4, 11, 12, 13, 14, 21, 22, 23, 24, 31, 32, 33, 34 };
  9. private static int[] dropsEmblem = new int[] { 101, 102, 103, 104, 111, 112, 113, 114, 121, 122, 123, 124, 131, 132, 133, 134 };
  10. private bool opened = false;
  11. private void Awake()
  12. {
  13. base.name = "chest";
  14. }
  15. private void Start() { }
  16. [RPC]
  17. private void Open()
  18. {
  19. if (!this.opened)
  20. {
  21. this.opened = true;
  22. base.GetComponent<NetworkView>().RPC("OpenMat", RPCMode.AllBuffered, new object[0]);
  23. this.DropItems();
  24. }
  25. }
  26. private void DropItems()
  27. {
  28. base.GetComponent<NetworkView>().RPC("DropLocal", RPCMode.All, new object[0]);
  29. }
  30. [RPC]
  31. private void DropLocal()
  32. {
  33. if (Menuu.curAugment == 12)
  34. StartCoroutine(DropLocalLoot());
  35. StartCoroutine(DropLocalLoot());
  36. }
  37. private IEnumerator DropLocalLoot()
  38. {
  39. yield return new WaitForSeconds(0.2f);
  40. if (Random.Range(0, 3) == 0)
  41. {
  42. var item = GadgetCoreAPI.EmptyItem();
  43. item.id = Core.itemOldTex.GetID();
  44. GadgetCoreAPI.DropItemLocal(gameObject.transform.position, item);
  45. }
  46. else
  47. {
  48. var item = GadgetCoreAPI.EmptyItem();
  49. item.id = dropsEmblem[Random.Range(0, dropsEmblem.Length)];
  50. GadgetCoreAPI.DropItemLocal(gameObject.transform.position, item);
  51. }
  52. for (int i = 0; i < 3; i++)
  53. {
  54. if (Random.Range(0, 3) > 0)
  55. {
  56. var item = GadgetCoreAPI.EmptyItem();
  57. item.id = dropsLoot[Random.Range(0, dropsLoot.Length)];
  58. GadgetCoreAPI.DropItemLocal(gameObject.transform.position, item);
  59. }
  60. }
  61. yield return new WaitForSeconds(0.2f);
  62. GadgetCoreAPI.SpawnExp(gameObject.transform.position, 25);
  63. yield return new WaitForSeconds(0.2f);
  64. GadgetCoreAPI.SpawnExp(gameObject.transform.position, 10);
  65. yield return new WaitForSeconds(0.2f);
  66. GadgetCoreAPI.SpawnExp(gameObject.transform.position, 20);
  67. yield break;
  68. }
  69. private static Texture2D textureOldChestOpen = GadgetCoreAPI.LoadTexture2D("Ship/oldChestOpen.png");
  70. [RPC]
  71. private void OpenMat()
  72. {
  73. Menuu.characterStat[8]++;
  74. GameScript.cadetValue += 2;
  75. base.GetComponent<AudioSource>().PlayOneShot((AudioClip)Resources.Load("Au/chest"), Menuu.soundLevel / 10f);
  76. base.GetComponent<Collider>().enabled = false;
  77. Renderer renderer = gameObject.transform.GetChild(0).gameObject.GetComponentInChildren<Renderer>();
  78. renderer.material = new Material(Shader.Find("Unlit/Transparent"))
  79. {
  80. mainTexture = textureOldChestOpen
  81. };
  82. }
  83. }
  84. }