SpiderHurt.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. public class SpiderHurt : EnemyBaseHurt
  5. {
  6. protected override void Update()
  7. {
  8. base.Update();
  9. Vector2? atkFollowPos = this._atkFollowPos;
  10. if (atkFollowPos != null)
  11. {
  12. Vector3 position = base.player.transform.position;
  13. Vector2? atkFollowPos2 = this._atkFollowPos;
  14. Vector3 position2 = position - ((atkFollowPos2 == null) ? default(Vector3) : (Vector3)atkFollowPos2.GetValueOrDefault());
  15. position2.y = Mathf.Clamp(position2.y, LayerManager.YNum.GetGroundHeight(base.gameObject) + 1f, float.PositiveInfinity);
  16. position2.z = LayerManager.ZNum.MMiddleE(this.eAttr.rankType);
  17. base.transform.position = position2;
  18. this._atkFollowTime += Time.unscaledDeltaTime;
  19. if (this._atkFollowTime >= this._atkFollowEnd)
  20. {
  21. this._atkFollowPos = null;
  22. }
  23. }
  24. }
  25. protected override void PlayHurtAudio()
  26. {
  27. R.Audio.PlayEffect(256, new Vector3?(base.transform.position));
  28. if (base.PlaySpHurtAudio())
  29. {
  30. R.Audio.PlayEffect(401, new Vector3?(base.transform.position));
  31. }
  32. }
  33. protected override void Init()
  34. {
  35. this._spider = base.GetComponent<SpiderAnimEvent>();
  36. this.defaultAnimName = "Hit1";
  37. this.defaultAirAnimName = "HitToFly2";
  38. this.airDieAnimName = "AirDieFlyToFall";
  39. this.airDieHitGroundAnimName = "AirDieHitGround";
  40. this.hurtData = SingletonMono<EnemyDataPreload>.Instance.hurt[EnemyType.蜘蛛];
  41. }
  42. public override void SetHitSpeed(Vector2 speed)
  43. {
  44. if (this.playerAtkName == "UpRising" || this.playerAtkName == "AtkUpRising" || this.playerAtkName == "AtkRollEnd" || this.playerAtkName == "NewExecute2_1")
  45. {
  46. this._spider.maxFlyHeight = 4.2f;
  47. }
  48. else
  49. {
  50. this._spider.maxFlyHeight = -1f;
  51. }
  52. base.SetHitSpeed(speed);
  53. }
  54. protected override void SpAttack()
  55. {
  56. if (this.eAttr.currentActionInterruptPoint < this.eAttr.actionInterruptPoint)
  57. {
  58. return;
  59. }
  60. if (this.playerAtkName == "RollEnd")
  61. {
  62. Vector2? atkFollowPos = this._atkFollowPos;
  63. if (atkFollowPos != null)
  64. {
  65. this._atkFollowPos = null;
  66. }
  67. return;
  68. }
  69. if (this.playerAtkName == "RollGround")
  70. {
  71. Vector2? atkFollowPos2 = this._atkFollowPos;
  72. if (atkFollowPos2 == null)
  73. {
  74. Transform transform = base.player.GetComponentInChildren<PlayerAtk>().transform;
  75. this._atkFollowPos = new Vector2?((transform.position - base.transform.position) * 0.9f);
  76. }
  77. this._atkFollowTime = 0f;
  78. this._atkFollowEnd = 0.2f;
  79. return;
  80. }
  81. if (this.playerAtkName == "RollReady" || this.playerAtkName == "BladeStormReady")
  82. {
  83. Vector2? atkFollowPos3 = this._atkFollowPos;
  84. if (atkFollowPos3 == null)
  85. {
  86. this._atkFollowPos = new Vector2?((base.player.transform.position - base.transform.position) * 0.7f);
  87. }
  88. this._atkFollowTime = 0f;
  89. this._atkFollowEnd = 0.2f;
  90. return;
  91. }
  92. if (this.playerAtkName == "Atk4")
  93. {
  94. base.StartCoroutine(this.CloseToPlayer());
  95. return;
  96. }
  97. this._atkFollowTime = 0f;
  98. this._atkFollowEnd = 0f;
  99. }
  100. private IEnumerator CloseToPlayer()
  101. {
  102. this.closeToPlayer.state.SetAnimation(0, "Show", false);
  103. this.closeToPlayer.skeleton.SetToSetupPose();
  104. Vector3 endPos = base.player.transform.position + Vector3.right * (float)base.pAttr.faceDir * UnityEngine.Random.Range(0.8f, 1.5f);
  105. endPos.z = LayerManager.ZNum.MMiddleE(this.eAttr.rankType);
  106. Vector3 startPos = base.transform.position;
  107. for (int i = 0; i < 5; i++)
  108. {
  109. yield return new WaitForFixedUpdate();
  110. }
  111. for (int j = 0; j < 6; j++)
  112. {
  113. base.transform.position = Vector3.Lerp(startPos, endPos, (float)j / 5f);
  114. yield return new WaitForFixedUpdate();
  115. }
  116. yield break;
  117. }
  118. protected override void ExecuteFollow()
  119. {
  120. }
  121. protected override void ExecuteDie()
  122. {
  123. base.ExecuteDie();
  124. this.SetHitSpeed(Vector2.zero);
  125. this.action.AnimChangeState(SpiderAction.StateEnum.Die, 1f);
  126. }
  127. public override void EnemyDie()
  128. {
  129. if (this.deadFlag)
  130. {
  131. return;
  132. }
  133. R.Audio.PlayEffect(245, new Vector3?(base.transform.position));
  134. base.EnemyDie();
  135. if (this.eAttr.isOnGround)
  136. {
  137. this.SetHitSpeed(Vector2.zero);
  138. base.NormalKill();
  139. this.action.AnimChangeState(SpiderAction.StateEnum.Die, 1f);
  140. base.Invoke("DieTimeControl", 0.12f);
  141. }
  142. else
  143. {
  144. base.NormalKill();
  145. base.DieTimeControl();
  146. this.action.AnimChangeState(SpiderAction.StateEnum.AirDieFlyToFall, 1f);
  147. base.StartCoroutine(this.DeathIEnumerator());
  148. }
  149. }
  150. protected override IEnumerator DeathIEnumerator()
  151. {
  152. bool deadFly = true;
  153. bool deadFall = false;
  154. while (this.eAttr.isDead)
  155. {
  156. if (deadFly && this.eAttr.timeController.GetCurrentSpeed().y <= 0f)
  157. {
  158. deadFly = false;
  159. deadFall = true;
  160. this.action.AnimChangeState(SpiderAction.StateEnum.AirDieFall, 1f);
  161. }
  162. if (deadFall && this.eAttr.isOnGround)
  163. {
  164. deadFall = false;
  165. this.action.AnimChangeState(this.airDieHitGroundAnimName, 1f);
  166. }
  167. yield return null;
  168. }
  169. yield break;
  170. }
  171. private SpiderAnimEvent _spider;
  172. private Vector2? _atkFollowPos;
  173. private float _atkFollowTime;
  174. private float _atkFollowEnd;
  175. [SerializeField]
  176. private SkeletonAnimation closeToPlayer;
  177. }