JackAction.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. using System;
  2. using System.Collections.Generic;
  3. using ExtensionMethods;
  4. using UnityEngine;
  5. public class JackAction : EnemyBaseAction
  6. {
  7. static Dictionary<string, int> _003C_003Ef__switch_0024map6;
  8. protected override void Start()
  9. {
  10. this.stateMachine.AddStates(typeof(JackAction.StateEnum));
  11. this.stateMachine.OnEnter += this.OnMyStateEnter;
  12. this.stateMachine.OnTransfer += this.OnStateTransfer;
  13. base.AnimChangeState(JackAction.StateEnum.Idle, 1f);
  14. }
  15. protected override void Update()
  16. {
  17. base.Update();
  18. this.UpdateHp();
  19. }
  20. private void FixedUpdate()
  21. {
  22. if (this.stateMachine.currentState != "FlyToFall")
  23. {
  24. return;
  25. }
  26. Vector2 currentSpeed = this.eAttr.timeController.GetCurrentSpeed();
  27. float f = currentSpeed.x;
  28. f = Mathf.Clamp(Mathf.Abs(f) - this._airFric * Time.fixedDeltaTime, 0f, float.MaxValue) * Mathf.Sign(f);
  29. currentSpeed.x = Mathf.Clamp(Mathf.Abs(f) - this._airFric * Time.fixedDeltaTime, 0f, float.PositiveInfinity) * Mathf.Sign(f);
  30. this.eAttr.timeController.SetSpeed(currentSpeed);
  31. }
  32. private void UpdateHp()
  33. {
  34. switch (R.GameData.Difficulty)
  35. {
  36. case 0:
  37. case 1:
  38. this.NormalModeHp();
  39. break;
  40. case 2:
  41. case 3:
  42. this.HardModeHp();
  43. break;
  44. }
  45. }
  46. private void NormalModeHp()
  47. {
  48. if (this.eAttr.currentHp < this.eAttr.maxHp * 65 / 100 && this._first65)
  49. {
  50. this._first65 = false;
  51. this.UseAtk5 = true;
  52. }
  53. if (this.eAttr.currentHp < this.eAttr.maxHp * 35 / 100 && this._first35)
  54. {
  55. this._first35 = false;
  56. this.UseAtk5 = true;
  57. }
  58. }
  59. private void HardModeHp()
  60. {
  61. if (this.eAttr.currentHp < this.eAttr.maxHp * 75 / 100 && this._first75)
  62. {
  63. this._first75 = false;
  64. this.UseAtk5 = true;
  65. }
  66. if (this.eAttr.currentHp < this.eAttr.maxHp * 55 / 100 && this._first55)
  67. {
  68. this._first55 = false;
  69. this.UseAtk5 = true;
  70. }
  71. if (this.eAttr.currentHp < this.eAttr.maxHp * 25 / 100 && this._first25)
  72. {
  73. this._first25 = false;
  74. this.UseAtk5 = true;
  75. }
  76. }
  77. private void OnMyStateEnter(object sender, StateMachine.StateEventArgs args)
  78. {
  79. string state = args.state;
  80. if (state != null)
  81. {
  82. if (JackAction._003C_003Ef__switch_0024map6 == null)
  83. {
  84. JackAction._003C_003Ef__switch_0024map6 = new Dictionary<string, int>(25)
  85. {
  86. {
  87. "Atk1",
  88. 0
  89. },
  90. {
  91. "Atk2",
  92. 0
  93. },
  94. {
  95. "Atk3",
  96. 0
  97. },
  98. {
  99. "Atk4",
  100. 0
  101. },
  102. {
  103. "Atk5Aim",
  104. 0
  105. },
  106. {
  107. "Atk5End",
  108. 0
  109. },
  110. {
  111. "Atk5Ready",
  112. 0
  113. },
  114. {
  115. "Atk5Shoot",
  116. 0
  117. },
  118. {
  119. "DieQTE",
  120. 0
  121. },
  122. {
  123. "FallHitGround",
  124. 0
  125. },
  126. {
  127. "FlyToFall",
  128. 0
  129. },
  130. {
  131. "GetUp",
  132. 0
  133. },
  134. {
  135. "Hit1",
  136. 0
  137. },
  138. {
  139. "Hit2",
  140. 0
  141. },
  142. {
  143. "HitQTE",
  144. 0
  145. },
  146. {
  147. "HitToFly1",
  148. 0
  149. },
  150. {
  151. "IdleToWeakMod",
  152. 0
  153. },
  154. {
  155. "Jump",
  156. 0
  157. },
  158. {
  159. "MoveAway",
  160. 0
  161. },
  162. {
  163. "WeakModToIdle",
  164. 0
  165. },
  166. {
  167. "Fall",
  168. 1
  169. },
  170. {
  171. "HitToFly2",
  172. 1
  173. },
  174. {
  175. "Idle",
  176. 1
  177. },
  178. {
  179. "Move",
  180. 1
  181. },
  182. {
  183. "WeakMod",
  184. 1
  185. }
  186. };
  187. }
  188. int num;
  189. if (JackAction._003C_003Ef__switch_0024map6.TryGetValue(state, out num))
  190. {
  191. if (num != 0)
  192. {
  193. if (num == 1)
  194. {
  195. this.spineAnim.Play(args.state, true, false, 1f);
  196. }
  197. }
  198. else
  199. {
  200. this.spineAnim.Play(args.state, false, true, 1f);
  201. }
  202. }
  203. }
  204. }
  205. private void OnStateTransfer(object sender, StateMachine.TransferEventArgs args)
  206. {
  207. if (args.nextState == "FlyToFall")
  208. {
  209. Vector2 currentSpeed = this.eAttr.timeController.GetCurrentSpeed();
  210. currentSpeed.y = 0f;
  211. this.eAttr.timeController.SetSpeed(currentSpeed);
  212. this.eAttr.timeController.SetGravity(0f);
  213. }
  214. if (args.lastState == "FlyToFall" || args.lastState == "Atk2" || args.lastState == "Atk3" || args.lastState == "Atk4" || args.lastState == "Jump")
  215. {
  216. this.eAttr.timeController.SetGravity(1f);
  217. }
  218. }
  219. public override void Attack1(int dir)
  220. {
  221. if (this.eAttr.isDead)
  222. {
  223. return;
  224. }
  225. if (!this.IsInNormalState())
  226. {
  227. return;
  228. }
  229. base.ChangeFace(dir);
  230. base.AnimChangeState(JackAction.StateEnum.Atk1, 1f);
  231. }
  232. public override void Attack2(int dir)
  233. {
  234. if (this.eAttr.isDead)
  235. {
  236. return;
  237. }
  238. if (!this.IsInNormalState())
  239. {
  240. return;
  241. }
  242. base.ChangeFace(dir);
  243. this.eAttr.timeController.SetGravity(0f);
  244. this.eAttr.timeController.SetSpeed(Vector2.zero);
  245. base.AnimChangeState(JackAction.StateEnum.Atk2, 1f);
  246. }
  247. public override void Attack3(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.SetGravity(0f);
  259. this.eAttr.timeController.SetSpeed(Vector2.zero);
  260. base.AnimChangeState(JackAction.StateEnum.Atk3, 1f);
  261. }
  262. public override void Attack4(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.SetGravity(0f);
  274. this.eAttr.timeController.SetSpeed(Vector2.zero);
  275. base.AnimChangeState(JackAction.StateEnum.Atk4, 1f);
  276. }
  277. public override void Attack5(int dir)
  278. {
  279. if (this.eAttr.isDead)
  280. {
  281. return;
  282. }
  283. if (!this.IsInNormalState())
  284. {
  285. return;
  286. }
  287. base.ChangeFace(dir);
  288. base.AnimChangeState(JackAction.StateEnum.Atk5Ready, 1f);
  289. }
  290. public override void CounterAttack(int dir)
  291. {
  292. if (this.eAttr.isDead)
  293. {
  294. return;
  295. }
  296. if (this.IsInAttackState())
  297. {
  298. return;
  299. }
  300. if (this.stateMachine.currentState.IsInArray(JackAction.QTESta) || this.IsInWeakSta())
  301. {
  302. return;
  303. }
  304. R.Effect.Generate(128, base.transform, Vector3.up * 2.5f, Vector3.zero, default(Vector3), true);
  305. base.ChangeFace(dir);
  306. this.eAttr.timeController.SetGravity(0f);
  307. this.eAttr.timeController.SetSpeed(Vector2.zero);
  308. base.AnimChangeState(JackAction.StateEnum.Atk3, 1f);
  309. }
  310. public void Jump()
  311. {
  312. if (this.eAttr.isDead)
  313. {
  314. return;
  315. }
  316. if (!this.IsInNormalState())
  317. {
  318. return;
  319. }
  320. base.FaceToPlayer();
  321. this.eAttr.timeController.SetGravity(0f);
  322. this.eAttr.timeController.SetSpeed(Vector2.zero);
  323. base.AnimChangeState(JackAction.StateEnum.Jump, 1f);
  324. }
  325. public override void SideStep()
  326. {
  327. if (this.eAttr.isDead)
  328. {
  329. return;
  330. }
  331. if (this.IsInSideStepState())
  332. {
  333. return;
  334. }
  335. if (!this.eAttr.isOnGround)
  336. {
  337. return;
  338. }
  339. base.SideStep();
  340. this.eAttr.timeController.SetSpeed(Vector2.zero);
  341. base.AnimChangeState(JackAction.StateEnum.MoveAway, 1f);
  342. }
  343. public override void AnimMove()
  344. {
  345. base.AnimChangeState(JackAction.StateEnum.Move, 1f);
  346. }
  347. public override void AnimReady()
  348. {
  349. base.AnimChangeState(JackAction.StateEnum.Idle, 1f);
  350. }
  351. public override bool IsInNormalState()
  352. {
  353. return this.stateMachine.currentState.IsInArray(JackAction.NormalSta) && base.IsInNormalState();
  354. }
  355. public override bool IsInAttackState()
  356. {
  357. return this.stateMachine.currentState.IsInArray(JackAction.AttackSta);
  358. }
  359. public override bool IsInDeadState(string state)
  360. {
  361. return state == "DieQTE";
  362. }
  363. public override bool IsInWeakSta()
  364. {
  365. return this.eAttr.inWeakState;
  366. }
  367. public override bool IsInIdle()
  368. {
  369. return this.stateMachine.currentState == "Idle";
  370. }
  371. protected override bool EnterAtkSta(string lastState, string nextState)
  372. {
  373. return nextState.IsInArray(JackAction.AttackSta) && !lastState.IsInArray(JackAction.AttackSta);
  374. }
  375. protected override bool ExitAtkSta(string lastState, string nextState)
  376. {
  377. return !nextState.IsInArray(JackAction.AttackSta) && lastState.IsInArray(JackAction.AttackSta);
  378. }
  379. public override void AnimQTEHurt()
  380. {
  381. int dir = (base.player.transform.localScale.x >= 0f) ? 1 : -1;
  382. base.ChangeFace(dir);
  383. base.ExitWeakState(true);
  384. this.eAttr.isFlyingUp = false;
  385. this.eAttr.checkHitGround = false;
  386. Vector3 position = base.transform.position;
  387. position.y = LayerManager.YNum.GetGroundHeight(base.gameObject);
  388. position.z = LayerManager.ZNum.TempEnemy;
  389. base.transform.position = position;
  390. base.AnimChangeState(JackAction.StateEnum.HitQTE, 1f);
  391. }
  392. public override void AnimExecute()
  393. {
  394. int dir = (base.player.transform.localScale.x >= 0f) ? 1 : -1;
  395. base.ChangeFace(dir);
  396. base.ExitWeakState(true);
  397. this.eAttr.isFlyingUp = false;
  398. this.eAttr.checkHitGround = false;
  399. Vector3 position = base.transform.position;
  400. position.y = LayerManager.YNum.GetGroundHeight(base.gameObject);
  401. position.z = LayerManager.ZNum.TempEnemy;
  402. base.transform.position = position;
  403. base.AnimChangeState(JackAction.StateEnum.DieQTE, 1f);
  404. }
  405. public bool UseAtk5;
  406. private bool _first75 = true;
  407. private bool _first65 = true;
  408. private bool _first55 = true;
  409. private bool _first35 = true;
  410. private bool _first25 = true;
  411. private static readonly string[] AttackSta = new string[]
  412. {
  413. "Atk1",
  414. "Atk2",
  415. "Atk3",
  416. "Atk4",
  417. "Atk5Aim",
  418. "Atk5End",
  419. "Atk5Ready",
  420. "Atk5Shoot"
  421. };
  422. public static readonly string[] NormalSta = new string[]
  423. {
  424. "Idle",
  425. "Move"
  426. };
  427. public static readonly string[] HurtSta = new string[]
  428. {
  429. "Fall",
  430. "FallHitGround",
  431. "FlyToFall",
  432. "GetUp",
  433. "Hit1",
  434. "Hit2",
  435. "HitQTE",
  436. "HitToFly1",
  437. "HitToFly2"
  438. };
  439. public static readonly string[] QTESta = new string[]
  440. {
  441. "DieQTE",
  442. "HitQTE"
  443. };
  444. private readonly float _airFric = 8f;
  445. public enum StateEnum
  446. {
  447. Idle,
  448. Atk1,
  449. Atk2,
  450. Atk3,
  451. Atk4,
  452. Atk5Aim,
  453. Atk5End,
  454. Atk5Ready,
  455. Atk5Shoot,
  456. DieQTE,
  457. Fall,
  458. FallHitGround,
  459. FlyToFall,
  460. GetUp,
  461. Hit1,
  462. Hit2,
  463. HitQTE,
  464. HitToFly1,
  465. HitToFly2,
  466. IdleToWeakMod,
  467. Jump,
  468. Move,
  469. MoveAway,
  470. WeakMod,
  471. WeakModToIdle
  472. }
  473. }