| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- using GadgetCore.API;
- using System.Collections;
- using System.Reflection;
- using UltimateNPCWeapons.Scripts;
- using UnityEngine;
- namespace UltimateNPCWeapons.Infos
- {
- public class WallacesBirthrightItemInfo : ItemInfo
- {
- private const string RPCId = nameof(WallacesBirthrightItemInfo) + "Attack";
- 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)
- : base(Type, Name, Desc, Tex, Value, Stats, HeldTex, HeadTex, BodyTex, ArmTex)
- {
- GadgetCoreAPI.RegisterCustomRPC(RPCId, (e) => { Attack(e); });
- }
- 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)
- : 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>();
- renderer.material = new Material(renderer.material)
- {
- mainTexture = textureMain
- };
- gameObject.transform.GetChild(0).localScale = new Vector3(8, 8, 1);
- gameObject.transform.GetChild(1).localScale = new Vector3(6, 6, 1);
- Renderer rendererPar = gameObject.transform.GetChild(1).GetComponentInChildren<Renderer>();
- rendererPar.material = new Material(rendererPar.material)
- {
- mainTexture = textureTrail
- };
- gameObject.transform.GetComponent<BoxCollider>().size = new Vector3(7.5f, 7.5f, 1);
- Component.DestroyImmediate(gameObject.GetComponent<Projectile>());
- gameObject.AddComponent<WallacesBirthrightProjectile>();
- 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<AudioSource>().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<AudioSource>().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;
- }
- }
- }
|