DaoPaoAction.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. using System;
  2. using ExtensionMethods;
  3. using UnityEngine;
  4. public class DaoPaoAction : EnemyBaseAction
  5. {
  6. protected override void Start()
  7. {
  8. this.stateMachine.AddStates(typeof(DaoPaoAction.StateEnum));
  9. this.stateMachine.OnEnter += this.OnMyStateEnter;
  10. this.stateMachine.OnTransfer += this.OnStateTransfer;
  11. base.AnimChangeState(DaoPaoAction.StateEnum.Idle, 1f);
  12. }
  13. private void FixedUpdate()
  14. {
  15. if (this.stateMachine.currentState == "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 == "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 (this.ExitAtkSta(args.lastState, args.nextState))
  42. {
  43. this.eAttr.paBody = false;
  44. this.atkBox.localScale = Vector3.zero;
  45. }
  46. if (args.nextState == "DaoAtk2")
  47. {
  48. base.GetComponent<DaoPaoAnimEvent>().Atk2Start();
  49. }
  50. if (this.EnterAtkSta(args.lastState, args.nextState))
  51. {
  52. base.GetComponentInChildren<EnemyAtk>().atkId = Incrementor.GetNextId();
  53. }
  54. if (args.nextState == "HitToFly3")
  55. {
  56. Vector2 currentSpeed = this.eAttr.timeController.GetCurrentSpeed();
  57. currentSpeed.y = 0f;
  58. this.eAttr.timeController.SetSpeed(currentSpeed);
  59. this.eAttr.timeController.SetGravity(0f);
  60. }
  61. if (args.lastState == "HitToFly3" && !this.eAttr.willBeExecute)
  62. {
  63. this.eAttr.timeController.SetGravity(1f);
  64. }
  65. if (args.nextState.IsInArray(DaoPaoAction.NormalSta))
  66. {
  67. this.hurtBox.localScale = Vector3.one;
  68. this.eAttr.timeController.SetGravity(1f);
  69. }
  70. if (args.nextState == "Jump" || args.nextState == "PaoAtk3")
  71. {
  72. this.eAttr.timeController.SetSpeed(Vector2.zero);
  73. this.eAttr.timeController.SetGravity(0f);
  74. this.hurtBox.localScale = Vector3.one;
  75. }
  76. }
  77. private void OnMyStateEnter(object sender, StateMachine.StateEventArgs args)
  78. {
  79. string state = args.state;
  80. switch (state)
  81. {
  82. case "Atk1":
  83. case "Atk1Ready":
  84. case "DaoAtk1":
  85. case "DaoAtk6_1":
  86. case "DaoAtk2Ready":
  87. case "DaoAtk6_2Ready":
  88. case "PaoAtk1":
  89. case "PaoAtk2":
  90. case "DaoAtk3":
  91. case "DaoAtk4":
  92. case "DaoAtk5":
  93. case "PaoAtk3":
  94. case "DaoPaoAtk1":
  95. this.spineAnim.Play(args.state, false, true, this.eAttr.atkSpeed);
  96. break;
  97. case "DaoAtk2":
  98. case "DaoAtk6_2":
  99. this.spineAnim.Play(args.state, true, false, this.eAttr.atkSpeed);
  100. break;
  101. case "FallHitGround":
  102. case "GetUp":
  103. case "Hit1":
  104. case "HitToFly1":
  105. case "HitToFly3":
  106. case "AirDie":
  107. case "HitGround":
  108. case "AirFly":
  109. case "AirFly2":
  110. case "HitWall":
  111. case "Idle2":
  112. case "Idle3":
  113. case "PaoAtk1ToIdle":
  114. case "Execute":
  115. case "Jump":
  116. case "JumpBack":
  117. case "RunAway":
  118. case "RunAwayReady":
  119. case "RunAwayEnd":
  120. case "MoveSlow":
  121. this.spineAnim.Play(args.state, false, true, 1f);
  122. break;
  123. case "Die":
  124. case "ExecuteDie":
  125. case "Die2":
  126. case "Null":
  127. this.spineAnim.Play(args.state, false, true, 1f);
  128. break;
  129. case "EMP":
  130. case "Fall":
  131. case "HitFall":
  132. case "AirDiePre":
  133. case "Idle":
  134. case "Move":
  135. case "DaoAtk2HitBack":
  136. case "HitToFly2":
  137. this.spineAnim.Play(args.state, true, false, 1f);
  138. break;
  139. }
  140. }
  141. public override bool IsInNormalState()
  142. {
  143. return this.stateMachine.currentState.IsInArray(DaoPaoAction.NormalSta) && base.IsInNormalState();
  144. }
  145. public override bool IsInDeadState(string state)
  146. {
  147. return state.IsInArray(DaoPaoAction.DeadSta);
  148. }
  149. public void RollToIdle()
  150. {
  151. base.AnimChangeState("DaoAtk2HitBack", 1f);
  152. base.GetComponent<EnemyBaseHurt>().SetHitSpeed(new Vector2((float)(this.eAttr.faceDir * -4), 15f));
  153. }
  154. public void Jump()
  155. {
  156. if (this.eAttr.isDead)
  157. {
  158. return;
  159. }
  160. if (!this.IsInNormalState())
  161. {
  162. return;
  163. }
  164. base.AnimChangeState(DaoPaoAction.StateEnum.Jump, 1f);
  165. }
  166. public void JumpBack()
  167. {
  168. if (this.eAttr.isDead)
  169. {
  170. return;
  171. }
  172. if (!this.IsInNormalState())
  173. {
  174. return;
  175. }
  176. this.eAttr.timeController.SetGravity(0f);
  177. base.AnimChangeState(DaoPaoAction.StateEnum.JumpBack, 1f);
  178. }
  179. public override void Idle2()
  180. {
  181. if (!this.IsInNormalState())
  182. {
  183. return;
  184. }
  185. base.AnimChangeState(DaoPaoAction.StateEnum.Idle2, 1f);
  186. }
  187. public override void Idle3()
  188. {
  189. if (!this.IsInNormalState())
  190. {
  191. return;
  192. }
  193. base.AnimChangeState(DaoPaoAction.StateEnum.Idle3, 1f);
  194. }
  195. public override void Attack1(int dir)
  196. {
  197. if (this.eAttr.isDead)
  198. {
  199. return;
  200. }
  201. if (!this.IsInNormalState())
  202. {
  203. return;
  204. }
  205. base.ChangeFace(dir);
  206. base.AnimChangeState(DaoPaoAction.StateEnum.DaoAtk1, 1f);
  207. }
  208. public override void Attack2(int dir)
  209. {
  210. if (this.eAttr.isDead)
  211. {
  212. return;
  213. }
  214. if (!this.IsInNormalState())
  215. {
  216. return;
  217. }
  218. base.ChangeFace(dir);
  219. base.AnimChangeState(DaoPaoAction.StateEnum.DaoAtk2Ready, 1f);
  220. }
  221. public override void Attack3(int dir)
  222. {
  223. if (this.eAttr.isDead)
  224. {
  225. return;
  226. }
  227. if (!this.IsInNormalState())
  228. {
  229. return;
  230. }
  231. base.ChangeFace(dir);
  232. base.AnimChangeState(DaoPaoAction.StateEnum.PaoAtk1, 1f);
  233. }
  234. public override void Attack5(int dir)
  235. {
  236. if (this.eAttr.isDead)
  237. {
  238. return;
  239. }
  240. if (!this.IsInNormalState())
  241. {
  242. return;
  243. }
  244. base.ChangeFace(dir);
  245. base.AnimChangeState(DaoPaoAction.StateEnum.PaoAtk2, 1f);
  246. }
  247. public override void Attack8(int dir)
  248. {
  249. if (this.eAttr.isDead)
  250. {
  251. return;
  252. }
  253. if (!this.IsInNormalState())
  254. {
  255. return;
  256. }
  257. base.ChangeFace(dir);
  258. this.eAttr.timeController.SetSpeed(Vector2.zero);
  259. this.eAttr.timeController.SetGravity(0f);
  260. base.AnimChangeState(DaoPaoAction.StateEnum.DaoAtk5, 1f);
  261. }
  262. public override void Attack11(int dir)
  263. {
  264. if (this.eAttr.isDead)
  265. {
  266. return;
  267. }
  268. if (!this.IsInNormalState())
  269. {
  270. return;
  271. }
  272. base.ChangeFace(dir);
  273. this.eAttr.timeController.SetSpeed(Vector2.zero);
  274. this.eAttr.timeController.SetGravity(0f);
  275. base.AnimChangeState(DaoPaoAction.StateEnum.DaoPaoAtk1, 1f);
  276. }
  277. public override void AnimMove()
  278. {
  279. base.AnimChangeState(DaoPaoAction.StateEnum.Move, 1f);
  280. }
  281. public override void AnimReady()
  282. {
  283. base.AnimChangeState(DaoPaoAction.StateEnum.Idle, 1f);
  284. }
  285. public override void SideStep()
  286. {
  287. if (this.eAttr.isDead)
  288. {
  289. return;
  290. }
  291. if (this.IsInSideStepState())
  292. {
  293. return;
  294. }
  295. if (!this.eAttr.isOnGround)
  296. {
  297. return;
  298. }
  299. base.SideStep();
  300. this.eAttr.timeController.SetSpeed(Vector2.zero);
  301. base.AnimChangeState(DaoPaoAction.StateEnum.JumpBack, 1f);
  302. }
  303. protected override bool EnterAtkSta(string lastState, string nextState)
  304. {
  305. return nextState.IsInArray(DaoPaoAction.AttackSta) && !lastState.IsInArray(DaoPaoAction.AttackSta);
  306. }
  307. protected override bool ExitAtkSta(string lastState, string nextState)
  308. {
  309. return !nextState.IsInArray(DaoPaoAction.AttackSta) && lastState.IsInArray(DaoPaoAction.AttackSta);
  310. }
  311. public override bool IsInAttackState()
  312. {
  313. return this.stateMachine.currentState.IsInArray(DaoPaoAction.AttackSta);
  314. }
  315. public override bool IsInWeakSta()
  316. {
  317. return this.eAttr.inWeakState;
  318. }
  319. public override bool IsInIdle()
  320. {
  321. return this.stateMachine.currentState == "Idle" || this.stateMachine.currentState == "Idle2" || this.stateMachine.currentState == "Idle3";
  322. }
  323. public static readonly string[] AttackSta = new string[]
  324. {
  325. "DaoAtk1",
  326. "DaoAtk2",
  327. "DaoAtk2Ready",
  328. "PaoAtk1",
  329. "Atk1",
  330. "Atk1Ready",
  331. "PaoAtk2",
  332. "DaoAtk3",
  333. "DaoAtk4",
  334. "DaoAtk5",
  335. "PaoAtk3",
  336. "DaoAtk6_1",
  337. "DaoAtk6_2",
  338. "DaoAtk6_2Ready",
  339. "DaoPaoAtk1"
  340. };
  341. public static readonly string[] DeadSta = new string[]
  342. {
  343. "AirDiePre",
  344. "AirDie",
  345. "Die",
  346. "ExecuteDie",
  347. "Die2",
  348. "Null"
  349. };
  350. public static readonly string[] NormalSta = new string[]
  351. {
  352. "Idle",
  353. "IDle2",
  354. "Idle3",
  355. "Move",
  356. "MoveSlow",
  357. "Jump"
  358. };
  359. private readonly float _airFric = 8f;
  360. [SerializeField]
  361. private SkeletonUtilityBone gun;
  362. public enum StateEnum
  363. {
  364. DaoAtk1,
  365. DaoAtk2,
  366. DaoAtk2Ready,
  367. DaoAtk2HitBack,
  368. PaoAtk1,
  369. Die,
  370. EMP,
  371. Fall,
  372. FallHitGround,
  373. GetUp,
  374. Hit1,
  375. HitToFly1,
  376. HitToFly3,
  377. Idle,
  378. Idle2,
  379. Idle3,
  380. Move,
  381. HitGround,
  382. AirFly,
  383. AirFly2,
  384. HitWall,
  385. Atk1,
  386. Atk1Ready,
  387. AirDiePre,
  388. AirDie,
  389. PaoAtk1ToIdle,
  390. HitToFly2,
  391. Execute,
  392. ExecuteDie,
  393. Die2,
  394. Null,
  395. Jump,
  396. JumpBack,
  397. RunAway,
  398. RunAwayReady,
  399. RunAwayEnd,
  400. PaoAtk2,
  401. HitFall,
  402. DaoAtk3,
  403. DaoAtk4,
  404. DaoAtk5,
  405. MoveSlow,
  406. PaoAtk3,
  407. DaoAtk6_1,
  408. DaoAtk6_2,
  409. DaoAtk6_2Ready,
  410. DaoPaoAtk1
  411. }
  412. }