RingaboltsOathItemInfo.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using GadgetCore.API;
  2. using System.Collections;
  3. using System.Reflection;
  4. using UltimateNPCWeapons.Scripts;
  5. using UnityEngine;
  6. namespace UltimateNPCWeapons.Infos
  7. {
  8. public class RingaboltsOathItemInfo : ItemInfo
  9. {
  10. private const string RPCId = nameof(RingaboltsOathItemInfo) + "Attack";
  11. public RingaboltsOathItemInfo(ItemType Type, string Name, string Desc, Texture Tex, int Value = -1, EquipStats Stats = default, Texture HeldTex = null, Texture HeadTex = null, Texture BodyTex = null, Texture ArmTex = null)
  12. : base(Type, Name, Desc, Tex, Value, Stats, HeldTex, HeadTex, BodyTex, ArmTex)
  13. {
  14. GadgetCoreAPI.RegisterCustomRPC(RPCId, (e) => { Attack(e); });
  15. }
  16. public RingaboltsOathItemInfo(ItemType Type, string Name, string Desc, Material Mat, int Value = -1, EquipStats Stats = default, Material HeldMat = null, Material HeadMat = null, Material BodyMat = null, Material ArmMat = null)
  17. : base(Type, Name, Desc, Mat, Value, Stats, HeldMat, HeadMat, BodyMat, ArmMat)
  18. {
  19. GadgetCoreAPI.RegisterCustomRPC(RPCId, (e) => { Attack(e); });
  20. }
  21. private static readonly FieldInfo canAttack = typeof(PlayerScript).GetField("canAttack", BindingFlags.NonPublic | BindingFlags.Instance);
  22. private static readonly FieldInfo attacking = typeof(PlayerScript).GetField("attacking", BindingFlags.NonPublic | BindingFlags.Instance);
  23. private static readonly FieldInfo t = typeof(PlayerScript).GetField("t", BindingFlags.NonPublic | BindingFlags.Instance);
  24. private static readonly FieldInfo r = typeof(PlayerScript).GetField("r", BindingFlags.NonPublic | BindingFlags.Instance);
  25. public void CreateProjectile(string main, string trail)
  26. {
  27. Texture2D textureMain = GadgetCoreAPI.LoadTexture2D(main);
  28. Texture2D textureTrail = GadgetCoreAPI.LoadTexture2D(trail);
  29. GameObject gameObject = UnityEngine.Object.Instantiate(GadgetCoreAPI.GetWeaponProjectileResource(496));
  30. gameObject.name = "shot" + GetID();
  31. Renderer renderer = gameObject.GetComponentInChildren<Renderer>();
  32. renderer.material = new Material(renderer.material)
  33. {
  34. mainTexture = textureMain,
  35. mainTextureScale = new Vector2(0.25f, 1f)
  36. };
  37. renderer.material.SetVector("_MainTex_ST", new Vector3(8, 1, 1));
  38. gameObject.transform.localScale = new Vector3(8, 1, 5);
  39. gameObject.transform.GetChild(0).localScale = new Vector3(4, 1, 1);
  40. Renderer rendererTrail = gameObject.transform.GetChild(1).GetComponentInChildren<Renderer>();
  41. rendererTrail.material = new Material(rendererTrail.material)
  42. {
  43. mainTexture = textureTrail
  44. };
  45. Component.DestroyImmediate(gameObject.GetComponent<Projectile>());
  46. gameObject.AddComponent<RingaboltsOathProjectile>();
  47. GadgetCoreAPI.AddCustomResource("proj/shot" + GetID(), gameObject);
  48. }
  49. private void Attack(object[] o)
  50. {
  51. Vector3 cursorPos = new Vector3((float)o[0], (float)o[1], (float)o[2]);
  52. Vector3 startPos = new Vector3((float)o[3], (float)o[4], (float)o[5]);
  53. int dmg = (int)o[6];
  54. int projRange = (int)o[7];
  55. Package2 package = new Package2(cursorPos, dmg, ProjectileID, projRange);
  56. GameObject gameObject2 = (GameObject)UnityEngine.Object.Instantiate(Resources.Load("proj/shot" + ProjectileID), startPos, Quaternion.identity);
  57. gameObject2.SendMessage("Set", package);
  58. }
  59. public IEnumerator Attack(PlayerScript script)
  60. {
  61. canAttack.SetValue(script, false);
  62. attacking.SetValue(script, true);
  63. script.StartCoroutine(script.ATKSOUND());
  64. script.GetComponent<AudioSource>().PlayOneShot((AudioClip)Resources.Load("Au/shoot"), Menuu.soundLevel / 10f);
  65. if (PlayerScript.grounded)
  66. {
  67. if (Camera.main.ScreenToWorldPoint(Input.mousePosition).x > ((Transform)t.GetValue(script)).position.x)
  68. {
  69. ((Rigidbody)r.GetValue(script)).velocity = new Vector3(((Rigidbody)r.GetValue(script)).velocity.x + 20f, ((Rigidbody)r.GetValue(script)).velocity.y + 5f, 0f);
  70. }
  71. else
  72. {
  73. ((Rigidbody)r.GetValue(script)).velocity = new Vector3(((Rigidbody)r.GetValue(script)).velocity.x - 20f, ((Rigidbody)r.GetValue(script)).velocity.y + 5f, 0f);
  74. }
  75. }
  76. script.Animate(5);
  77. yield return new WaitForSeconds(0.3f);
  78. script.attackCube3.SetActive(true);
  79. if (PlayerScript.inmagemash > 0)
  80. {
  81. script.MageMash();
  82. }
  83. yield return new WaitForSeconds(0.2f);
  84. script.attackCube3.SetActive(false);
  85. int dmg = GetDamage(script);
  86. if (TryCrit(script))
  87. {
  88. dmg = MultiplyCrit(script, dmg);
  89. script.GetComponent<AudioSource>().PlayOneShot(script.critSound, Menuu.soundLevel / 10f);
  90. UnityEngine.Object.Instantiate(script.crit, script.transform.position, Quaternion.identity);
  91. }
  92. {
  93. Vector3 cursorPos = Camera.main.ScreenToWorldPoint(Input.mousePosition) - ((Transform)t.GetValue(script)).position;
  94. Vector3 startPos;
  95. if (Camera.main.ScreenToWorldPoint(Input.mousePosition).x > ((Transform)t.GetValue(script)).position.x)
  96. startPos = new Vector3(((Transform)t.GetValue(script)).position.x + 5f, ((Transform)t.GetValue(script)).position.y, 0f);
  97. else
  98. startPos = new Vector3(((Transform)t.GetValue(script)).position.x - 5f, ((Transform)t.GetValue(script)).position.y, 0f);
  99. Package2 package = new Package2(cursorPos, dmg, ProjectileID, (float)GameScript.MODS[10]);
  100. GameObject gameObject2 = (GameObject)UnityEngine.Object.Instantiate(Resources.Load("proj/shot" + ProjectileID), startPos, Quaternion.identity);
  101. gameObject2.SendMessage("Set", package);
  102. GadgetCoreAPI.CallCustomRPC(RPCId, RPCMode.Others, cursorPos.x, cursorPos.y, cursorPos.z,
  103. startPos.x, startPos.y, startPos.z, dmg, PlayerGearModsTracker.GetGearMods(script)[10]);
  104. }
  105. attacking.SetValue(script, false);
  106. yield return new WaitForSeconds(0.1f);
  107. canAttack.SetValue(script, true);
  108. yield break;
  109. }
  110. }
  111. }