Example #1
0
    protected override IEnumerator abilityActionSequence()
    {
        cooldownStartTime = Time.time;

        //Wait until the attack frame in the animation has been reached
        while (!caster.getAttackTrigger().hasAttackTriggered())
        {
            yield return(null);
        }

        caster.getAttackTrigger().resetTrigger();

        //After shot nudge caster back a tad
        caster.rb2D.AddForce(direction * abilityVelocity / Time.timeScale);

        //Instantiate Bullet
        LanceBullet b = ObjectPool.instance.getLanceBullet();

        //Setup and turn on bullet
        b.gameObject.SetActive(true);
        b.Setup(caster, direction);

        //Play sound
        caster.audioSource.clip = abilitySound;
        caster.audioSource.Play();

        RaycastHit2D[] hitObject = Physics2D.RaycastAll(pos, direction, abilityRange, CMoveCombatable.attackMask, -10, 10);
        Debug.DrawRay(pos, direction * abilityRange, Color.blue, 3f);

        //If the Raycast hits an object on the layer Enemy
        foreach (RaycastHit2D r in hitObject)
        {
            if (r && r.transform.gameObject != caster.gameObject && caster.attacking)
            {
                //If an object has been hit first
                if (r.transform.gameObject.tag == "Object")
                {
                    continue;
                }

                //Hit attack
                CHitable        objectHit = r.transform.gameObject.GetComponentInParent <CHitable>();
                CMoveCombatable targetHit = r.transform.gameObject.GetComponentInParent <CMoveCombatable>();

                if (objectHit.isInvuln() || targetHit.faction == caster.faction || targetHit.isDead())
                {
                    continue;
                }

                //Apply damage and knockback
                objectHit.setAttacker(caster);
                objectHit.loseHealth(abilityDamage);
                objectHit.knockback(pos, abilityKnockback, objectHit.objectHeight); //Need to use original pos for knockback so the position of where you attacked from is the knockback
                objectHit.knockUp(pos, abilityKnockback, abilityKnockUp, objectHit.objectHeight);



                if (targetHit != null)
                {
                    targetHit.causeOfDeath = causeOfDeath;
                }

                //caster.audioSource.clip = abilitySound;
                //caster.audioSource.Play();
            }
        }


        caster.canCombo  = false;
        caster.canMove   = true;
        caster.attacking = false;
    }
    protected override IEnumerator abilityActionSequence()
    {
        caster.rb2D.AddForce(direction * abilityVelocity / Time.timeScale);

        while (!caster.getAttackTrigger().hasAttackTriggered())
            yield return null;

        caster.getAttackTrigger().resetTrigger();

        //Check if attack can go through
        if (!caster.isDead())
        {

            Vector2 newPos = new Vector2(caster.transform.position.x, caster.transform.position.y + caster.objectHeight / 2);

            RaycastHit2D[] hitObject = Physics2D.RaycastAll(newPos, direction, abilityRange, CMoveCombatable.attackMask, -10, 10);
            Debug.DrawRay(newPos, direction * abilityRange, Color.red, 3f);

            bool hitTarget = false;

            //If the Raycast hits an object on the layer Enemy
            foreach (RaycastHit2D r in hitObject)
            {

                if (r && r.transform.gameObject != caster.gameObject)
                {
                    //If an object has been hit first
                    if (r.transform.gameObject.tag == "Object")
                    {
                        if (r.collider.isTrigger)
                            continue;
                        else
                            break;
                    }

                    //Hit attack
                    CHitable objectHit = r.transform.gameObject.GetComponentInParent<CHitable>();

                    if (objectHit.tag == caster.tag)
                        continue;

                    //Apply damage and knockback
                    objectHit.setAttacker(caster);
                    objectHit.knockback(pos, abilityKnockback, objectHit.objectHeight); //Need to use original pos for knockback so the position of where you attacked from is the knockback
                    objectHit.knockUp(pos, abilityKnockback, abilityKnockUp, objectHit.objectHeight);
                    objectHit.loseHealth(abilityDamage);

                    CMoveCombatable targetHit = r.transform.gameObject.GetComponentInParent<CMoveCombatable>();

                    if (targetHit != null)
                    {
                        targetHit.causeOfDeath = causeOfDeath;
                    }

                    caster.audioSource.clip = caster.attackSound;
                    caster.audioSource.Play();
                    caster.attackHit();

                    hitTarget = true;
                    break;
                }
            }

            if (!hitTarget)
            {
                caster.audioSource.clip = caster.missSound;
                caster.audioSource.Play();
            }

            if (caster.pauseAfterAttack < 0.5f)
                yield return new WaitForSeconds(0.5f);
            else
                yield return new WaitForSeconds(caster.pauseAfterAttack);
        }
        caster.canMove = true;
        caster.attacking = false;
        caster.canCombo = false;
    }
Example #3
0
    protected override IEnumerator abilityActionSequence()
    {
        //Start Cooldown
        cooldownStartTime = Time.time;

        string oldLayer = LayerMask.LayerToName(caster.gameObject.layer);

        caster.gameObject.layer = C.noCollisionLayer;

        caster.setInvulnerable(timeBeforeRay);

        caster.rb2D.AddForce(direction * abilityVelocity / Time.timeScale);

        yield return(new WaitForSeconds(timeBeforeRay));

        //Check if attack can go through
        if (!caster.isDead())
        {
            //Actual distance travelled by caster
            float distanceCovered = Mathf.Abs(caster.transform.position.x - pos.x);

            RaycastHit2D[] hitObject = Physics2D.RaycastAll(pos, direction, distanceCovered, CMoveCombatable.attackMask, -10, 10);
            Debug.DrawRay(pos, direction * distanceCovered, Color.blue, 3f);

            bool hitTarget = false;

            //If the Raycast hits an object on the layer Enemy
            foreach (RaycastHit2D r in hitObject)
            {
                if (r && r.transform.gameObject != caster.gameObject && caster.attacking)
                {
                    //If an object has been hit first
                    if (r.transform.gameObject.tag == "Object")
                    {
                        continue;
                    }

                    //Hit attack
                    CHitable        objectHit = r.transform.gameObject.GetComponentInParent <CHitable>();
                    CMoveCombatable targetHit = r.transform.gameObject.GetComponentInParent <CMoveCombatable>();

                    if (objectHit.isInvuln() || targetHit.faction == caster.faction || targetHit.isDead())
                    {
                        continue;
                    }

                    //Apply damage and knockback
                    objectHit.setAttacker(caster);
                    objectHit.loseHealth(abilityDamage);
                    objectHit.knockback(pos, abilityKnockback, objectHit.objectHeight); //Need to use original pos for knockback so the position of where you attacked from is the knockback
                    objectHit.knockUp(pos, abilityKnockback, abilityKnockUp, objectHit.objectHeight);



                    if (targetHit != null)
                    {
                        targetHit.causeOfDeath = causeOfDeath;
                    }

                    caster.audioSource.clip = abilitySound;
                    caster.audioSource.Play();

                    hitTarget = true;
                }
            }

            if (!hitTarget)
            {
                caster.audioSource.clip = abilitySound;
                caster.audioSource.Play();
            }


            caster.gameObject.layer = LayerMask.NameToLayer(oldLayer);
            yield return(new WaitForSeconds(caster.pauseAfterAttack));
        }

        caster.getAttackTrigger().resetTrigger();
        caster.canMove   = true;
        caster.attacking = false;
    }