Пример #1
0
    private void OnTriggerEnter2D(Collider2D collider)
    {
        //If bullet is rebounding then don't detect collisions
        if (rebounded + reboundTime > Time.time)
        {
            return;
        }
        //If an object has been hit first, destroy the bullet
        if (collider.transform.gameObject.tag == "Object")
        {
            if (!collider.isTrigger)
            {
                this.gameObject.SetActive(false);
            }
            //Add destoryed particle effect here
        }

        CHitable targetHit = collider.GetComponentInParent <CHitable>();

        //If object hit is hitable, and this bullet hasn't hit anything else this life
        if (targetHit != null && !hitTarget)
        {
            if (targetHit.isInvuln() || targetHit.isKnockedback())
            {
                return;
            }

            CMoveCombatable enemy = collider.GetComponentInParent <CMoveCombatable>();

            if (enemy != null && !FactionManager.instance.isHostile(enemy.faction, faction))
            {
                return;
            }
            else if (enemy != null && enemy.parrying)
            {
                dir      *= -1;
                rebounded = Time.time;

                //Change the bullets caster and faction so the ricochet bullet can hit enemies of the parrying target
                faction = enemy.faction;
                caster  = enemy;
                return;
            }

            hitTarget = true;

            //Apply damage and knockback
            targetHit.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
            targetHit.loseHealth(damage);

            //Apply stun to the target
            targetHit.applyStun(stunTime);

            //TODO: Play audio sound
            caster.attackHit();

            this.gameObject.SetActive(false);
        }
    }
Пример #2
0
    private void OnTriggerEnter2D(Collider2D collider)
    {
        //If bullet is rebounding then don't detect collisions
        if (rebounded + reboundTime > Time.time)
        {
            return;
        }
        //If an object has been hit first, destroy the bullet
        if (collider.transform.gameObject.tag == "Object")
        {
            if (!collider.isTrigger)
            {
                this.gameObject.SetActive(false);
            }
            //Add destoryed particle effect here
        }

        CHitable        targetHit = collider.GetComponentInParent <CHitable>();
        CMoveCombatable enemy     = collider.GetComponentInParent <CMoveCombatable>();

        //If object hit is hitable, and this bullet hasn't already hit the target
        if (targetHit != null && !targetsHit.Contains(enemy))
        {
            if (targetHit.isInvuln() || targetHit.isKnockedback())
            {
                return;
            }

            if (enemy != null && enemy.parrying)
            {
                this.gameObject.SetActive(false);
            }

            //Apply damage and knockback
            targetHit.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
            targetHit.loseHealth(damage);

            //Apply stun to the target
            targetHit.applyStun(stunTime);

            //TODO: Play audio sound
            caster.attackHit();
            durability--;

            if (durability <= 0)
            {
                this.gameObject.SetActive(false);
            }
            else
            {
                targetsHit.Add(enemy);
                findNewTarget();
                if (target == null)
                {
                    this.gameObject.SetActive(false);
                }
            }
        }
    }
Пример #3
0
    private void OnTriggerEnter2D(Collider2D collider)
    {
        //If an object has been hit first, destroy the bullet
        if (collider.transform.gameObject.tag == "Object")
        {
            if (!collider.isTrigger)
            {
                this.gameObject.SetActive(false);
            }
            //Add destoryed particle effect here
        }

        CHitable targetHit = collider.GetComponentInParent <CHitable>();

        //If object hit is hitable, and this bullet hasn't hit anything else this life
        if (targetHit != null && !targetsHit.Contains(targetHit))
        {
            if (targetHit.isInvuln() || targetHit.isKnockedback())
            {
                return;
            }

            CMoveCombatable enemy = collider.GetComponentInParent <CMoveCombatable>();

            if (enemy != null && !FactionManager.instance.isHostile(enemy.faction, faction))
            {
                return;
            }

            targetsHit.Add(targetHit);

            //Apply damage and knockback
            targetHit.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
            targetHit.loseHealth(damage);

            //Apply stun to the target
            targetHit.applyStun(stunTime);

            //TODO: Play audio sound
            caster.attackHit();
        }
    }
    public 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);

                    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;
    }
Пример #5
0
    public IEnumerator abilityActionSequence()
    {
        //Wait until the attack frame in the animation has been reached
        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.black, 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")
                    {
                        if (r.collider.isTrigger)
                        {
                            continue;
                        }
                        else
                        {
                            break;
                        }
                    }

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

                    if (objectHit.isInvuln() || objectHit.tag == caster.tag || objectHit.isKnockedback()) //Add faction to hitables to use here instead of tags
                    {
                        continue;
                    }

                    //Set attacker and info on hit
                    objectHit.setAttacker(caster);
                    objectHit.lastAttackInfo = "A basic hit";
                    //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.loseHealth(abilityDamage);

                    //Apply stun to the target
                    objectHit.applyStun(stunTime);

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

                    lastAttack = Time.time;
                    //caster.canCombo = true;
                    caster.setComboAnimation(true);

                    hitTarget = true;
                    break;
                }
            }

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

            //Wait till attack animation is over
            while (!caster.getAttackTrigger().isAttackOver())
            {
                yield return(null);
            }

            caster.getAttackTrigger().resetAttack();
        }

        if (caster.canCombo)
        {
            caster.attack(comboAttack);
            yield break;
        }
        else
        {
            //Pause for caster
            yield return(new WaitForSeconds(caster.pauseAfterAttack));

            caster.setComboAnimation(false);
        }
        caster.canCombo  = false;
        caster.canMove   = true;
        caster.attacking = false;
    }