GalacticSilenceItemInfo.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using GadgetCore.API;
  2. using System.Collections;
  3. using System.Reflection;
  4. using UnityEngine;
  5. namespace UltimateNPCWeapons.Infos
  6. {
  7. public class GalacticSilenceItemInfo : ItemInfo
  8. {
  9. private const string RPCId = nameof(GalacticSilenceItemInfo) + "Attack";
  10. public GalacticSilenceItemInfo(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 GalacticSilenceItemInfo(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(470));
  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.transform.position = rendererParticles.transform.position + new Vector3(0, 0, 0.5f);
  37. rendererParticles.material = new Material(Shader.Find("Unlit/Transparent"))
  38. {
  39. mainTexture = textureTrail
  40. };
  41. GadgetCoreAPI.AddCustomResource("proj/shot" + GetID(), gameObject);
  42. }
  43. private void Attack(object[] o)
  44. {
  45. Vector3 cursorPos = new Vector3((float)o[0], (float)o[1], (float)o[2]);
  46. Vector3 startPos = new Vector3((float)o[3], (float)o[4], (float)o[5]);
  47. int dmg = (int)o[6];
  48. int projRange = (int)o[7];
  49. Package2 package = new Package2(cursorPos, dmg, ProjectileID, projRange);
  50. GameObject gameObject2 = (GameObject)UnityEngine.Object.Instantiate(Resources.Load("proj/shot" + ProjectileID), startPos, Quaternion.identity);
  51. gameObject2.SendMessage("Set", package);
  52. }
  53. public IEnumerator Attack(PlayerScript script)
  54. {
  55. canAttack.SetValue(script, false);
  56. attacking.SetValue(script, true);
  57. script.StartCoroutine(script.ATKSOUND());
  58. script.GetComponent<AudioSource>().PlayOneShot((AudioClip)Resources.Load("Au/shoot"), Menuu.soundLevel / 10f);
  59. script.Animate(4);
  60. yield return new WaitForSeconds(0.3f);
  61. int dmg = GetDamage(script);
  62. if (TryCrit(script))
  63. {
  64. dmg = MultiplyCrit(script, dmg);
  65. script.GetComponent<AudioSource>().PlayOneShot(script.critSound, Menuu.soundLevel / 10f);
  66. UnityEngine.Object.Instantiate(script.crit, script.transform.position, Quaternion.identity);
  67. }
  68. {
  69. if (Camera.main.ScreenToWorldPoint(Input.mousePosition).x > ((Transform)t.GetValue(script)).position.x)
  70. ((Rigidbody)r.GetValue(script)).velocity = new Vector3(-10f, ((Rigidbody)r.GetValue(script)).velocity.y + 5f, 0f);
  71. else
  72. ((Rigidbody)r.GetValue(script)).velocity = new Vector3(10f, ((Rigidbody)r.GetValue(script)).velocity.y + 5f, 0f);
  73. Vector3 cursorPos = Camera.main.ScreenToWorldPoint(Input.mousePosition) - ((Transform)t.GetValue(script)).position;
  74. Vector3 startPos = script.shot.transform.position;
  75. Package2 package = new Package2(cursorPos, dmg, ProjectileID, (float)GameScript.MODS[10]);
  76. GameObject gameObject2 = (GameObject)UnityEngine.Object.Instantiate(Resources.Load("proj/shot" + ProjectileID), startPos, Quaternion.identity);
  77. gameObject2.SendMessage("Set", package);
  78. GadgetCoreAPI.CallCustomRPC(RPCId, RPCMode.Others, cursorPos.x, cursorPos.y, cursorPos.z,
  79. startPos.x, startPos.y, startPos.z, dmg, PlayerGearModsTracker.GetGearMods(script)[10]);
  80. }
  81. yield return new WaitForSeconds(0.3f);
  82. attacking.SetValue(script, false);
  83. yield return new WaitForSeconds(0.1f);
  84. canAttack.SetValue(script, true);
  85. yield break;
  86. }
  87. }
  88. }