PlayerAttackAbility.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using System;
  2. using ExtensionMethods;
  3. using UnityEngine;
  4. public class PlayerAttackAbility : CharacterState
  5. {
  6. public override void Update()
  7. {
  8. if (this.listener.airAtkDown && this.pAttr.isOnGround)
  9. {
  10. this.listener.airAtkDown = false;
  11. this.listener.PhysicReset();
  12. R.Player.TimeController.SetSpeed(Vector2.zero);
  13. this.pac.ChangeState(PlayerAction.StateEnum.AirAtkHv5, 1f);
  14. }
  15. }
  16. public void PlayerAttack(int attackDir, bool cirtAtk)
  17. {
  18. if (this.stateMachine.currentState.IsInArray(PlayerAction.AttackSta))
  19. {
  20. if (this.weapon.canChangeAtkAnim)
  21. {
  22. this.weapon.cirtAttack = cirtAtk;
  23. this.weapon.CanPlayNextAttack();
  24. }
  25. else
  26. {
  27. this.weapon.HandleAttack(cirtAtk);
  28. }
  29. return;
  30. }
  31. if (this.stateMachine.currentState.IsInArray(PlayerAction.AirAttackSta))
  32. {
  33. if (this.weapon.canChangeAirAtkAnim)
  34. {
  35. this.weapon.cirtAttack = cirtAtk;
  36. this.weapon.CanPlayNextAirAttack();
  37. }
  38. else
  39. {
  40. this.weapon.HandleAirAttack(cirtAtk);
  41. }
  42. return;
  43. }
  44. if (R.Player.TimeController.isPause)
  45. {
  46. return;
  47. }
  48. if (this.stateMachine.currentState.IsInArray(PlayerAttackAbility.CanAttackSta) || this.pac.canChangeAnim)
  49. {
  50. if (attackDir != 3)
  51. {
  52. this.pac.TurnRound(attackDir);
  53. }
  54. this.listener.PhysicReset();
  55. if (this.pAttr.isOnGround)
  56. {
  57. R.Player.TimeController.SetSpeed(Vector2.zero);
  58. this.weapon.HandleAttack(cirtAtk);
  59. }
  60. else
  61. {
  62. this.listener.checkFallDown = false;
  63. this.weapon.HandleAirAttack(cirtAtk);
  64. }
  65. }
  66. }
  67. public void PlayerCirtPressAttack(int attackDir)
  68. {
  69. if (R.Player.TimeController.isPause)
  70. {
  71. return;
  72. }
  73. if (this.stateMachine.currentState.IsInArray(PlayerAttackAbility.CanAttackSta) && this._pressRelease)
  74. {
  75. if (attackDir != 3)
  76. {
  77. this.pac.TurnRound(attackDir);
  78. }
  79. this.listener.PhysicReset();
  80. R.Player.TimeController.SetSpeed(Vector2.zero);
  81. if (this.stateMachine.currentState.IsInArray(PlayerAction.NormalSta))
  82. {
  83. R.Player.TimeController.SetSpeed(Vector2.zero);
  84. this.weapon.CirtAttackHold();
  85. }
  86. else
  87. {
  88. this.weapon.AirCirtAttackHold();
  89. }
  90. this._pressRelease = false;
  91. }
  92. }
  93. public void PlayerCirtPressAttackReleasd()
  94. {
  95. this._pressRelease = true;
  96. }
  97. public override void OnStateMachineStateTransfer(object sender, StateMachine.TransferEventArgs args)
  98. {
  99. this.listener.atkBox.localScale = new Vector3(0f, 0f, 1f);
  100. this.listener.atkBox.localPosition = Vector3.zero;
  101. if (args.lastState.IsInArray(PlayerAction.AirAttackSta) && !args.nextState.IsInArray(PlayerAction.AirAttackSta))
  102. {
  103. this.weapon.AirAttackRecover();
  104. }
  105. }
  106. private bool _pressRelease = true;
  107. private static readonly string[] CanAttackSta = new string[]
  108. {
  109. "EndAtk",
  110. "GetUp",
  111. "Idle",
  112. "Ready",
  113. "Run",
  114. "RunSlow",
  115. "Jump",
  116. "Fall1",
  117. "Fall2",
  118. "Flash2",
  119. "FlashDown2",
  120. "FlashUp2",
  121. "FlashGround"
  122. };
  123. }