Пример #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
    protected virtual void fire_laser(Vector2 hitHere)
    {
        if (m_target == null)
        {
            return;
        }
        Vector3 p;

        p   = transform.position;
        p.z = -0.1f;
        m_lineRend.SetPosition(0, p);
        p.x = hitHere.x;
        p.y = hitHere.y;
        p.z = -0.1f;
        m_lineRend.SetPosition(1, p);
        m_lineRend.enabled = true;
        CHitable hit = m_target.GetComponent <CHitable>();

        if (!System.Object.ReferenceEquals(hit, null))
        {
            Vector3 v = m_target.transform.position - transform.position;
            v.Normalize();
            hit.takeDamage(gameObject, v, 1.0f);
        }
        StartCoroutine(waitAndDestroy(0.15f));
    }
Пример #3
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);
                }
            }
        }
    }
Пример #4
0
    void Awake()
    {
        m_rend = GetComponent <Renderer>();
        m_hitt = GetComponent <CHitable>();
        if (m_rend != null)
        {
//            Debug.Log("have m_rend");
            m_mat = m_rend.material;
            if (m_mat != null)
            {
//                Debug.Log("have m_mat");
            }
        }
        if (m_hitt != null)
        {
            m_hitt.a += callback_from_hitable;
        }
    }
Пример #5
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();
        }
    }
Пример #6
0
    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;
    }
Пример #7
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;
    }
Пример #8
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;
    }
Пример #9
0
    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.loseHealth(abilityDamage);

                    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;
    }
Пример #10
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;
    }