DahalFAction.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. using System;
  2. using ExtensionMethods;
  3. using UnityEngine;
  4. public class DahalFAction : EnemyBaseAction
  5. {
  6. protected override void Awake()
  7. {
  8. base.Awake();
  9. this._enemyAtk = base.GetComponentInChildren<EnemyAtk>();
  10. }
  11. protected override void Start()
  12. {
  13. this.stateMachine.AddStates(typeof(DahalFAction.StateEnum));
  14. this.stateMachine.OnEnter += this.OnMyStateEnter;
  15. this.stateMachine.OnTransfer += this.OnStateTransfer;
  16. base.AnimChangeState(DahalFAction.StateEnum.Idle, 1f);
  17. }
  18. private void FixedUpdate()
  19. {
  20. if (this.stateMachine.currentState == "HitToFly3")
  21. {
  22. Vector2 currentSpeed = this.eAttr.timeController.GetCurrentSpeed();
  23. float f = currentSpeed.x;
  24. f = Mathf.Clamp(Mathf.Abs(f) - this._airFric * Time.fixedDeltaTime, 0f, float.MaxValue) * Mathf.Sign(f);
  25. currentSpeed.x = Mathf.Clamp(Mathf.Abs(f) - this._airFric * Time.fixedDeltaTime, 0f, float.PositiveInfinity) * Mathf.Sign(f);
  26. this.eAttr.timeController.SetSpeed(currentSpeed);
  27. }
  28. }
  29. protected override void Update()
  30. {
  31. base.Update();
  32. if (this.stateMachine.currentState == "Idle")
  33. {
  34. base.FaceToPlayer();
  35. }
  36. if (this.stateMachine.currentState == "HitToFly3")
  37. {
  38. Vector2 currentSpeed = this.eAttr.timeController.GetCurrentSpeed();
  39. if (currentSpeed.y > 0f)
  40. {
  41. currentSpeed.y = 0f;
  42. this.eAttr.timeController.SetSpeed(currentSpeed);
  43. }
  44. }
  45. if (this.stateMachine.currentState == "Atk10_2")
  46. {
  47. this.eAttr.timeController.SetSpeed(Vector2.zero);
  48. if (base.transform.position.y - this._atk102StartPos.y >= 4f)
  49. {
  50. base.FaceToPlayer();
  51. base.AnimChangeState(DahalFAction.StateEnum.Atk10_3, 1f);
  52. }
  53. }
  54. this.UpdateHp();
  55. }
  56. private void UpdateHp()
  57. {
  58. switch (R.GameData.Difficulty)
  59. {
  60. case 0:
  61. case 1:
  62. this.NormalModeHp();
  63. break;
  64. case 2:
  65. case 3:
  66. this.HardModeHp();
  67. break;
  68. }
  69. }
  70. private void NormalModeHp()
  71. {
  72. if (this.eAttr.currentHp < this.eAttr.maxHp * 60 / 100 && this._first60)
  73. {
  74. this._first60 = false;
  75. this.UseAtk2 = true;
  76. }
  77. if (this.eAttr.currentHp >= this.eAttr.maxHp * 35 / 100 || !this._first30)
  78. {
  79. return;
  80. }
  81. this._first30 = false;
  82. this.UseAtk2 = true;
  83. }
  84. private void HardModeHp()
  85. {
  86. if (this.eAttr.currentHp < this.eAttr.maxHp * 75 / 100 && this._first75)
  87. {
  88. this._first75 = false;
  89. this.UseAtk2 = true;
  90. }
  91. if (this.eAttr.currentHp < this.eAttr.maxHp * 50 / 100 && this._first50)
  92. {
  93. this._first50 = false;
  94. this.UseAtk2 = true;
  95. }
  96. if (this.eAttr.currentHp >= this.eAttr.maxHp * 25 / 100 || !this._first25)
  97. {
  98. return;
  99. }
  100. this._first25 = false;
  101. this.UseAtk2 = true;
  102. }
  103. private void OnMyStateEnter(object sender, StateMachine.StateEventArgs args)
  104. {
  105. string state = args.state;
  106. switch (state)
  107. {
  108. case "AirPush":
  109. case "Atk10_2":
  110. case "Atk2":
  111. case "Atk6":
  112. this.spineAnim.Play(args.state, true, false, this.eAttr.atkSpeed);
  113. break;
  114. case "Atk1End1":
  115. case "Atk1Ready1":
  116. case "Atk1_1":
  117. case "Atk1_2":
  118. case "Atk1_3":
  119. case "Atk7":
  120. case "Atk72":
  121. case "Atk9":
  122. case "AirStandUp":
  123. case "AirPushEnd":
  124. case "Atk10_1":
  125. case "Atk10_3":
  126. case "Atk1Move1":
  127. case "Atk1Move2":
  128. case "Atk1Move3":
  129. case "Atk2Ready":
  130. case "Atk2End":
  131. case "Atk6Ready":
  132. case "Atk6End":
  133. this.spineAnim.Play(args.state, false, true, this.eAttr.atkSpeed);
  134. break;
  135. case "QTEDie2":
  136. case "Hit1":
  137. case "HitToFly1":
  138. case "HitToFly2":
  139. case "HitToFly3":
  140. case "GetUp":
  141. case "HitGround":
  142. case "GroundDodge":
  143. case "QTEHit":
  144. this.spineAnim.Play(args.state, false, true, 1f);
  145. break;
  146. case "Idle":
  147. case "Move":
  148. case "WeakMod":
  149. case "Fall":
  150. case "Rush":
  151. this.spineAnim.Play(args.state, true, false, 1f);
  152. break;
  153. }
  154. }
  155. private void OnStateTransfer(object sender, StateMachine.TransferEventArgs args)
  156. {
  157. base.GetComponent<EnemyBaseHurt>().StopFollowLeftHand();
  158. if (this.ExitAtkSta(args.lastState, args.nextState))
  159. {
  160. this.eAttr.paBody = false;
  161. this.atkBox.localScale = Vector3.zero;
  162. DahalFAnim component = base.GetComponent<DahalFAnim>();
  163. component.StopShoot();
  164. component.StopATK6Effect();
  165. }
  166. if (this.EnterAtkSta(args.lastState, args.nextState))
  167. {
  168. this._enemyAtk.atkId = Incrementor.GetNextId();
  169. }
  170. if (args.nextState == "HitToFly3")
  171. {
  172. Vector2 currentSpeed = this.eAttr.timeController.GetCurrentSpeed();
  173. currentSpeed.y = 0f;
  174. this.eAttr.timeController.SetSpeed(currentSpeed);
  175. this.eAttr.timeController.SetGravity(0f);
  176. }
  177. if (args.lastState == "HitToFly3" && !this.eAttr.willBeExecute)
  178. {
  179. this.eAttr.timeController.SetGravity(1f);
  180. }
  181. if (args.nextState == "Atk10_2")
  182. {
  183. this._atk102StartPos = base.transform.position;
  184. }
  185. if (args.nextState == "Atk1Ready1" || args.nextState == "AirStandUp" || args.nextState == "Atk92")
  186. {
  187. this.eAttr.timeController.SetSpeed(Vector2.zero);
  188. this.eAttr.timeController.SetGravity(0f);
  189. }
  190. if (args.nextState == "Fall")
  191. {
  192. this.eAttr.timeController.SetGravity(1f);
  193. }
  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(DahalFAction.StateEnum.Atk1Ready1, 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. this.Atk2HitWallTimes = 0;
  220. base.AnimChangeState(DahalFAction.StateEnum.Atk2Ready, 1f);
  221. }
  222. public override void Attack6(int dir)
  223. {
  224. if (this.eAttr.isDead)
  225. {
  226. return;
  227. }
  228. if (!this.IsInNormalState())
  229. {
  230. return;
  231. }
  232. base.ChangeFace(dir);
  233. this.Atk6HitWall = false;
  234. base.AnimChangeState(DahalFAction.StateEnum.Atk6Ready, 1f);
  235. }
  236. public override void Attack7(int dir)
  237. {
  238. if (this.eAttr.isDead)
  239. {
  240. return;
  241. }
  242. if (!this.IsInNormalState())
  243. {
  244. return;
  245. }
  246. base.ChangeFace(dir);
  247. base.AnimChangeState(DahalFAction.StateEnum.Atk7, 1f);
  248. }
  249. public override void Attack9(int dir)
  250. {
  251. if (this.eAttr.isDead)
  252. {
  253. return;
  254. }
  255. if (!this.IsInNormalState())
  256. {
  257. return;
  258. }
  259. base.AnimChangeState(DahalFAction.StateEnum.Atk9, 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. this.eAttr.timeController.SetSpeed(Vector2.zero);
  272. this.eAttr.timeController.SetGravity(0f);
  273. base.AnimChangeState(DahalFAction.StateEnum.Atk10_1, 1f);
  274. }
  275. public override void SideStep()
  276. {
  277. if (this.eAttr.isDead)
  278. {
  279. return;
  280. }
  281. if (this.IsInSideStepState())
  282. {
  283. return;
  284. }
  285. if (!this.eAttr.isOnGround)
  286. {
  287. return;
  288. }
  289. if (this.IsInWeakSta())
  290. {
  291. return;
  292. }
  293. base.SideStep();
  294. base.AnimChangeState(DahalFAction.StateEnum.GroundDodge, 1f);
  295. }
  296. public override void CounterAttack(int dir)
  297. {
  298. if (this.eAttr.isDead)
  299. {
  300. return;
  301. }
  302. if (this.IsInAttackState())
  303. {
  304. return;
  305. }
  306. if (base.GetComponent<DahalFHurt>().currentPhase != 1)
  307. {
  308. return;
  309. }
  310. if (this.stateMachine.currentState.IsInArray(DahalFAction.QTESta) || this.IsInWeakSta())
  311. {
  312. return;
  313. }
  314. R.Effect.Generate(128, base.transform, Vector3.up * 4f, new Vector3(0f, 0f, 0f), default(Vector3), true);
  315. base.ChangeFace(dir);
  316. this.eAttr.paBody = true;
  317. SingletonMono<WorldTime>.Instance.TimeSlowByFrameOn60Fps(60, 0.5f);
  318. base.AnimChangeState(DahalFAction.StateEnum.AirStandUp, 1f);
  319. }
  320. public override void Idle1()
  321. {
  322. if (!this.IsInNormalState())
  323. {
  324. return;
  325. }
  326. base.AnimChangeState(DahalFAction.StateEnum.Idle, 1f);
  327. }
  328. public override bool IsInNormalState()
  329. {
  330. return this.stateMachine.currentState.IsInArray(DahalFAction.NormalSta) && base.IsInNormalState();
  331. }
  332. public override bool IsInDeadState(string state)
  333. {
  334. return state == "QTEDie2";
  335. }
  336. public override void AnimReady()
  337. {
  338. base.AnimChangeState(DahalFAction.StateEnum.Idle, 1f);
  339. }
  340. public override void AnimExecute()
  341. {
  342. base.AnimExecute();
  343. int dir = (base.player.transform.localScale.x >= 0f) ? 1 : -1;
  344. base.ChangeFace(dir);
  345. base.ExitWeakState(true);
  346. base.WeakEffectDisappear("RollEnd");
  347. R.Camera.Controller.CameraZoom(base.transform.position + Vector3.up * 3f, 0.166666672f, 2f);
  348. R.Camera.Controller.CameraShake(0.2f, 0.2f, CameraController.ShakeTypeEnum.Rect, false);
  349. this.eAttr.isFlyingUp = false;
  350. this.eAttr.checkHitGround = false;
  351. base.AnimChangeState(DahalFAction.StateEnum.QTEDie2, 1f);
  352. }
  353. public override void AnimQTEHurt()
  354. {
  355. base.AnimQTEHurt();
  356. int dir = (base.player.transform.localScale.x >= 0f) ? 1 : -1;
  357. base.ChangeFace(dir);
  358. base.ExitWeakState(true);
  359. this.eAttr.isFlyingUp = false;
  360. this.eAttr.checkHitGround = false;
  361. R.Camera.Controller.CameraZoom(base.transform.position + Vector3.up * 3f, 0.166666672f, 2f);
  362. R.Camera.Controller.CameraShake(0.2f, 0.2f, CameraController.ShakeTypeEnum.Rect, false);
  363. base.AnimChangeState(DahalFAction.StateEnum.QTEHit, 1f);
  364. Transform transform = R.Effect.Generate(178, null, base.transform.position, default(Vector3), default(Vector3), true);
  365. transform.localScale = base.transform.localScale;
  366. }
  367. public bool DahyalAutoMove(int type)
  368. {
  369. if (this.isAutoMoveing)
  370. {
  371. return true;
  372. }
  373. bool flag = this.IsInNormalState();
  374. if (flag)
  375. {
  376. this.isAutoMoveing = true;
  377. if (type != 1)
  378. {
  379. if (type == 2)
  380. {
  381. this.AnimMoveQuick();
  382. }
  383. }
  384. else
  385. {
  386. this.AnimMove();
  387. }
  388. return true;
  389. }
  390. return false;
  391. }
  392. public override void AnimMove()
  393. {
  394. base.AnimChangeState(DahalFAction.StateEnum.Move, 1f);
  395. }
  396. private void AnimMoveQuick()
  397. {
  398. base.AnimChangeState(DahalFAction.StateEnum.Rush, 1f);
  399. }
  400. public override bool IsInSideStepState()
  401. {
  402. return this.stateMachine.currentState.IsInArray(DahalFAction.SideStepSta);
  403. }
  404. public override bool IsInWeakSta()
  405. {
  406. return this.eAttr.inWeakState;
  407. }
  408. public override bool IsInAttackState()
  409. {
  410. return this.stateMachine.currentState.IsInArray(DahalFAction.AttackSta);
  411. }
  412. protected override bool EnterAtkSta(string lastState, string nextState)
  413. {
  414. return nextState.IsInArray(DahalFAction.AttackSta) && !lastState.IsInArray(DahalFAction.AttackSta);
  415. }
  416. protected override bool ExitAtkSta(string lastState, string nextState)
  417. {
  418. return !nextState.IsInArray(DahalFAction.AttackSta) && lastState.IsInArray(DahalFAction.AttackSta);
  419. }
  420. private Vector3 _atk102StartPos;
  421. private readonly float _airFric = 8f;
  422. public bool UseAtk2;
  423. private bool _first60 = true;
  424. private bool _first30 = true;
  425. private bool _first75 = true;
  426. private bool _first50 = true;
  427. private bool _first25 = true;
  428. public bool Atk6HitWall;
  429. public int Atk2HitWallTimes;
  430. private static readonly string[] NormalSta = new string[]
  431. {
  432. "Idle",
  433. "Move",
  434. "Rush"
  435. };
  436. public static readonly string[] AttackSta = new string[]
  437. {
  438. "Atk1_1",
  439. "Atk1_2",
  440. "Atk1_3",
  441. "Atk1Move1",
  442. "Atk1Move2",
  443. "Atk1Move3",
  444. "Atk1End1",
  445. "Atk1Ready1",
  446. "Atk2",
  447. "Atk2End",
  448. "Atk2Ready",
  449. "Atk6Ready",
  450. "Atk6",
  451. "Atk6End",
  452. "Atk7",
  453. "Atk72",
  454. "Atk9",
  455. "AirPush",
  456. "AirPushEnd",
  457. "AirStandUp",
  458. "Atk10_1",
  459. "Atk10_2",
  460. "Atk10_3"
  461. };
  462. private static readonly string[] SideStepSta = new string[]
  463. {
  464. "GroundDodge",
  465. "Rush"
  466. };
  467. private static readonly string[] QTESta = new string[]
  468. {
  469. "QTEDie2",
  470. "QTEHit"
  471. };
  472. private EnemyAtk _enemyAtk;
  473. public enum StateEnum
  474. {
  475. Atk1_1,
  476. Atk1_2,
  477. Atk1_3,
  478. Atk1Move1,
  479. Atk1Move2,
  480. Atk1Move3,
  481. Atk12,
  482. Atk13,
  483. Atk1End1,
  484. Atk1End2,
  485. Atk1Ready1,
  486. Atk1Ready2,
  487. Atk1Ready3,
  488. Atk7,
  489. Atk72,
  490. Atk9,
  491. Atk92,
  492. AirPush,
  493. AirPushEnd,
  494. AirStandUp,
  495. Atk10_1,
  496. Atk10_2,
  497. Atk10_3,
  498. Idle,
  499. Move,
  500. Hit1,
  501. WeakMod,
  502. HitToFly1,
  503. HitToFly2,
  504. HitToFly3,
  505. Fall,
  506. HitGround,
  507. GetUp,
  508. GroundDodge,
  509. Rush,
  510. QTEDie2,
  511. QTEHit,
  512. Atk2Ready,
  513. Atk2,
  514. Atk2End,
  515. Atk6Ready,
  516. Atk6,
  517. Atk6End
  518. }
  519. }