EnemyBaseHurt.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using Core;
  5. using ExtensionMethods;
  6. using GameWorld;
  7. using LitJson;
  8. using UnityEngine;
  9. public class EnemyBaseHurt : BaseBehaviour
  10. {
  11. protected int flashAttackDamage
  12. {
  13. get
  14. {
  15. if (R.Player.Enhancement.FlashAttack == 0)
  16. {
  17. return 0;
  18. }
  19. return (int)((float)this.eAttr.maxHp * 0.05f * UnityEngine.Random.Range(0.95f, 1.05f));
  20. }
  21. }
  22. protected bool flashPercent
  23. {
  24. get
  25. {
  26. int num = UnityEngine.Random.Range(1, 100);
  27. int flashAttack = R.Player.Enhancement.FlashAttack;
  28. if (flashAttack == 1)
  29. {
  30. return num < 30;
  31. }
  32. if (flashAttack != 2)
  33. {
  34. return flashAttack == 3;
  35. }
  36. return num < 60;
  37. }
  38. }
  39. protected GameObject player
  40. {
  41. get
  42. {
  43. return R.Player.GameObject;
  44. }
  45. }
  46. protected PlayerAttribute pAttr
  47. {
  48. get
  49. {
  50. return R.Player.Attribute;
  51. }
  52. }
  53. public List<int> phaseHp
  54. {
  55. get
  56. {
  57. if (this._phaseHp != null && this._phaseHp.Count != 0)
  58. {
  59. return this._phaseHp;
  60. }
  61. this._phaseHp = new List<int>();
  62. if (this.hpPercent.Length == 0)
  63. {
  64. this.maxPhase = 1;
  65. this._phaseHp.Add(this.eAttr.maxHp);
  66. return this._phaseHp;
  67. }
  68. this.maxPhase = this.hpPercent.Length;
  69. if (this.eAttr.rankType != EnemyAttribute.RankType.Normal)
  70. {
  71. for (int i = 0; i < this.hpPercent.Length; i++)
  72. {
  73. this._phaseHp.Add(this.eAttr.maxHp * this.hpPercent[i] / 100);
  74. }
  75. }
  76. return this._phaseHp;
  77. }
  78. }
  79. private float speedDir
  80. {
  81. get
  82. {
  83. return Mathf.Sign(base.transform.localScale.x);
  84. }
  85. }
  86. protected void Awake()
  87. {
  88. this.eAttr = base.GetComponent<EnemyAttribute>();
  89. this.armor = base.GetComponent<EnemyArmor>();
  90. this.action = base.GetComponent<EnemyBaseAction>();
  91. this.Pivot = base.GetComponent<Pivot>();
  92. }
  93. protected void Start()
  94. {
  95. this.frameShakeOffset = this.m_frameShakeOffset;
  96. this.spHurtAudio = 6;
  97. this.chaseEnd = 0f;
  98. this.Init();
  99. }
  100. protected void OnEnable()
  101. {
  102. EventManager.RegisterEvent<EnemyHurtAtkEventArgs>("EnemyHurtAtk", new EventManager.FBEventHandler<EnemyHurtAtkEventArgs>(this.EnemyHurt), EventManager.ListenerQueue.Game);
  103. }
  104. protected void OnDisable()
  105. {
  106. EventManager.UnregisterEvent<EnemyHurtAtkEventArgs>("EnemyHurtAtk", new EventManager.FBEventHandler<EnemyHurtAtkEventArgs>(this.EnemyHurt), EventManager.ListenerQueue.Game);
  107. }
  108. private void OnDestroy()
  109. {
  110. this.QTECameraFinish();
  111. }
  112. protected virtual void Update()
  113. {
  114. this.UpdateEnemyDie();
  115. this.UpdateExecuteFollow();
  116. if (this.deadFlag)
  117. {
  118. return;
  119. }
  120. this.UpdateChase();
  121. }
  122. private void UpdateEnemyDie()
  123. {
  124. if (this.eAttr.isDead && !this.deadFlag && this.eAttr.rankType == EnemyAttribute.RankType.Normal)
  125. {
  126. this.EnemyDie();
  127. }
  128. }
  129. private void UpdateExecuteFollow()
  130. {
  131. if (this.eAttr.followLeftHand)
  132. {
  133. Vector3 position = R.Player.Action.executeFollow.position + new Vector3((float)this.eAttr.faceDir * this.centerOffset.x, this.centerOffset.y, this.centerOffset.z);
  134. position.z = LayerManager.ZNum.Fx;
  135. base.transform.position = position;
  136. }
  137. }
  138. private void UpdateChase()
  139. {
  140. if (this.eAttr.canBeChased)
  141. {
  142. this.chaseEnd += Time.unscaledDeltaTime;
  143. if (this.chaseEnd >= 1.3f)
  144. {
  145. this.ChaseEnd();
  146. }
  147. }
  148. }
  149. protected virtual void Init()
  150. {
  151. }
  152. protected void QTEZPositionRecover()
  153. {
  154. Vector3 position = base.transform.position;
  155. position.z = LayerManager.ZNum.MMiddleE(this.eAttr.rankType);
  156. base.transform.position = position;
  157. }
  158. private bool EnemyHurt(string eventName, object sender, EnemyHurtAtkEventArgs args)
  159. {
  160. if (args.hurted != base.gameObject)
  161. {
  162. return false;
  163. }
  164. switch (args.hurtType)
  165. {
  166. case EnemyHurtAtkEventArgs.HurtTypeEnum.Normal:
  167. this.NormalHurt(args.attackData, args.attackId, args.body, args.hurtPos);
  168. break;
  169. case EnemyHurtAtkEventArgs.HurtTypeEnum.ExecuteFollow:
  170. this.ExecuteFollow();
  171. break;
  172. case EnemyHurtAtkEventArgs.HurtTypeEnum.Execute:
  173. this.Execute(args.attackData.atkName, true);
  174. break;
  175. case EnemyHurtAtkEventArgs.HurtTypeEnum.QTEHurt:
  176. this.QTEHurt();
  177. break;
  178. case EnemyHurtAtkEventArgs.HurtTypeEnum.Flash:
  179. this.FlashAttackHurt();
  180. break;
  181. }
  182. return true;
  183. }
  184. public IEnumerator ClipShake(int frame)
  185. {
  186. for (int i = 0; i < frame; i++)
  187. {
  188. if (i % 2 == 0)
  189. {
  190. this.frameShakeBody.localPosition += Vector3.right * this.frameShakeOffset;
  191. }
  192. else
  193. {
  194. this.frameShakeBody.localPosition -= Vector3.right * this.frameShakeOffset;
  195. }
  196. yield return null;
  197. }
  198. this.frameShakeBody.localPosition = Vector3.zero;
  199. yield break;
  200. }
  201. protected void TimeFrozenAndCameraShake(int frozenFrame, int frameShakeFrame, int shakeType, int shakeFrame, float shakeOffset)
  202. {
  203. WorldTime.FrozenArgs.FrozenType type = (!(this.playerAtkName == "HitGround")) ? WorldTime.FrozenArgs.FrozenType.All : WorldTime.FrozenArgs.FrozenType.Enemy;
  204. SingletonMono<WorldTime>.Instance.TimeFrozenByFixedFrame(frozenFrame, type, true);
  205. base.StopCoroutine("ClipShake");
  206. base.StartCoroutine(this.ClipShake(frameShakeFrame));
  207. if (shakeType != 0)
  208. {
  209. if (shakeType != 1)
  210. {
  211. if (shakeType == 2)
  212. {
  213. R.Camera.Controller.CameraShake((float)shakeFrame / 60f, shakeOffset, CameraController.ShakeTypeEnum.Vertical, false);
  214. }
  215. }
  216. else
  217. {
  218. R.Camera.Controller.CameraShake((float)shakeFrame / 60f, shakeOffset, CameraController.ShakeTypeEnum.Horizon, false);
  219. }
  220. }
  221. else
  222. {
  223. R.Camera.Controller.CameraShake((float)shakeFrame / 60f, shakeOffset, CameraController.ShakeTypeEnum.Rect, false);
  224. }
  225. }
  226. public virtual void SetHitSpeed(Vector2 speed)
  227. {
  228. if (this.eAttr.isDead && speed.y > 0f)
  229. {
  230. return;
  231. }
  232. this.eAttr.timeController.SetSpeed(speed);
  233. }
  234. protected void PlayHurtAnim(string normalSta, string airSta, Vector2 speed, Vector2 airSpeed)
  235. {
  236. if (this.eAttr.isDead)
  237. {
  238. return;
  239. }
  240. if (!this.eAttr.iCanFly)
  241. {
  242. this.eAttr.timeController.SetGravity(1f);
  243. }
  244. this.eAttr.isFlyingUp = false;
  245. this.eAttr.checkHitGround = false;
  246. this.action.AnimChangeState((!this.eAttr.isOnGround) ? airSta : normalSta, 1f);
  247. this.SetHitSpeed((!this.eAttr.isOnGround) ? airSpeed : speed);
  248. }
  249. public void HitEffect(Vector3 pos, string atkName = "Atk1")
  250. {
  251. R.Effect.Generate(1, base.transform, pos, new Vector3(0f, 0f, 0f), default(Vector3), true);
  252. R.Effect.Generate(71, base.transform, pos + Vector3.right * (float)this.pAttr.faceDir * 0.5f, new Vector3(0f, (float)((this.pAttr.faceDir <= 0) ? 0 : 180), UnityEngine.Random.Range(-90f, 0f)), default(Vector3), true);
  253. R.Effect.Generate(151, base.transform, pos, new Vector3(0f, 0f, 0f), default(Vector3), true);
  254. if (atkName.IsInArray(PlayerAtkType.HeavyEffectAttack))
  255. {
  256. R.Effect.Generate(156, base.transform, pos, default(Vector3), default(Vector3), true);
  257. }
  258. }
  259. private void HitIntoWeakEffect(Vector3 pos, string atkName)
  260. {
  261. SingletonMono<WorldTime>.Instance.TimeSlowByFrameOn60Fps(48, 0.5f);
  262. this.HitEffect(pos, atkName);
  263. }
  264. protected virtual void PlayHurtAudio()
  265. {
  266. R.Audio.PlayEffect(UnityEngine.Random.Range(129, 132), new Vector3?(base.transform.position));
  267. }
  268. protected bool PlaySpHurtAudio()
  269. {
  270. if (!this.SoundJudge())
  271. {
  272. return true;
  273. }
  274. bool flag = UnityEngine.Random.Range(0, 100) < this.spHurtAudio;
  275. if (flag)
  276. {
  277. this.spHurtAudio = 6;
  278. return true;
  279. }
  280. this.spHurtAudio += 6;
  281. return false;
  282. }
  283. private bool SoundJudge()
  284. {
  285. int enemyType = (int)this.eAttr.baseData.enemyType;
  286. switch (enemyType)
  287. {
  288. case 1:
  289. case 2:
  290. case 3:
  291. break;
  292. default:
  293. switch (enemyType)
  294. {
  295. case 22:
  296. case 23:
  297. case 26:
  298. break;
  299. default:
  300. switch (enemyType)
  301. {
  302. case 15:
  303. case 18:
  304. break;
  305. default:
  306. if (enemyType != 33 && enemyType != 37)
  307. {
  308. return false;
  309. }
  310. break;
  311. }
  312. break;
  313. }
  314. break;
  315. }
  316. return true;
  317. }
  318. protected virtual void PhysicAndEffect(Vector2 speed, Vector2 airSpeed, string normalAtkType, string airAtkType)
  319. {
  320. if (this.playerAtkName != "Charge1EndLevel1" && !this.playerAtkName.IsInArray(PlayerAction.ExecuteSta))
  321. {
  322. if (this.eAttr.paBody)
  323. {
  324. return;
  325. }
  326. if (this.eAttr.currentActionInterruptPoint < this.eAttr.actionInterruptPoint && !this.defecnceBreak)
  327. {
  328. return;
  329. }
  330. }
  331. this.defecnceBreak = false;
  332. if (this.eAttr.isOnGround && normalAtkType != "NoStiff")
  333. {
  334. this.eAttr.stiffTime = 1f;
  335. this.PlayHurtAnim(normalAtkType, airAtkType, speed, airSpeed);
  336. }
  337. else if (!this.eAttr.isOnGround && airAtkType != "NoStiff")
  338. {
  339. this.eAttr.stiffTime = 1f;
  340. this.PlayHurtAnim(normalAtkType, airAtkType, speed, airSpeed);
  341. }
  342. else
  343. {
  344. this.eAttr.stiffTime = 0f;
  345. }
  346. }
  347. public void QTECameraStart()
  348. {
  349. if (!this.qteCameraEffectOn)
  350. {
  351. this.qteCameraEffectOn = true;
  352. }
  353. }
  354. public void QTECameraFinish()
  355. {
  356. if (this.qteCameraEffectOn)
  357. {
  358. this.qteCameraEffectOn = false;
  359. }
  360. }
  361. protected bool BloodWeak()
  362. {
  363. return this.HpInWeak() && !this.eAttr.isDead && !this.action.IsInWeakSta() && this.eAttr.accpectExecute;
  364. }
  365. protected bool HpInWeak()
  366. {
  367. int num = 0;
  368. for (int i = 0; i < this.currentPhase; i++)
  369. {
  370. num += this.GetPhaseHp(i);
  371. }
  372. num += (int)((float)this.GetPhaseHp(this.currentPhase) * ((this.eAttr.rankType != EnemyAttribute.RankType.Normal) ? 0.9f : 0.7f));
  373. return this.eAttr.currentHp < this.eAttr.maxHp - num;
  374. }
  375. public void GenerateCritHurtNum(int damage)
  376. {
  377. if (damage == 0)
  378. {
  379. return;
  380. }
  381. this.HpMinus(damage);
  382. }
  383. protected virtual void HpMinus(int num)
  384. {
  385. if (this.eAttr.rankType != EnemyAttribute.RankType.Normal)
  386. {
  387. this.eAttr.currentHp = Mathf.Clamp(this.eAttr.currentHp - num, this.MinLockedHp(), int.MaxValue);
  388. return;
  389. }
  390. this.eAttr.currentHp -= num;
  391. }
  392. protected void QTEHpMinus()
  393. {
  394. int num = 0;
  395. for (int i = 0; i < this.currentPhase; i++)
  396. {
  397. num += this.GetPhaseHp(i);
  398. }
  399. this.eAttr.currentHp = this.eAttr.maxHp - num;
  400. }
  401. protected int MinLockedHp()
  402. {
  403. int num = 0;
  404. for (int i = 0; i < this.currentPhase + 1; i++)
  405. {
  406. int phaseHp = this.GetPhaseHp(i);
  407. num += phaseHp;
  408. }
  409. return this.eAttr.maxHp - num + 1;
  410. }
  411. protected void HpRecover()
  412. {
  413. int num = 0;
  414. for (int i = 0; i < this.currentPhase; i++)
  415. {
  416. num += this.GetPhaseHp(i);
  417. }
  418. num += (int)((float)this.GetPhaseHp(this.currentPhase) * 0.7f);
  419. this.eAttr.currentHp = this.eAttr.maxHp - num;
  420. }
  421. protected virtual bool Counterattack(int damage, bool groundOnly)
  422. {
  423. return HurtDataTools.Counterattack(damage, groundOnly, ref this.actionInterrupt, ref this.eAttr, ref this.action);
  424. }
  425. protected void AddActionInterruptPoint(int damage, string atkName)
  426. {
  427. HurtDataTools.AddActionInterruptPoint(damage, atkName, ref this.eAttr, ref this.actionInterrupt);
  428. }
  429. protected bool CalculateMonsterDefence(int damage)
  430. {
  431. return HurtDataTools.CalculateMonsterDefence(damage, ref this.defenceTrigger, ref this.action, ref this.eAttr);
  432. }
  433. protected bool CalculateMonsterSideStep(int damage)
  434. {
  435. return HurtDataTools.CalculateMonsterSideStep(damage, ref this.sideStepTrigger, ref this.action, ref this.eAttr);
  436. }
  437. protected int GetPhaseHp(int phase)
  438. {
  439. if (phase < 0 || phase > this.phaseHp.Count)
  440. {
  441. return 0;
  442. }
  443. return this.phaseHp[phase];
  444. }
  445. public void StopFollowLeftHand()
  446. {
  447. this.eAttr.followLeftHand = false;
  448. }
  449. protected virtual void HitIntoWeakState(Vector2 speed, Vector2 airSpeed, string normalAtkType, string airAtkType)
  450. {
  451. this.ChaseEnd();
  452. this.action.EnterWeakState();
  453. this.eAttr.stiffTime = 1f;
  454. if (this.eAttr.isOnGround && normalAtkType != "NoStiff")
  455. {
  456. this.action.FaceToPlayer();
  457. this.PlayHurtAnim(normalAtkType, airAtkType, speed, airSpeed);
  458. }
  459. else if (!this.eAttr.isOnGround && airAtkType != "NoStiff")
  460. {
  461. this.action.FaceToPlayer();
  462. this.PlayHurtAnim(normalAtkType, airAtkType, speed, airSpeed);
  463. }
  464. if (!base.IsInvoking("ExitWeak"))
  465. {
  466. this.exitWeakPhase = this.currentPhase;
  467. base.Invoke("ExitWeak", 5f);
  468. }
  469. }
  470. protected virtual void ExitWeak()
  471. {
  472. if (!this.action.IsInWeakSta() || this.exitWeakPhase != this.currentPhase || this.eAttr.willBeExecute)
  473. {
  474. return;
  475. }
  476. this.HpRecover();
  477. this.action.ExitWeakState(false);
  478. }
  479. public virtual void NormalHurt(EnemyHurtAtkEventArgs.PlayerNormalAtkData atkData, int atkId, HurtCheck.BodyType body, Vector2 hurtPos)
  480. {
  481. if (this.hurtId >= atkId || !this.hurtData.Contains(atkData.atkName))
  482. {
  483. return;
  484. }
  485. this.GetHurt(atkId);
  486. EnemyBaseHurt.HurtAttribute hurtAttribute = new EnemyBaseHurt.HurtAttribute(this.hurtData[atkData.atkName], this.defaultAnimName, this.defaultAirAnimName);
  487. this.SpeedAdjust(atkData.atkName, ref hurtAttribute);
  488. this.playerAtkName = atkData.atkName;
  489. Vector2 speed = new Vector2(hurtAttribute.xSpeed, hurtAttribute.ySpeed);
  490. Vector2 airSpeed = new Vector2(hurtAttribute.airXSpeed, hurtAttribute.airYSpeed);
  491. Vector3 pos = (Vector3)hurtPos - base.transform.position;
  492. int finalDamage = PlayerDamageCalculate.GetFinalDamage(atkData.damagePercent, HurtDataTools.GetAtkLevel(this.playerAtkName), this.playerAtkName);
  493. if (this.eAttr.isArmorBroken)
  494. {
  495. this.AddActionInterruptPoint(finalDamage, this.playerAtkName);
  496. bool flag = this.CalDefense(finalDamage);
  497. bool flag2 = this.CalSideStep(finalDamage);
  498. this.canCounterattack = this.Counterattack(finalDamage, this.eAttr.isOnGround);
  499. if (atkData.joystickShakeNum > 0)
  500. {
  501. Core.Input.Vibration.Vibrate(atkData.joystickShakeNum);
  502. }
  503. if (this.canCounterattack)
  504. {
  505. this.PlayHurtAudio();
  506. this.DoCounterAttack(atkData, pos);
  507. this.GenerateCritHurtNum(finalDamage);
  508. this.DoWeak(pos, speed, airSpeed, hurtAttribute, atkData);
  509. return;
  510. }
  511. this.CanDefenseOrSideStep(ref flag, ref flag2, ref finalDamage);
  512. if (this.InDefense(flag, atkData, pos))
  513. {
  514. return;
  515. }
  516. flag = false;
  517. this.NotInDefense();
  518. speed.x *= this.speedDir;
  519. airSpeed.x *= this.speedDir;
  520. if (!this.eAttr.isDead)
  521. {
  522. this.GenerateCritHurtNum(finalDamage);
  523. }
  524. if (this.DoWeak(pos, speed, airSpeed, hurtAttribute, atkData))
  525. {
  526. return;
  527. }
  528. if (!flag2)
  529. {
  530. this.HitEffect(pos, atkData.atkName);
  531. }
  532. if (!flag && !flag2)
  533. {
  534. this.DoHurt(atkData, speed, airSpeed, hurtAttribute);
  535. }
  536. }
  537. else
  538. {
  539. this.armor.HitArmor(finalDamage, atkData.atkName);
  540. }
  541. }
  542. private void GetHurt(int atkId)
  543. {
  544. this.hurtId = atkId;
  545. if (this.atkBox != null)
  546. {
  547. this.atkBox.localScale = Vector3.zero;
  548. }
  549. }
  550. private void SpeedAdjust(string name, ref EnemyBaseHurt.HurtAttribute hurtAttr)
  551. {
  552. if ((name == "UpRising" || name == "AtkUpRising") && hurtAttr.airYSpeed > 0f)
  553. {
  554. float num = Mathf.Clamp(Physics2D.Raycast(base.transform.position, -Vector2.up, 100f, LayerManager.GroundMask).distance, 0f, float.PositiveInfinity);
  555. hurtAttr.airYSpeed = Mathf.Lerp(hurtAttr.ySpeed, 6f, num / 4f);
  556. }
  557. }
  558. private bool CalDefense(int hitNumber)
  559. {
  560. bool flag = this.CalculateMonsterDefence(hitNumber);
  561. if (flag)
  562. {
  563. this.eAttr.dynamicDefence = (int)((float)this.eAttr.baseDefence * UnityEngine.Random.Range(0.7f, 1.3f));
  564. this.defenceTrigger = 0f;
  565. }
  566. return flag;
  567. }
  568. private bool CalSideStep(int hitNumber)
  569. {
  570. bool flag = this.CalculateMonsterSideStep(hitNumber);
  571. if (flag)
  572. {
  573. this.eAttr.dynamicSideStep = (int)((float)this.eAttr.baseSideStep * UnityEngine.Random.Range(0.7f, 1.3f));
  574. this.sideStepTrigger = 0f;
  575. }
  576. return flag;
  577. }
  578. private void DoCounterAttack(EnemyHurtAtkEventArgs.PlayerNormalAtkData atkData, Vector3 pos)
  579. {
  580. this.TimeFrozenAndCameraShake(atkData.frozenFrame, atkData.shakeFrame, atkData.shakeType, atkData.camShakeFrame, atkData.shakeStrength);
  581. this.HitEffect(pos, atkData.atkName);
  582. this.eAttr.currentDefence = 0;
  583. this.eAttr.currentSideStep = 0;
  584. int dir = InputSetting.JudgeDir(base.transform.position.x, this.player.transform.position.x);
  585. this.action.CounterAttack(dir);
  586. }
  587. private void CanDefenseOrSideStep(ref bool defence, ref bool sideStep, ref int hitNumber)
  588. {
  589. if (defence || sideStep)
  590. {
  591. if (defence && sideStep)
  592. {
  593. if (UnityEngine.Random.Range(0, 2) == 0)
  594. {
  595. this.eAttr.currentSideStep /= 2;
  596. this.action.Defence();
  597. sideStep = false;
  598. }
  599. else
  600. {
  601. this.eAttr.currentDefence /= 2;
  602. this.action.SideStep();
  603. defence = false;
  604. hitNumber = 0;
  605. }
  606. }
  607. else if (defence)
  608. {
  609. this.action.Defence();
  610. }
  611. else
  612. {
  613. this.action.SideStep();
  614. hitNumber = 0;
  615. }
  616. }
  617. }
  618. private bool InDefense(bool defence, EnemyHurtAtkEventArgs.PlayerNormalAtkData atkData, Vector3 pos)
  619. {
  620. if (defence)
  621. {
  622. this.DoDefenseSucces(atkData, pos);
  623. return true;
  624. }
  625. if (!this.action.IsInDefenceState())
  626. {
  627. return false;
  628. }
  629. if (!this.playerAtkName.IsInArray(PlayerAtkType.BreakDefense))
  630. {
  631. this.DoDefenseSucces(atkData, pos);
  632. return true;
  633. }
  634. this.DoFefenseBreak();
  635. return false;
  636. }
  637. private void DoDefenseSucces(EnemyHurtAtkEventArgs.PlayerNormalAtkData atkData, Vector3 pos)
  638. {
  639. R.Effect.Generate(157, base.transform.Find("HurtBox"), default(Vector3), default(Vector3), default(Vector3), true);
  640. this.action.FaceToPlayer();
  641. this.action.DefenceSuccess();
  642. this.HitEffect(pos, atkData.atkName);
  643. }
  644. private void NotInDefense()
  645. {
  646. if (this.canChangeFace && !this.eAttr.paBody && this.eAttr.currentActionInterruptPoint >= this.eAttr.actionInterruptPoint)
  647. {
  648. int dir = (R.Player.Attribute.faceDir != 1) ? 1 : -1;
  649. this.action.ChangeFace(dir);
  650. }
  651. }
  652. private void DoFefenseBreak()
  653. {
  654. R.Audio.PlayEffect(192, new Vector3?(base.transform.position));
  655. R.Effect.Generate(160, base.transform.Find("HurtBox"), default(Vector3), default(Vector3), default(Vector3), true);
  656. Core.Input.Vibration.Vibrate(4);
  657. this.eAttr.currentActionInterruptPoint = 0;
  658. this.defecnceBreak = true;
  659. this.eAttr.paBody = false;
  660. }
  661. private bool DoWeak(Vector3 pos, Vector2 speed, Vector2 airSpeed, EnemyBaseHurt.HurtAttribute hurtAttr, EnemyHurtAtkEventArgs.PlayerNormalAtkData atkData)
  662. {
  663. if (this.BloodWeak())
  664. {
  665. this.HitIntoWeakState(speed, airSpeed, hurtAttr.normalAtkType, hurtAttr.airAtkType);
  666. this.HitIntoWeakEffect(pos, atkData.atkName);
  667. return true;
  668. }
  669. return false;
  670. }
  671. private void DoHurt(EnemyHurtAtkEventArgs.PlayerNormalAtkData atkData, Vector2 speed, Vector2 airSpeed, EnemyBaseHurt.HurtAttribute hurtAttr)
  672. {
  673. this.PlayHurtAudio();
  674. if (!this.eAttr.isDead && HurtDataTools.ChaseAttack())
  675. {
  676. this.currentChaseTime = 0;
  677. this.ChaseStart();
  678. }
  679. this.SpAttack();
  680. this.PhysicAndEffect(speed, airSpeed, hurtAttr.normalAtkType, hurtAttr.airAtkType);
  681. this.TimeFrozenAndCameraShake(atkData.frozenFrame, atkData.shakeFrame, atkData.shakeType, atkData.camShakeFrame, atkData.shakeStrength);
  682. }
  683. protected virtual void FlashAttackHurt()
  684. {
  685. HurtDataTools.FlashHPRecover();
  686. if (this.eAttr.rankType == EnemyAttribute.RankType.Normal)
  687. {
  688. this.Execute("NewExecute1_2", false);
  689. }
  690. else if (this.flashPercent)
  691. {
  692. R.Effect.Generate(127, base.transform, default(Vector3), default(Vector3), default(Vector3), true);
  693. }
  694. Core.Input.Vibration.Vibrate(4);
  695. if (this.BloodWeak())
  696. {
  697. this.action.EnterWeakState();
  698. if (!base.IsInvoking("ExitWeak"))
  699. {
  700. base.Invoke("ExitWeak", 5f);
  701. }
  702. }
  703. }
  704. public virtual void QTEHurt()
  705. {
  706. if (this.eAttr.rankType == EnemyAttribute.RankType.Normal)
  707. {
  708. return;
  709. }
  710. this.eAttr.willBeExecute = false;
  711. this.eAttr.inWeakState = false;
  712. this.eAttr.isFlyingUp = false;
  713. this.eAttr.checkHitGround = false;
  714. this.eAttr.timeController.SetGravity(1f);
  715. this.SetHitSpeed(Vector2.zero);
  716. this.action.hurtBox.gameObject.SetActive(true);
  717. this.currentPhase = Mathf.Clamp(this.currentPhase + 1, 0, this.maxPhase);
  718. this.ExecuteDieEffect();
  719. SingletonMono<WorldTime>.Instance.TimeSlowByFrameOn60Fps(30, 0.2f);
  720. R.Camera.Controller.CameraShake(0.5f, 0.3f, CameraController.ShakeTypeEnum.Rect, false);
  721. R.Effect.Generate(127, base.transform, default(Vector3), default(Vector3), default(Vector3), true);
  722. }
  723. protected virtual void ExecuteFollow()
  724. {
  725. int dir = (this.player.transform.localScale.x >= 0f) ? 1 : -1;
  726. this.action.ChangeFace(dir);
  727. this.action.WeakEffectDisappear("RollEnd");
  728. this.eAttr.followLeftHand = true;
  729. this.eAttr.willBeExecute = true;
  730. this.eAttr.checkHitGround = false;
  731. this.eAttr.flyToFall = false;
  732. this.eAttr.isFlyingUp = false;
  733. this.SetHitSpeed(Vector2.zero);
  734. this.eAttr.timeController.SetGravity(0f);
  735. base.StartCoroutine(this.ClipShake(17));
  736. }
  737. protected virtual void SpAttack()
  738. {
  739. if (this.eAttr.currentActionInterruptPoint < this.eAttr.actionInterruptPoint)
  740. {
  741. return;
  742. }
  743. }
  744. public void ChaseStart()
  745. {
  746. if (this.action.IsInWeakSta())
  747. {
  748. return;
  749. }
  750. if (this.player.GetComponent<PlayerAbilities>().flashAttack.CheckEnemy(base.gameObject))
  751. {
  752. return;
  753. }
  754. if (this.currentChaseTime > 2)
  755. {
  756. return;
  757. }
  758. this.currentChaseTime++;
  759. this.chaseEnd = 0f;
  760. this.eAttr.canBeChased = true;
  761. if (this._chaseCoroutine != null)
  762. {
  763. base.StopCoroutine(this._chaseCoroutine);
  764. }
  765. this._chaseCoroutine = base.StartCoroutine(this.ChaseCoroutine());
  766. }
  767. private IEnumerator ChaseCoroutine()
  768. {
  769. yield return new WaitForSeconds(0.3f);
  770. this.ChaseAttack();
  771. yield return new WaitForSeconds(0.3f);
  772. this.ChaseAttack();
  773. this.ChaseEnd();
  774. yield break;
  775. }
  776. private void ChaseAttack()
  777. {
  778. Vector3 position = base.transform.position;
  779. R.Audio.PlayEffect(UnityEngine.Random.Range(18, 21), new Vector3?(base.transform.position));
  780. position.y = Mathf.Clamp(position.y, LayerManager.YNum.GetGroundHeight(base.gameObject), float.MaxValue);
  781. Transform transform = R.Effect.Generate(182, null, position, default(Vector3), default(Vector3), true);
  782. Vector3 localScale = transform.localScale;
  783. localScale.x = (float)((UnityEngine.Random.Range(0, 2) != 0) ? -1 : 1);
  784. transform.localScale = localScale;
  785. }
  786. public void ChaseEnd()
  787. {
  788. this.chaseEnd = 0f;
  789. this.currentChaseTime = 0;
  790. this.eAttr.canBeChased = false;
  791. }
  792. protected void Execute(string playerState, bool chargeUp = true)
  793. {
  794. this.eAttr.willBeExecute = false;
  795. this.eAttr.inWeakState = false;
  796. this.action.hurtBox.gameObject.SetActive(true);
  797. this.playerAtkName = playerState;
  798. this.ExecuteDie();
  799. if (chargeUp || this.flashPercent)
  800. {
  801. R.Effect.Generate(127, base.transform, default(Vector3), default(Vector3), default(Vector3), true);
  802. }
  803. }
  804. protected virtual void ExecuteDie()
  805. {
  806. R.Audio.PlayEffect(UnityEngine.Random.Range(105, 108), new Vector3?(base.transform.position));
  807. this.deadFlag = true;
  808. this.eAttr.currentHp = 0;
  809. this.eAttr.inWeakState = false;
  810. this.eAttr.isFlyingUp = false;
  811. this.eAttr.checkHitGround = false;
  812. this.eAttr.stiffTime = 0f;
  813. this.eAttr.timeController.SetGravity(1f);
  814. EventManager.PostEvent<EnemyAttribute>("EnemyKilled", this.eAttr);
  815. this.action.WeakEffectDisappear("Null");
  816. R.Effect.Generate(91, null, base.transform.position + new Vector3(0f, 1.2f, LayerManager.ZNum.Fx), Vector3.zero, default(Vector3), true);
  817. R.Effect.Generate(49, base.transform, default(Vector3), default(Vector3), default(Vector3), true);
  818. R.Effect.Generate(14, null, base.transform.position + new Vector3(0f, 1.2f, LayerManager.ZNum.Fx), default(Vector3), default(Vector3), true);
  819. this.AddCoinAndExp();
  820. this.ExecuteDieEffect();
  821. R.Effect.Generate(213, null, default(Vector3), default(Vector3), default(Vector3), true);
  822. R.Effect.Generate(214, null, default(Vector3), default(Vector3), default(Vector3), true);
  823. SingletonMono<WorldTime>.Instance.TimeSlowByFrameOn60Fps(45, 0.2f);
  824. R.Camera.Controller.CameraShake(0.9166667f, 0.3f, CameraController.ShakeTypeEnum.Rect, false);
  825. R.Camera.Controller.OpenMotionBlur(0.13333334f, 1f, base.transform.position);
  826. }
  827. public virtual void EnemyDie()
  828. {
  829. if (this.eAttr.rankType != EnemyAttribute.RankType.Normal)
  830. {
  831. return;
  832. }
  833. R.Audio.PlayEffect(UnityEngine.Random.Range(105, 108), new Vector3?(base.transform.position));
  834. this.deadFlag = true;
  835. this.eAttr.inWeakState = false;
  836. this.eAttr.isFlyingUp = false;
  837. this.eAttr.checkHitGround = false;
  838. this.eAttr.stiffTime = 0f;
  839. this.eAttr.timeController.SetGravity(1f);
  840. EventManager.PostEvent<EnemyAttribute>("EnemyKilled", this.eAttr);
  841. this.action.WeakEffectDisappear("Null");
  842. base.StartCoroutine(this.GenerateEnergyBall());
  843. this.AddCoinAndExp();
  844. }
  845. private IEnumerator GenerateEnergyBall()
  846. {
  847. yield return new WaitForSeconds(0.8f);
  848. R.Effect.Generate(91, null, base.transform.position + new Vector3(0f, 1.2f, LayerManager.ZNum.Fx), Vector3.zero, default(Vector3), true);
  849. yield break;
  850. }
  851. protected void AddCoinAndExp()
  852. {
  853. R.Equipment.CoinNum += this.eAttr.dropCoins;
  854. }
  855. protected void DieTimeControl()
  856. {
  857. SingletonMono<WorldTime>.Instance.TimeFrozenByFixedFrame(25, WorldTime.FrozenArgs.FrozenType.Enemy, true);
  858. R.Camera.Controller.CameraShake(0.416666657f, 0.3f, CameraController.ShakeTypeEnum.Rect, false);
  859. if (base.gameObject.activeSelf)
  860. {
  861. base.StartCoroutine(this.ClipShake(12));
  862. }
  863. }
  864. public void NormalKill()
  865. {
  866. R.Audio.PlayEffect(24, new Vector3?(base.transform.position));
  867. R.Camera.Controller.CameraBloom(0.25f, 0f);
  868. R.Effect.Generate(49, base.transform, new Vector3(0f, 1.2f, LayerManager.ZNum.Fx), Vector3.zero, default(Vector3), true);
  869. R.Effect.Generate(9, base.transform, new Vector3(0f, 1.2f, LayerManager.ZNum.Fx), new Vector3(0f, 0f, 0f), default(Vector3), true);
  870. R.Effect.Generate(14, base.transform, new Vector3(0f, 1.2f, -0.1f), new Vector3(0f, 0f, 0f), default(Vector3), true);
  871. }
  872. protected virtual void ExecuteDieEffect()
  873. {
  874. R.Effect.Generate(156, null, this.center.position, default(Vector3), default(Vector3), true);
  875. }
  876. protected virtual IEnumerator DeathIEnumerator()
  877. {
  878. bool deadFly = true;
  879. bool deadFall = false;
  880. while (this.eAttr.isDead)
  881. {
  882. if (deadFly && this.eAttr.timeController.GetCurrentSpeed().y <= 0f)
  883. {
  884. deadFly = false;
  885. deadFall = true;
  886. this.action.AnimChangeState(this.airDieAnimName, 1f);
  887. }
  888. if (deadFall && this.eAttr.isOnGround)
  889. {
  890. deadFall = false;
  891. this.action.AnimChangeState(this.airDieHitGroundAnimName, 1f);
  892. }
  893. yield return null;
  894. }
  895. yield break;
  896. }
  897. public bool canCounterattack;
  898. public Transform center;
  899. public int currentPhase;
  900. public const int maxChaseTime = 2;
  901. public int currentChaseTime;
  902. protected int hurtId;
  903. protected bool deadFlag;
  904. protected string defaultAnimName;
  905. protected string defaultAirAnimName;
  906. protected string airDieAnimName;
  907. protected string airDieHitGroundAnimName;
  908. protected string flyToFallAnimName;
  909. protected Pivot Pivot;
  910. protected EnemyAttribute eAttr;
  911. protected EnemyBaseAction action;
  912. protected JsonData hurtData;
  913. protected string playerAtkName;
  914. protected bool actionInterrupt;
  915. protected bool defecnceBreak;
  916. protected int spHurtAudio;
  917. [SerializeField]
  918. private List<int> _phaseHp;
  919. protected int maxPhase;
  920. [SerializeField]
  921. private Transform atkBox;
  922. [SerializeField]
  923. private bool canChangeFace = true;
  924. [SerializeField]
  925. private Transform frameShakeBody;
  926. private EnemyArmor armor;
  927. [SerializeField]
  928. private Vector3 centerOffset;
  929. [SerializeField]
  930. [Header("左右抖动幅度")]
  931. private float m_frameShakeOffset;
  932. [SerializeField]
  933. private int[] hpPercent;
  934. private float frameShakeOffset;
  935. private float defenceTrigger;
  936. private float sideStepTrigger;
  937. private float chaseEnd;
  938. private int exitWeakPhase;
  939. private bool qteCameraEffectOn;
  940. private Coroutine _chaseCoroutine;
  941. private class HurtAttribute
  942. {
  943. public HurtAttribute(JsonData hurt, string defaultAnimName, string defaultAirAnimName)
  944. {
  945. this.xSpeed = hurt.Get<float>("xSpeed", 0f);
  946. this.ySpeed = hurt.Get<float>("ySpeed", 0f);
  947. this.airXSpeed = hurt.Get<float>("airXSpeed", 0f);
  948. this.airYSpeed = hurt.Get<float>("airYSpeed", 0f);
  949. this.normalAtkType = hurt.Get<string>("normalAtkType", defaultAnimName);
  950. this.airAtkType = hurt.Get<string>("airAtkType", defaultAirAnimName);
  951. }
  952. public float xSpeed;
  953. public float ySpeed;
  954. public float airXSpeed;
  955. public float airYSpeed;
  956. public string normalAtkType;
  957. public string airAtkType;
  958. }
  959. }