using System; using System.Collections; using DatabaseModel; using LitJson; using OnionSkin; using UnityEngine; public class DaoPaoAnimEvent : BaseBehaviour { private Transform player { get { return R.Player.Transform; } } private void Start() { this._rollLoopTimes = 2; this._eAction = base.GetComponent(); this._eAttr = base.GetComponent(); this._atkData = SingletonMono.Instance.attack[EnemyType.刀炮混合]; this._onion = base.GetComponent(); this._rigidbody2D = base.GetComponent(); } private void Update() { if (this._eAttr.isDead) { return; } if (this._rollAttackFly && this._eAttr.isOnGround && this._rigidbody2D.velocity.y <= 0f) { this._rollAttackFly = false; this._eAction.AnimChangeState(DaoPaoAction.StateEnum.HitGround, 1f); } if (this._eAttr.isFlyingUp) { bool flag = this.maxFlyHeight > 0f && this._eAttr.height >= this.maxFlyHeight; if (flag) { Vector2 currentSpeed = this._eAttr.timeController.GetCurrentSpeed(); currentSpeed.y = 0f; this._eAttr.timeController.SetSpeed(currentSpeed); } if (this._rigidbody2D.velocity.y <= 0f) { this._eAttr.isFlyingUp = false; this._eAction.AnimChangeState(DaoPaoAction.StateEnum.HitToFly3, 1f); } } if (this._eAttr.checkHitGround && this._eAttr.isOnGround) { this._eAttr.checkHitGround = false; R.Effect.Generate(6, base.transform, default(Vector3), default(Vector3), default(Vector3), true); if (this._eAction.stateMachine.currentState == "HitFall") { this.maxFlyHeight = 4f; this._eAttr.timeController.SetSpeed(Vector2.up * 25f); this._eAction.AnimChangeState(DaoPaoAction.StateEnum.HitToFly1, 1f); } else { this._eAction.AnimChangeState(DaoPaoAction.StateEnum.FallHitGround, 1f); } } } public void ChangeState(DaoPaoAction.StateEnum sta) { this._eAction.AnimChangeState(sta.ToString(), 1f); } public void PlaySound(int index) { R.Audio.PlayEffect(index, new Vector3?(base.transform.position)); } public void PlayMoveSound() { R.Audio.PlayEffect(this.moveSound[UnityEngine.Random.Range(0, this.moveSound.Length)], new Vector3?(base.transform.position)); } public void PlayHitGroundSound() { R.Audio.PlayEffect(this.hitGroundSound[UnityEngine.Random.Range(0, this.hitGroundSound.Length)], new Vector3?(base.transform.position)); } public void RollStart() { if (this._rollOver) { this._rollOver = false; this._rollLoopTimes = 2; } } public void Atk2Start() { this._rollOver = true; this._eAttr.paBody = true; } public void RollOver() { this._rollLoopTimes--; if (this._rollLoopTimes <= 0) { if (this._eAction.stateMachine.currentState == "DaoAtk6_2" && UnityEngine.Random.Range(0, 100) < 50) { this._eAction.FaceToPlayer(); this.atk.atkId = Incrementor.GetNextId(); this._eAction.AnimChangeState(DaoPaoAction.StateEnum.DaoAtk4, 1f); } else { this._eAction.AnimChangeState(DaoPaoAction.StateEnum.Idle, 1f); } this._rollOver = true; } } public void Atk6_1Over() { if (UnityEngine.Random.Range(0, 100) < 50) { this._eAction.FaceToPlayer(); this.atk.atkId = Incrementor.GetNextId(); this._eAction.AnimChangeState(DaoPaoAction.StateEnum.DaoAtk6_2Ready, 1f); } else { this._eAction.AnimChangeState(DaoPaoAction.StateEnum.Idle, 1f); } } public void HitGround() { this._rollAttackFly = false; this._eAttr.checkHitGround = true; } public void FlyUp() { this._rollAttackFly = false; this._eAttr.isFlyingUp = true; } public void SetAtkData() { this.atk.atkData = this._atkData[this._eAction.stateMachine.currentState]; } public void SwordFightStart() { this._rollAttackFly = true; } public void RunAwayEnd() { this.BackToIdle(); if (!this._eAction.IsInNormalState()) { return; } if (UnityEngine.Random.Range(0, 2) == 0) { int dir = InputSetting.JudgeDir(base.transform.position, this.player.position); this._eAction.Attack3(dir); } } public void GetUp() { if (this._eAttr.isDead) { this.DieBlock(); this.DestroySelf(); } else { this._eAction.AnimChangeState(DaoPaoAction.StateEnum.GetUp, 1f); } } public void BackToIdle() { if (this._eAction.IsInWeakSta()) { this._eAttr.enterWeakMod = false; } this._eAction.AnimChangeState(DaoAction.StateEnum.Idle, 1f); } public void WeakOver() { if (!this._eAction.IsInWeakSta()) { this._eAction.AnimChangeState(DaoPaoAction.StateEnum.Idle, 1f); } } public void DestroySelf() { this.RealDestroy(); } private void RealDestroy() { UnityEngine.Object.Destroy(base.gameObject); } public void Shoot() { Transform transform = UnityEngine.Object.Instantiate(this.bullet); EnemyBullet component = transform.GetComponent(); component.damage = this._eAttr.atk; component.origin = base.gameObject; transform.position = this.gunPos.position; Vector2 from = this.gunPos.position - this.gunAssistant.position; if (Vector2.Angle(from, Vector2.right) < 3f) { from = Vector2.right; } if (Vector2.Angle(from, -Vector2.right) < 3f) { from = -Vector2.right; } transform.GetComponent().velocity = from.normalized * 12f; component.SetAtkData(this._atkData["Bullet"]); } public IEnumerator TargetingPlayer() { float angle = Vector2.Angle(this.player.position + Vector3.up - base.transform.position, Vector2.up); if (angle >= 45f) { this.gun.GetComponent().mode = SkeletonUtilityBone.Mode.Override; Vector3 startEuler = this.gun.localEulerAngles; float targetAngle = Mathf.Clamp(angle - 8f, 37f, 128f); for (int i = 0; i < 40; i++) { this.gun.localEulerAngles = Vector3.Lerp(startEuler, new Vector3(0f, 0f, targetAngle), (float)i / 39f); yield return null; } } yield break; } public IEnumerator TargetingRecover() { if (this.gun.GetComponent().mode == SkeletonUtilityBone.Mode.Override) { Vector3 startEuler = this.gun.localEulerAngles; int clips = (int)(startEuler.z / 2f); if (clips > 1) { for (int i = 0; i < clips; i++) { this.gun.localEulerAngles = Vector3.Lerp(startEuler, new Vector3(0f, 0f, 80f), (float)i * 1f / (float)(clips - 1)); yield return null; } } } this.gun.GetComponent().mode = SkeletonUtilityBone.Mode.Follow; yield break; } public void PlayHitGroundEffect() { R.Effect.Generate(40, base.transform, Vector3.zero, new Vector3(0f, (float)(90 * this._eAttr.faceDir), 0f), default(Vector3), true); } public void DieBlock() { R.Effect.Generate(163, null, new Vector3(base.transform.position.x, base.transform.position.y, base.transform.position.z - 0.1f), Vector3.zero, default(Vector3), true); } public void ChargingDieEffect() { if (!R.Camera.IsInView(base.gameObject)) { return; } GameObject prefab = CameraEffectProxyPrefabData.GetPrefab(9); UnityEngine.Object.Instantiate(prefab, this._eAttr.bounds.center, Quaternion.identity); } public void OpenOnion() { this._onion.Open(true, 0.7f, this.onionObj); } [SerializeField] private EnemyAtk atk; private JsonData _atkData; [SerializeField] private Transform bullet; private DaoPaoAction _eAction; private EnemyAttribute _eAttr; [SerializeField] private Transform gun; [SerializeField] private Transform gunAssistant; [SerializeField] private Transform gunPos; [SerializeField] private int[] hitGroundSound; public float maxFlyHeight; [SerializeField] private int[] moveSound; private OnionCreator _onion; [SerializeField] private GameObject[] onionObj; private bool _rollAttackFly; private int _rollLoopTimes; private bool _rollOver; private Rigidbody2D _rigidbody2D; }