PlayerFlashAbility.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. using System;
  2. using ExtensionMethods;
  3. using GameWorld;
  4. using UnityEngine;
  5. public class PlayerFlashAbility : CharacterState
  6. {
  7. private bool IsOnObstacle
  8. {
  9. get
  10. {
  11. RaycastHit2D hit = Physics2D.Raycast(this.pac.transform.position + new Vector3(-0.45f, 0.4f, 0f), Vector2.down, 0.6f, LayerManager.ObstacleMask);
  12. RaycastHit2D hit2 = Physics2D.Raycast(this.pac.transform.position + new Vector3(0.45f, 0.4f, 0f), Vector2.down, 0.6f, LayerManager.ObstacleMask);
  13. return hit || hit2;
  14. }
  15. }
  16. private int CoolDown
  17. {
  18. get
  19. {
  20. if (!R.Mode.IsInBattleMode())
  21. {
  22. return WorldTime.SecondToFrame(0.5f);
  23. }
  24. switch (R.GameData.Difficulty)
  25. {
  26. case 0:
  27. return WorldTime.SecondToFrame(1.5f);
  28. case 1:
  29. return WorldTime.SecondToFrame(2.5f);
  30. case 2:
  31. return WorldTime.SecondToFrame(3f);
  32. default:
  33. return WorldTime.SecondToFrame(1.5f);
  34. }
  35. }
  36. }
  37. public override void Update()
  38. {
  39. if (this.pAttr.isDead)
  40. {
  41. return;
  42. }
  43. this.UpdateFlash();
  44. }
  45. public void FlashFace()
  46. {
  47. this.Swipe(R.Player.Attribute.faceDir);
  48. }
  49. public void FlashRight()
  50. {
  51. this.Swipe(1);
  52. }
  53. public void FlashLeft()
  54. {
  55. this.Swipe(-1);
  56. }
  57. public void FlashUp()
  58. {
  59. this.Swipe(2);
  60. }
  61. public void FlashDown()
  62. {
  63. if (this.FlashOnObstacle())
  64. {
  65. this.Swipe(-2);
  66. return;
  67. }
  68. if (this.pAttr.isOnGround)
  69. {
  70. return;
  71. }
  72. this.Swipe(-2);
  73. }
  74. public void FlashRightUp()
  75. {
  76. this.Swipe(4);
  77. }
  78. public void FlashRightDown()
  79. {
  80. this.Swipe((!this.pAttr.isOnGround) ? -4 : 1);
  81. }
  82. public void FlashLeftUp()
  83. {
  84. this.Swipe(5);
  85. }
  86. public void FlashLeftDown()
  87. {
  88. this.Swipe((!this.pAttr.isOnGround) ? -5 : -1);
  89. }
  90. private bool FlashLevelCheck()
  91. {
  92. return this.pAttr.currentFlashTimes > 0;
  93. }
  94. private bool FlashOnObstacle()
  95. {
  96. bool flag = R.Player.Attribute.flashLevel == 3;
  97. return flag && this.IsOnObstacle;
  98. }
  99. private void Swipe(int dir)
  100. {
  101. if (R.Player.TimeController.isPause)
  102. {
  103. return;
  104. }
  105. if ((this.stateMachine.currentState.IsInArray(PlayerFlashAbility.CanFlashSta) || this.pac.canChangeAnim) && this.FlashLevelCheck())
  106. {
  107. this.listener.StopIEnumerator("FlashPositionSet");
  108. if (dir == 1 || dir == -4 || dir == 4)
  109. {
  110. this.pac.TurnRound(1);
  111. }
  112. if (dir == -1 || dir == -5 || dir == 5)
  113. {
  114. this.pac.TurnRound(-1);
  115. }
  116. this.listener.flashDir = dir;
  117. switch (dir + 5)
  118. {
  119. case 0:
  120. case 1:
  121. this.pac.ChangeState(PlayerAction.StateEnum.FlashDown45_1, 1f);
  122. break;
  123. case 3:
  124. this.pac.ChangeState(PlayerAction.StateEnum.FlashDown1, 1f);
  125. break;
  126. case 4:
  127. case 6:
  128. this.pac.ChangeState(PlayerAction.StateEnum.Flash1, 1f);
  129. break;
  130. case 7:
  131. this.pac.ChangeState(PlayerAction.StateEnum.FlashUp1, 1f);
  132. break;
  133. case 9:
  134. case 10:
  135. this.pac.ChangeState(PlayerAction.StateEnum.FlashUp45_1, 1f);
  136. break;
  137. }
  138. EventManager.PostEvent<PlayerFlashAbility, AssessmentEventArgs>("Assessment", this, new AssessmentEventArgs(AssessmentEventArgs.EventType.CurrentComboFinish));
  139. this.StateInit();
  140. this.listener.FlashStart();
  141. this.pAttr.currentFlashTimes = Mathf.Clamp(this.pAttr.currentFlashTimes - 1, 0, this.pAttr.flashTimes);
  142. R.Ui.Flash.OnFlash(this.pAttr.currentFlashTimes);
  143. }
  144. }
  145. private void StateInit()
  146. {
  147. this.listener.isFalling = false;
  148. this.listener.airAtkDown = false;
  149. this.listener.checkFallDown = false;
  150. this.listener.checkHitGround = false;
  151. R.Player.TimeController.SetSpeed(Vector2.zero);
  152. this.listener.AirPhysic(0f);
  153. }
  154. public override void OnStateMachineStateTransfer(object sender, StateMachine.TransferEventArgs args)
  155. {
  156. this.pAttr.flashFlag = false;
  157. ParticleSystem.EmissionModule emission = this.pac.blockPartical.emission;
  158. if (args.nextState.IsInArray(PlayerAction.FlashAttackSta) && Math.Abs(emission.rateOverDistance.constant - 10f) > 1.401298E-45f)
  159. {
  160. emission.rateOverDistance = 10f;
  161. }
  162. if (!args.nextState.IsInArray(PlayerAction.FlashAttackSta) && Math.Abs(emission.rateOverDistance.constant) > 1.401298E-45f)
  163. {
  164. emission.rateOverDistance = 0f;
  165. }
  166. }
  167. public void FlashOnce()
  168. {
  169. this.listener.StopIEnumerator("FlashPositionSet");
  170. this.listener.flashDir = this.pAttr.faceDir;
  171. this.pac.ChangeState(PlayerAction.StateEnum.Flash1, 1f);
  172. this.StateInit();
  173. }
  174. private void UpdateFlash()
  175. {
  176. if (this.pAttr.currentFlashTimes < this.pAttr.flashTimes)
  177. {
  178. this.pAttr.FlashCd++;
  179. if (this.pAttr.FlashCd >= this.CoolDown)
  180. {
  181. this.pAttr.FlashCd = 0;
  182. this.pAttr.currentFlashTimes = Mathf.Clamp(this.pAttr.currentFlashTimes + 1, 0, this.pAttr.flashTimes);
  183. bool isFilled = this.pAttr.currentFlashTimes == this.pAttr.flashTimes;
  184. R.Ui.Flash.OnRecover(this.pAttr.currentFlashTimes - 1, isFilled);
  185. }
  186. }
  187. }
  188. private static readonly string[] CanFlashSta = new string[]
  189. {
  190. "EndAtk",
  191. "Fall1",
  192. "Fall2",
  193. "Idle",
  194. "Jump",
  195. "Jump2",
  196. "RollJump",
  197. "Ready",
  198. "Run",
  199. "RunSlow",
  200. "Atk1",
  201. "Atk2",
  202. "Atk3",
  203. "Atk4",
  204. "Atk5",
  205. "Atk6",
  206. "Atk7",
  207. "Atk8",
  208. "Atk11",
  209. "Atk12",
  210. "Atk13",
  211. "Atk14",
  212. "Atk23",
  213. "Atk15",
  214. "Atk16",
  215. "AtkHv1",
  216. "AtkHv2",
  217. "AtkHv3",
  218. "AtkHv1Push",
  219. "UpRising",
  220. "AtkUpRising",
  221. "HitGround",
  222. "HitGround2",
  223. "RollReady",
  224. "Roll",
  225. "RollEnd",
  226. "Flash2",
  227. "FlashDown2",
  228. "FlashUp2",
  229. "Charge1Ready",
  230. "Charging1",
  231. "Charge1End",
  232. "IdleToDefense",
  233. "Defense",
  234. "FallToDefenseAir",
  235. "DefenseAir",
  236. "AirAtk1",
  237. "AirAtk2",
  238. "AirAtk3",
  239. "AirAtk4",
  240. "AirAtk6",
  241. "AirAtkHv1",
  242. "AirAtkHv2",
  243. "AirAtkHv3",
  244. "AirAtkHv4",
  245. "AirAtkHv5",
  246. "AirAtkHv1Push",
  247. "ExecuteToIdle",
  248. "Execute2ToFall",
  249. "FlashGround",
  250. "AtkRollReady",
  251. "AtkRollEnd",
  252. "AirAtkRollReady",
  253. "AirAtkRoll"
  254. };
  255. }