Exemplo n.º 1
0
 public AIHitInfo(AIAttackObject attackObject, AIHitBox hitBox, Collider targetCollider, Vector3 hitPoint)
 {
     this.aiattackObject = attackObject;
     this.aiHitBox       = hitBox;
     this.targetCollider = targetCollider;
     this.hitPoint       = hitPoint;
 }
Exemplo n.º 2
0
    void Start()
    {
        #region GETTING COMPONENTS

        currentHealth = maxHealth;
        var skinRender = GetComponentsInChildren <SkinnedMeshRenderer>();


        foreach (var mesh in skinRender)
        {
            render = mesh.GetComponentInChildren <SkinnedMeshRenderer>();
        }

        healthBar = GetComponentInChildren <UIHealthBar>();

        #endregion

        #region GETTING RIGIDBODIES

        var rigidBodies = GetComponentsInChildren <Rigidbody>();
        foreach (var rb in rigidBodies)
        {
            AIHitBox hitBox = rb.gameObject.AddComponent <AIHitBox>();
            hitBox.health = this;
            if (hitBox.gameObject != gameObject)
            {
                hitBox.gameObject.layer = LayerMask.NameToLayer("Hitbox");
            }
        }

        #endregion

        OnStart();
    }
Exemplo n.º 3
0
    /// <summary>
    /// Apply damage to target collider (SendMessage(TakeDamage,damage))
    /// </summary>
    /// <param name="hitBox">vHitBox object</param>
    /// <param name="other">collider target</param>
    /// <param name="damage"> damage</param>
    public void ApplyDamage(AIHitBox hitBox, Collider other, Damage damage)
    {
        Damage _damage = new Damage(damage);

        _damage.damageValue = (int)Mathf.RoundToInt(((float)(damage.damageValue + damageModifier) * (((float)hitBox.damagePercentage) * 0.01f)));
        //_damage.sender = transform;
        _damage.hitPosition = hitBox.transform.position;
        if (other.gameObject.IsAMeleeFighter())
        {
            other.gameObject.GetMeleeFighter().OnReceiveAttack(_damage, aiManager.fighter);
        }
        else if (other.gameObject.CanReceiveDamage())
        {
            other.gameObject.ApplyDamage(_damage);
        }
    }
Exemplo n.º 4
0
    public virtual void OnHit(AIHitBox hitBox, Collider other)
    {
        //Check  first contition for hit
        if (canApplyDamage && !targetColliders[hitBox].Contains(other.gameObject) && (aiManager != null && other.gameObject != aiManager.gameObject))
        {
            var inDamage = false;

            if (aiManager == null)
            {
                aiManager = GetComponentInParent <AIManager>();
            }
            //check if meleeManager exist and apply  his hitProperties  to this
            HitProperties _hitProperties = aiManager.hitProperties;

            /// Damage Conditions
            if ((_hitProperties.hitDamageTags.Contains(other.tag)))
            {
                inDamage = true;
            }

            if (inDamage)
            {
                ///add target collider in list to control frequency of hit him
                targetColliders[hitBox].Add(other.gameObject);
                AIHitInfo hitInfo = new AIHitInfo(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 (aiManager)
                    {
                        aiManager.OnDamageHit(hitInfo);
                    }
                    else
                    {
                        damage.sender = transform;
                        ApplyDamage(hitBox, other, damage);
                    }
                    onDamageHit.Invoke(hitInfo);
                }
            }
        }
    }