PlayerExecuteAbility.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using ExtensionMethods;
  6. using UnityEngine;
  7. public class PlayerExecuteAbility : CharacterState
  8. {
  9. public bool CanExecute
  10. {
  11. get
  12. {
  13. return this.stateMachine.currentState.IsInArray(PlayerExecuteAbility.CanExecuteSta);
  14. }
  15. }
  16. public override void Update()
  17. {
  18. if (this._invincibleRecover > 0)
  19. {
  20. this._invincibleRecover--;
  21. if (this._invincibleRecover <= 0)
  22. {
  23. this.pab.hurt.Invincible = false;
  24. }
  25. }
  26. }
  27. public void Execute()
  28. {
  29. if (this.CanExecute)
  30. {
  31. base.StartCoroutine((!this.pAttr.isOnGround) ? this.AirMoveToExecuteEnemy() : this.GroundMoveToExecuteEnemy());
  32. }
  33. }
  34. private IEnumerator GroundMoveToExecuteEnemy()
  35. {
  36. Transform executeTarget = this.GetExecuteEnemy(false);
  37. if (executeTarget == null)
  38. {
  39. yield break;
  40. }
  41. executeTarget.GetComponent<EnemyBaseAction>().hurtBox.gameObject.SetActive(false);
  42. float distance = Mathf.Abs(this.pac.transform.position.x - executeTarget.position.x) - 1f;
  43. distance = Mathf.Clamp(distance, 0f, float.PositiveInfinity);
  44. float deltaLen = distance / 5f;
  45. for (int i = 0; i < 5; i++)
  46. {
  47. Vector3 nextPos = this.pac.transform.position + Vector3.right * (float)this.pAttr.faceDir * deltaLen;
  48. R.Player.TimeController.NextPosition(nextPos);
  49. yield return new WaitForFixedUpdate();
  50. }
  51. yield break;
  52. }
  53. private IEnumerator AirMoveToExecuteEnemy()
  54. {
  55. Transform executeTarget = this.GetExecuteEnemy(true);
  56. if (executeTarget == null)
  57. {
  58. yield break;
  59. }
  60. EnemyAttribute eAttr = executeTarget.GetComponent<EnemyAttribute>();
  61. if (eAttr.isOnGround && eAttr.rankType == EnemyAttribute.RankType.Normal)
  62. {
  63. eAttr.stiffTime = 1f;
  64. eAttr.GetComponent<EnemyBaseAction>().AnimReady();
  65. }
  66. executeTarget.GetComponent<EnemyBaseAction>().hurtBox.gameObject.SetActive(false);
  67. eAttr.timeController.SetSpeed(Vector2.zero);
  68. executeTarget.GetComponent<Rigidbody2D>().gravityScale = 0f;
  69. Vector3 startPos = this.pac.transform.position;
  70. Vector3 endPos = executeTarget.transform.position - Vector3.right * (float)this.pAttr.faceDir;
  71. if (this.pAttr.faceDir == 1)
  72. {
  73. endPos.x = Mathf.Clamp(endPos.x, startPos.x, float.MaxValue);
  74. }
  75. else if (this.pAttr.faceDir == -1)
  76. {
  77. endPos.x = Mathf.Clamp(endPos.x, float.MinValue, startPos.x);
  78. }
  79. for (int i = 0; i < 5; i++)
  80. {
  81. Vector3 nextPos = Vector3.Lerp(startPos, endPos, (float)i / 4f);
  82. R.Player.TimeController.NextPosition(nextPos);
  83. yield return new WaitForFixedUpdate();
  84. }
  85. yield break;
  86. }
  87. private Transform GetExecuteEnemy(bool inAir)
  88. {
  89. GameObject[] array = (from e in this.GetEmenies()
  90. orderby Mathf.Abs(e.transform.position.x - this.pac.transform.position.x)
  91. select e).ToArray<GameObject>();
  92. Transform transform = null;
  93. int num = 0;
  94. if (num < array.Length)
  95. {
  96. EnemyAttribute component = array[num].GetComponent<EnemyAttribute>();
  97. component.willBeExecute = true;
  98. R.Player.TimeController.SetSpeed(Vector2.zero);
  99. transform = array[num].transform;
  100. this.pac.TurnRound((this.pac.transform.position.x - transform.position.x <= 0f) ? 1 : -1);
  101. this.weapon.HandleExecute(inAir, component);
  102. this.listener.executeEnemyList.Clear();
  103. this.listener.executeEnemyList.Add(array[num]);
  104. }
  105. return transform;
  106. }
  107. public override void OnStateMachineStateTransfer(object sender, StateMachine.TransferEventArgs args)
  108. {
  109. for (int i = 0; i < R.Enemy.Count; i++)
  110. {
  111. R.Enemy.EnemyAttributes[i].GetComponent<EnemyBaseHurt>().StopFollowLeftHand();
  112. }
  113. if (args.nextState == "QTECharge1Ready")
  114. {
  115. this.listener.charge = true;
  116. }
  117. if (args.nextState.IsInArray(PlayerAction.ExecuteSta))
  118. {
  119. this.pac.hurtBox.localScale = Vector3.zero;
  120. }
  121. if (args.lastState.IsInArray(PlayerAction.ExecuteSta) && !args.nextState.IsInArray(PlayerAction.ExecuteSta))
  122. {
  123. this.listener.executeEnemyList.Clear();
  124. SingletonMono<CameraController>.Instance.CameraZoomFinished();
  125. this.pab.hurt.Invincible = true;
  126. this._invincibleRecover = WorldTime.SecondToFrame(0.2f);
  127. }
  128. if (args.nextState == "NewExecuteAir1_1" || args.nextState == "NewExecuteAir2_1")
  129. {
  130. this.listener.checkFallDown = false;
  131. this.listener.isFalling = false;
  132. this.listener.checkHitGround = false;
  133. this.listener.AirPhysic(0f);
  134. R.Player.TimeController.SetSpeed(Vector2.zero);
  135. }
  136. }
  137. private List<GameObject> GetEmenies()
  138. {
  139. List<GameObject> list = new List<GameObject>();
  140. for (int i = 0; i < R.Enemy.EnemyAttributes.Count; i++)
  141. {
  142. Transform transform = R.Enemy.EnemyAttributes[i].transform;
  143. EnemyAttribute enemyAttribute = R.Enemy.EnemyAttributes[i];
  144. if (enemyAttribute.CurrentCanBeExecute)
  145. {
  146. list.Add(transform.gameObject);
  147. }
  148. }
  149. return list;
  150. }
  151. private int _invincibleRecover;
  152. private static readonly string[] CanExecuteSta = new string[]
  153. {
  154. "Atk1",
  155. "Atk2",
  156. "Atk3",
  157. "Atk4",
  158. "Atk5",
  159. "Atk6",
  160. "Atk7",
  161. "Atk8",
  162. "Atk11",
  163. "Atk12",
  164. "Atk13",
  165. "Atk14",
  166. "Atk23",
  167. "Atk15",
  168. "AtkHv1",
  169. "AtkHv2",
  170. "AtkHv3",
  171. "Atk16",
  172. "AtkHv1Push",
  173. "Flash1",
  174. "FlashDown1",
  175. "FlashUp1",
  176. "UpRising",
  177. "AtkUpRising",
  178. "HitGround",
  179. "HitGround2",
  180. "RollReady",
  181. "Roll",
  182. "RollEnd",
  183. "EndAtk",
  184. "GetUp",
  185. "Idle",
  186. "Ready",
  187. "Run",
  188. "RunSlow",
  189. "Charge1Ready",
  190. "Charging1",
  191. "Charge1End",
  192. "IdleToDefense",
  193. "Defense",
  194. "FallToDefenseAir",
  195. "DefenseAir",
  196. "AirAtk1",
  197. "AirAtk2",
  198. "AirAtk3",
  199. "AirAtk4",
  200. "AirAtk6",
  201. "AirAtkHv1",
  202. "AirAtkHv2",
  203. "AirAtkHv3",
  204. "AirAtkHv4",
  205. "AirAtkHv5",
  206. "AirAtkHv1Push",
  207. "Fall1",
  208. "Fall2",
  209. "Flash2",
  210. "FlashDown2",
  211. "FlashUp2",
  212. "Jump",
  213. "Jump2",
  214. "RollJump",
  215. "FlashGround"
  216. };
  217. }