PlayerMoveAbility.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. using System;
  2. using Core;
  3. using ExtensionMethods;
  4. using GameWorld;
  5. using UnityEngine;
  6. public class PlayerMoveAbility : CharacterState
  7. {
  8. public override void Update()
  9. {
  10. this.moveStopCounter--;
  11. if (this.moveStopCounter == 0)
  12. {
  13. this.Move(0);
  14. }
  15. }
  16. public override void FixedUpdate()
  17. {
  18. if ((this.stateMachine.currentState.IsInArray(PlayerAction.JumpSta) || this.stateMachine.currentState.IsInArray(PlayerAction.FlySta)) && !this.pAttr.isOnGround)
  19. {
  20. this.DealAirFric(this.pAttr.moveSpeed, true);
  21. }
  22. if (this.stateMachine.currentState.IsInArray(PlayerAction.UpRisingSta) && !this.pAttr.isOnGround)
  23. {
  24. this.DealAirFric(this.pAttr.moveSpeed / 2f, false);
  25. }
  26. if (this.stateMachine.currentState == "BladeStorm")
  27. {
  28. this.DealAirFric(this.pAttr.moveSpeed / 4f, false);
  29. }
  30. }
  31. private void DealAirFric(float maxSpeed, bool canTurn)
  32. {
  33. Vector2 currentSpeed = R.Player.TimeController.GetCurrentSpeed();
  34. float num = currentSpeed.x;
  35. num = Mathf.Clamp(Mathf.Abs(num) - this.airFric * Time.fixedDeltaTime, 0f, float.MaxValue) * Mathf.Sign(num);
  36. if (Core.Input.Game.MoveLeft.Pressed || Core.Input.Game.MoveRight.Pressed)
  37. {
  38. int num2 = (!Core.Input.Game.MoveLeft.Pressed) ? 1 : -1;
  39. int num3 = (!Core.Input.Game.MoveLeft.Pressed) ? 1 : -1;
  40. if (num2 != this.pAttr.faceDir && canTurn)
  41. {
  42. this.pac.TurnRound(num2);
  43. }
  44. num += (float)num3 * this.extraFric * Time.fixedDeltaTime;
  45. }
  46. currentSpeed.x = Mathf.Clamp(Mathf.Abs(num) - this.airFric * Time.fixedDeltaTime, 0f, maxSpeed) * Mathf.Sign(num);
  47. if (!this.pAttr.isOnGround)
  48. {
  49. Collider2D[] array = Physics2D.OverlapAreaAll(this.pac.transform.position + new Vector3(0.5f * (float)this.pAttr.faceDir, 0f, 0f), this.pac.transform.position + new Vector3(0.6f * (float)this.pAttr.faceDir, 2.2f, 0f), LayerManager.WallMask);
  50. int num4 = 0;
  51. for (int i = 0; i < array.Length; i++)
  52. {
  53. if (array[i].gameObject.layer == LayerManager.WallLayerID || array[i].gameObject.layer == LayerManager.GroundLayerID)
  54. {
  55. num4++;
  56. }
  57. }
  58. bool flag = num4 > 0;
  59. if (flag)
  60. {
  61. currentSpeed.x = Mathf.Sign(currentSpeed.x) * -1f * 0.1f;
  62. }
  63. num4 = 0;
  64. for (int j = 0; j < array.Length; j++)
  65. {
  66. if (array[j].gameObject.layer == LayerManager.CeilingLayerID)
  67. {
  68. num4++;
  69. }
  70. }
  71. bool flag2 = num4 > 0;
  72. if (flag2 && currentSpeed.y > 0f)
  73. {
  74. currentSpeed.y = 0f;
  75. }
  76. }
  77. R.Player.TimeController.SetSpeed(currentSpeed);
  78. }
  79. public void Move(int dir)
  80. {
  81. if (this.pAttr.isDead)
  82. {
  83. return;
  84. }
  85. if (dir == 0)
  86. {
  87. this.pac.tempDir = 3;
  88. if (this.stateMachine.currentState == PlayerAction.CanRunSlow)
  89. {
  90. R.Player.TimeController.SetSpeed(Vector2.zero);
  91. this.pac.ChangeState(PlayerAction.StateEnum.RunSlow, 1f);
  92. }
  93. if (this.stateMachine.currentState.IsInArray(PlayerAction.AttackSta))
  94. {
  95. R.Player.TimeController.SetSpeed(Vector2.zero);
  96. }
  97. }
  98. else
  99. {
  100. this.pac.tempDir = dir;
  101. if (this.stateMachine.currentState.IsInArray(PlayerAction.NormalSta) || this.pac.canChangeAnim)
  102. {
  103. this.PlayerMove(dir == -1, this.pAttr.moveSpeed, Vector2.zero, true);
  104. }
  105. if (this.stateMachine.currentState.IsInArray(PlayerMoveAbility.AttackSta) && dir == this.pAttr.faceDir)
  106. {
  107. this.PlayerMove(dir == -1, this.pAttr.moveSpeed / 4f, this.addSpeed, false);
  108. }
  109. if ((this.stateMachine.currentState.IsInArray(PlayerAction.AirLightAttackSta) || this.stateMachine.currentState == "AirAtkHv1" || this.stateMachine.currentState == "AirAtkHv2") && dir == this.pAttr.faceDir)
  110. {
  111. this.PlayerMove(dir == -1, this.pAttr.moveSpeed / 4f, this.addSpeed, false);
  112. }
  113. if (this.stateMachine.currentState == "BladeStorm")
  114. {
  115. this.PlayerMove(dir == -1, this.pAttr.moveSpeed / 2f, Vector2.zero, false);
  116. }
  117. }
  118. }
  119. private void PlayerMove(bool isLeft, float walkSpeed, Vector2 aSpeed, bool playRun = true)
  120. {
  121. if (R.Player.TimeController.isPause)
  122. {
  123. return;
  124. }
  125. walkSpeed = this.AirWallCheck(walkSpeed);
  126. int num = (!isLeft) ? 1 : -1;
  127. Vector2 vector = new Vector2(walkSpeed * (float)num, R.Player.TimeController.GetCurrentSpeed().y);
  128. vector += aSpeed;
  129. vector = this.EdgeCheck(vector);
  130. vector = this.SlopeCheck(vector);
  131. R.Player.TimeController.SetSpeed(vector);
  132. if (playRun)
  133. {
  134. this.pac.TurnRound((!isLeft) ? 1 : -1);
  135. this.pac.ChangeState(PlayerAction.StateEnum.Run, 1f);
  136. }
  137. this.moveStopCounter = 4;
  138. }
  139. private float AirWallCheck(float walkSpeed)
  140. {
  141. if (!this.pAttr.isOnGround && Physics2D.OverlapAreaAll(this.pac.transform.position + new Vector3(0.5f * (float)this.pAttr.faceDir, 0f, 0f), this.pac.transform.position + new Vector3(0.6f * (float)this.pAttr.faceDir, 2.2f, 0f), LayerManager.GroundMask).Length > 0)
  142. {
  143. walkSpeed = 0f;
  144. }
  145. return walkSpeed;
  146. }
  147. private Vector2 EdgeCheck(Vector2 speed)
  148. {
  149. Vector3 position = this.pac.transform.position;
  150. if (position.x >= GameArea.PlayerRange.max.x - this.pAttr.bounds.size.x / 2f)
  151. {
  152. speed.x = ((speed.x <= 0f) ? speed.x : 0f);
  153. }
  154. if (position.x <= GameArea.PlayerRange.min.x + this.pAttr.bounds.size.x / 2f)
  155. {
  156. speed.x = ((speed.x >= 0f) ? speed.x : 0f);
  157. }
  158. return speed;
  159. }
  160. private Vector2 SlopeCheck(Vector2 speed)
  161. {
  162. if (this.pac.IsInNormalState())
  163. {
  164. PlatformMovement component = this.pac.GetComponent<PlatformMovement>();
  165. Vector2 groundNormal = component.GetGroundNormal();
  166. Vector2 vector = Vector3.ProjectOnPlane(speed, groundNormal);
  167. float d = Mathf.Clamp(Mathf.Abs(vector.x), Mathf.Abs(speed.x / 2f), Mathf.Abs(speed.x));
  168. if (speed.y > 0f)
  169. {
  170. speed = vector.normalized * d;
  171. }
  172. else
  173. {
  174. speed = vector;
  175. }
  176. }
  177. return speed;
  178. }
  179. public override void OnStateMachineStateTransfer(object sender, StateMachine.TransferEventArgs args)
  180. {
  181. if (args.nextState.IsInArray(PlayerAction.NormalSta) && !args.lastState.IsInArray(PlayerAction.NormalSta))
  182. {
  183. EventManager.PostEvent<PlayerMoveAbility, AssessmentEventArgs>("Assessment", this, new AssessmentEventArgs(AssessmentEventArgs.EventType.CurrentComboFinish));
  184. }
  185. }
  186. private static readonly string[] AttackSta = new string[]
  187. {
  188. "Atk1",
  189. "Atk2",
  190. "Atk5",
  191. "Atk6",
  192. "Atk7",
  193. "Atk8",
  194. "Atk11",
  195. "Atk12",
  196. "Atk13",
  197. "Atk14",
  198. "Atk15",
  199. "AtkHv1",
  200. "AtkHv2",
  201. "AtkHv3",
  202. "AtkHv1Push",
  203. "AtkRollReady",
  204. "AtkRollEnd"
  205. };
  206. private const int maxMoveStopCount = 4;
  207. private int moveStopCounter;
  208. private float airFric = 8f;
  209. private float extraFric = 60f;
  210. public Vector2 addSpeed = Vector2.zero;
  211. }