WallacesBirthrightItemInfo.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 WallacesBirthrightItemInfo : ItemInfo
  9. {
  10. private const string RPCId = nameof(WallacesBirthrightItemInfo) + "Attack";
  11. public WallacesBirthrightItemInfo(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 WallacesBirthrightItemInfo(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. };
  36. gameObject.transform.GetChild(0).localScale = new Vector3(8, 8, 1);
  37. gameObject.transform.GetChild(1).localScale = new Vector3(6, 6, 1);
  38. Renderer rendererPar = gameObject.transform.GetChild(1).GetComponentInChildren<Renderer>();
  39. rendererPar.material = new Material(rendererPar.material)
  40. {
  41. mainTexture = textureTrail
  42. };
  43. gameObject.transform.GetComponent<BoxCollider>().size = new Vector3(7.5f, 7.5f, 1);
  44. Component.DestroyImmediate(gameObject.GetComponent<Projectile>());
  45. gameObject.AddComponent<WallacesBirthrightProjectile>();
  46. GadgetCoreAPI.AddCustomResource("proj/shot" + GetID(), gameObject);
  47. }
  48. private void Attack(object[] o)
  49. {
  50. Vector3 cursorPos = new Vector3((float)o[0], (float)o[1], (float)o[2]);
  51. Vector3 startPos = new Vector3((float)o[3], (float)o[4], (float)o[5]);
  52. int dmg = (int)o[6];
  53. int projRange = (int)o[7];
  54. Package2 package = new Package2(cursorPos, dmg, ProjectileID, projRange);
  55. GameObject gameObject2 = (GameObject)UnityEngine.Object.Instantiate(Resources.Load("proj/shot" + ProjectileID), startPos, Quaternion.identity);
  56. gameObject2.SendMessage("Set", package);
  57. }
  58. public IEnumerator Attack(PlayerScript script)
  59. {
  60. canAttack.SetValue(script, false);
  61. attacking.SetValue(script, true);
  62. script.StartCoroutine(script.ATKSOUND());
  63. script.GetComponent<AudioSource>().PlayOneShot((AudioClip)Resources.Load("Au/shoot"), Menuu.soundLevel / 10f);
  64. if (PlayerScript.grounded)
  65. {
  66. if (Camera.main.ScreenToWorldPoint(Input.mousePosition).x > ((Transform)t.GetValue(script)).position.x)
  67. {
  68. ((Rigidbody)r.GetValue(script)).velocity = new Vector3(((Rigidbody)r.GetValue(script)).velocity.x + 20f, ((Rigidbody)r.GetValue(script)).velocity.y + 5f, 0f);
  69. }
  70. else
  71. {
  72. ((Rigidbody)r.GetValue(script)).velocity = new Vector3(((Rigidbody)r.GetValue(script)).velocity.x - 20f, ((Rigidbody)r.GetValue(script)).velocity.y + 5f, 0f);
  73. }
  74. }
  75. script.Animate(5);
  76. yield return new WaitForSeconds(0.3f);
  77. script.attackCube3.SetActive(true);
  78. if (PlayerScript.inmagemash > 0)
  79. {
  80. script.MageMash();
  81. }
  82. yield return new WaitForSeconds(0.2f);
  83. script.attackCube3.SetActive(false);
  84. int dmg = GetDamage(script);
  85. if (TryCrit(script))
  86. {
  87. dmg = MultiplyCrit(script, dmg);
  88. script.GetComponent<AudioSource>().PlayOneShot(script.critSound, Menuu.soundLevel / 10f);
  89. UnityEngine.Object.Instantiate(script.crit, script.transform.position, Quaternion.identity);
  90. }
  91. {
  92. Vector3 cursorPos = Camera.main.ScreenToWorldPoint(Input.mousePosition) - ((Transform)t.GetValue(script)).position;
  93. Vector3 startPos;
  94. if (Camera.main.ScreenToWorldPoint(Input.mousePosition).x > ((Transform)t.GetValue(script)).position.x)
  95. startPos = new Vector3(((Transform)t.GetValue(script)).position.x + 5f, ((Transform)t.GetValue(script)).position.y, 0f);
  96. else
  97. startPos = new Vector3(((Transform)t.GetValue(script)).position.x - 5f, ((Transform)t.GetValue(script)).position.y, 0f);
  98. Package2 package = new Package2(cursorPos, dmg, ProjectileID, (float)GameScript.MODS[10]);
  99. GameObject gameObject2 = (GameObject)UnityEngine.Object.Instantiate(Resources.Load("proj/shot" + ProjectileID), startPos, Quaternion.identity);
  100. gameObject2.SendMessage("Set", package);
  101. GadgetCoreAPI.CallCustomRPC(RPCId, RPCMode.Others, cursorPos.x, cursorPos.y, cursorPos.z,
  102. startPos.x, startPos.y, startPos.z, dmg, PlayerGearModsTracker.GetGearMods(script)[10]);
  103. }
  104. attacking.SetValue(script, false);
  105. yield return new WaitForSeconds(0.1f);
  106. canAttack.SetValue(script, true);
  107. yield break;
  108. }
  109. }
  110. }