DahalAIAction.cs 7.7 KB

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