GalacticDarkfireItemInfo.cs 5.1 KB

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