SpiderAction.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. using System;
  2. using System.Collections.Generic;
  3. using ExtensionMethods;
  4. using UnityEngine;
  5. public class SpiderAction : EnemyBaseAction
  6. {
  7. static Dictionary<string, int> _003C_003Ef__switch_0024map13;
  8. protected override void Start()
  9. {
  10. this.stateMachine.AddStates(typeof(SpiderAction.StateEnum));
  11. this.stateMachine.OnEnter += this.OnMyStateEnter;
  12. this.stateMachine.OnTransfer += this.OnStateTransfer;
  13. base.AnimChangeState(SpiderAction.StateEnum.Show, 1f);
  14. }
  15. private void FixedUpdate()
  16. {
  17. if (this.stateMachine.currentState == "FlyToFall")
  18. {
  19. Vector2 currentSpeed = this.eAttr.timeController.GetCurrentSpeed();
  20. float f = currentSpeed.x;
  21. f = Mathf.Clamp(Mathf.Abs(f) - this.airFric * Time.fixedDeltaTime, 0f, float.MaxValue) * Mathf.Sign(f);
  22. currentSpeed.x = Mathf.Clamp(Mathf.Abs(f) - this.airFric * Time.fixedDeltaTime, 0f, float.PositiveInfinity) * Mathf.Sign(f);
  23. this.eAttr.timeController.SetSpeed(currentSpeed);
  24. }
  25. }
  26. protected override void Update()
  27. {
  28. base.Update();
  29. if (this.stateMachine.currentState == "FlyToFall")
  30. {
  31. Vector2 currentSpeed = this.eAttr.timeController.GetCurrentSpeed();
  32. if (currentSpeed.y > 0f)
  33. {
  34. currentSpeed.y = 0f;
  35. this.eAttr.timeController.SetSpeed(currentSpeed);
  36. }
  37. }
  38. }
  39. private void OnStateTransfer(object sender, StateMachine.TransferEventArgs args)
  40. {
  41. base.GetComponent<EnemyBaseHurt>().StopFollowLeftHand();
  42. if (this.ExitAtkSta(args.lastState, args.nextState))
  43. {
  44. this.eAttr.paBody = false;
  45. this.atkBox.localScale = Vector3.zero;
  46. }
  47. if (args.nextState == "FlyToFall")
  48. {
  49. Vector2 currentSpeed = this.eAttr.timeController.GetCurrentSpeed();
  50. currentSpeed.y = 0f;
  51. this.eAttr.timeController.SetSpeed(currentSpeed);
  52. this.eAttr.timeController.SetGravity(0f);
  53. }
  54. if (args.lastState == "FlyToFall" && !this.eAttr.willBeExecute)
  55. {
  56. this.eAttr.timeController.SetGravity(1f);
  57. }
  58. if (args.lastState == "JumpForwad" || args.lastState == "JumpBack" || args.lastState == "Atk2")
  59. {
  60. this.eAttr.timeController.SetGravity(1f);
  61. }
  62. }
  63. private void OnMyStateEnter(object sender, StateMachine.StateEventArgs args)
  64. {
  65. string state = args.state;
  66. if (state != null)
  67. {
  68. if (SpiderAction._003C_003Ef__switch_0024map13 == null)
  69. {
  70. SpiderAction._003C_003Ef__switch_0024map13 = new Dictionary<string, int>(21)
  71. {
  72. {
  73. "Atk1",
  74. 0
  75. },
  76. {
  77. "Atk2",
  78. 0
  79. },
  80. {
  81. "Die",
  82. 0
  83. },
  84. {
  85. "Execute",
  86. 0
  87. },
  88. {
  89. "FallHitGround",
  90. 0
  91. },
  92. {
  93. "FlyToFall",
  94. 0
  95. },
  96. {
  97. "GetUp",
  98. 0
  99. },
  100. {
  101. "Hit1",
  102. 0
  103. },
  104. {
  105. "HitToFly1",
  106. 0
  107. },
  108. {
  109. "JumpBack",
  110. 0
  111. },
  112. {
  113. "JumpForward",
  114. 0
  115. },
  116. {
  117. "Null",
  118. 0
  119. },
  120. {
  121. "Show",
  122. 0
  123. },
  124. {
  125. "AirDieFlyToFall",
  126. 0
  127. },
  128. {
  129. "AirDieHitGround",
  130. 0
  131. },
  132. {
  133. "Fall",
  134. 1
  135. },
  136. {
  137. "HitToFly2",
  138. 1
  139. },
  140. {
  141. "Idle",
  142. 1
  143. },
  144. {
  145. "Move",
  146. 1
  147. },
  148. {
  149. "HitFall",
  150. 1
  151. },
  152. {
  153. "AirDieFall",
  154. 1
  155. }
  156. };
  157. }
  158. int num;
  159. if (SpiderAction._003C_003Ef__switch_0024map13.TryGetValue(state, out num))
  160. {
  161. if (num != 0)
  162. {
  163. if (num == 1)
  164. {
  165. this.spineAnim.Play(args.state, true, false, 1f);
  166. }
  167. }
  168. else
  169. {
  170. this.spineAnim.Play(args.state, false, true, 1f);
  171. }
  172. }
  173. }
  174. }
  175. public override void Attack1(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(SpiderAction.StateEnum.Atk1, 1f);
  187. }
  188. public override void Attack2(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. this.eAttr.timeController.SetGravity(0f);
  200. base.AnimChangeState(SpiderAction.StateEnum.Atk2, 1f);
  201. }
  202. public void Jump(bool back)
  203. {
  204. if (this.eAttr.isDead)
  205. {
  206. return;
  207. }
  208. if (!this.IsInNormalState())
  209. {
  210. return;
  211. }
  212. base.FaceToPlayer();
  213. this.eAttr.timeController.SetGravity(0f);
  214. SpiderAction.StateEnum stateEnum = (!back) ? SpiderAction.StateEnum.JumpForward : SpiderAction.StateEnum.JumpBack;
  215. base.AnimChangeState(stateEnum, 1f);
  216. }
  217. public override void AnimMove()
  218. {
  219. base.AnimChangeState(SpiderAction.StateEnum.Move, 1f);
  220. }
  221. public override void AnimReady()
  222. {
  223. base.AnimChangeState(SpiderAction.StateEnum.Idle, 1f);
  224. }
  225. public override bool IsInNormalState()
  226. {
  227. return this.stateMachine.currentState.IsInArray(SpiderAction.NormalSta) && base.IsInNormalState();
  228. }
  229. public override bool IsInAttackState()
  230. {
  231. return this.stateMachine.currentState.IsInArray(SpiderAction.AttackSta);
  232. }
  233. public override bool IsInDeadState(string state)
  234. {
  235. return state.IsInArray(SpiderAction.DieSta);
  236. }
  237. public override bool IsInWeakSta()
  238. {
  239. return this.eAttr.inWeakState;
  240. }
  241. protected override bool EnterAtkSta(string lastState, string nextState)
  242. {
  243. return nextState.IsInArray(SpiderAction.AttackSta) && !lastState.IsInArray(SpiderAction.AttackSta);
  244. }
  245. protected override bool ExitAtkSta(string lastState, string nextState)
  246. {
  247. return !nextState.IsInArray(SpiderAction.AttackSta) && lastState.IsInArray(SpiderAction.AttackSta);
  248. }
  249. public override bool IsInIdle()
  250. {
  251. return this.stateMachine.currentState == "Idle";
  252. }
  253. public float airFric = 8f;
  254. public static readonly string[] NormalSta = new string[]
  255. {
  256. "Idle",
  257. "Move"
  258. };
  259. public static readonly string[] AttackSta = new string[]
  260. {
  261. "Atk1",
  262. "Atk2"
  263. };
  264. public static readonly string[] HurtSta = new string[]
  265. {
  266. "Fall",
  267. "FallHitGround",
  268. "FlyToFall",
  269. "Hit1",
  270. "HitToFly1",
  271. "HitToFly2",
  272. "HitFall"
  273. };
  274. public static readonly string[] JumpSta = new string[]
  275. {
  276. "JumpForward",
  277. "JumpBack"
  278. };
  279. public static readonly string[] DieSta = new string[]
  280. {
  281. "Die",
  282. "Null",
  283. "AirDieFlyToFall",
  284. "AirDieFall",
  285. "AirDieHitGround"
  286. };
  287. public enum StateEnum
  288. {
  289. Idle,
  290. Move,
  291. Show,
  292. Atk1,
  293. Atk2,
  294. Die,
  295. Null,
  296. Execute,
  297. Fall,
  298. FallHitGround,
  299. FlyToFall,
  300. GetUp,
  301. Hit1,
  302. HitToFly1,
  303. HitToFly2,
  304. JumpForward,
  305. JumpBack,
  306. HitFall,
  307. AirDieFlyToFall,
  308. AirDieFall,
  309. AirDieHitGround
  310. }
  311. }