| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- using Base.Common;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class AttackTrigger : MonoBehaviour
- {
- public enum attackTpye
- {
- summon = 0,
- march = 1,
- }
- [Header("是否是远程角色")]
- public bool isShoot;
- public attackTpye type;
- public Character owner;
- [Header("是否为单体攻击")]
- public bool isSingleAttack;
- [Header("攻击对象")]
- public List<BeHitTrigger> trigedObjs;
- [Header("攻击属性")]
- public int damage;
- public Vector3 force;
- public bool changeHurt;
- public float repelValue;
- public int offsetY = 1;
- public float hitRate = 1;
- private bool isInVain; //击中光球,攻击无效
- [Header("只有空中单位会被造成眩晕")]
- public bool onlyFlyCanWeak;
- private void Awake()
- {
- owner = GetComponentInParent<Character>();
- }
- private void OnTriggerEnter(Collider other)
- {
- if (isInVain)
- {
- return;
- }
- Photosphere photosphere = other.GetComponentInParent<Photosphere>();
- if (photosphere && Util.CheckCanHit(owner.tag, "Player"))
- {
- isInVain = true;
- photosphere.Reflex(owner.beHitTrigger, damage);
- return;
- }
- BeHitTrigger hitTrigger = other.GetComponent<BeHitTrigger>();
- if (hitTrigger != null)
- {
- bool triged = false;
- for (int i = 0; i < trigedObjs.Count; i++)
- {
- if (trigedObjs[i] == hitTrigger)
- {
- triged = true;
- break;
- }
- }
- if (!triged)
- {
- trigedObjs.Add(hitTrigger);
- }
- }
- }
- private void OnEnable()
- {
- trigedObjs.Clear();
- }
- private void OnDisable()
- {
- if (isShoot)
- {
- CharacterColliders cc = GetComponentInParent<CharacterColliders>();
- switch (type)
- {
- case attackTpye.summon:
- cc.Attack_summonShootEvent(0);
- break;
- case attackTpye.march:
- cc.Attack_marchShootEvent(0);
- break;
- }
- }
- else
- {
- int attackTimeLimit = 1;
- if (isInVain)
- {
- isInVain = false;
- }
- else
- {
- for (int i = 0; i < trigedObjs.Count; i++)
- {
- if (trigedObjs[i] && Util.CheckCanHit(owner.tag, trigedObjs[i].owner.tag) && !trigedObjs[i].owner.isDie)
- {
- if (isSingleAttack && attackTimeLimit == 0)
- {
- break;
- }
- if (onlyFlyCanWeak && !trigedObjs[i].owner.canFly)
- {
- MoveCharacter moveCharacter = trigedObjs[i].owner.GetComponent<MoveCharacter>();
- if (moveCharacter)
- {
- moveCharacter.newTotalWeakTime = 0;
- }
- }
- //计算护甲减免
- int curDamage = damage;
- int am = trigedObjs[i].owner.armor;
- if (am > 0)
- {
- int ap = owner.armorPiercing;
- int c = am - ap;
- if (c < 0)
- {
- c = 0;
- }
- curDamage = (int)(curDamage * (100f / (100 + c)) + 0.5f);
- }
- trigedObjs[i].BeHit(curDamage, force, changeHurt, repelValue);
- if (trigedObjs[i].owner.debugAttackFrom)
- {
- trigedObjs[i].owner.DebugAttackFrom(owner.name, curDamage);
- }
- if (owner.GetComponent<Demonic>())
- {
- trigedObjs[i].attackerID = owner.GetComponent<Demonic>().id;
- }
- if (isSingleAttack)
- {
- attackTimeLimit--;
- }
- }
- }
- }
- }
- }
- }
|