using GadgetCore.API; using System.Collections; using System.Reflection; using UltimateNPCWeapons.Scripts; using UnityEngine; namespace UltimateNPCWeapons.Infos { public class RingaboltsOathItemInfo : ItemInfo { private const string RPCId = nameof(RingaboltsOathItemInfo) + "Attack"; 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) : base(Type, Name, Desc, Tex, Value, Stats, HeldTex, HeadTex, BodyTex, ArmTex) { GadgetCoreAPI.RegisterCustomRPC(RPCId, (e) => { Attack(e); }); } 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) : base(Type, Name, Desc, Mat, Value, Stats, HeldMat, HeadMat, BodyMat, ArmMat) { GadgetCoreAPI.RegisterCustomRPC(RPCId, (e) => { Attack(e); }); } private static readonly FieldInfo canAttack = typeof(PlayerScript).GetField("canAttack", BindingFlags.NonPublic | BindingFlags.Instance); private static readonly FieldInfo attacking = typeof(PlayerScript).GetField("attacking", BindingFlags.NonPublic | BindingFlags.Instance); private static readonly FieldInfo t = typeof(PlayerScript).GetField("t", BindingFlags.NonPublic | BindingFlags.Instance); private static readonly FieldInfo r = typeof(PlayerScript).GetField("r", BindingFlags.NonPublic | BindingFlags.Instance); public void CreateProjectile(string main, string trail) { Texture2D textureMain = GadgetCoreAPI.LoadTexture2D(main); Texture2D textureTrail = GadgetCoreAPI.LoadTexture2D(trail); GameObject gameObject = UnityEngine.Object.Instantiate(GadgetCoreAPI.GetWeaponProjectileResource(496)); gameObject.name = "shot" + GetID(); Renderer renderer = gameObject.GetComponentInChildren(); renderer.material = new Material(renderer.material) { mainTexture = textureMain, mainTextureScale = new Vector2(0.25f, 1f) }; renderer.material.SetVector("_MainTex_ST", new Vector3(8, 1, 1)); gameObject.transform.localScale = new Vector3(8, 1, 5); gameObject.transform.GetChild(0).localScale = new Vector3(4, 1, 1); Renderer rendererTrail = gameObject.transform.GetChild(1).GetComponentInChildren(); rendererTrail.material = new Material(rendererTrail.material) { mainTexture = textureTrail }; Component.DestroyImmediate(gameObject.GetComponent()); gameObject.AddComponent(); GadgetCoreAPI.AddCustomResource("proj/shot" + GetID(), gameObject); } private void Attack(object[] o) { Vector3 cursorPos = new Vector3((float)o[0], (float)o[1], (float)o[2]); Vector3 startPos = new Vector3((float)o[3], (float)o[4], (float)o[5]); int dmg = (int)o[6]; int projRange = (int)o[7]; Package2 package = new Package2(cursorPos, dmg, ProjectileID, projRange); GameObject gameObject2 = (GameObject)UnityEngine.Object.Instantiate(Resources.Load("proj/shot" + ProjectileID), startPos, Quaternion.identity); gameObject2.SendMessage("Set", package); } public IEnumerator Attack(PlayerScript script) { canAttack.SetValue(script, false); attacking.SetValue(script, true); script.StartCoroutine(script.ATKSOUND()); script.GetComponent().PlayOneShot((AudioClip)Resources.Load("Au/shoot"), Menuu.soundLevel / 10f); if (PlayerScript.grounded) { if (Camera.main.ScreenToWorldPoint(Input.mousePosition).x > ((Transform)t.GetValue(script)).position.x) { ((Rigidbody)r.GetValue(script)).velocity = new Vector3(((Rigidbody)r.GetValue(script)).velocity.x + 20f, ((Rigidbody)r.GetValue(script)).velocity.y + 5f, 0f); } else { ((Rigidbody)r.GetValue(script)).velocity = new Vector3(((Rigidbody)r.GetValue(script)).velocity.x - 20f, ((Rigidbody)r.GetValue(script)).velocity.y + 5f, 0f); } } script.Animate(5); yield return new WaitForSeconds(0.3f); script.attackCube3.SetActive(true); if (PlayerScript.inmagemash > 0) { script.MageMash(); } yield return new WaitForSeconds(0.2f); script.attackCube3.SetActive(false); int dmg = GetDamage(script); if (TryCrit(script)) { dmg = MultiplyCrit(script, dmg); script.GetComponent().PlayOneShot(script.critSound, Menuu.soundLevel / 10f); UnityEngine.Object.Instantiate(script.crit, script.transform.position, Quaternion.identity); } { Vector3 cursorPos = Camera.main.ScreenToWorldPoint(Input.mousePosition) - ((Transform)t.GetValue(script)).position; Vector3 startPos; if (Camera.main.ScreenToWorldPoint(Input.mousePosition).x > ((Transform)t.GetValue(script)).position.x) startPos = new Vector3(((Transform)t.GetValue(script)).position.x + 5f, ((Transform)t.GetValue(script)).position.y, 0f); else startPos = new Vector3(((Transform)t.GetValue(script)).position.x - 5f, ((Transform)t.GetValue(script)).position.y, 0f); Package2 package = new Package2(cursorPos, dmg, ProjectileID, (float)GameScript.MODS[10]); GameObject gameObject2 = (GameObject)UnityEngine.Object.Instantiate(Resources.Load("proj/shot" + ProjectileID), startPos, Quaternion.identity); gameObject2.SendMessage("Set", package); GadgetCoreAPI.CallCustomRPC(RPCId, RPCMode.Others, cursorPos.x, cursorPos.y, cursorPos.z, startPos.x, startPos.y, startPos.z, dmg, PlayerGearModsTracker.GetGearMods(script)[10]); } attacking.SetValue(script, false); yield return new WaitForSeconds(0.1f); canAttack.SetValue(script, true); yield break; } } }