// Use this for initialization
 void Start()
 {
     instance = this;
 }
Exemple #2
0
    //Crit chance deprecated, now a function of player precision

    /*  protected bool rollCritChance()
     * {
     *    int chance = Random.Range(0, 11);
     *    if (chance > CRIT_THRESHOLD)
     *    {
     *        Debug.Log(chance + " Attack Critical Hit!");
     *        return true;
     *    }
     *    else {
     *        Debug.Log(chance+ " Attack normal Hit.");
     *        return false;
     *    }
     * }*/



    protected void AttackTarget()
    {
        // bool criticalHit = false;
        //For each target when attack queued up
        foreach (GameObject target in thisAttackTargets)
        {
            if (target != null)
            {
                tar = target;
                // Debug.Log("Step " + stepsIntoCombo);
                switch (stepsIntoCombo) //Trigger appropriate combo animation
                {
                case 0:
                    anim.SetTrigger("Attack1");
                    if (!rangedAbilityFlag && !playSpellAnimation)
                    {
                        swing1.Play();
                        attackDamage = getDamageAtTime(timerWindow, step1Damage);
                    }
                    else if (playSpellAnimation)
                    {
                        spellDamageToDeal += step1Damage;
                        MageFX1.gameObject.SetActive(true);
                    }
                    else
                    {
                        // attackDamage = step1Damage / thisAttackTargets.Count;
                        attackDamage = getDamageAtTime(timerWindow, step1Damage);
                    }
                    break;

                case 1:
                    anim.SetTrigger("Attack2");
                    if (!rangedAbilityFlag && !playSpellAnimation)
                    {
                        swing2.Play();
                        attackDamage = getDamageAtTime(timerWindow, step1Damage);
                    }
                    else if (playSpellAnimation)
                    {
                        spellDamageToDeal += step2Damage;
                        //MageFX1.gameObject.SetActive(false);
                        MageFX2.gameObject.SetActive(true);
                    }
                    else
                    {
                        // attackDamage = step1Damage / thisAttackTargets.Count;
                        attackDamage = getDamageAtTime(timerWindow, step2Damage);
                    }
                    break;

                case 2:
                    anim.SetTrigger("Attack3");
                    if (!rangedAbilityFlag && !playSpellAnimation)
                    {
                        swing3.Play();
                        attackDamage = getDamageAtTime(timerWindow, step1Damage);
                    }
                    else if (playSpellAnimation)
                    {
                        spellDamageToDeal += step3Damage;
                        //MageFX2.gameObject.SetActive(false);
                        MageFX3.gameObject.SetActive(true);
                    }
                    else
                    {
                        // attackDamage = step1Damage;
                        attackDamage = getDamageAtTime(timerWindow, step3Damage);
                    }
                    break;
                }

                if (
                    tar.gameObject.GetComponent <Unit>().WillDieFromDamage(attackDamage) ||
                    tar.gameObject.GetComponent <Unit>().WillDieFromDamage(spellDamageToDeal)
                    ) //if lethal damage
                {
                    if (thisAttackTargets.Count == 1)
                    {
                        listenForComboInput = false;
                        Destroy(theFloatingInputText);
                        anim.SetTrigger("ComboFail"); //Isn't actually a fail, just exit to idle because enemy dead
                        pauseHourglass = true;
                    }
                    Destroy(theFloatingInputText);
                    if (!playSpellAnimation)   //if melee do immediate damage
                    {
                        if (rangedAbilityFlag) //ranged
                        {
                            GameObject arrow = RangerArrowFactory.CreateArrow(attackDamage / thisAttackTargets.Count, tar, this.gameObject, false);
                            // Debug.Log("Final blow to  " + tar.gameObject.name + "dealing " + attackDamage);
                            if (thisAttackTargets.Count == 1)
                            {
                                Invoke("EndCombat", 0.5f);
                            }
                            else
                            {
                                //someone take target out of list
                            }
                        }
                        else //melee
                        {
                            tar.GetComponent <Unit>().takeDamage(attackDamage, aggressor);

                            // Debug.Log("Final blow to  " + tar.gameObject.name + "dealing " + attackDamage);
                            if (thisAttackTargets.Count == 1)
                            {
                                Invoke("EndCombat", 0.5f);
                            }
                            else
                            {
                                //someone take target out of list
                            }
                        }
                    }
                    else //if spell, accumulate damage automatically
                    {
                        if (thisAttackTargets.Count == 1)
                        {
                            Invoke("EndCombat", 0.5f);
                        }
                    }
                }
                else //if hit is not lethal
                {
                    if (!playSpellAnimation)//if a melee, do damage immediately
                    {
                        if (rangedAbilityFlag && tar != null)   //ranged
                        {
                            GameObject arrow = RangerArrowFactory.CreateArrow(attackDamage, tar, this.gameObject, false);
                        }
                        else                                    //melee
                        {
                            if (stepsIntoCombo == 1)
                            {
                                tar.GetComponent <Unit>().takeCriticalDamage(attackDamage, aggressor);
                            }
                            else
                            {
                                tar.GetComponent <Unit>().takeDamage(attackDamage, aggressor);
                            }
                        }
                    }
                    else //if spell accumulate damage
                    {
                    }
                }
            }
        }
    }