SupplyBoxHurt.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. using System;
  2. using BasicTools;
  3. using DG.Tweening;
  4. using ExtensionMethods;
  5. using GameWorld;
  6. using UnityEngine;
  7. public class SupplyBoxHurt : BaseBehaviour
  8. {
  9. private void Awake()
  10. {
  11. this.action = base.GetComponent<SupplyBoxAction>();
  12. this.attribute = base.GetComponent<SupplyAttribute>();
  13. }
  14. private void OnEnable()
  15. {
  16. EventManager.RegisterEvent<EnemyHurtAtkEventArgs>("EnemyHurtAtk", new EventManager.FBEventHandler<EnemyHurtAtkEventArgs>(this.EventHurt), EventManager.ListenerQueue.Game);
  17. }
  18. private void OnDisable()
  19. {
  20. EventManager.UnregisterEvent<EnemyHurtAtkEventArgs>("EnemyHurtAtk", new EventManager.FBEventHandler<EnemyHurtAtkEventArgs>(this.EventHurt), EventManager.ListenerQueue.Game);
  21. }
  22. private void Update()
  23. {
  24. }
  25. private bool EventHurt(string eventName, object sender, EnemyHurtAtkEventArgs args)
  26. {
  27. if (args.hurted != base.gameObject)
  28. {
  29. return false;
  30. }
  31. EnemyHurtAtkEventArgs.HurtTypeEnum hurtType = args.hurtType;
  32. if (hurtType != EnemyHurtAtkEventArgs.HurtTypeEnum.Normal)
  33. {
  34. return false;
  35. }
  36. this.Hurt();
  37. return true;
  38. }
  39. private void Hurt()
  40. {
  41. if (this.attribute.Opened || this.attribute.CurrentHp == 0u)
  42. {
  43. return;
  44. }
  45. if (!DOTween.IsTweening(base.transform, false))
  46. {
  47. base.transform.DOShakePosition(0.2f, new Vector3(0.2f, 0.2f, 0f), 20, 90f, false, true);
  48. R.Audio.PlayEffect(401, new Vector3?(base.transform.position));
  49. }
  50. this.attribute.CurrentHp -= 1u;
  51. switch (this.attribute.SupplyBox)
  52. {
  53. case SupplyAttribute.SupplyBoxType.Money:
  54. this.action.ChangeState(SupplyBoxAction.StateEnum.MoneyHit);
  55. return;
  56. case SupplyAttribute.SupplyBoxType.Cheat:
  57. switch (this.attribute.CurrentHp / (this.attribute.MaxHp / 4u))
  58. {
  59. case 0u:
  60. this.action.ChangeState(SupplyBoxAction.StateEnum.WPLv3ToLv4);
  61. break;
  62. case 1u:
  63. this.action.ChangeState(SupplyBoxAction.StateEnum.WPLv2ToLv3);
  64. break;
  65. case 2u:
  66. this.action.ChangeState(SupplyBoxAction.StateEnum.WPLv1ToLv2);
  67. break;
  68. case 3u:
  69. this.action.ChangeState(SupplyBoxAction.StateEnum.WPLv0ToLv1);
  70. break;
  71. }
  72. return;
  73. case SupplyAttribute.SupplyBoxType.Flash:
  74. switch (this.attribute.CurrentHp / (this.attribute.MaxHp / 4u))
  75. {
  76. case 0u:
  77. this.action.ChangeState(SupplyBoxAction.StateEnum.EnLv3ToLv4);
  78. break;
  79. case 1u:
  80. this.action.ChangeState(SupplyBoxAction.StateEnum.EnLv2ToLv3);
  81. break;
  82. case 2u:
  83. this.action.ChangeState(SupplyBoxAction.StateEnum.EnLv1ToLv2);
  84. break;
  85. case 3u:
  86. this.action.ChangeState(SupplyBoxAction.StateEnum.EnLv0ToLv1);
  87. break;
  88. }
  89. return;
  90. }
  91. throw new ArgumentOutOfRangeException();
  92. }
  93. private void SupplyBroken()
  94. {
  95. SupplyAttribute.SupplyBoxType supplyBox = this.attribute.SupplyBox;
  96. if (supplyBox != SupplyAttribute.SupplyBoxType.Cheat)
  97. {
  98. if (supplyBox != SupplyAttribute.SupplyBoxType.Flash)
  99. {
  100. if (supplyBox == SupplyAttribute.SupplyBoxType.Money)
  101. {
  102. this.action.ChangeState(SupplyBoxAction.StateEnum.MoneyNull);
  103. Transform transform = R.Effect.Generate(192, base.transform, default(Vector3), default(Vector3), default(Vector3), true);
  104. transform.GetComponent<Coin>().GenerateCoin(1.5f, 8, this.attribute.Bonus);
  105. R.Audio.PlayEffect(464, new Vector3?(base.transform.position));
  106. }
  107. }
  108. else
  109. {
  110. this.action.ChangeState(SupplyBoxAction.StateEnum.EnLv4ToNull);
  111. this.SupplyBoxAnim(189);
  112. }
  113. }
  114. else
  115. {
  116. this.action.ChangeState(SupplyBoxAction.StateEnum.WPLv4ToNull);
  117. this.SupplyBoxAnim(188);
  118. }
  119. }
  120. private Transform SupplyBoxAnim(int effectId)
  121. {
  122. R.Audio.PlayEffect(265, new Vector3?(base.transform.position));
  123. Transform transform = R.Effect.Generate(effectId, null, Camera.main.transform.position.AddY(-2.4f).SetZ(-5f), Vector3.zero, Vector3.zero, false);
  124. transform.gameObject.AddComponent<FollowGameObject>().Init(Camera.main.transform, new Vector3(0f, -2.4f, -5f), FollowGameObject.IgnoreParam.Z);
  125. return transform;
  126. }
  127. public void OpenDetect()
  128. {
  129. if (!this.attribute.Opened && this.attribute.CurrentHp == 0u)
  130. {
  131. this.attribute.Opened = true;
  132. this.SupplyBroken();
  133. }
  134. }
  135. private SupplyBoxAction action;
  136. private SupplyAttribute attribute;
  137. }