AttackTrigger.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using Base.Common;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class AttackTrigger : MonoBehaviour
  6. {
  7. public enum attackTpye
  8. {
  9. summon = 0,
  10. march = 1,
  11. }
  12. [Header("是否是远程角色")]
  13. public bool isShoot;
  14. public attackTpye type;
  15. public Character owner;
  16. [Header("是否为单体攻击")]
  17. public bool isSingleAttack;
  18. [Header("攻击对象")]
  19. public List<BeHitTrigger> trigedObjs;
  20. [Header("攻击属性")]
  21. public int damage;
  22. public Vector3 force;
  23. public bool changeHurt;
  24. public float repelValue;
  25. public int offsetY = 1;
  26. public float hitRate = 1;
  27. private bool isInVain; //击中光球,攻击无效
  28. [Header("只有空中单位会被造成眩晕")]
  29. public bool onlyFlyCanWeak;
  30. private void Awake()
  31. {
  32. owner = GetComponentInParent<Character>();
  33. }
  34. private void OnTriggerEnter(Collider other)
  35. {
  36. if (isInVain)
  37. {
  38. return;
  39. }
  40. Photosphere photosphere = other.GetComponentInParent<Photosphere>();
  41. if (photosphere && Util.CheckCanHit(owner.tag, "Player"))
  42. {
  43. isInVain = true;
  44. photosphere.Reflex(owner.beHitTrigger, damage);
  45. return;
  46. }
  47. BeHitTrigger hitTrigger = other.GetComponent<BeHitTrigger>();
  48. if (hitTrigger != null)
  49. {
  50. bool triged = false;
  51. for (int i = 0; i < trigedObjs.Count; i++)
  52. {
  53. if (trigedObjs[i] == hitTrigger)
  54. {
  55. triged = true;
  56. break;
  57. }
  58. }
  59. if (!triged)
  60. {
  61. trigedObjs.Add(hitTrigger);
  62. }
  63. }
  64. }
  65. private void OnEnable()
  66. {
  67. trigedObjs.Clear();
  68. }
  69. private void OnDisable()
  70. {
  71. if (isShoot)
  72. {
  73. CharacterColliders cc = GetComponentInParent<CharacterColliders>();
  74. switch (type)
  75. {
  76. case attackTpye.summon:
  77. cc.Attack_summonShootEvent(0);
  78. break;
  79. case attackTpye.march:
  80. cc.Attack_marchShootEvent(0);
  81. break;
  82. }
  83. }
  84. else
  85. {
  86. int attackTimeLimit = 1;
  87. if (isInVain)
  88. {
  89. isInVain = false;
  90. }
  91. else
  92. {
  93. for (int i = 0; i < trigedObjs.Count; i++)
  94. {
  95. if (trigedObjs[i] && Util.CheckCanHit(owner.tag, trigedObjs[i].owner.tag) && !trigedObjs[i].owner.isDie)
  96. {
  97. if (isSingleAttack && attackTimeLimit == 0)
  98. {
  99. break;
  100. }
  101. if (onlyFlyCanWeak && !trigedObjs[i].owner.canFly)
  102. {
  103. MoveCharacter moveCharacter = trigedObjs[i].owner.GetComponent<MoveCharacter>();
  104. if (moveCharacter)
  105. {
  106. moveCharacter.newTotalWeakTime = 0;
  107. }
  108. }
  109. //计算护甲减免
  110. int curDamage = damage;
  111. int am = trigedObjs[i].owner.armor;
  112. if (am > 0)
  113. {
  114. int ap = owner.armorPiercing;
  115. int c = am - ap;
  116. if (c < 0)
  117. {
  118. c = 0;
  119. }
  120. curDamage = (int)(curDamage * (100f / (100 + c)) + 0.5f);
  121. }
  122. trigedObjs[i].BeHit(curDamage, force, changeHurt, repelValue);
  123. if (trigedObjs[i].owner.debugAttackFrom)
  124. {
  125. trigedObjs[i].owner.DebugAttackFrom(owner.name, curDamage);
  126. }
  127. if (owner.GetComponent<Demonic>())
  128. {
  129. trigedObjs[i].attackerID = owner.GetComponent<Demonic>().id;
  130. }
  131. if (isSingleAttack)
  132. {
  133. attackTimeLimit--;
  134. }
  135. }
  136. }
  137. }
  138. }
  139. }
  140. }