GalacticDarkfireItemInfo.cs 5.2 KB

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