EatingBossAnimEvent.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. using System;
  2. using System.Collections;
  3. using GameWorld;
  4. using LitJson;
  5. using UnityEngine;
  6. public class EatingBossAnimEvent : BaseBehaviour
  7. {
  8. private Transform player
  9. {
  10. get
  11. {
  12. return R.Player.Transform;
  13. }
  14. }
  15. private void Awake()
  16. {
  17. this._action = base.GetComponent<EatingBossAction>();
  18. this._eAttr = base.GetComponent<EnemyAttribute>();
  19. this._enemyAtk = base.GetComponentInChildren<EnemyAtk>();
  20. }
  21. private void Start()
  22. {
  23. this._atk2LoopTimes = 2;
  24. this._jsonData = SingletonMono<EnemyDataPreload>.Instance.attack[EnemyType.卡洛斯];
  25. }
  26. private void Update()
  27. {
  28. if (!this._cameraFollow)
  29. {
  30. return;
  31. }
  32. Vector3 position = R.Camera.Controller.MovableCamera.position;
  33. position.x = base.transform.position.x;
  34. Vector3 one = Vector3.one;
  35. Vector3.SmoothDamp(R.Camera.Controller.MovableCamera.position, position, ref one, 0.1f);
  36. }
  37. public void ChangeState(EatingBossAction.StateEnum sta)
  38. {
  39. this._action.AnimChangeState(sta, 1f);
  40. }
  41. public void Atk5Loop()
  42. {
  43. this.atk5Loop--;
  44. if (this.atk5Loop <= 0)
  45. {
  46. this.ChangeState(EatingBossAction.StateEnum.Atk5End);
  47. }
  48. }
  49. public void SetAtkData()
  50. {
  51. this._enemyAtk.atkData = this._jsonData[this._action.stateMachine.currentState];
  52. this.SetAtkId();
  53. }
  54. public void SetAtkId()
  55. {
  56. this._enemyAtk.atkId = Incrementor.GetNextId();
  57. }
  58. public void SummonEnemyOne()
  59. {
  60. EnemyType type = (R.GameData.Difficulty > 1) ? EnemyType.暴食 : EnemyType.斩轮式一型;
  61. if (R.Enemy.GetEnemyCountByType(type) < 1)
  62. {
  63. this.SummonEnemy(type);
  64. }
  65. }
  66. public void SummonEnemyTwo()
  67. {
  68. EnemyType type = (R.GameData.Difficulty > 1) ? EnemyType.炮击式一型 : EnemyType.蜜蜂;
  69. if (R.Enemy.GetEnemyCountByType(type) < 1)
  70. {
  71. this.SummonEnemy(type);
  72. }
  73. }
  74. public void SummonEnemy(EnemyType type)
  75. {
  76. Vector2 value = new Vector2(UnityEngine.Random.Range(GameArea.EnemyRange.xMin + 3f, GameArea.EnemyRange.xMax - 3f), base.transform.position.y);
  77. GameObject gameObject = Singleton<EnemyGenerator>.Instance.GenerateEnemy(type, new Vector2?(value), true, true);
  78. gameObject.GetComponent<EnemyAttribute>().playerInView = true;
  79. }
  80. public void Attack2Judge()
  81. {
  82. if (this._action.attack2Success)
  83. {
  84. this._action.AnimChangeState(EatingBossAction.StateEnum.Atk2Success, 1f);
  85. }
  86. else
  87. {
  88. this._action.AnimChangeState(EatingBossAction.StateEnum.Atk2End, 1f);
  89. }
  90. }
  91. public void Attack2End()
  92. {
  93. this._atk2LoopTimes--;
  94. if (this._atk2LoopTimes < 0)
  95. {
  96. this._atk2LoopTimes = 2;
  97. this._action.AnimChangeState(EatingBossAction.StateEnum.Atk2SuccessEnd, 1f);
  98. }
  99. }
  100. public void Attack2Release()
  101. {
  102. this._action.attack2Success = false;
  103. this.player.GetComponent<Collider2D>().enabled = false;
  104. this.player.localRotation = Quaternion.identity;
  105. PlayerHurtAtkEventArgs args = new PlayerHurtAtkEventArgs(this.player.gameObject, base.gameObject, base.gameObject, this._eAttr.atk, Incrementor.GetNextId(), this._jsonData["Atk2Release"], true);
  106. EventManager.PostEvent<Transform, PlayerHurtAtkEventArgs>("PlayerHurtAtk", base.transform, args);
  107. }
  108. public void PlayBiteEffect()
  109. {
  110. R.Effect.Generate(134, base.transform, new Vector3(-1.36f, 1.8f, 0f), default(Vector3), default(Vector3), true);
  111. }
  112. public void Atk4Effect()
  113. {
  114. Transform transform = R.Effect.Generate(210, null, base.transform.position, default(Vector3), default(Vector3), true);
  115. Vector3 localScale = transform.localScale;
  116. localScale.x *= Mathf.Sign(base.transform.localScale.x);
  117. transform.localScale = localScale;
  118. EnemyBullet componentInChildren = transform.GetComponentInChildren<EnemyBullet>();
  119. componentInChildren.SetAtkData(this._jsonData[this._action.stateMachine.currentState]);
  120. componentInChildren.origin = base.gameObject;
  121. componentInChildren.damage = this._eAttr.atk;
  122. }
  123. public void BackToIdle()
  124. {
  125. if (this._action.IsInWeakSta())
  126. {
  127. this._eAttr.enterWeakMod = false;
  128. this._action.AnimChangeState(EatingBossAction.StateEnum.IdleToWeakMod, 1f);
  129. }
  130. else
  131. {
  132. this._action.AnimChangeState(EatingBossAction.StateEnum.Idle, 1f);
  133. }
  134. }
  135. public IEnumerator WeakOver()
  136. {
  137. for (int i = 0; i < 75; i++)
  138. {
  139. if (this._action.stateMachine.currentState == "WeakMod" && !this._action.IsInWeakSta())
  140. {
  141. this._action.AnimChangeState(EatingBossAction.StateEnum.WeakModToIdle, 1f);
  142. break;
  143. }
  144. yield return new WaitForFixedUpdate();
  145. }
  146. yield break;
  147. }
  148. private void RealDestroy()
  149. {
  150. UnityEngine.Object.Destroy(base.gameObject);
  151. }
  152. public void CameraZoomIn()
  153. {
  154. R.Camera.Controller.CameraZoom((this.player.position + base.transform.position) / 2f + Vector3.up * 1.5f, 0.3f, 3f);
  155. }
  156. public void CameraFollowStart()
  157. {
  158. this._cameraFollow = true;
  159. }
  160. public void QTEHurtShadeAtk()
  161. {
  162. Transform transform = R.Effect.Generate(177, null, base.transform.position + Vector3.up * 1.5f, default(Vector3), default(Vector3), true);
  163. Vector3 one = Vector3.one;
  164. one.x *= (float)this._eAttr.faceDir;
  165. transform.localScale = one;
  166. }
  167. public void QTEHurtShadeAtkBack()
  168. {
  169. Transform transform = R.Effect.Generate(177, null, base.transform.position + Vector3.up * 1.5f, default(Vector3), default(Vector3), true);
  170. Vector3 one = Vector3.one;
  171. one.x *= (float)(-(float)this._eAttr.faceDir);
  172. transform.localScale = one;
  173. }
  174. public void CameraShake(int frame)
  175. {
  176. R.Camera.Controller.CameraShake((float)frame / 60f, 0.2f, CameraController.ShakeTypeEnum.Rect, false);
  177. }
  178. public void QTEHurtEffect()
  179. {
  180. R.Audio.PlayEffect(254, new Vector3?(base.transform.position));
  181. EnemyBaseHurt component = base.GetComponent<EnemyBaseHurt>();
  182. component.HitEffect(component.center.localPosition, "Atk1");
  183. }
  184. public void PlayerRollAttack()
  185. {
  186. this.player.position += Vector3.up * 5f;
  187. R.Player.Action.ChangeState(PlayerAction.StateEnum.QTERoll, 1f);
  188. this.player.GetComponent<PlayerTimeController>().SetSpeed(Vector2.right * 4f * (float)R.Player.Attribute.faceDir);
  189. }
  190. public void PlayerRollAttackEffect()
  191. {
  192. R.Audio.PlayEffect(254, new Vector3?(base.transform.position));
  193. base.GetComponent<EnemyBaseHurt>().HitEffect(this.player.transform.position - base.transform.position, "Atk1");
  194. R.Camera.Controller.CameraShake(0.06666667f, 0.2f, CameraController.ShakeTypeEnum.Rect, false);
  195. }
  196. public void QTEFinalHurt()
  197. {
  198. EnemyHurtAtkEventArgs args = new EnemyHurtAtkEventArgs(base.gameObject, EnemyHurtAtkEventArgs.HurtTypeEnum.QTEHurt);
  199. EventManager.PostEvent<GameObject, EnemyHurtAtkEventArgs>("EnemyHurtAtk", this.player.gameObject, args);
  200. }
  201. public void PlayerEndAtk()
  202. {
  203. R.Player.Action.ChangeState(PlayerAction.StateEnum.EndAtk, 1f);
  204. }
  205. public void CameraFollowEnd()
  206. {
  207. this._cameraFollow = false;
  208. }
  209. public void ExecutePlayerPush()
  210. {
  211. R.Player.Action.ChangeState(PlayerAction.StateEnum.QTEPush, 1f);
  212. }
  213. public void ExecuteFinalHurt()
  214. {
  215. EnemyHurtAtkEventArgs args = new EnemyHurtAtkEventArgs(base.gameObject, EnemyHurtAtkEventArgs.HurtTypeEnum.Execute, string.Empty);
  216. EventManager.PostEvent<GameObject, EnemyHurtAtkEventArgs>("EnemyHurtAtk", this.player.gameObject, args);
  217. }
  218. public void DestroySelf()
  219. {
  220. base.gameObject.SetActive(false);
  221. base.Invoke("RealDestroy", Time.deltaTime);
  222. }
  223. public void PlayAudio(int id)
  224. {
  225. R.Audio.PlayEffect(id, new Vector3?(base.transform.position));
  226. }
  227. public void Play2DAudio(int id)
  228. {
  229. R.Audio.PlayEffect(id, null);
  230. }
  231. public void PlayMoveAudio()
  232. {
  233. int id = this.moveAudio[UnityEngine.Random.Range(0, this.moveAudio.Length)];
  234. R.Audio.PlayEffect(id, new Vector3?(base.transform.position));
  235. }
  236. private JsonData _jsonData;
  237. private EatingBossAction _action;
  238. private EnemyAttribute _eAttr;
  239. private EnemyAtk _enemyAtk;
  240. public int atk5Loop;
  241. private int _atk2LoopTimes;
  242. [SerializeField]
  243. private int[] moveAudio;
  244. private bool _cameraFollow;
  245. }