예제 #1
0
    private void CheckHealRange()
    {
        bool hasStaff = false;

        for (int i = 0; i < currSelectedChar.GetComponent <Stats>().weapons.Count; i++)
        {
            if (currSelectedChar.GetComponent <Stats>().weapons[i].typeOfWeapon == Weapon.WeaponType.STAFF)
            {
                hasStaff = true;
            }
        }

        if (currSelectedChar != null && hasStaff)
        {
            List <GameObject> allies = tileData.CheckEnemiesInRange(Mathf.RoundToInt(currSelectedChar.transform.position.x - 0.5f), Mathf.RoundToInt(currSelectedChar.transform.position.y - 0.5f), currSelectedChar.GetComponent <Stats>().equippedWeapon.range, currSelectedChar.GetComponent <Stats>().equippedWeapon.rangeOneAndTwo, false, true);

            List <GameObject> alliesCount = new List <GameObject>();

            for (int i = 0; i < allies.Count; i++)
            {
                Debug.Log(allies[i]);
                if (allies[i].GetComponent <Stats>().maxHP > allies[i].GetComponent <Stats>().hp&& allies[i] != currSelectedChar)
                {
                    alliesCount.Add(allies[i]);
                }
            }

            if (alliesCount.Count > 0)
            {
                currSelectedChar.GetComponent <Heal>().SetAllies(alliesCount);

                GameObject.FindGameObjectWithTag("Canvas").GetComponent <SelectChoices>().healChoice.SetActive(true);
            }
        }
        else if (!hasStaff)
        {
            GameObject.FindGameObjectWithTag("Canvas").GetComponent <SelectChoices>().healChoice.SetActive(false);
        }
    }
예제 #2
0
    public void CheckAttackRange(bool healing)
    {
        if (gameObject.CompareTag("Player") && !healing)
        {
            enemies = tileData.CheckEnemiesInRange(Mathf.RoundToInt(transform.position.x - 0.5f), Mathf.RoundToInt(transform.position.y - 0.5f), stats.equippedWeapon.range, stats.equippedWeapon.rangeOneAndTwo, true, false);
        }
        else if (gameObject.CompareTag("Enemy") && !healing)
        {
            enemies      = tileData.CheckEnemiesInRange(Mathf.RoundToInt(transform.position.x - 0.5f), Mathf.RoundToInt(transform.position.y - 0.5f), stats.equippedWeapon.range, stats.equippedWeapon.rangeOneAndTwo, false, false);
            indexEnemies = enemies.IndexOf(GetComponent <EnemyAI>().target.gameObject);
        }

        if (enemies.Count > 0 && !healing || heal.GetAllies().Count > 0 && healing)
        {
            if (!healing)
            {
                greenTiles = false;
                target     = enemies[indexEnemies];
                cursor.transform.position = enemies[indexEnemies].transform.position;
            }
            else
            {
                greenTiles = true;
                target     = heal.GetAllies()[indexEnemies];
                cursor.transform.position = heal.GetAllies()[indexEnemies].transform.position;
            }

            if (gameObject.CompareTag("Player"))
            {
                cursor.GetComponent <Cursor>().selectPanel.SetActive(false);
                cursor.GetComponent <Cursor>().attackPanel.SetActive(true);
            }

            Transform attackPanel = cursor.GetComponent <Cursor>().attackPanel.transform;
            Transform statsPanel  = null;
            Transform hpPanel     = null;
            Transform mtPanel     = null;
            Transform hitPanel    = null;
            Transform critPanel   = null;
            Transform weaponPanel = null;

            int x      = Mathf.RoundToInt(transform.position.x - 0.5f);
            int y      = Mathf.RoundToInt(transform.position.y - 0.5f);
            int xEnemy = Mathf.RoundToInt(target.transform.position.x - 0.5f);
            int yEnemy = Mathf.RoundToInt(target.transform.position.y - 0.5f);
            Debug.Log(xEnemy + " " + yEnemy);

            //MT calc
            triangleBonus      = 0;
            triangleBonusEnemy = 0;

            if (!healing)
            {
                damage   = CalcDamage(gameObject, target);
                doubling = CalcSpeed(gameObject, target);

                //Hit calc
                float hit        = CalcHit(gameObject);
                float enemyEvade = CalcEvade(target, xEnemy, yEnemy);
                acc = CalcAccuracy(hit, enemyEvade, gameObject);
                //Crit calc
                float critRate       = CalcCrit(gameObject);
                float enemyCritEvade = CalcCritEvade(target);
                crit = CalcCritHit(critRate, enemyCritEvade);

                enemyDamage   = 0;
                enemyCrit     = 0;
                enemyDoubling = 0;
                float enemyHit      = 0;
                float evade         = 0;
                float enemyCritRate = 0;
                float critEvade     = 0;
                enemyAcc = 0;

                distance = Mathf.Abs(transform.position.x - target.transform.position.x) + Mathf.Abs(transform.position.y - target.transform.position.y);

                if (distance <= target.GetComponent <Stats>().equippedWeapon.range&& target.GetComponent <Stats>().equippedWeapon.rangeOneAndTwo || distance != 1 && distance <= target.GetComponent <Stats>().equippedWeapon.range&& !target.GetComponent <Stats>().equippedWeapon.rangeOneAndTwo || target.GetComponent <Stats>().equippedWeapon.counterAll)
                {
                    if (target.GetComponent <Stats>().equippedWeapon.typeOfWeapon != Weapon.WeaponType.STAFF)
                    {
                        enemyDamage   = CalcDamage(target, gameObject);
                        enemyDoubling = CalcSpeed(target, gameObject);
                        enemyHit      = CalcHit(target);
                        evade         = CalcEvade(gameObject, x, y);
                        enemyAcc      = CalcAccuracy(enemyHit, evade, target);

                        enemyCritRate = CalcCrit(target);
                        critEvade     = CalcCritEvade(gameObject);
                        enemyCrit     = CalcCritHit(enemyCritRate, critEvade);
                    }
                }
            }
            else
            {
                distance = Mathf.Abs(gameObject.transform.position.x - target.transform.position.x) + Mathf.Abs(gameObject.transform.position.y - target.transform.position.y);
                damage   = stats.scr + stats.equippedWeapon.heal;
                doubling = 1;
                acc      = 100;
                crit     = 0;

                enemyDamage   = 0;
                enemyDoubling = 0;
                enemyAcc      = 0;
                enemyCrit     = 0;
            }

            if (gameObject.CompareTag("Player"))
            {
                for (int i = 0; i < attackPanel.childCount; i++)
                {
                    if (attackPanel.GetChild(i).name == "Stats")
                    {
                        statsPanel = attackPanel.GetChild(i);
                        Debug.Log("StatsFound");
                    }
                    else if (attackPanel.GetChild(i).name == "Weapon")
                    {
                        weaponPanel = attackPanel.GetChild(i);

                        for (int j = 0; j < weaponPanel.childCount; j++)
                        {
                            if (weaponPanel.GetChild(j).name == "Weapon")
                            {
                                Transform weaponEmpty = weaponPanel.GetChild(j);

                                for (int k = 0; k < weaponEmpty.childCount; k++)
                                {
                                    if (weaponEmpty.GetChild(k).name == "Text")
                                    {
                                        weaponEmpty.GetChild(k).GetComponent <Text>().text = stats.equippedWeapon.weaponName;
                                    }
                                    else if (weaponEmpty.GetChild(k).name == "Dur")
                                    {
                                        weaponEmpty.GetChild(k).GetComponent <Text>().text = stats.equippedWeapon.uses.ToString();
                                    }
                                }
                            }
                            else if (weaponPanel.GetChild(j).name == "Arrow")
                            {
                                Image arrow = weaponPanel.GetChild(j).GetComponent <Image>();

                                if (triangleBonus == 15)
                                {
                                    arrow.gameObject.SetActive(true);
                                    arrow.transform.rotation = Quaternion.Euler(0, 0, 0);
                                    arrow.color = new Color32(105, 255, 102, 255);
                                }
                                else if (triangleBonus == 0)
                                {
                                    arrow.gameObject.SetActive(false);
                                }
                                else if (triangleBonus == -15)
                                {
                                    arrow.gameObject.SetActive(true);
                                    arrow.transform.rotation = Quaternion.Euler(0, 0, 180);
                                    arrow.color = new Color32(255, 104, 102, 255);
                                }
                            }
                        }
                    }
                    else if (attackPanel.GetChild(i).name == "EnemyWeapon")
                    {
                        weaponPanel = attackPanel.GetChild(i);

                        for (int j = 0; j < weaponPanel.childCount; j++)
                        {
                            if (weaponPanel.GetChild(j).name == "Weapon")
                            {
                                Transform weaponEmpty = weaponPanel.GetChild(j);

                                weaponEmpty.GetComponentInChildren <Text>().text = target.GetComponent <Stats>().equippedWeapon.weaponName;
                            }
                            else if (weaponPanel.GetChild(j).name == "Arrow")
                            {
                                Image arrow = weaponPanel.GetChild(j).GetComponent <Image>();

                                if (triangleBonusEnemy == 15)
                                {
                                    arrow.gameObject.SetActive(true);
                                    arrow.transform.rotation = Quaternion.Euler(0, 0, 0);
                                    arrow.color = new Color32(105, 255, 102, 255);
                                }
                                else if (triangleBonusEnemy == 0)
                                {
                                    arrow.gameObject.SetActive(false);
                                }
                                else if (triangleBonusEnemy == -15)
                                {
                                    arrow.gameObject.SetActive(true);
                                    arrow.transform.rotation = Quaternion.Euler(0, 0, 180);
                                    arrow.color = new Color32(255, 104, 102, 255);
                                }
                            }
                        }
                    }
                }

                for (int i = 0; i < statsPanel.childCount; i++)
                {
                    switch (statsPanel.GetChild(i).name)
                    {
                    case "HP":
                        hpPanel = statsPanel.GetChild(i);

                        for (int j = 0; j < hpPanel.childCount; j++)
                        {
                            if (hpPanel.GetChild(j).name == "PlayerHPbar")
                            {
                                Debug.Log(hpPanel.GetChild(j));
                                for (int k = 0; k < hpPanel.GetChild(j).childCount; k++)
                                {
                                    if (hpPanel.GetChild(j).GetChild(k).name == "Health")
                                    {
                                        Image bar = hpPanel.GetChild(j).GetChild(k).GetComponent <Image>();
                                        bar.fillAmount = stats.hp / stats.maxHP;
                                    }
                                    else if (hpPanel.GetChild(j).GetChild(k).name == "HealthAfterAttack")
                                    {
                                        float healthAfterAttack = stats.hp - (enemyDamage * enemyDoubling);
                                        if (healthAfterAttack < 0)
                                        {
                                            healthAfterAttack = 0;
                                        }

                                        Image bar = hpPanel.GetChild(j).GetChild(k).GetComponent <Image>();
                                        bar.fillAmount = healthAfterAttack / stats.maxHP;
                                    }
                                    else if (hpPanel.GetChild(j).GetChild(k).name == "Text")
                                    {
                                        Text hp = hpPanel.GetChild(j).GetChild(k).GetComponent <Text>();
                                        hp.text = stats.hp.ToString();
                                    }
                                    else if (hpPanel.GetChild(j).GetChild(k).name == "TextAfterAttack")
                                    {
                                        float healthAfterAttack = stats.hp - (enemyDamage * enemyDoubling);
                                        if (healthAfterAttack < 0)
                                        {
                                            healthAfterAttack = 0;
                                        }

                                        Text hp = hpPanel.GetChild(j).GetChild(k).GetComponent <Text>();
                                        hp.text = healthAfterAttack.ToString();
                                    }
                                }
                            }
                            else if (hpPanel.GetChild(j).name == "EnemyHPbar")
                            {
                                for (int k = 0; k < hpPanel.GetChild(j).childCount; k++)
                                {
                                    if (hpPanel.GetChild(j).GetChild(k).name == "Health")
                                    {
                                        float healthAfterAttack = 0;

                                        if (healing)
                                        {
                                            healthAfterAttack = target.GetComponent <Stats>().hp + damage;
                                            if (healthAfterAttack > target.GetComponent <Stats>().maxHP)
                                            {
                                                healthAfterAttack = target.GetComponent <Stats>().maxHP;
                                            }

                                            Image bar = hpPanel.GetChild(j).GetChild(k).GetComponent <Image>();
                                            bar.fillAmount = healthAfterAttack / target.GetComponent <Stats>().maxHP;
                                        }
                                        else
                                        {
                                            Image bar = hpPanel.GetChild(j).GetChild(k).GetComponent <Image>();
                                            bar.fillAmount = target.GetComponent <Stats>().hp / target.GetComponent <Stats>().maxHP;
                                        }
                                    }
                                    else if (hpPanel.GetChild(j).GetChild(k).name == "HealthAfterAttack")
                                    {
                                        float healthAfterAttack = 0;

                                        if (!healing)
                                        {
                                            healthAfterAttack = target.GetComponent <Stats>().hp - (damage * doubling);
                                            if (healthAfterAttack < 0)
                                            {
                                                healthAfterAttack = 0;
                                            }

                                            Image bar = hpPanel.GetChild(j).GetChild(k).GetComponent <Image>();
                                            bar.fillAmount = healthAfterAttack / target.GetComponent <Stats>().maxHP;
                                        }
                                        else
                                        {
                                            Image bar = hpPanel.GetChild(j).GetChild(k).GetComponent <Image>();
                                            bar.fillAmount = target.GetComponent <Stats>().hp / target.GetComponent <Stats>().maxHP;
                                        }
                                    }
                                    else if (hpPanel.GetChild(j).GetChild(k).name == "Text")
                                    {
                                        Text hp = hpPanel.GetChild(j).GetChild(k).GetComponent <Text>();
                                        hp.text = target.GetComponent <Stats>().hp.ToString();
                                    }
                                    else if (hpPanel.GetChild(j).GetChild(k).name == "TextAfterAttack")
                                    {
                                        float healthAfterAttack = 0;
                                        if (!healing)
                                        {
                                            healthAfterAttack = target.GetComponent <Stats>().hp - (damage * doubling);
                                            if (healthAfterAttack < 0)
                                            {
                                                healthAfterAttack = 0;
                                            }
                                        }
                                        else
                                        {
                                            healthAfterAttack = target.GetComponent <Stats>().hp + damage;

                                            if (healthAfterAttack > target.GetComponent <Stats>().maxHP)
                                            {
                                                healthAfterAttack = target.GetComponent <Stats>().maxHP;
                                            }
                                        }

                                        Text hp = hpPanel.GetChild(j).GetChild(k).GetComponent <Text>();
                                        hp.text = healthAfterAttack.ToString("F0");
                                    }
                                }
                            }
                        }
                        break;

                    case "MT":
                        mtPanel = statsPanel.GetChild(i);

                        for (int j = 0; j < mtPanel.childCount; j++)
                        {
                            if (mtPanel.GetChild(j).name == "PlayerMT")
                            {
                                Debug.Log(mtPanel.GetChild(j));
                                for (int k = 0; k < mtPanel.GetChild(j).childCount; k++)
                                {
                                    if (mtPanel.GetChild(j).GetChild(k).name == "Text")
                                    {
                                        Text mt = mtPanel.GetChild(j).GetChild(k).GetComponent <Text>();
                                        mt.text = damage.ToString();
                                        Debug.Log("Damage: " + damage);
                                    }
                                    else if (mtPanel.GetChild(j).GetChild(k).name == "X2")
                                    {
                                        GameObject x2 = mtPanel.GetChild(j).GetChild(k).gameObject;
                                        x2.SetActive(false);

                                        switch (doubling)
                                        {
                                        case 2:
                                            x2.SetActive(true);
                                            break;

                                        case 4:
                                            x2.SetActive(true);
                                            x2.GetComponentInChildren <Text>().text = "x4";
                                            break;
                                        }
                                    }
                                }
                            }
                            else if (mtPanel.GetChild(j).name == "EnemyMT")
                            {
                                Debug.Log(mtPanel.GetChild(j));
                                for (int k = 0; k < mtPanel.GetChild(j).childCount; k++)
                                {
                                    if (mtPanel.GetChild(j).GetChild(k).name == "Text")
                                    {
                                        Text mt = mtPanel.GetChild(j).GetChild(k).GetComponent <Text>();
                                        mt.text = enemyDamage.ToString();
                                        Debug.Log("EnemyDamage: " + enemyDamage);
                                    }
                                    else if (mtPanel.GetChild(j).GetChild(k).name == "X2")
                                    {
                                        GameObject x2 = mtPanel.GetChild(j).GetChild(k).gameObject;
                                        x2.SetActive(false);

                                        switch (enemyDoubling)
                                        {
                                        case 2:
                                            x2.SetActive(true);
                                            break;

                                        case 4:
                                            x2.SetActive(true);
                                            x2.GetComponentInChildren <Text>().text = "x4";
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        break;

                    case "Hit":
                        hitPanel = statsPanel.GetChild(i);

                        for (int j = 0; j < hitPanel.childCount; j++)
                        {
                            if (hitPanel.GetChild(j).name == "Player")
                            {
                                Debug.Log(hitPanel.GetChild(j));
                                for (int k = 0; k < hitPanel.GetChild(j).childCount; k++)
                                {
                                    if (hitPanel.GetChild(j).GetChild(k).name == "Text")
                                    {
                                        Text hitTxt = hitPanel.GetChild(j).GetChild(k).GetComponent <Text>();
                                        hitTxt.text = acc.ToString("F0");
                                    }
                                }
                            }
                            else if (hitPanel.GetChild(j).name == "Enemy")
                            {
                                Debug.Log(hitPanel.GetChild(j));
                                for (int k = 0; k < hitPanel.GetChild(j).childCount; k++)
                                {
                                    if (hitPanel.GetChild(j).GetChild(k).name == "Text")
                                    {
                                        Text hitTxt = hitPanel.GetChild(j).GetChild(k).GetComponent <Text>();
                                        hitTxt.text = enemyAcc.ToString("F0");
                                    }
                                }
                            }
                        }
                        break;

                    case "Crit":
                        critPanel = statsPanel.GetChild(i);

                        for (int j = 0; j < critPanel.childCount; j++)
                        {
                            if (critPanel.GetChild(j).name == "Player")
                            {
                                Debug.Log(critPanel.GetChild(j));
                                for (int k = 0; k < critPanel.GetChild(j).childCount; k++)
                                {
                                    if (critPanel.GetChild(j).GetChild(k).name == "Text")
                                    {
                                        Text critTxt = critPanel.GetChild(j).GetChild(k).GetComponent <Text>();
                                        critTxt.text = crit.ToString("F0");
                                    }
                                }
                            }
                            else if (critPanel.GetChild(j).name == "Enemy")
                            {
                                Debug.Log(critPanel.GetChild(j));
                                for (int k = 0; k < critPanel.GetChild(j).childCount; k++)
                                {
                                    if (critPanel.GetChild(j).GetChild(k).name == "Text")
                                    {
                                        Text critTxt = critPanel.GetChild(j).GetChild(k).GetComponent <Text>();
                                        critTxt.text = enemyCrit.ToString("F0");
                                    }
                                }
                            }
                        }
                        break;
                    }
                }
            }
            StartCoroutine(cursor.GetComponent <Cursor>().DoneCalcStats());

            if (gameObject.CompareTag("Enemy"))
            {
                cursor.GetComponent <Cursor>().EnemyFight(gameObject);
            }
        }
    }