DahalFAIAction.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. using System;
  2. using BehaviorDesigner.Runtime.Tasks;
  3. using ExtensionMethods;
  4. using UnityEngine;
  5. public class DahalFAIAction
  6. {
  7. [TaskCategory("Enemy/DahalF")]
  8. [TaskDescription("Dahal闪避")]
  9. public class DahalFSideStep : BehaviorDesigner.Runtime.Tasks.Action
  10. {
  11. public override void OnAwake()
  12. {
  13. this._action = base.GetComponent<DahalFAction>();
  14. }
  15. public override void OnStart()
  16. {
  17. this._action.SideStep();
  18. }
  19. public override TaskStatus OnUpdate()
  20. {
  21. return (!(this._action.stateMachine.currentState == "GroundDodge")) ? TaskStatus.Success : TaskStatus.Running;
  22. }
  23. private DahalFAction _action;
  24. }
  25. [TaskDescription("向前移动一段距离,距离参数在属性里设置")]
  26. [TaskCategory("Enemy/DahalF")]
  27. public class DahalFMoveSomeDistance : BehaviorDesigner.Runtime.Tasks.Action
  28. {
  29. public override void OnAwake()
  30. {
  31. this._eAttr = base.GetComponent<EnemyAttribute>();
  32. this._enemy = base.GetComponent<DahalFAction>();
  33. }
  34. public override void OnStart()
  35. {
  36. if (this.randomDis)
  37. {
  38. this.dis = UnityEngine.Random.Range(this.randomMin, this.randomMax);
  39. }
  40. this.aimPosX = this._enemy.transform.position.x + (float)this._eAttr.faceDir * this.dis;
  41. this.aimPosX = Mathf.Clamp(this.aimPosX, GameArea.EnemyRange.min.x + this._eAttr.bounds.size.x, GameArea.EnemyRange.max.x - this._eAttr.bounds.size.x);
  42. }
  43. public override TaskStatus OnUpdate()
  44. {
  45. if (!this._enemy.DahyalAutoMove(this.moveType))
  46. {
  47. return TaskStatus.Failure;
  48. }
  49. bool flag = InputSetting.JudgeDir(this._enemy.transform.position.x, this.aimPosX) == this._eAttr.faceDir;
  50. if (flag)
  51. {
  52. return TaskStatus.Running;
  53. }
  54. if (!this.isArrivedStopAnim)
  55. {
  56. return TaskStatus.Success;
  57. }
  58. if (this._enemy.StopMoveToIdle())
  59. {
  60. return TaskStatus.Success;
  61. }
  62. return TaskStatus.Failure;
  63. }
  64. [BehaviorDesigner.Runtime.Tasks.Tooltip("移动距离")]
  65. public float dis;
  66. public bool randomDis;
  67. public float randomMin;
  68. public float randomMax;
  69. [BehaviorDesigner.Runtime.Tasks.Tooltip("到达了后是否停止播放移动动画")]
  70. public bool isArrivedStopAnim = true;
  71. [BehaviorDesigner.Runtime.Tasks.Tooltip("1普通移动 2快速移动")]
  72. public int moveType;
  73. private EnemyAttribute _eAttr;
  74. private DahalFAction _enemy;
  75. private float aimPosX;
  76. }
  77. [TaskDescription("移动距离主角的某个位置范围")]
  78. [TaskCategory("Enemy/DahalF")]
  79. public class DahalFMoveDistanceRange : BehaviorDesigner.Runtime.Tasks.Action
  80. {
  81. private Transform player
  82. {
  83. get
  84. {
  85. return R.Player.Transform;
  86. }
  87. }
  88. public override void OnAwake()
  89. {
  90. this._action = base.GetComponent<DahalFAction>();
  91. this._eAttr = base.GetComponent<EnemyAttribute>();
  92. }
  93. public override void OnStart()
  94. {
  95. this._finalMoveLen = UnityEngine.Random.Range(this.moveRangeMin, this.moveRangeMax);
  96. int num = (UnityEngine.Random.Range(0, 2) != 0) ? -1 : 1;
  97. this._aimPos = this.player.transform.position.x + this._finalMoveLen * (float)num;
  98. int dir = InputSetting.JudgeDir(this.transform.position.x, this._aimPos);
  99. this._action.TurnRound(dir);
  100. this._aimPos = Mathf.Clamp(this._aimPos, GameArea.EnemyRange.min.x + this._eAttr.bounds.size.x, GameArea.EnemyRange.max.x - this._eAttr.bounds.size.x);
  101. }
  102. public override TaskStatus OnUpdate()
  103. {
  104. if (!this._action.DahyalAutoMove(this.moveType))
  105. {
  106. return TaskStatus.Failure;
  107. }
  108. bool flag = InputSetting.JudgeDir(this._action.transform.position.x, this._aimPos) == this._eAttr.faceDir;
  109. if (!flag)
  110. {
  111. return (!this._action.StopMoveToIdle()) ? TaskStatus.Failure : TaskStatus.Success;
  112. }
  113. float x = Mathf.Abs(this.player.position.x - this.transform.position.x);
  114. if (MathfX.isInRange(x, this.moveRangeMin, this.moveRangeMax))
  115. {
  116. this._action.StopMoveToIdle();
  117. return TaskStatus.Success;
  118. }
  119. return TaskStatus.Running;
  120. }
  121. private DahalFAction _action;
  122. private EnemyAttribute _eAttr;
  123. public float moveRangeMin;
  124. public float moveRangeMax;
  125. [BehaviorDesigner.Runtime.Tasks.Tooltip("1普通移动 2快速移动")]
  126. public int moveType;
  127. private float _aimPos;
  128. private float _finalMoveLen;
  129. }
  130. [TaskCategory("Enemy/DahalF")]
  131. [TaskDescription("Atk2")]
  132. public class Atk2 : BehaviorDesigner.Runtime.Tasks.Action
  133. {
  134. private int overTimes
  135. {
  136. get
  137. {
  138. return (R.GameData.Difficulty > 1) ? 4 : 2;
  139. }
  140. }
  141. public override void OnAwake()
  142. {
  143. this._action = base.GetComponent<DahalFAction>();
  144. this._eAttr = base.GetComponent<EnemyAttribute>();
  145. }
  146. public override void OnStart()
  147. {
  148. this._action.FaceToPlayer();
  149. this._action.Attack2(this._eAttr.faceDir);
  150. }
  151. public override TaskStatus OnUpdate()
  152. {
  153. if (!this._action.stateMachine.currentState.IsInArray(DahalFAction.AttackSta))
  154. {
  155. return TaskStatus.Failure;
  156. }
  157. if (this._eAttr.faceDir == -1)
  158. {
  159. if (this.transform.position.x > GameArea.EnemyRange.min.x + 0.9f)
  160. {
  161. return TaskStatus.Running;
  162. }
  163. this._action.Atk2HitWallTimes++;
  164. if (this._action.Atk2HitWallTimes >= this.overTimes)
  165. {
  166. this._action.AnimChangeState(DahalFAction.StateEnum.Atk2End, 1f);
  167. return TaskStatus.Success;
  168. }
  169. this.TurnBack();
  170. return TaskStatus.Running;
  171. }
  172. else
  173. {
  174. if (this.transform.position.x < GameArea.EnemyRange.max.x - 0.9f)
  175. {
  176. return TaskStatus.Running;
  177. }
  178. this._action.Atk2HitWallTimes++;
  179. if (this._action.Atk2HitWallTimes >= this.overTimes)
  180. {
  181. this._action.AnimChangeState(DahalFAction.StateEnum.Atk2End, 1f);
  182. return TaskStatus.Success;
  183. }
  184. this.TurnBack();
  185. return TaskStatus.Running;
  186. }
  187. }
  188. private void TurnBack()
  189. {
  190. int dir = (this._eAttr.faceDir != -1) ? -1 : 1;
  191. this._action.ChangeFace(dir);
  192. }
  193. private DahalFAction _action;
  194. private EnemyAttribute _eAttr;
  195. }
  196. [TaskCategory("Enemy/DahalF")]
  197. [TaskDescription("Atk6")]
  198. public class Atk6 : BehaviorDesigner.Runtime.Tasks.Action
  199. {
  200. private bool Atk6End
  201. {
  202. get
  203. {
  204. return R.GameData.Difficulty <= 1 || this._action.Atk6HitWall;
  205. }
  206. }
  207. public override void OnAwake()
  208. {
  209. this._action = base.GetComponent<DahalFAction>();
  210. this._eAttr = base.GetComponent<EnemyAttribute>();
  211. }
  212. public override void OnStart()
  213. {
  214. this._action.FaceToPlayer();
  215. this._action.Attack6(this._eAttr.faceDir);
  216. }
  217. public override TaskStatus OnUpdate()
  218. {
  219. if (!this._action.stateMachine.currentState.IsInArray(DahalFAction.AttackSta))
  220. {
  221. return TaskStatus.Failure;
  222. }
  223. if (this._eAttr.faceDir == -1)
  224. {
  225. if (this.transform.position.x > GameArea.EnemyRange.min.x + 0.9f)
  226. {
  227. return TaskStatus.Running;
  228. }
  229. if (this.Atk6End)
  230. {
  231. this._action.AnimChangeState(DahalFAction.StateEnum.Atk6End, 1f);
  232. return TaskStatus.Success;
  233. }
  234. this._action.Atk6HitWall = true;
  235. return TaskStatus.Running;
  236. }
  237. else
  238. {
  239. if (this.transform.position.x < GameArea.EnemyRange.max.x - 0.9f)
  240. {
  241. return TaskStatus.Running;
  242. }
  243. if (this.Atk6End)
  244. {
  245. this._action.AnimChangeState(DahalFAction.StateEnum.Atk6End, 1f);
  246. return TaskStatus.Success;
  247. }
  248. this._action.Atk6HitWall = true;
  249. return TaskStatus.Running;
  250. }
  251. }
  252. private DahalFAction _action;
  253. private EnemyAttribute _eAttr;
  254. }
  255. }