EnemyDaoHurt.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. using System;
  2. using System.Collections;
  3. using ExtensionMethods;
  4. using GameWorld;
  5. using UnityEngine;
  6. public class EnemyDaoHurt : EnemyBaseHurt
  7. {
  8. protected override void Update()
  9. {
  10. base.Update();
  11. Vector2? vector = this.atkFollowPos;
  12. if (vector != null)
  13. {
  14. Vector3 position = base.player.transform.position;
  15. Vector2? vector2 = this.atkFollowPos;
  16. Vector3 position2 = position - ((vector2 == null) ? default(Vector3) : (Vector3)vector2.GetValueOrDefault());
  17. position2.y = Mathf.Clamp(position2.y, LayerManager.YNum.GetGroundHeight(base.gameObject) + 1f, float.PositiveInfinity);
  18. position2.z = LayerManager.ZNum.MMiddleE(this.eAttr.rankType);
  19. base.transform.position = position2;
  20. this.atkFollowTime += Time.unscaledDeltaTime;
  21. if (this.atkFollowTime >= this.atkFollowEnd)
  22. {
  23. this.atkFollowPos = null;
  24. }
  25. }
  26. }
  27. protected override void Init()
  28. {
  29. this._dao = base.GetComponent<DaoEnemyAnimListener>();
  30. this.defaultAnimName = "Hit1";
  31. this.defaultAirAnimName = "HitToFly1";
  32. this.airDieAnimName = "Fall";
  33. this.airDieHitGroundAnimName = "AirDie";
  34. this.flyToFallAnimName = "AirDiePre";
  35. this.hurtData = SingletonMono<EnemyDataPreload>.Instance.hurt[EnemyType.斩轮式一型];
  36. }
  37. public override void SetHitSpeed(Vector2 speed)
  38. {
  39. if (this.playerAtkName == "UpRising" || this.playerAtkName == "AtkUpRising" || this.playerAtkName == "AtkRollEnd" || this.playerAtkName == "NewExecute2_1")
  40. {
  41. this._dao.maxFlyHeight = 4.5f;
  42. }
  43. else
  44. {
  45. this._dao.maxFlyHeight = -1f;
  46. }
  47. base.SetHitSpeed(speed);
  48. }
  49. public override void NormalHurt(EnemyHurtAtkEventArgs.PlayerNormalAtkData atkData, int atkId, HurtCheck.BodyType body, Vector2 hurtPos)
  50. {
  51. if (this.action.stateMachine.currentState.IsInArray(DaoAction.SideStepSta))
  52. {
  53. return;
  54. }
  55. base.NormalHurt(atkData, atkId, body, hurtPos);
  56. }
  57. private void RollHurt()
  58. {
  59. Vector2 vector = new Vector2((float)(this.eAttr.faceDir * -8), 12f);
  60. base.PlayHurtAnim("HitToFly1", "HitToFly1", vector, vector);
  61. }
  62. protected override void SpAttack()
  63. {
  64. if (this.eAttr.currentActionInterruptPoint < this.eAttr.actionInterruptPoint)
  65. {
  66. return;
  67. }
  68. if (this.playerAtkName == "RollEnd")
  69. {
  70. Vector2? vector = this.atkFollowPos;
  71. if (vector != null)
  72. {
  73. this.atkFollowPos = null;
  74. }
  75. return;
  76. }
  77. if (this.playerAtkName == "RollGround")
  78. {
  79. Vector2? vector2 = this.atkFollowPos;
  80. if (vector2 == null)
  81. {
  82. Transform transform = base.player.GetComponentInChildren<PlayerAtk>().transform;
  83. this.atkFollowPos = new Vector2?((transform.position - base.transform.position) * 0.9f);
  84. }
  85. this.atkFollowTime = 0f;
  86. this.atkFollowEnd = 0.2f;
  87. return;
  88. }
  89. if (this.playerAtkName == "RollReady" || this.playerAtkName == "BladeStormReady")
  90. {
  91. Vector2? vector3 = this.atkFollowPos;
  92. if (vector3 == null)
  93. {
  94. this.atkFollowPos = new Vector2?((base.player.transform.position - base.transform.position) * 0.7f);
  95. }
  96. this.atkFollowTime = 0f;
  97. this.atkFollowEnd = 0.2f;
  98. return;
  99. }
  100. if (this.playerAtkName == "Atk4")
  101. {
  102. base.StartCoroutine(this.CloseToPlayer());
  103. return;
  104. }
  105. this.atkFollowTime = 0f;
  106. this.atkFollowEnd = 0f;
  107. }
  108. private IEnumerator CloseToPlayer()
  109. {
  110. this.closeToPlayer.state.SetAnimation(0, "Show", false);
  111. this.closeToPlayer.skeleton.SetToSetupPose();
  112. Vector3 endPos = base.player.transform.position + Vector3.right * (float)base.pAttr.faceDir * UnityEngine.Random.Range(0.8f, 1.5f);
  113. endPos.z = LayerManager.ZNum.MMiddleE(this.eAttr.rankType);
  114. Vector3 startPos = base.transform.position;
  115. for (int i = 0; i < 5; i++)
  116. {
  117. yield return new WaitForFixedUpdate();
  118. }
  119. for (int j = 0; j < 6; j++)
  120. {
  121. base.transform.position = Vector3.Lerp(startPos, endPos, (float)j / 5f);
  122. yield return new WaitForFixedUpdate();
  123. }
  124. yield break;
  125. }
  126. protected override void ExecuteFollow()
  127. {
  128. this.action.AnimChangeState(DaoAction.StateEnum.Execute, 1f);
  129. base.ExecuteFollow();
  130. }
  131. protected override void PlayHurtAudio()
  132. {
  133. R.Audio.PlayEffect(401, new Vector3?(base.transform.position));
  134. if (base.PlaySpHurtAudio())
  135. {
  136. R.Audio.PlayEffect(UnityEngine.Random.Range(57, 59), new Vector3?(base.transform.position));
  137. }
  138. }
  139. protected override void ExecuteDie()
  140. {
  141. base.ExecuteDie();
  142. this.eAttr.timeController.SetGravity(1f);
  143. this.SetHitSpeed(Vector2.zero);
  144. this.SpDieEffect();
  145. }
  146. public override void EnemyDie()
  147. {
  148. if (this.deadFlag)
  149. {
  150. return;
  151. }
  152. base.EnemyDie();
  153. if (this.eAttr.isOnGround)
  154. {
  155. this.SetHitSpeed(Vector2.zero);
  156. base.NormalKill();
  157. this.action.AnimChangeState("Die", 1f);
  158. base.Invoke("DieTimeControl", 0.12f);
  159. }
  160. else
  161. {
  162. base.NormalKill();
  163. base.DieTimeControl();
  164. base.StartCoroutine(this.DeathIEnumerator());
  165. }
  166. }
  167. private void SpDieEffect()
  168. {
  169. DaoAction daoAction = (DaoAction)this.action;
  170. Transform transform = R.Effect.Generate(219, null, this.center.position, Vector3.zero, default(Vector3), true);
  171. transform.localScale = base.transform.localScale;
  172. transform.GetComponent<SkeletonAnimation>().skeleton.SetSkin((!daoAction.isPao) ? "DaoBrother" : "PaoSister");
  173. Transform transform2 = R.Effect.Generate(220, null, this.center.position, Vector3.zero, default(Vector3), true);
  174. transform2.localScale = base.transform.localScale;
  175. this.action.AnimChangeState(DaoAction.StateEnum.Null, 1f);
  176. string playerAtkName = this.playerAtkName;
  177. if (playerAtkName != null)
  178. {
  179. if (!(playerAtkName == "NewExecute1_2") && !(playerAtkName == "NewExecute2_2") && !(playerAtkName == "NewExecuteAir2_2"))
  180. {
  181. if (playerAtkName == "NewExecuteAir1_2")
  182. {
  183. transform.GetComponent<Rigidbody2D>().velocity = new Vector2(Mathf.Sign(base.transform.localScale.x) * 2f, 15f);
  184. transform2.GetComponent<Rigidbody2D>().velocity = new Vector2(Mathf.Sign(base.transform.localScale.x) * -2f, 15f);
  185. }
  186. }
  187. else
  188. {
  189. transform.GetComponent<Rigidbody2D>().velocity = new Vector2(Mathf.Sign(base.transform.localScale.x) * 2f, 15f);
  190. transform2.GetComponent<Rigidbody2D>().velocity = new Vector2(Mathf.Sign(base.transform.localScale.x) * -2f, -5f);
  191. }
  192. }
  193. }
  194. protected override IEnumerator DeathIEnumerator()
  195. {
  196. bool deadFly = true;
  197. bool deadFall = false;
  198. while (this.eAttr.isDead)
  199. {
  200. if (deadFly && this.eAttr.timeController.GetCurrentSpeed().y <= 0f)
  201. {
  202. deadFly = false;
  203. deadFall = true;
  204. this.action.AnimChangeState(this.flyToFallAnimName, 1f);
  205. }
  206. if (deadFall && this.eAttr.isOnGround)
  207. {
  208. deadFall = false;
  209. this.action.AnimChangeState(this.airDieHitGroundAnimName, 1f);
  210. base.Invoke("RealDie", 0.5f);
  211. }
  212. yield return new WaitForFixedUpdate();
  213. }
  214. yield break;
  215. }
  216. private void RealDie()
  217. {
  218. base.GetComponent<DaoEnemyAnimListener>().GetUp();
  219. }
  220. private DaoEnemyAnimListener _dao;
  221. private Vector2? atkFollowPos;
  222. private float atkFollowTime;
  223. private float atkFollowEnd;
  224. [SerializeField]
  225. private SkeletonAnimation closeToPlayer;
  226. }