BeelzebubAction.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. using System;
  2. using DatabaseModel;
  3. using ExtensionMethods;
  4. using UnityEngine;
  5. public class BeelzebubAction : EnemyBaseAction
  6. {
  7. protected override void Start()
  8. {
  9. this.stateMachine.AddStates(typeof(BeelzebubAction.StateEnum));
  10. this.stateMachine.OnEnter += this.OnMyStateEnter;
  11. this.stateMachine.OnTransfer += this.OnStateTransfer;
  12. base.AnimChangeState(BeelzebubAction.StateEnum.Idle, 1f);
  13. this._beelzebubAnimListener = base.GetComponent<BeelzebubAnimListener>();
  14. }
  15. protected override void Update()
  16. {
  17. base.Update();
  18. if (this.EatSuccess)
  19. {
  20. base.player.position = new Vector3(base.transform.position.x, base.transform.position.y, base.player.position.z);
  21. }
  22. if (this.SawSuccess)
  23. {
  24. base.player.position = new Vector3(this.sawPos.position.x, this.sawPos.position.y, base.player.position.z) - Vector3.up;
  25. }
  26. }
  27. private void OnMyStateEnter(object sender, StateMachine.StateEventArgs args)
  28. {
  29. string state = args.state;
  30. switch (state)
  31. {
  32. case "Atk1":
  33. case "Atk1Eat":
  34. case "Atk1Fail":
  35. case "Atk1Success":
  36. case "Atk1SuccessEnd":
  37. case "Atk2End":
  38. case "Atk2Ready":
  39. case "Atk3":
  40. case "Atk4":
  41. case "Angry":
  42. this.spineAnim.Play(args.state, false, true, this.eAttr.atkSpeed);
  43. break;
  44. case "Die":
  45. case "DieQTE":
  46. case "Hit":
  47. case "HitQTE":
  48. case "Die2":
  49. case "CallEnemy":
  50. case "Idle2":
  51. this.spineAnim.Play(args.state, false, true, 1f);
  52. break;
  53. case "Idle":
  54. case "Move":
  55. case "WeakMod":
  56. case "Atk2Hit":
  57. case "Atk2":
  58. this.spineAnim.Play(args.state, true, false, 1f);
  59. break;
  60. }
  61. }
  62. private void OnStateTransfer(object sender, StateMachine.TransferEventArgs args)
  63. {
  64. base.GetComponent<EnemyBaseHurt>().StopFollowLeftHand();
  65. if (args.nextState == "Atk2End" || args.nextState == "Die" || args.nextState == "Atk2Hit" || args.nextState == "Idle" || args.nextState == "Hit")
  66. {
  67. this._beelzebubAnimListener.LSawUpper2.gameObject.SetActive(false);
  68. }
  69. if (args.nextState == "Atk2Hit")
  70. {
  71. this.LArm.localPosition = new Vector3(0f, 0f, -1f);
  72. }
  73. if (args.lastState == "Atk2Hit")
  74. {
  75. this.LArm.localPosition = Vector3.zero;
  76. this._beelzebubAnimListener.BeelzebubATK2.gameObject.SetActive(false);
  77. }
  78. if (!args.nextState.IsInArray(BeelzebubAction.AttackSta))
  79. {
  80. if (this.EatSuccess || this.SawSuccess)
  81. {
  82. this.Angry = true;
  83. }
  84. else
  85. {
  86. this.Angry = false;
  87. }
  88. if (this.EatSuccess)
  89. {
  90. this._beelzebubAnimListener.EatAtkSuccess();
  91. }
  92. if (this.SawSuccess)
  93. {
  94. this._beelzebubAnimListener.SawAttackFinish();
  95. }
  96. }
  97. if (this.ExitAtkSta(args.lastState, args.nextState))
  98. {
  99. this.eAttr.paBody = false;
  100. this.atkBox.localScale = Vector3.zero;
  101. }
  102. if (this.EnterAtkSta(args.lastState, args.nextState))
  103. {
  104. base.GetComponentInChildren<EnemyAtk>().atkId = Incrementor.GetNextId();
  105. }
  106. }
  107. public void EatAttack()
  108. {
  109. this.EatSuccess = true;
  110. GameObject prefab = CameraEffectProxyPrefabData.GetPrefab(7);
  111. GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(prefab, base.transform.position + Vector3.up * 2f, Quaternion.identity);
  112. gameObject.transform.parent = base.transform;
  113. }
  114. public void SawAttack()
  115. {
  116. this.SawSuccess = true;
  117. base.AnimChangeState(BeelzebubAction.StateEnum.Atk2Hit, 1f);
  118. R.Camera.Controller.CameraShake(2f, 0.2f, CameraController.ShakeTypeEnum.Rect, false);
  119. R.Camera.Controller.OpenMotionBlur(2f, 0.1f, base.transform.position + Vector3.up * 2f);
  120. }
  121. public override void Attack1(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. this.eAttr.paBody = true;
  133. base.AnimChangeState(BeelzebubAction.StateEnum.Atk1, 1f);
  134. }
  135. public override void Attack2(int dir)
  136. {
  137. if (this.eAttr.isDead)
  138. {
  139. return;
  140. }
  141. if (!this.IsInNormalState())
  142. {
  143. return;
  144. }
  145. base.ChangeFace(dir);
  146. this._beelzebubAnimListener.Atk2MoveLoopTime = 1;
  147. base.AnimChangeState(BeelzebubAction.StateEnum.Atk2Ready, 1f);
  148. }
  149. public override void Attack4(int dir)
  150. {
  151. if (this.eAttr.isDead)
  152. {
  153. return;
  154. }
  155. if (!this.IsInNormalState())
  156. {
  157. return;
  158. }
  159. base.ChangeFace(dir);
  160. this.eAttr.paBody = true;
  161. base.AnimChangeState(BeelzebubAction.StateEnum.Atk4, 1f);
  162. }
  163. public override void Attack5(int dir)
  164. {
  165. if (this.eAttr.isDead)
  166. {
  167. return;
  168. }
  169. if (!this.IsInNormalState())
  170. {
  171. return;
  172. }
  173. base.ChangeFace(dir);
  174. this.eAttr.paBody = true;
  175. base.AnimChangeState(BeelzebubAction.StateEnum.Angry, 1f);
  176. }
  177. public override void CounterAttack(int dir)
  178. {
  179. if (this.eAttr.isDead)
  180. {
  181. return;
  182. }
  183. if (this.IsInAttackState())
  184. {
  185. return;
  186. }
  187. if (this.stateMachine.currentState.IsInArray(BeelzebubAction.QTESta) || this.IsInWeakSta())
  188. {
  189. return;
  190. }
  191. R.Effect.Generate(128, base.transform, Vector3.up * 4f, Vector3.zero, default(Vector3), true);
  192. base.ChangeFace(dir);
  193. this.eAttr.paBody = true;
  194. int num = UnityEngine.Random.Range(0, 100);
  195. base.AnimChangeState((num > 60) ? BeelzebubAction.StateEnum.Angry : BeelzebubAction.StateEnum.Atk2Ready, 1f);
  196. }
  197. public override void KillSelf()
  198. {
  199. if (this.eAttr.rankType == EnemyAttribute.RankType.BOSS)
  200. {
  201. return;
  202. }
  203. SingletonMono<WorldTime>.Instance.TimeFrozenByFixedFrame(25, WorldTime.FrozenArgs.FrozenType.Enemy, true);
  204. R.Camera.Controller.CameraShake(0.416666657f, 0.3f, CameraController.ShakeTypeEnum.Rect, false);
  205. base.GetComponent<BeelzebubHurt>().NormalKill();
  206. this.eAttr.currentHp = 0;
  207. BeelzebubAction.StateEnum stateEnum = (UnityEngine.Random.Range(0, 2) != 0) ? BeelzebubAction.StateEnum.Die2 : BeelzebubAction.StateEnum.Die;
  208. base.AnimChangeState(stateEnum, 1f);
  209. }
  210. public override void Idle1()
  211. {
  212. if (!this.IsInNormalState())
  213. {
  214. return;
  215. }
  216. base.AnimChangeState(BeelzebubAction.StateEnum.Idle, 1f);
  217. }
  218. public override bool IsInNormalState()
  219. {
  220. return this.stateMachine.currentState.IsInArray(BeelzebubAction.NormalSta) && base.IsInNormalState();
  221. }
  222. public override bool IsInDeadState(string state)
  223. {
  224. return state.IsInArray(BeelzebubAction.DieSta);
  225. }
  226. public override void AnimReady()
  227. {
  228. base.AnimChangeState(BeelzebubAction.StateEnum.Idle, 1f);
  229. }
  230. public override void AnimMove()
  231. {
  232. base.AnimChangeState(BeelzebubAction.StateEnum.Move, 1f);
  233. }
  234. public override void Idle2()
  235. {
  236. if (this.eAttr.isDead)
  237. {
  238. return;
  239. }
  240. if (!this.IsInNormalState())
  241. {
  242. return;
  243. }
  244. base.AnimChangeState(BeelzebubAction.StateEnum.Idle2, 1f);
  245. }
  246. public override bool IsInWeakSta()
  247. {
  248. return this.eAttr.inWeakState;
  249. }
  250. public override bool IsInAttackState()
  251. {
  252. return this.stateMachine.currentState.IsInArray(BeelzebubAction.AttackSta);
  253. }
  254. protected override bool EnterAtkSta(string lastState, string nextState)
  255. {
  256. return nextState.IsInArray(BeelzebubAction.AttackSta) && !lastState.IsInArray(BeelzebubAction.AttackSta);
  257. }
  258. protected override bool ExitAtkSta(string lastState, string nextState)
  259. {
  260. return !nextState.IsInArray(BeelzebubAction.AttackSta) && lastState.IsInArray(BeelzebubAction.AttackSta);
  261. }
  262. public override void AnimQTEHurt()
  263. {
  264. base.AnimQTEHurt();
  265. int dir = (base.player.transform.localScale.x >= 0f) ? 1 : -1;
  266. base.ChangeFace(dir);
  267. base.ExitWeakState(true);
  268. Vector3 position = base.transform.position;
  269. position.z = LayerManager.ZNum.TempEnemy;
  270. base.transform.position = position;
  271. base.AnimChangeState(BeelzebubAction.StateEnum.HitQTE, 1f);
  272. Transform transform = R.Effect.Generate(179, null, position, default(Vector3), default(Vector3), true);
  273. transform.localScale = base.transform.localScale;
  274. }
  275. public override void AnimExecute()
  276. {
  277. base.AnimExecute();
  278. int dir = (base.player.transform.localScale.x >= 0f) ? 1 : -1;
  279. base.ChangeFace(dir);
  280. base.ExitWeakState(true);
  281. Vector3 position = base.transform.position;
  282. position.z = LayerManager.ZNum.TempEnemy;
  283. base.transform.position = position;
  284. base.AnimChangeState(BeelzebubAction.StateEnum.DieQTE, 1f);
  285. }
  286. public override bool IsInIdle()
  287. {
  288. return this.stateMachine.currentState == "Idle";
  289. }
  290. public static readonly string[] AttackSta = new string[]
  291. {
  292. "Atk1",
  293. "Atk1Eat",
  294. "Atk1Fail",
  295. "Atk1Success",
  296. "Atk1SuccessEnd",
  297. "Atk2",
  298. "Atk2End",
  299. "Atk2Ready",
  300. "Atk3",
  301. "Atk2Hit",
  302. "Atk4",
  303. "Angry"
  304. };
  305. public static readonly string[] HurtSta = new string[]
  306. {
  307. "Hit",
  308. "HItQTE"
  309. };
  310. private static readonly string[] DieSta = new string[]
  311. {
  312. "Die",
  313. "Die2",
  314. "DieQTE"
  315. };
  316. private static readonly string[] NormalSta = new string[]
  317. {
  318. "Idle",
  319. "Move",
  320. "CallEnemy",
  321. "Idle2"
  322. };
  323. private static readonly string[] QTESta = new string[]
  324. {
  325. "HItQTE",
  326. "DieQTE"
  327. };
  328. public bool EatSuccess;
  329. public bool SawSuccess;
  330. public bool Angry;
  331. private BeelzebubAnimListener _beelzebubAnimListener;
  332. [SerializeField]
  333. private Transform sawPos;
  334. [SerializeField]
  335. private Transform LArm;
  336. public enum StateEnum
  337. {
  338. Atk1,
  339. Atk1Eat,
  340. Atk1Fail,
  341. Atk1Success,
  342. Atk1SuccessEnd,
  343. Atk2,
  344. Atk2End,
  345. Atk2Ready,
  346. Atk3,
  347. Atk4,
  348. Die,
  349. Hit,
  350. Idle,
  351. Move,
  352. WeakMod,
  353. Atk2Hit,
  354. Die2,
  355. Angry,
  356. CallEnemy,
  357. Idle2,
  358. DieQTE,
  359. HitQTE
  360. }
  361. }