DaoBrotherAIAction.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. using System;
  2. using BehaviorDesigner.Runtime.Tasks;
  3. using ExtensionMethods;
  4. using UnityEngine;
  5. public class DaoBrotherAIAction
  6. {
  7. [TaskCategory("Enemy/DaoBrother")]
  8. [TaskDescription("在丢飞刀攻击距离内")]
  9. public class WithinNormalAtkRange : BehaviorDesigner.Runtime.Tasks.Action
  10. {
  11. private Transform player
  12. {
  13. get
  14. {
  15. return R.Player.Transform;
  16. }
  17. }
  18. private EnemyAIAttribute.ExpectationParam normalAtk
  19. {
  20. get
  21. {
  22. return this.ai.attackExpectations[0];
  23. }
  24. }
  25. public override void OnAwake()
  26. {
  27. this.ai = base.GetComponent<EnemyAIAttribute>();
  28. }
  29. public override TaskStatus OnUpdate()
  30. {
  31. if (Mathf.Abs(this.transform.position.x - this.player.position.x) < this.normalAtk.distance + this.normalAtk.range)
  32. {
  33. return TaskStatus.Success;
  34. }
  35. return TaskStatus.Failure;
  36. }
  37. private EnemyAIAttribute ai;
  38. }
  39. [TaskDescription("在两种攻击的攻击力距离内")]
  40. [TaskCategory("Enemy/DaoBrother")]
  41. public class BetweenTwoAtkEange : BehaviorDesigner.Runtime.Tasks.Action
  42. {
  43. private Transform player
  44. {
  45. get
  46. {
  47. return R.Player.Transform;
  48. }
  49. }
  50. private EnemyAIAttribute.ExpectationParam normalAtk
  51. {
  52. get
  53. {
  54. return this.ai.attackExpectations[0];
  55. }
  56. }
  57. private EnemyAIAttribute.ExpectationParam rollAtk
  58. {
  59. get
  60. {
  61. return this.ai.attackExpectations[1];
  62. }
  63. }
  64. public override void OnAwake()
  65. {
  66. this.ai = base.GetComponent<EnemyAIAttribute>();
  67. }
  68. public override TaskStatus OnUpdate()
  69. {
  70. if (Mathf.Abs(this.transform.position.x - this.player.position.x) >= this.normalAtk.distance + this.normalAtk.range && Mathf.Abs(this.transform.position.x - this.player.position.x) < this.rollAtk.distance + this.rollAtk.range)
  71. {
  72. return TaskStatus.Success;
  73. }
  74. return TaskStatus.Failure;
  75. }
  76. private EnemyAIAttribute ai;
  77. }
  78. [TaskDescription("在滚动攻击距离外")]
  79. [TaskCategory("Enemy/DaoBrother")]
  80. public class WithoutRollAtkRange : BehaviorDesigner.Runtime.Tasks.Action
  81. {
  82. private Transform player
  83. {
  84. get
  85. {
  86. return R.Player.Transform;
  87. }
  88. }
  89. private EnemyAIAttribute.ExpectationParam rollAtk
  90. {
  91. get
  92. {
  93. return this.ai.attackExpectations[1];
  94. }
  95. }
  96. public override void OnAwake()
  97. {
  98. this.ai = base.GetComponent<EnemyAIAttribute>();
  99. }
  100. public override TaskStatus OnUpdate()
  101. {
  102. if (Mathf.Abs(this.transform.position.x - this.player.position.x) >= this.rollAtk.distance + this.rollAtk.range)
  103. {
  104. return TaskStatus.Success;
  105. }
  106. return TaskStatus.Failure;
  107. }
  108. private EnemyAIAttribute ai;
  109. }
  110. [TaskCategory("Enemy/DaoBrother")]
  111. [TaskDescription("刀哥攻击")]
  112. public class DaoBrotherAtk : BehaviorDesigner.Runtime.Tasks.Action
  113. {
  114. private Transform player
  115. {
  116. get
  117. {
  118. return R.Player.Transform;
  119. }
  120. }
  121. public override void OnAwake()
  122. {
  123. this.action = base.GetComponent<DaoAction>();
  124. }
  125. public override void OnStart()
  126. {
  127. int dir = InputSetting.JudgeDir(this.transform.position, this.player.position);
  128. DaoBrotherAIAction.DaoBrotherAtk.DaoAtkType daoAtkType = this.atkType;
  129. if (daoAtkType != DaoBrotherAIAction.DaoBrotherAtk.DaoAtkType.NormalAtk)
  130. {
  131. if (daoAtkType == DaoBrotherAIAction.DaoBrotherAtk.DaoAtkType.RollAtk)
  132. {
  133. this.action.Attack2(dir);
  134. }
  135. }
  136. else
  137. {
  138. this.action.Attack1(dir);
  139. }
  140. }
  141. public override TaskStatus OnUpdate()
  142. {
  143. if (this.action.stateMachine.currentState.IsInArray(DaoAction.AttackSta))
  144. {
  145. return TaskStatus.Running;
  146. }
  147. return TaskStatus.Success;
  148. }
  149. public DaoBrotherAIAction.DaoBrotherAtk.DaoAtkType atkType;
  150. private DaoAction action;
  151. public enum DaoAtkType
  152. {
  153. NormalAtk,
  154. RollAtk
  155. }
  156. }
  157. [TaskDescription("刀哥卖萌")]
  158. [TaskCategory("Enemy/DaoBrother")]
  159. public class Moe : BehaviorDesigner.Runtime.Tasks.Action
  160. {
  161. public override void OnAwake()
  162. {
  163. this.action = base.GetComponent<DaoAction>();
  164. }
  165. public override void OnStart()
  166. {
  167. this.action.FaceToPlayer();
  168. if (UnityEngine.Random.Range(0, 2) == 0)
  169. {
  170. this.action.Idle2();
  171. }
  172. else
  173. {
  174. this.action.Idle3();
  175. }
  176. }
  177. public override TaskStatus OnUpdate()
  178. {
  179. string currentState = this.action.stateMachine.currentState;
  180. if (currentState == DaoAction.State.Idle2 || currentState == DaoAction.State.Idle3)
  181. {
  182. return TaskStatus.Running;
  183. }
  184. return TaskStatus.Success;
  185. }
  186. private DaoAction action;
  187. }
  188. [TaskDescription("移动到攻击1和攻击2距离之间")]
  189. [TaskCategory("Enemy/DaoBrother")]
  190. public class MoveToAPosition : BehaviorDesigner.Runtime.Tasks.Action
  191. {
  192. private Transform player
  193. {
  194. get
  195. {
  196. return R.Player.Transform;
  197. }
  198. }
  199. private float randomLen
  200. {
  201. get
  202. {
  203. return UnityEngine.Random.Range(0f, Mathf.Abs(this.ai.attackExpectations[0].distance + this.ai.attackExpectations[0].range - (this.ai.attackExpectations[1].distance + this.ai.attackExpectations[1].range)));
  204. }
  205. }
  206. public override void OnAwake()
  207. {
  208. this.ai = base.GetComponent<EnemyAIAttribute>();
  209. this.action = base.GetComponent<DaoAction>();
  210. this.eAttr = base.GetComponent<EnemyAttribute>();
  211. }
  212. public override void OnStart()
  213. {
  214. float num = Mathf.Abs(this.transform.position.x - this.player.position.x) - (this.ai.attackExpectations[1].range + this.ai.attackExpectations[1].distance);
  215. float num2 = num + this.randomLen;
  216. this.aimPos = ((this.transform.position.x - this.player.position.x <= 0f) ? (this.transform.position.x + num2) : (this.transform.position.x - num2));
  217. this.aimPos = Mathf.Clamp(this.aimPos, GameArea.EnemyRange.min.x + this.eAttr.bounds.size.x, GameArea.EnemyRange.max.x - this.eAttr.bounds.size.x);
  218. }
  219. public override TaskStatus OnUpdate()
  220. {
  221. if (!this.action.AutoMove())
  222. {
  223. return TaskStatus.Failure;
  224. }
  225. bool flag = InputSetting.JudgeDir(this.action.transform.position.x, this.aimPos) == this.eAttr.faceDir;
  226. if (flag)
  227. {
  228. return TaskStatus.Running;
  229. }
  230. return (!this.action.StopMoveToIdle()) ? TaskStatus.Failure : TaskStatus.Success;
  231. }
  232. private EnemyAIAttribute ai;
  233. private DaoAction action;
  234. private EnemyAttribute eAttr;
  235. private float aimPos;
  236. }
  237. [TaskCategory("Enemy/DaoBrother")]
  238. [TaskDescription("移动到主角对面")]
  239. public class MoveToPlayer : BehaviorDesigner.Runtime.Tasks.Action
  240. {
  241. private Transform player
  242. {
  243. get
  244. {
  245. return R.Player.Transform;
  246. }
  247. }
  248. public override void OnAwake()
  249. {
  250. this.action = base.GetComponent<DaoAction>();
  251. this.eAttr = base.GetComponent<EnemyAttribute>();
  252. }
  253. public override void OnStart()
  254. {
  255. this.moveDis = UnityEngine.Random.Range(1f, 5f);
  256. if (this.transform.position.x - this.player.position.x >= 0f)
  257. {
  258. this.aimPos = this.player.position.x - this.moveDis;
  259. }
  260. else
  261. {
  262. this.aimPos = this.player.position.x + this.moveDis;
  263. }
  264. this.aimPos = Mathf.Clamp(this.aimPos, GameArea.EnemyRange.min.x + this.eAttr.bounds.size.x, GameArea.EnemyRange.max.x - this.eAttr.bounds.size.x);
  265. this.action.FaceToPlayer();
  266. }
  267. public override TaskStatus OnUpdate()
  268. {
  269. if (!this.action.AutoMove())
  270. {
  271. return TaskStatus.Failure;
  272. }
  273. bool flag = InputSetting.JudgeDir(this.action.transform.position.x, this.aimPos) == this.eAttr.faceDir;
  274. if (flag)
  275. {
  276. return TaskStatus.Running;
  277. }
  278. return (!this.action.StopMoveToIdle()) ? TaskStatus.Failure : TaskStatus.Success;
  279. }
  280. private float moveDis;
  281. private float aimPos;
  282. private DaoAction action;
  283. private EnemyAttribute eAttr;
  284. }
  285. [TaskDescription("刀哥跳跃")]
  286. [TaskCategory("Enemy/DaoBrother")]
  287. public class DaoJump : BehaviorDesigner.Runtime.Tasks.Action
  288. {
  289. private Transform player
  290. {
  291. get
  292. {
  293. return R.Player.Transform;
  294. }
  295. }
  296. public override void OnAwake()
  297. {
  298. this.action = base.GetComponent<DaoAction>();
  299. }
  300. public override void OnStart()
  301. {
  302. this.action.FaceToPlayer();
  303. if (this.back)
  304. {
  305. this.action.JumpBack();
  306. }
  307. else
  308. {
  309. this.action.Jump();
  310. }
  311. }
  312. public override TaskStatus OnUpdate()
  313. {
  314. string currentState = this.action.stateMachine.currentState;
  315. if (currentState == DaoAction.State.Jump || currentState == DaoAction.State.JumpBack)
  316. {
  317. return TaskStatus.Running;
  318. }
  319. return TaskStatus.Success;
  320. }
  321. public bool back;
  322. private float moveDis;
  323. private float aimPos;
  324. private DaoAction action;
  325. }
  326. }