RingaboltsOathItemInfo.cs 6.0 KB

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