BeeAction.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. using System;
  2. using ExtensionMethods;
  3. using GameWorld;
  4. using UnityEngine;
  5. public class BeeAction : EnemyBaseAction
  6. {
  7. protected override void Start()
  8. {
  9. this.stateMachine.AddStates(typeof(BeeAction.StateEnum));
  10. this.stateMachine.OnEnter += this.OnMyStateEnter;
  11. this.stateMachine.OnTransfer += this.OnStateTransfer;
  12. base.AnimChangeState(BeeAction.StateEnum.Idle, 1f);
  13. Vector3 position = base.transform.position;
  14. position.y = LayerManager.YNum.GetGroundHeight(base.gameObject) + UnityEngine.Random.Range(3f, 4f);
  15. base.transform.position = position;
  16. }
  17. protected override void Update()
  18. {
  19. if (this.eAttr.isDead)
  20. {
  21. return;
  22. }
  23. this.eAttr.stiffTime = Mathf.Clamp(this.eAttr.stiffTime - Time.deltaTime, 0f, float.PositiveInfinity);
  24. if (this.QTE)
  25. {
  26. this.QTE.transform.localScale = ((base.transform.localScale.x >= 0f) ? Vector3.one : new Vector3(-1f, 1f, 1f));
  27. }
  28. if (!this.IsInNormalState())
  29. {
  30. this.isAutoMoveing = false;
  31. }
  32. if (this.isAutoMoveing && !SingletonMono<WorldTime>.Instance.IsFrozen)
  33. {
  34. float y = 0f;
  35. float num = Mathf.Abs(this.eAttr.moveSpeed * Time.deltaTime);
  36. if (this.eAttr.iCanFly)
  37. {
  38. y = num * Mathf.Tan(this.moveAngle * 0.0174532924f);
  39. }
  40. Vector3 position = base.transform.position += new Vector3(num * (float)this.eAttr.faceDir, y, 0f);
  41. float groundHeight = LayerManager.YNum.GetGroundHeight(base.gameObject);
  42. position.y = Mathf.Clamp(position.y, groundHeight + this.minFlyHeight, groundHeight + this.maxFlyHeight);
  43. base.transform.position = position;
  44. }
  45. if (this.stateMachine.currentState == "Idle")
  46. {
  47. base.FaceToPlayer();
  48. }
  49. }
  50. private void OnMyStateEnter(object sender, StateMachine.StateEventArgs args)
  51. {
  52. string state = args.state;
  53. switch (state)
  54. {
  55. case "Atk1":
  56. case "Atk1End":
  57. case "Atk1Ready":
  58. case "Atk2":
  59. case "Atk2End":
  60. case "Atk2Ready":
  61. case "Atk3End":
  62. case "Atk3Ready":
  63. case "Atk3_1":
  64. case "Atk3_2":
  65. case "Atk3_3":
  66. this.spineAnim.Play(args.state, false, true, this.eAttr.atkSpeed);
  67. break;
  68. case "Hit":
  69. case "MoveAway":
  70. case "Idle2":
  71. case "Die":
  72. this.spineAnim.Play(args.state, false, true, 1f);
  73. break;
  74. case "Idle":
  75. case "Move":
  76. case "WeakMod":
  77. this.spineAnim.Play(args.state, true, false, 1f);
  78. break;
  79. }
  80. }
  81. private void OnStateTransfer(object sender, StateMachine.TransferEventArgs args)
  82. {
  83. base.GetComponent<EnemyBaseHurt>().StopFollowLeftHand();
  84. if (args.nextState == "Hit")
  85. {
  86. EventManager.PostEvent<GameObject>("DestroyEffect", base.gameObject);
  87. base.GetComponent<BeeAnimListener>().beeLaserHalo.gameObject.SetActive(false);
  88. }
  89. if (this.ExitAtkSta(args.lastState, args.nextState))
  90. {
  91. base.GetComponent<BeeAnimListener>().bone.mode = SkeletonUtilityBone.Mode.Follow;
  92. this.eAttr.paBody = false;
  93. }
  94. }
  95. public override void Attack1(int dir)
  96. {
  97. if (this.eAttr.isDead)
  98. {
  99. return;
  100. }
  101. if (!this.IsInNormalState())
  102. {
  103. return;
  104. }
  105. base.ChangeFace(dir);
  106. base.AnimChangeState(BeeAction.StateEnum.Atk1Ready, 1f);
  107. }
  108. public override void Attack2(int dir)
  109. {
  110. if (this.eAttr.isDead)
  111. {
  112. return;
  113. }
  114. if (!this.IsInNormalState())
  115. {
  116. return;
  117. }
  118. base.ChangeFace(dir);
  119. base.AnimChangeState(BeeAction.StateEnum.Atk2Ready, 1f);
  120. }
  121. public override void Attack3(int dir)
  122. {
  123. if (this.eAttr.isDead)
  124. {
  125. return;
  126. }
  127. if (!this.IsInNormalState())
  128. {
  129. return;
  130. }
  131. base.ChangeFace(dir);
  132. base.AnimChangeState(BeeAction.StateEnum.Atk3Ready, 1f);
  133. }
  134. public override void Attack4(int dir)
  135. {
  136. if (this.eAttr.isDead)
  137. {
  138. return;
  139. }
  140. if (!this.IsInNormalState())
  141. {
  142. return;
  143. }
  144. base.ChangeFace(dir);
  145. base.AnimChangeState(BeeAction.StateEnum.Atk2Ready, 1f);
  146. }
  147. public override void Idle1()
  148. {
  149. if (!this.IsInNormalState())
  150. {
  151. return;
  152. }
  153. base.FaceToPlayer();
  154. base.AnimChangeState(BeeAction.StateEnum.Idle, 1f);
  155. }
  156. public override void Idle2()
  157. {
  158. if (!this.IsInNormalState())
  159. {
  160. return;
  161. }
  162. base.FaceToPlayer();
  163. base.AnimChangeState(BeeAction.StateEnum.Idle2, 1f);
  164. }
  165. public override void AnimReady()
  166. {
  167. base.AnimChangeState(BeeAction.StateEnum.Idle, 1f);
  168. }
  169. public override void AnimMove()
  170. {
  171. base.AnimChangeState(BeeAction.StateEnum.Move, 1f);
  172. }
  173. public override void SideStep()
  174. {
  175. if (this.eAttr.isDead)
  176. {
  177. return;
  178. }
  179. if (this.IsInSideStepState())
  180. {
  181. return;
  182. }
  183. if (this.IsInWeakSta())
  184. {
  185. return;
  186. }
  187. base.SideStep();
  188. base.FaceToPlayer();
  189. base.AnimChangeState(BeeAction.StateEnum.MoveAway, 1f);
  190. }
  191. public override bool IsInNormalState()
  192. {
  193. return this.stateMachine.currentState.IsInArray(BeeAction.NormalSta) && base.IsInNormalState();
  194. }
  195. public override bool IsInDeadState(string state)
  196. {
  197. return state == "Die";
  198. }
  199. public override bool IsInWeakSta()
  200. {
  201. return this.eAttr.inWeakState;
  202. }
  203. public override bool IsInAttackState()
  204. {
  205. return this.stateMachine.currentState.IsInArray(BeeAction.AttackSta);
  206. }
  207. protected override bool EnterAtkSta(string lastState, string nextState)
  208. {
  209. return this.stateMachine.currentState.IsInArray(BeeAction.AttackSta) && !this.stateMachine.currentState.IsInArray(BeeAction.AttackSta);
  210. }
  211. protected override bool ExitAtkSta(string lastState, string nextState)
  212. {
  213. return !this.stateMachine.currentState.IsInArray(BeeAction.AttackSta) && this.stateMachine.currentState.IsInArray(BeeAction.AttackSta);
  214. }
  215. public override bool IsInDefenceState()
  216. {
  217. return false;
  218. }
  219. public override bool IsInSideStepState()
  220. {
  221. return this.stateMachine.currentState == "MoveAway";
  222. }
  223. public float moveAngle;
  224. public float minFlyHeight;
  225. public float maxFlyHeight;
  226. public bool atk4Flag;
  227. private static readonly string[] NormalSta = new string[]
  228. {
  229. "Idle",
  230. "Idle2",
  231. "Move"
  232. };
  233. private static readonly string[] AttackSta = new string[]
  234. {
  235. "Atk1",
  236. "Atk1End",
  237. "Atk1Ready",
  238. "Atk2",
  239. "Atk2End",
  240. "Atk2Ready",
  241. "Atk3_1",
  242. "Atk3_2",
  243. "Atk3_3",
  244. "Atk3End",
  245. "Atk3Ready",
  246. "Atk4_1",
  247. "Atk4_2",
  248. "Atk4End",
  249. "Atk4Ready"
  250. };
  251. public enum StateEnum
  252. {
  253. Atk1,
  254. Atk1End,
  255. Atk1Ready,
  256. Atk2,
  257. Atk2End,
  258. Atk2Ready,
  259. Atk3_1,
  260. Atk3_2,
  261. Atk3_3,
  262. Atk3End,
  263. Atk3Ready,
  264. Die,
  265. Hit,
  266. Idle,
  267. Idle2,
  268. Move,
  269. MoveAway,
  270. WeakMod
  271. }
  272. }