예제 #1
0
 //Called when ability is created
 public override void Init(GameObject newOwner)
 {
     base.Init(newOwner);
     //Player should only be able to cancel attack on hit
     abilityData.canCancelActive  = false;
     abilityData.canCancelRecover = false;
     //Get owner health
     _ownerHealth = owner.GetComponent <HealthBehaviour>();
 }
예제 #2
0
        /// <summary>
        /// Stuns the object that came in contact with a link
        /// </summary>
        /// <param name="args"></param>
        private void StunEntity(params object[] args)
        {
            //Get health beahviour
            GameObject      entity       = (GameObject)args[0];
            HealthBehaviour entityHealth = entity.GetComponent <HealthBehaviour>();

            //If there  is a health behaviour...
            if (entityHealth)
            {
                //...stun the entity
                entityHealth.Stun(abilityData.GetCustomStatValue("StunTime"));
            }
        }
        private void OnTriggerEnter(Collider other)
        {
            //If the object has already been hit or if the collider is multihit return
            if (Collisions.Contains(other.gameObject) || IsMultiHit)
            {
                return;
            }

            ColliderBehaviour otherCollider = null;

            if (other.attachedRigidbody)
            {
                if (other.attachedRigidbody.gameObject != Owner)
                {
                    otherCollider = other.attachedRigidbody.gameObject.GetComponentInChildren <ColliderBehaviour>();
                }
                else
                {
                    return;
                }
            }

            if (other.CompareTag("ParryBox"))
            {
                return;
            }

            if (otherCollider && !other.CompareTag("Player") && !other.CompareTag("Entity"))
            {
                if (IgnoreColliders || otherCollider.IgnoreColliders || otherCollider.ColliderOwner == Owner)
                {
                    return;
                }
                else if (otherCollider is HitColliderBehaviour)
                {
                    if (((HitColliderBehaviour)otherCollider).Priority >= Priority && otherCollider.ColliderOwner != ColliderOwner)
                    {
                        Destroy(gameObject);
                        return;
                    }

                    return;
                }
            }

            float newHitAngle = _hitAngle;

            //Calculates new angle if this object should change trajectory based on direction of hit
            if (_adjustAngleBasedOnCollision)
            {
                //Find a vector that point from the collider to the object hit
                Vector3 directionOfImpact = other.transform.position - transform.position;
                directionOfImpact.Normalize();
                directionOfImpact.x = Mathf.Round(directionOfImpact.x);

                //Find the direction this collider was going to apply force originally
                Vector3 currentForceDirection = new Vector3(Mathf.Cos(newHitAngle), Mathf.Sin(newHitAngle), 0);
                currentForceDirection.x *= directionOfImpact.x;

                //Find the new angle based on the direction of the attack on the x axis
                float dotProduct = Vector3.Dot(currentForceDirection, Vector3.right);
                newHitAngle = Mathf.Acos(dotProduct);

                //Find if the angle should be negative or positive
                if (Vector3.Dot(currentForceDirection, Vector3.up) < 0)
                {
                    newHitAngle *= -1;
                }
            }

            //Add the game object to the list of collisions so it is not collided with again
            Collisions.Add(other.gameObject);

            //Grab whatever health script is attached to this object
            HealthBehaviour damageScript = other.GetComponent <HealthBehaviour>();

            if (Owner)
            {
                OwnerName = Owner.name;
            }

            //If the damage script wasn't null damage the object
            if (damageScript != null)
            {
                damageScript.TakeDamage(OwnerName, _damage, _knockBackScale, newHitAngle, damageType, _hitStunTime);
            }

            onHit?.Invoke(other.gameObject, otherCollider);

            if (DestroyOnHit)
            {
                Destroy(gameObject);
            }
        }
        private void OnTriggerStay(Collider other)
        {
            //Only allow damage to be applied this way if the collider is a multi-hit collider
            if (!IsMultiHit || other.gameObject == Owner || !CheckHitTime())
            {
                return;
            }

            ColliderBehaviour otherCollider = null;

            if (other.attachedRigidbody)
            {
                otherCollider = other.attachedRigidbody.gameObject.GetComponent <ColliderBehaviour>();
            }

            if (other.CompareTag("ParryBox"))
            {
                return;
            }

            if (otherCollider && IgnoreColliders)
            {
                return;
            }

            else if (otherCollider is HitColliderBehaviour)
            {
                if (((HitColliderBehaviour)otherCollider).Priority >= Priority && otherCollider.ColliderOwner != ColliderOwner)
                {
                    Destroy(gameObject);
                    return;
                }
                return;
            }

            //Grab whatever health script is attached to this object. If none return
            HealthBehaviour damageScript = other.GetComponent <HealthBehaviour>();


            float newHitAngle = _hitAngle;

            //Calculates new angle if this object should change trajectory based on direction of hit
            if (_adjustAngleBasedOnCollision)
            {
                //Find a vector that point from the collider to the object hit
                Vector3 directionOfImpact = other.transform.position - transform.position;
                directionOfImpact.Normalize();
                directionOfImpact.x = Mathf.Round(directionOfImpact.x);

                //Find the direction this collider was going to apply force originally
                Vector3 currentForceDirection = new Vector3(Mathf.Cos(newHitAngle), Mathf.Sin(newHitAngle), 0);
                currentForceDirection.x *= directionOfImpact.x;

                //Find the new angle based on the direction of the attack on the x axis
                float dotProduct = Vector3.Dot(currentForceDirection, Vector3.right);
                newHitAngle = Mathf.Acos(dotProduct);

                //Find if the angle should be negative or positive
                if (Vector3.Dot(currentForceDirection, Vector3.up) < 0)
                {
                    newHitAngle *= -1;
                }
            }

            if (Owner)
            {
                OwnerName = Owner.name;
            }

            //If the damage script wasn't null damage the object
            if (damageScript != null)
            {
                damageScript.TakeDamage(OwnerName, _damage, _knockBackScale, newHitAngle, damageType, _hitStunTime);
            }

            onHit?.Invoke(other.gameObject);

            if (DestroyOnHit)
            {
                Destroy(gameObject);
            }
        }