JumperAction.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. using System;
  2. using DatabaseModel;
  3. using ExtensionMethods;
  4. using UnityEngine;
  5. public class JumperAction : EnemyBaseAction
  6. {
  7. protected override void Start()
  8. {
  9. this.stateMachine.AddStates(typeof(JumperAction.StateEnum));
  10. this.stateMachine.OnEnter += this.OnMyStateEnter;
  11. this.stateMachine.OnTransfer += this.OnStateTransfer;
  12. base.AnimChangeState(JumperAction.StateEnum.Ready, 1f);
  13. }
  14. private void FixedUpdate()
  15. {
  16. if (this.stateMachine.currentState == "FlyToFall")
  17. {
  18. Vector2 currentSpeed = this.eAttr.timeController.GetCurrentSpeed();
  19. float f = currentSpeed.x;
  20. f = Mathf.Clamp(Mathf.Abs(f) - this.airFric * Time.fixedDeltaTime, 0f, float.MaxValue) * Mathf.Sign(f);
  21. currentSpeed.x = Mathf.Clamp(Mathf.Abs(f) - this.airFric * Time.fixedDeltaTime, 0f, float.PositiveInfinity) * Mathf.Sign(f);
  22. this.eAttr.timeController.SetSpeed(currentSpeed);
  23. }
  24. }
  25. protected override void Update()
  26. {
  27. base.Update();
  28. if (this.catchFollow)
  29. {
  30. base.player.position = new Vector3(this.catachPos.position.x, this.catachPos.position.y, base.player.position.z);
  31. Vector3 eulerAngles = this.catachPos.localRotation.eulerAngles;
  32. base.player.localRotation = Quaternion.Euler(new Vector3(eulerAngles.x, eulerAngles.y, (float)this.eAttr.faceDir * -eulerAngles.z));
  33. }
  34. if (this.IsInDefenceState() && Time.time - this.startDefenceTime >= this.defenceTime)
  35. {
  36. base.AnimChangeState(JumperAction.StateEnum.DefenseToIdle, 1f);
  37. }
  38. if (this.stateMachine.currentState == "FlyToFall")
  39. {
  40. Vector2 currentSpeed = this.eAttr.timeController.GetCurrentSpeed();
  41. if (currentSpeed.y > 0f)
  42. {
  43. currentSpeed.y = 0f;
  44. this.eAttr.timeController.SetSpeed(currentSpeed);
  45. }
  46. }
  47. }
  48. private void OnMyStateEnter(object sender, StateMachine.StateEventArgs args)
  49. {
  50. string state = args.state;
  51. switch (state)
  52. {
  53. case "Atk1":
  54. case "Atk2":
  55. case "Atk3":
  56. case "Atk3Fail":
  57. case "Atk3Success":
  58. case "Atk4":
  59. case "Atk5":
  60. case "Atk5_1":
  61. case "Atk5_2":
  62. this.spineAnim.Play(args.state, false, true, this.eAttr.atkSpeed);
  63. break;
  64. case "Die":
  65. case "AirDie":
  66. case "AirDiePre":
  67. case "FlyToFall":
  68. case "GetUp":
  69. case "Hit1":
  70. case "Hit2":
  71. case "HitGround":
  72. case "HitToFly":
  73. case "Execute":
  74. case "ExecuteDie":
  75. case "Die2":
  76. case "Die3":
  77. case "DefenseToIdle":
  78. this.spineAnim.Play(args.state, false, true, 1f);
  79. break;
  80. case "Move":
  81. case "Ready":
  82. case "Fall":
  83. case "DieFall":
  84. case "HitToFly2":
  85. case "WeakMod":
  86. case "Defense":
  87. case "HitFall":
  88. this.spineAnim.Play(args.state, true, false, 1f);
  89. break;
  90. }
  91. }
  92. private void OnStateTransfer(object sender, StateMachine.TransferEventArgs args)
  93. {
  94. base.GetComponent<EnemyBaseHurt>().StopFollowLeftHand();
  95. if (!args.nextState.IsInArray(JumperAction.AttackSta))
  96. {
  97. if (this.catchFollow)
  98. {
  99. this.catchResult = true;
  100. base.GetComponent<JumperAnimListener>().Atk3Success();
  101. }
  102. else
  103. {
  104. this.catchResult = false;
  105. }
  106. }
  107. if (this.ExitAtkSta(args.lastState, args.nextState))
  108. {
  109. this.eAttr.paBody = false;
  110. this.atkBox.localScale = Vector3.zero;
  111. }
  112. if (this.EnterAtkSta(args.lastState, args.nextState))
  113. {
  114. base.GetComponentInChildren<EnemyAtk>().atkId = Incrementor.GetNextId();
  115. }
  116. if (args.nextState == "FlyToFall")
  117. {
  118. Vector2 currentSpeed = this.eAttr.timeController.GetCurrentSpeed();
  119. currentSpeed.y = 0f;
  120. this.eAttr.timeController.SetSpeed(currentSpeed);
  121. this.eAttr.timeController.SetGravity(0f);
  122. }
  123. if (args.lastState == "FlyToFall" && !this.eAttr.willBeExecute)
  124. {
  125. this.eAttr.timeController.SetGravity(1f);
  126. }
  127. }
  128. public void CatchSuccess()
  129. {
  130. GameObject prefab = CameraEffectProxyPrefabData.GetPrefab(14);
  131. UnityEngine.Object.Instantiate<GameObject>(prefab, base.player.position, Quaternion.identity);
  132. this.catchFollow = true;
  133. }
  134. public override bool IsInNormalState()
  135. {
  136. return this.stateMachine.currentState.IsInArray(JumperAction.NormalSta) && base.IsInNormalState();
  137. }
  138. public override bool IsInDeadState(string state)
  139. {
  140. return state.IsInArray(JumperAction.DieSta);
  141. }
  142. public override void AnimReady()
  143. {
  144. base.AnimChangeState(JumperAction.StateEnum.Ready, 1f);
  145. }
  146. public override void AnimMove()
  147. {
  148. base.AnimChangeState(JumperAction.StateEnum.Move, 1f);
  149. }
  150. public override bool IsInAttackState()
  151. {
  152. return this.stateMachine.currentState.IsInArray(JumperAction.AttackSta);
  153. }
  154. protected override bool EnterAtkSta(string lastState, string nextState)
  155. {
  156. return !lastState.IsInArray(JumperAction.AttackSta) && nextState.IsInArray(JumperAction.AttackSta);
  157. }
  158. protected override bool ExitAtkSta(string lastState, string nextState)
  159. {
  160. return lastState.IsInArray(JumperAction.AttackSta) && !nextState.IsInArray(JumperAction.AttackSta);
  161. }
  162. public override void Attack1(int dir)
  163. {
  164. if (this.eAttr.isDead)
  165. {
  166. return;
  167. }
  168. if (!this.IsInNormalState())
  169. {
  170. return;
  171. }
  172. base.ChangeFace(dir);
  173. base.AnimChangeState(JumperAction.StateEnum.Atk1, 1f);
  174. }
  175. public override void Attack2(int dir)
  176. {
  177. if (this.eAttr.isDead)
  178. {
  179. return;
  180. }
  181. if (!this.IsInNormalState())
  182. {
  183. return;
  184. }
  185. base.ChangeFace(dir);
  186. base.AnimChangeState(JumperAction.StateEnum.Atk2, 1f);
  187. }
  188. public override void Attack3(int dir)
  189. {
  190. if (this.eAttr.isDead)
  191. {
  192. return;
  193. }
  194. if (!this.IsInNormalState())
  195. {
  196. return;
  197. }
  198. base.ChangeFace(dir);
  199. base.AnimChangeState(JumperAction.StateEnum.Atk3, 1f);
  200. }
  201. public override void Attack4(int dir)
  202. {
  203. if (this.eAttr.isDead)
  204. {
  205. return;
  206. }
  207. if (!this.IsInNormalState())
  208. {
  209. return;
  210. }
  211. base.ChangeFace(dir);
  212. base.AnimChangeState(JumperAction.StateEnum.Atk4, 1f);
  213. }
  214. public override void Attack5(int dir)
  215. {
  216. if (this.eAttr.isDead)
  217. {
  218. return;
  219. }
  220. if (!this.IsInNormalState())
  221. {
  222. return;
  223. }
  224. base.ChangeFace(dir);
  225. base.AnimChangeState(JumperAction.StateEnum.Atk5_1, 1f);
  226. }
  227. public override void CounterAttack(int dir)
  228. {
  229. if (this.eAttr.isDead)
  230. {
  231. return;
  232. }
  233. if (this.IsInAttackState())
  234. {
  235. return;
  236. }
  237. R.Effect.Generate(128, base.transform, Vector3.up * 1.5f, Vector3.zero, default(Vector3), true);
  238. base.ChangeFace(dir);
  239. base.AnimChangeState(JumperAction.StateEnum.Atk3, 1f);
  240. }
  241. public override void Defence()
  242. {
  243. if (this.eAttr.isDead)
  244. {
  245. return;
  246. }
  247. if (this.IsInDefenceState())
  248. {
  249. return;
  250. }
  251. if (this.IsInWeakSta())
  252. {
  253. return;
  254. }
  255. if (!this.eAttr.isOnGround)
  256. {
  257. return;
  258. }
  259. base.Defence();
  260. this.eAttr.timeController.SetSpeed(Vector2.zero);
  261. this.startDefenceTime = Time.time;
  262. this.defenceTime = UnityEngine.Random.Range(2f, 4f);
  263. base.AnimChangeState(JumperAction.StateEnum.Defense, 1f);
  264. }
  265. public override void DefenceSuccess()
  266. {
  267. if (this.eAttr.isDead)
  268. {
  269. return;
  270. }
  271. if (!this.eAttr.isOnGround)
  272. {
  273. return;
  274. }
  275. if (this.IsInWeakSta())
  276. {
  277. return;
  278. }
  279. R.Audio.PlayEffect(406, new Vector3?(base.transform.position));
  280. base.AnimChangeState(JumperAction.StateEnum.Defense, 1f);
  281. }
  282. public override bool IsInWeakSta()
  283. {
  284. return this.eAttr.inWeakState;
  285. }
  286. public override bool IsInDefenceState()
  287. {
  288. return this.stateMachine.currentState.IsInArray(JumperAction.DefenceSta);
  289. }
  290. [SerializeField]
  291. private Transform catachPos;
  292. public bool catchFollow;
  293. public bool catchResult;
  294. private static readonly string[] NormalSta = new string[]
  295. {
  296. "Atk3Fail",
  297. "Move",
  298. "Ready"
  299. };
  300. public static readonly string[] AttackSta = new string[]
  301. {
  302. "Atk1",
  303. "Atk2",
  304. "Atk3",
  305. "Atk4",
  306. "Atk5",
  307. "Atk3Success",
  308. "Atk3Fail",
  309. "Atk5_1",
  310. "Atk5_2"
  311. };
  312. public static readonly string[] HurtSta = new string[]
  313. {
  314. "FlyToFall",
  315. "GetUp",
  316. "Hit1",
  317. "Hit2",
  318. "Fall",
  319. "HitGround",
  320. "HitToFly",
  321. "HitToFly2",
  322. "HitFall"
  323. };
  324. private static readonly string[] DieSta = new string[]
  325. {
  326. "Die",
  327. "AirDiePre",
  328. "DieFall",
  329. "AirDie",
  330. "ExecuteDie",
  331. "Die2",
  332. "Die3"
  333. };
  334. private static readonly string[] DefenceSta = new string[]
  335. {
  336. "Defense",
  337. "DefenseHit"
  338. };
  339. public float airFric = 8f;
  340. public enum StateEnum
  341. {
  342. Atk1,
  343. Atk2,
  344. Atk3,
  345. Atk4,
  346. Atk5,
  347. Atk3Fail,
  348. Atk3Success,
  349. Die,
  350. FlyToFall,
  351. GetUp,
  352. Hit1,
  353. Hit2,
  354. HitGround,
  355. HitToFly,
  356. Move,
  357. Ready,
  358. Fall,
  359. HitToFly2,
  360. AirDiePre,
  361. DieFall,
  362. AirDie,
  363. WeakMod,
  364. Execute,
  365. ExecuteDie,
  366. Atk5_1,
  367. Atk5_2,
  368. Die2,
  369. Die3,
  370. Defense,
  371. DefenseHit,
  372. DefenseToIdle,
  373. HitFall
  374. }
  375. }