PaoSisterAIAction.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. using System;
  2. using BehaviorDesigner.Runtime.Tasks;
  3. using UnityEngine;
  4. public class PaoSisterAIAction
  5. {
  6. [TaskCategory("Enemy/PaoSister")]
  7. [TaskDescription("炮姐攻击")]
  8. public class PaoAtk : BehaviorDesigner.Runtime.Tasks.Action
  9. {
  10. private Transform player
  11. {
  12. get
  13. {
  14. return R.Player.Transform;
  15. }
  16. }
  17. public override void OnAwake()
  18. {
  19. this.action = base.GetComponent<DaoAction>();
  20. }
  21. public override void OnStart()
  22. {
  23. int dir = InputSetting.JudgeDir(this.transform.position.x, this.player.position.x);
  24. this.action.ChangeFace(dir);
  25. PaoSisterAIAction.PaoAtk.PaoAtkType paoAtkType = this.paoAtkType;
  26. if (paoAtkType != PaoSisterAIAction.PaoAtk.PaoAtkType.Atk1)
  27. {
  28. if (paoAtkType == PaoSisterAIAction.PaoAtk.PaoAtkType.Atk2)
  29. {
  30. this.action.Attack3(dir);
  31. }
  32. }
  33. else
  34. {
  35. this.action.Attack3(dir);
  36. }
  37. }
  38. public override TaskStatus OnUpdate()
  39. {
  40. string currentState = this.action.stateMachine.currentState;
  41. if (currentState == DaoAction.State.PaoAtk1)
  42. {
  43. return TaskStatus.Running;
  44. }
  45. return TaskStatus.Success;
  46. }
  47. public PaoSisterAIAction.PaoAtk.PaoAtkType paoAtkType;
  48. private DaoAction action;
  49. public enum PaoAtkType
  50. {
  51. Atk1,
  52. Atk2
  53. }
  54. }
  55. [TaskCategory("Enemy/PaoSister")]
  56. [TaskDescription("炮姐在主角两个身位外")]
  57. public class InAttackRange : BehaviorDesigner.Runtime.Tasks.Action
  58. {
  59. private Transform player
  60. {
  61. get
  62. {
  63. return R.Player.Transform;
  64. }
  65. }
  66. public override void OnAwake()
  67. {
  68. this.ai = base.GetComponent<EnemyAIAttribute>();
  69. }
  70. public override TaskStatus OnUpdate()
  71. {
  72. EnemyAIAttribute.ExpectationParam expectationParam = this.ai.attackExpectations[0];
  73. float num = Mathf.Abs(this.player.position.x - this.transform.position.x);
  74. if (num > expectationParam.distance + expectationParam.range)
  75. {
  76. return TaskStatus.Success;
  77. }
  78. return TaskStatus.Failure;
  79. }
  80. private EnemyAIAttribute ai;
  81. }
  82. [TaskDescription("炮姐闪避")]
  83. [TaskCategory("Enemy/PaoSister")]
  84. public class PaoRunAway : BehaviorDesigner.Runtime.Tasks.Action
  85. {
  86. private Transform player
  87. {
  88. get
  89. {
  90. return R.Player.Transform;
  91. }
  92. }
  93. public override void OnAwake()
  94. {
  95. this.action = base.GetComponent<DaoAction>();
  96. }
  97. public override void OnStart()
  98. {
  99. this.action.SideStep();
  100. }
  101. public override TaskStatus OnUpdate()
  102. {
  103. string currentState = this.action.stateMachine.currentState;
  104. if (currentState == DaoAction.State.RunAwayReady)
  105. {
  106. return TaskStatus.Running;
  107. }
  108. return TaskStatus.Success;
  109. }
  110. private DaoAction action;
  111. }
  112. [TaskCategory("Enemy/PaoSister")]
  113. [TaskDescription("移动到两个身位外")]
  114. public class FarAwayPlayer : BehaviorDesigner.Runtime.Tasks.Action
  115. {
  116. private Transform player
  117. {
  118. get
  119. {
  120. return R.Player.Transform;
  121. }
  122. }
  123. public override void OnAwake()
  124. {
  125. this.action = base.GetComponent<DaoAction>();
  126. this.eAttr = base.GetComponent<EnemyAttribute>();
  127. this.paoAtk = base.GetComponent<EnemyAIAttribute>().attackExpectations[0];
  128. this.atkRange = this.paoAtk.distance + this.paoAtk.range;
  129. }
  130. public override void OnStart()
  131. {
  132. this.randomMoveLen = UnityEngine.Random.Range(0f, 1f);
  133. int dir = this.JudeMoveDir();
  134. this.action.ChangeFace(dir);
  135. this.aimPos = this.transform.position.x + (this.randomMoveLen + this.atkRange) * (float)this.eAttr.faceDir;
  136. this.aimPos = Mathf.Clamp(this.aimPos, GameArea.EnemyRange.min.x + this.eAttr.bounds.size.x, GameArea.EnemyRange.max.x - this.eAttr.bounds.size.x);
  137. }
  138. public override TaskStatus OnUpdate()
  139. {
  140. if (!this.action.AutoMove())
  141. {
  142. return TaskStatus.Failure;
  143. }
  144. bool flag = InputSetting.JudgeDir(this.action.transform.position.x, this.aimPos) == this.eAttr.faceDir;
  145. if (flag)
  146. {
  147. return TaskStatus.Running;
  148. }
  149. return (!this.action.StopMoveToIdle()) ? TaskStatus.Failure : TaskStatus.Success;
  150. }
  151. private int JudeMoveDir()
  152. {
  153. float num = this.atkRange + this.randomMoveLen;
  154. if (Mathf.Abs(this.transform.position.x - GameArea.EnemyRange.min.x) < num || Mathf.Abs(this.transform.position.x - GameArea.EnemyRange.max.x) < num)
  155. {
  156. return (Mathf.Abs(this.transform.position.x - GameArea.EnemyRange.min.x) >= num) ? -1 : 1;
  157. }
  158. return (this.transform.position.x - this.player.position.x <= 0f) ? -1 : 1;
  159. }
  160. private DaoAction action;
  161. private EnemyAttribute eAttr;
  162. private EnemyAIAttribute.ExpectationParam paoAtk;
  163. private float atkRange;
  164. private float randomMoveLen;
  165. private float aimPos;
  166. }
  167. }