DaoAction.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. using System;
  2. using ExtensionMethods;
  3. using UnityEngine;
  4. public class DaoAction : EnemyBaseAction
  5. {
  6. protected override void Start()
  7. {
  8. this.stateMachine.AddStates(DaoAction.State.StateArray);
  9. this.stateMachine.OnEnter += this.OnMyStateEnter;
  10. this.stateMachine.OnTransfer += this.OnStateTransfer;
  11. base.AnimChangeState(DaoAction.StateEnum.Idle, 1f);
  12. }
  13. private void FixedUpdate()
  14. {
  15. if (this.stateMachine.currentState == DaoAction.State.HitToFly3)
  16. {
  17. Vector2 currentSpeed = this.eAttr.timeController.GetCurrentSpeed();
  18. float f = currentSpeed.x;
  19. f = Mathf.Clamp(Mathf.Abs(f) - this.airFric * Time.fixedDeltaTime, 0f, float.MaxValue) * Mathf.Sign(f);
  20. currentSpeed.x = Mathf.Clamp(Mathf.Abs(f) - this.airFric * Time.fixedDeltaTime, 0f, float.PositiveInfinity) * Mathf.Sign(f);
  21. this.eAttr.timeController.SetSpeed(currentSpeed);
  22. }
  23. }
  24. protected override void Update()
  25. {
  26. base.Update();
  27. if (this.stateMachine.currentState == DaoAction.State.HitToFly3)
  28. {
  29. Vector2 currentSpeed = this.eAttr.timeController.GetCurrentSpeed();
  30. if (currentSpeed.y > 0f)
  31. {
  32. currentSpeed.y = 0f;
  33. this.eAttr.timeController.SetSpeed(currentSpeed);
  34. }
  35. }
  36. }
  37. private void OnStateTransfer(object sender, StateMachine.TransferEventArgs args)
  38. {
  39. base.GetComponent<EnemyBaseHurt>().StopFollowLeftHand();
  40. this.atkBox.GetComponent<Collider2D>().enabled = true;
  41. if (args.nextState != DaoAction.State.PaoAtk1ToIdle && this.isPao && this.gun != null)
  42. {
  43. this.gun.mode = SkeletonUtilityBone.Mode.Follow;
  44. }
  45. if (this.ExitAtkSta(args.lastState, args.nextState))
  46. {
  47. this.eAttr.paBody = false;
  48. this.atkBox.localScale = Vector3.zero;
  49. }
  50. if (args.nextState == "DaoAtk2")
  51. {
  52. base.GetComponent<DaoEnemyAnimListener>().Atk2Start();
  53. }
  54. if (this.EnterAtkSta(args.lastState, args.nextState))
  55. {
  56. base.GetComponentInChildren<EnemyAtk>().atkId = Incrementor.GetNextId();
  57. }
  58. if (args.nextState == DaoAction.State.HitToFly3)
  59. {
  60. Vector2 currentSpeed = this.eAttr.timeController.GetCurrentSpeed();
  61. currentSpeed.y = 0f;
  62. this.eAttr.timeController.SetSpeed(currentSpeed);
  63. this.eAttr.timeController.SetGravity(0f);
  64. }
  65. if (args.lastState == DaoAction.State.HitToFly3 && !this.eAttr.willBeExecute)
  66. {
  67. this.eAttr.timeController.SetGravity(1f);
  68. }
  69. if (args.nextState.IsInArray(DaoAction.NormalSta))
  70. {
  71. this.eAttr.timeController.SetGravity(1f);
  72. }
  73. if (args.nextState == DaoAction.State.Jump || args.nextState == DaoAction.State.PaoAtk3)
  74. {
  75. this.eAttr.timeController.SetSpeed(Vector2.zero);
  76. this.eAttr.timeController.SetGravity(0f);
  77. }
  78. }
  79. private void OnMyStateEnter(object sender, StateMachine.StateEventArgs args)
  80. {
  81. string state = args.state;
  82. switch (state)
  83. {
  84. case "Atk1":
  85. case "Atk1Ready":
  86. case "DaoAtk1":
  87. case "DaoAtk6_1":
  88. case "DaoAtk2Ready":
  89. case "DaoAtk6_2Ready":
  90. case "PaoAtk1":
  91. case "PaoAtk2":
  92. case "DaoAtk3":
  93. case "DaoAtk4":
  94. case "DaoAtk5":
  95. case "PaoAtk3":
  96. this.spineAnim.Play(state, false, true, this.eAttr.atkSpeed);
  97. break;
  98. case "DaoAtk2":
  99. case "DaoAtk6_2":
  100. this.spineAnim.Play(state, true, false, this.eAttr.atkSpeed);
  101. break;
  102. case "FallHitGround":
  103. case "GetUp":
  104. case "Hit1":
  105. case "HitToFly1":
  106. case "HitToFly3":
  107. case "AirDie":
  108. case "HitGround":
  109. case "AirFly":
  110. case "AirFly2":
  111. case "HitWall":
  112. case "Idle2":
  113. case "Idle3":
  114. case "PaoAtk1ToIdle":
  115. case "Execute":
  116. case "Jump":
  117. case "JumpBack":
  118. case "RunAway":
  119. case "RunAwayReady":
  120. case "RunAwayEnd":
  121. case "MoveSlow":
  122. this.spineAnim.Play(state, false, true, 1f);
  123. break;
  124. case "Die":
  125. case "ExecuteDie":
  126. case "Die2":
  127. case "Null":
  128. this.spineAnim.Play(state, false, true, 1f);
  129. break;
  130. case "EMP":
  131. case "Fall":
  132. case "HitFall":
  133. case "AirDiePre":
  134. case "Idle":
  135. case "Move":
  136. case "DaoAtk2HitBack":
  137. case "HitToFly2":
  138. this.spineAnim.Play(state, true, false, 1f);
  139. break;
  140. }
  141. }
  142. public override bool IsInNormalState()
  143. {
  144. return this.stateMachine.currentState.IsInArray(DaoAction.NormalSta) && base.IsInNormalState();
  145. }
  146. public override bool IsInDeadState(string state)
  147. {
  148. return state.IsInArray(DaoAction.DeadSta);
  149. }
  150. public void RollToIdle()
  151. {
  152. base.AnimChangeState(DaoAction.StateEnum.DaoAtk2HitBack, 1f);
  153. base.GetComponent<EnemyDaoHurt>().SetHitSpeed(new Vector2((float)(this.eAttr.faceDir * -4), 15f));
  154. }
  155. public void Jump()
  156. {
  157. if (this.eAttr.isDead)
  158. {
  159. return;
  160. }
  161. if (!this.IsInNormalState())
  162. {
  163. return;
  164. }
  165. base.AnimChangeState(DaoAction.StateEnum.Jump, 1f);
  166. }
  167. public void JumpBack()
  168. {
  169. if (this.eAttr.isDead)
  170. {
  171. return;
  172. }
  173. if (!this.IsInNormalState())
  174. {
  175. return;
  176. }
  177. this.eAttr.timeController.SetSpeed(Vector2.zero);
  178. this.eAttr.timeController.SetGravity(0f);
  179. base.AnimChangeState(DaoAction.StateEnum.JumpBack, 1f);
  180. }
  181. public override void Attack1(int dir)
  182. {
  183. if (this.eAttr.isDead)
  184. {
  185. return;
  186. }
  187. if (!this.IsInNormalState())
  188. {
  189. return;
  190. }
  191. base.ChangeFace(dir);
  192. base.AnimChangeState(DaoAction.StateEnum.DaoAtk1, 1f);
  193. }
  194. public override void Attack2(int dir)
  195. {
  196. if (this.eAttr.isDead)
  197. {
  198. return;
  199. }
  200. if (!this.IsInNormalState())
  201. {
  202. return;
  203. }
  204. base.ChangeFace(dir);
  205. base.AnimChangeState(DaoAction.StateEnum.DaoAtk2Ready, 1f);
  206. }
  207. public override void Attack3(int dir)
  208. {
  209. if (this.eAttr.isDead)
  210. {
  211. return;
  212. }
  213. if (!this.IsInNormalState())
  214. {
  215. return;
  216. }
  217. base.ChangeFace(dir);
  218. base.AnimChangeState(DaoAction.StateEnum.PaoAtk1, 1f);
  219. }
  220. public override void Attack5(int dir)
  221. {
  222. if (this.eAttr.isDead)
  223. {
  224. return;
  225. }
  226. if (!this.IsInNormalState())
  227. {
  228. return;
  229. }
  230. base.ChangeFace(dir);
  231. base.AnimChangeState(DaoAction.StateEnum.PaoAtk2, 1f);
  232. }
  233. public override void Attack8(int dir)
  234. {
  235. if (this.eAttr.isDead)
  236. {
  237. return;
  238. }
  239. if (!this.IsInNormalState())
  240. {
  241. return;
  242. }
  243. base.ChangeFace(dir);
  244. this.eAttr.timeController.SetSpeed(Vector2.zero);
  245. this.eAttr.timeController.SetGravity(0f);
  246. base.AnimChangeState(DaoAction.StateEnum.DaoAtk5, 1f);
  247. }
  248. public override void Attack9(int dir)
  249. {
  250. if (this.eAttr.isDead)
  251. {
  252. return;
  253. }
  254. if (!this.IsInNormalState())
  255. {
  256. return;
  257. }
  258. base.ChangeFace(dir);
  259. base.AnimChangeState(DaoAction.StateEnum.PaoAtk3, 1f);
  260. }
  261. public override void Attack10(int dir)
  262. {
  263. if (this.eAttr.isDead)
  264. {
  265. return;
  266. }
  267. if (!this.IsInNormalState())
  268. {
  269. return;
  270. }
  271. base.ChangeFace(dir);
  272. base.AnimChangeState(DaoAction.StateEnum.DaoAtk6_1, 1f);
  273. }
  274. public override void Idle1()
  275. {
  276. if (!this.IsInNormalState())
  277. {
  278. return;
  279. }
  280. base.AnimChangeState(DaoAction.StateEnum.Idle, 1f);
  281. }
  282. public override void Idle2()
  283. {
  284. if (!this.IsInNormalState())
  285. {
  286. return;
  287. }
  288. base.AnimChangeState(DaoAction.StateEnum.Idle2, 1f);
  289. }
  290. public override void Idle3()
  291. {
  292. if (!this.IsInNormalState())
  293. {
  294. return;
  295. }
  296. base.AnimChangeState(DaoAction.StateEnum.Idle3, 1f);
  297. }
  298. public override void AnimReady()
  299. {
  300. base.AnimChangeState(DaoAction.StateEnum.Idle, 1f);
  301. }
  302. public override void AnimMove()
  303. {
  304. base.AnimChangeState(DaoAction.StateEnum.Move, 1f);
  305. }
  306. public override void SideStep()
  307. {
  308. if (this.eAttr.isDead)
  309. {
  310. return;
  311. }
  312. if (this.IsInSideStepState())
  313. {
  314. return;
  315. }
  316. if (!this.eAttr.isOnGround)
  317. {
  318. return;
  319. }
  320. base.SideStep();
  321. this.eAttr.timeController.SetSpeed(Vector2.zero);
  322. base.AnimChangeState((!this.isPao) ? DaoAction.StateEnum.JumpBack : DaoAction.StateEnum.RunAwayReady, 1f);
  323. }
  324. protected override bool EnterAtkSta(string lastState, string nextState)
  325. {
  326. return nextState.IsInArray(DaoAction.AttackSta) && !lastState.IsInArray(DaoAction.AttackSta);
  327. }
  328. protected override bool ExitAtkSta(string lastState, string nextState)
  329. {
  330. return !nextState.IsInArray(DaoAction.AttackSta) && lastState.IsInArray(DaoAction.AttackSta);
  331. }
  332. public override bool IsInAttackState()
  333. {
  334. return this.stateMachine.currentState.IsInArray(DaoAction.AttackSta);
  335. }
  336. public override bool IsInWeakSta()
  337. {
  338. return this.eAttr.inWeakState;
  339. }
  340. public override bool IsInIdle()
  341. {
  342. return this.stateMachine.currentState == "Idle" || this.stateMachine.currentState == "Idle2" || this.stateMachine.currentState == "Idle3";
  343. }
  344. public static string[] AttackSta = new string[]
  345. {
  346. "DaoAtk1",
  347. "DaoAtk2",
  348. "DaoAtk2Ready",
  349. "PaoAtk1",
  350. "Atk1",
  351. "Atk1Ready",
  352. "PaoAtk2",
  353. "DaoAtk3",
  354. "DaoAtk4",
  355. "DaoAtk5",
  356. "PaoAtk3",
  357. "DaoAtk6_1",
  358. "DaoAtk6_2",
  359. "DaoAtk6_2Ready"
  360. };
  361. public static string[] DeadSta = new string[]
  362. {
  363. "AirDiePre",
  364. "AirDie",
  365. "Die",
  366. "ExecuteDie",
  367. "Die2",
  368. "Null"
  369. };
  370. public static string[] HurtSta = new string[]
  371. {
  372. "DaoAtk2HitBack",
  373. "Fall",
  374. "FallHitGround",
  375. "GetUp",
  376. "Hit1",
  377. "HitToFly1",
  378. "HitToFly3",
  379. "AirFly",
  380. "AirFly2",
  381. "HitWall",
  382. "HitToFly2",
  383. "HitFall"
  384. };
  385. public static string[] NormalSta = new string[]
  386. {
  387. "Idle",
  388. "IDle2",
  389. "Idle3",
  390. "Move",
  391. "MoveSlow",
  392. "Jump"
  393. };
  394. public static string[] SideStepSta = new string[]
  395. {
  396. "RunAway",
  397. "RunAwayReady",
  398. "RunAwayEnd",
  399. "JumpBack"
  400. };
  401. [SerializeField]
  402. private SkeletonUtilityBone gun;
  403. public bool isPao;
  404. public float airFric = 8f;
  405. public enum StateEnum
  406. {
  407. DaoAtk1,
  408. DaoAtk2,
  409. DaoAtk2Ready,
  410. DaoAtk2HitBack,
  411. PaoAtk1,
  412. Die,
  413. EMP,
  414. Fall,
  415. FallHitGround,
  416. GetUp,
  417. Hit1,
  418. HitToFly1,
  419. HitToFly3,
  420. Idle,
  421. Idle2,
  422. Idle3,
  423. Move,
  424. HitGround,
  425. AirFly,
  426. AirFly2,
  427. HitWall,
  428. Atk1,
  429. Atk1Ready,
  430. AirDiePre,
  431. AirDie,
  432. PaoAtk1ToIdle,
  433. HitToFly2,
  434. Execute,
  435. ExecuteDie,
  436. Die2,
  437. Null,
  438. Jump,
  439. JumpBack,
  440. RunAway,
  441. RunAwayReady,
  442. RunAwayEnd,
  443. PaoAtk2,
  444. HitFall,
  445. DaoAtk3,
  446. DaoAtk4,
  447. DaoAtk5,
  448. MoveSlow,
  449. PaoAtk3,
  450. DaoAtk6_1,
  451. DaoAtk6_2,
  452. DaoAtk6_2Ready
  453. }
  454. public static class State
  455. {
  456. public static string[] StateArray = new string[]
  457. {
  458. "DaoAtk1",
  459. "DaoAtk2",
  460. "DaoAtk2Ready",
  461. "DaoAtk2HitBack",
  462. "PaoAtk1",
  463. "Die",
  464. "EMP",
  465. "Fall",
  466. "FallHitGround",
  467. "GetUp",
  468. "Hit1",
  469. "HitToFly1",
  470. "HitToFly3",
  471. "Idle",
  472. "Idle2",
  473. "Idle3",
  474. "Move",
  475. "HitGround",
  476. "AirFly",
  477. "AirFly2",
  478. "HitWall",
  479. "Atk1",
  480. "Atk1Ready",
  481. "AirDiePre",
  482. "AirDie",
  483. "PaoAtk1ToIdle",
  484. "HitToFly2",
  485. "Execute",
  486. "ExecuteDie",
  487. "Die2",
  488. "Null",
  489. "Jump",
  490. "JumpBack",
  491. "RunAway",
  492. "RunAwayReady",
  493. "RunAwayEnd",
  494. "PaoAtk2",
  495. "HitFall",
  496. "DaoAtk3",
  497. "DaoAtk4",
  498. "DaoAtk5",
  499. "MoveSlow",
  500. "PaoAtk3",
  501. "DaoAtk6_1",
  502. "DaoAtk6_2",
  503. "DaoAtk6_2Ready"
  504. };
  505. public static string DaoAtk1 = DaoAction.State.StateArray[0];
  506. public static string DaoAtk2 = DaoAction.State.StateArray[1];
  507. public static string DaoAtk2Ready = DaoAction.State.StateArray[2];
  508. public static string DaoAtk2HitBack = DaoAction.State.StateArray[3];
  509. public static string PaoAtk1 = DaoAction.State.StateArray[4];
  510. public static string Die = DaoAction.State.StateArray[5];
  511. public static string EMP = DaoAction.State.StateArray[6];
  512. public static string Fall = DaoAction.State.StateArray[7];
  513. public static string FallHitGround = DaoAction.State.StateArray[8];
  514. public static string GetUp = DaoAction.State.StateArray[9];
  515. public static string Hit1 = DaoAction.State.StateArray[10];
  516. public static string HitToFly1 = DaoAction.State.StateArray[11];
  517. public static string HitToFly3 = DaoAction.State.StateArray[12];
  518. public static string Idle = DaoAction.State.StateArray[13];
  519. public static string Idle2 = DaoAction.State.StateArray[14];
  520. public static string Idle3 = DaoAction.State.StateArray[15];
  521. public static string Move = DaoAction.State.StateArray[16];
  522. public static string HitGround = DaoAction.State.StateArray[17];
  523. public static string AirFly = DaoAction.State.StateArray[18];
  524. public static string AirFly2 = DaoAction.State.StateArray[19];
  525. public static string HitWall = DaoAction.State.StateArray[20];
  526. public static string Atk1 = DaoAction.State.StateArray[21];
  527. public static string Atk1Ready = DaoAction.State.StateArray[22];
  528. public static string AirDiePre = DaoAction.State.StateArray[23];
  529. public static string AirDie = DaoAction.State.StateArray[24];
  530. public static string PaoAtk1ToIdle = DaoAction.State.StateArray[25];
  531. public static string HitToFly2 = DaoAction.State.StateArray[26];
  532. public static string Execute = DaoAction.State.StateArray[27];
  533. public static string ExecuteDie = DaoAction.State.StateArray[28];
  534. public static string Die2 = DaoAction.State.StateArray[29];
  535. public static string Null = DaoAction.State.StateArray[30];
  536. public static string Jump = DaoAction.State.StateArray[31];
  537. public static string JumpBack = DaoAction.State.StateArray[32];
  538. public static string RunAway = DaoAction.State.StateArray[33];
  539. public static string RunAwayReady = DaoAction.State.StateArray[34];
  540. public static string RunAwayEnd = DaoAction.State.StateArray[35];
  541. public static string PaoAtk2 = DaoAction.State.StateArray[36];
  542. public static string HitFall = DaoAction.State.StateArray[37];
  543. public static string DaoAtk3 = DaoAction.State.StateArray[38];
  544. public static string DaoAtk4 = DaoAction.State.StateArray[39];
  545. public static string DaoAtk5 = DaoAction.State.StateArray[40];
  546. public static string MoveSlow = DaoAction.State.StateArray[41];
  547. public static string PaoAtk3 = DaoAction.State.StateArray[42];
  548. public static string DaoAtk6_1 = DaoAction.State.StateArray[43];
  549. public static string DaoAtk6_2 = DaoAction.State.StateArray[44];
  550. public static string DaoAtk6_2Ready = DaoAction.State.StateArray[45];
  551. }
  552. }