Beispiel #1
0
 public vHitInfo(vMeleeAttackObject attackObject, vHitBox hitBox, Collider targetCollider, Vector3 hitPoint)
 {
     this.attackObject   = attackObject;
     this.hitBox         = hitBox;
     this.targetCollider = targetCollider;
     this.hitPoint       = hitPoint;
 }
Beispiel #2
0
        /// <summary>
        /// Apply damage to target collider (TakeDamage, damage))
        /// </summary>
        /// <param name="hitBox">vHitBox object</param>
        /// <param name="other">collider target</param>
        /// <param name="damage"> damage</param>
        public void ApplyDamage(vHitBox hitBox, Collider other, vDamage damage)
        {
            vDamage _damage = new vDamage(damage);

            _damage.receiver    = other.transform;
            _damage.damageValue = (int)Mathf.RoundToInt(((float)(damage.damageValue + damageModifier) * (((float)hitBox.damagePercentage) * 0.01f)));
            _damage.hitPosition = hitBox.transform.position;
            other.gameObject.ApplyDamage(_damage, meleeManager.fighter);
        }
Beispiel #3
0
        /// <summary>
        /// Apply damage to target collider (TakeDamage, damage))
        /// </summary>
        /// <param name="hitBox">vHitBox object</param>
        /// <param name="other">collider target</param>
        /// <param name="damage"> damage</param>
        public bool ApplyDamage(vHitBox hitBox, Collider other, vDamage damage)
        {
            vDamage _damage = new vDamage(damage);

            _damage.receiver    = other.transform;
            _damage.damageValue = Mathf.RoundToInt(((damage.damageValue + damageModifier) * (hitBox.damagePercentage * 0.01f)));
            _damage.hitPosition = hitBox.transform.position;
            other.gameObject.ApplyDamage(_damage, meleeManager.fighter);

            return(_damage.hitReaction);
        }
Beispiel #4
0
        /// <summary>
        /// Call Back of hitboxes
        /// </summary>
        /// <param name="hitBox">vHitBox object</param>
        /// <param name="other">target Collider</param>
        public virtual void OnHit(vHitBox hitBox, Collider other)
        {
            //Check  first contition for hit
            if (canApplyDamage && !targetColliders[hitBox].Contains(other.gameObject) && (meleeManager != null && other.gameObject != meleeManager.gameObject))
            {
                var inDamage = false;
                var inRecoil = false;
                if (meleeManager == null)
                {
                    meleeManager = GetComponentInParent <vMeleeManager>();
                }
                //check if meleeManager exist and apply  his hitProperties  to this
                HitProperties _hitProperties = meleeManager.hitProperties;

                /// Damage Conditions
                if (((hitBox.triggerType & vHitBoxType.Damage) != 0) && _hitProperties.hitDamageTags == null || _hitProperties.hitDamageTags.Count == 0)
                {
                    inDamage = true;
                }
                else if (((hitBox.triggerType & vHitBoxType.Damage) != 0) && _hitProperties.hitDamageTags.Contains(other.tag))
                {
                    inDamage = true;
                }
                else   ///Recoil Conditions
                if (((hitBox.triggerType & vHitBoxType.Recoil) != 0) && (_hitProperties.hitRecoilLayer == (_hitProperties.hitRecoilLayer | (1 << other.gameObject.layer))))
                {
                    inRecoil = true;
                }
                if (inDamage || inRecoil)
                {
                    ///add target collider in list to control frequency of hit him
                    targetColliders[hitBox].Add(other.gameObject);
                    vHitInfo hitInfo = new vHitInfo(this, hitBox, other, hitBox.transform.position);
                    if (inDamage == true)
                    {
                        /// If meleeManager
                        /// call onDamageHit to control damage values
                        /// and  meleemanager will call the ApplyDamage after to filter the damage
                        /// if meleeManager is null
                        /// The damage will be  directly applied
                        /// Finally the OnDamageHit event is called
                        if (meleeManager)
                        {
                            meleeManager.OnDamageHit(hitInfo);
                        }
                        else
                        {
                            damage.sender = transform;
                            ApplyDamage(hitBox, other, damage);
                        }
                        onDamageHit.Invoke(hitInfo);
                    }
                    /// Recoil just work with OnRecoilHit event and meleeManger
                    if (inRecoil == true)
                    {
                        if (meleeManager)
                        {
                            meleeManager.OnRecoilHit(hitInfo);
                        }
                        onRecoilHit.Invoke(hitInfo);
                    }
                }
            }
        }