/// <summary>
 /// Check collision and apply damage if other object is enemy
 /// </summary>
 /// <param name="other"></param>
 public void OnTriggerEnter(Collider other)
 {
     if (alive)
     {
         TriggerSender ts = other.GetComponent <TriggerSender>();
         if (ts != null)
         {
             GameObject triggerReciever = ts.GetReciever().GetRecieverGameObject();
             IDamagable damagable       = triggerReciever.GetComponent <IDamagable>();
             if (damagable != null)
             {
                 if ((damagable.GetFaction() & oppositeFaction) != 0)
                 {
                     if (damagable.RecieveAttack(gameObject, other, attackDamage, dir, attackForce))
                     {
                         SoundManager.GetInstance().Play(destructionClip);
                         Clear();
                     }
                 }
             }
         }
         else
         {
             if (other.CompareTag("Enviorment"))
             {
                 SoundManager.GetInstance().Play(destructionClip);
                 Clear();
             }
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Checks for an IDamagable on the target GameObject, then attempts to call its ApplyDamage method.
        /// If an IDamagable isn't found, returns false.
        /// </summary>
        /// <param name="damageTarget"> The Target to look for an IDamagable on.</param>
        /// <param name="e"> Damage Event Arguments.</param>
        /// <returns></returns>
        public virtual bool TryDealDamage(GameObject damageTarget, Damage.DamageEventArgs e)
        {
            if (!CanDealDamage)
            {
                return(false);
            }
            if (e.DamageValue <= 0)
            {
                return(false);
            }
            IDamagable damagable = damageTarget.GetComponent <IDamagable>();

            if (damagable != null)
            {
                if (this.faction == damagable.GetFaction())
                {
                    return(false);
                }
                damagable.ApplyDamage(this, e);
                OnDealDamage(this, e);
                return(true);
            }
            // No IDamagable Found - Return false.
            return(false);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Apply damage to player if self attackHitbox collides with it.
 /// </summary>
 /// <param name="origin">GameObject on which OnTriggerExit method was called.</param>
 /// <param name="other">Collider data of the OnTriggerExit method.</param>
 public void OnExtensionTriggerEnter(GameObject origin, Collider other)
 {
     if (origin == attackHitbox)
     {
         IDamagable damagable = other.GetComponent <IDamagable>();
         if (damagable != null)
         {
             if ((damagable.GetFaction() & oppositeFaction) != 0)
             {
                 damagable.Damage(stats.attackDamageMultiplier, lookingDirection, stats.attackForceMultiplier);
             }
         }
     }
 }
Ejemplo n.º 4
0
    /// <summary>
    /// Evaluate trigger and damage other instance.
    /// </summary>
    /// <param name="col"></param>
    void OnTriggerStay(Collider col)
    {
        IDamagable    other = null;
        TriggerSender ts    = col.gameObject.GetComponent <TriggerSender>();

        // Get IDamagable component on child or parent.
        if (ts != null)
        {
            other = ts.GetReciever().GetRecieverGameObject().GetComponent <IDamagable>();
        }
        if (other == null)
        {
            other = col.gameObject.GetComponent <IDamagable>();
        }

        // Check not null and other faction.
        if (other != null && (other.GetFaction() & targetFaction) != 0)
        {
            // Check state
            switch (state)
            {
            case SpikeState.hidden: {
                // Prepare spikes
                state = SpikeState.anticipated;
                anticipationProgress = 0;
                SoundManager.GetInstance().Play(anticipationClip);
            } break;

            case SpikeState.rised: {
                // Effect damage
                if (ignoreProgress == 0)
                {
                    Vector3 proy = Vector3.ProjectOnPlane(col.gameObject.transform.position - transform.position, Vector3.up);
                    int     dir;
                    if (Mathf.Abs(proy.z) > Mathf.Abs(proy.x))
                    {
                        dir = proy.z > 0 ? 0 : 2;
                    }
                    else
                    {
                        dir = proy.x > 0 ? 3 : 1;
                    }
                    other.Damage(damage, dir, pushForce, stunForce);
                    ignoreProgress = ignoreTime;
                }
            } break;
            }
        }
    }
Ejemplo n.º 5
0
 /// <summary>
 /// Apply damage to player if self attackHitbox collides with it.
 /// </summary>
 /// <param name="origin">GameObject on which OnTriggerExit method was called.</param>
 /// <param name="other">Collider data of the OnTriggerExit method.</param>
 public void OnExtensionTriggerEnter(GameObject origin, Collider other)
 {
     if (origin == attackHitbox)
     {
         TriggerSender ts = other.GetComponent <TriggerSender>();
         if (ts != null)
         {
             GameObject triggerReciever = ts.GetReciever().GetRecieverGameObject();
             IDamagable damagable       = triggerReciever.GetComponent <IDamagable>();
             if (damagable != null)
             {
                 if ((damagable.GetFaction() & oppositeFaction) != 0)
                 {
                     damagable.RecieveAttack(origin, other, stats.attackDamageMultiplier, lookingDirection, stats.attackForceMultiplier);
                 }
             }
         }
     }
 }
Ejemplo n.º 6
0
    /// <summary>
    /// Apply damage to player if the attack hitbox of any of the body trails collides with it.
    /// </summary>
    /// <param name="origin">GameObject on which OnTriggerExit method was called.</param>
    /// <param name="other">Collider data of the OnTriggerExit method.</param>
    public void OnExtensionTriggerEnter(GameObject origin, Collider other)
    {
        if (alive)
        {
            bool attackCollision = false;
            if (origin == attackHitbox)
            {
                attackCollision = true;
            }
            for (int i = 0; i < trailSections.Length; i++)
            {
                if (origin == trailSections[i].gameObject)
                {
                    attackCollision = true;
                    break;
                }
            }

            if (attackCollision)
            {
                TriggerSender ts = other.GetComponent <TriggerSender>();
                if (ts != null)
                {
                    GameObject triggerReciever = ts.GetReciever().GetRecieverGameObject();
                    IDamagable damagable       = triggerReciever.GetComponent <IDamagable>();
                    if (damagable != null)
                    {
                        if ((damagable.GetFaction() & oppositeFaction) != 0)
                        {
                            damagable.RecieveAttack(origin, other, stats.attackDamageMultiplier, Tools.Vector3ToDir4Int(other.transform.position - origin.transform.position), stats.attackForceMultiplier);
                        }
                    }
                }
            }
        }
    }
Ejemplo n.º 7
0
    /// <summary>
    /// Check the colisions of the bodyHitbox and attackHitobx, and respond acordingly.
    /// </summary>
    /// <param name="origin"></param>
    /// <param name="other"></param>
    public void OnExtensionTriggerEnter(GameObject origin, Collider other)
    {
        if (isActive && isAlive && !isDespawning)
        {
            // Check attack
            if (attackCheck && origin == attackHitbox)
            {
                TriggerSender ts = other.GetComponent <TriggerSender>();
                if (ts != null)
                {
                    // Attacking enemy entities
                    GameObject triggerReciever = ts.GetReciever().GetRecieverGameObject();
                    IDamagable damagable       = triggerReciever.GetComponent <IDamagable>();
                    if (damagable != null)
                    {
                        // Apply damage
                        if (!attackWhitelist.Contains(triggerReciever))
                        {
                            if ((damagable.GetFaction() & oppositeFaction) != 0)
                            {
                                bool recieved = damagable.RecieveAttack(origin, other, attackDamage, facingDirection, pushForce, stunForce);
                                if (recieved)
                                {
                                    attackWhitelist.Add(triggerReciever);
                                }
                            }
                        }
                    }
                }
                else
                {
                    // Attacking destructible enviorment.
                    IDamagable damagable = other.GetComponent <IDamagable>();
                    if (damagable != null)
                    {
                        if (!attackWhitelist.Contains(other.gameObject))
                        {
                            if ((damagable.GetFaction() & oppositeFaction) != 0)
                            {
                                bool recieved = damagable.RecieveAttack(origin, other, attackDamage, facingDirection, pushForce, stunForce);
                                if (recieved)
                                {
                                    attackWhitelist.Add(other.gameObject);
                                }
                            }
                        }
                    }
                }
            }

            // Check other collisions
            if (origin == bodyHitbox)
            {
                // Pickups
                if (other.CompareTag("Collectible"))
                {
                    other.GetComponent <ICollectible>().Collect();
                }

                // Level end
                if (other.CompareTag("Endpoint"))
                {
                    if (other.GetComponent <EndpointController>().GoNextLevel())
                    {
                        despawnPosition = other.transform.position;
                        animator.SetTrigger("Despawn");
                        isDespawning = true;
                    }
                }
            }
        }
    }