Пример #1
0
    void GetPlayerHighlight()
    {
        GameObject playerUnit = playerCursor.GetComponent <SelectionCursor>().player;

        if (playerUnit != null && (enemyTurnManger.GetComponent <EnemyTurnManager>() as MonoBehaviour).enabled == false && (playerTurnManager.GetComponent <PlayerTurnManager>() as MonoBehaviour).enabled == true)
        {
            FEFriendlyUnit unitStats = playerUnit.GetComponent <FEFriendlyUnit>();

            pHighlight.enabled = true;

            playerStatsText[0].text = "" + unitStats.GetCurrentHP() + "/" + unitStats.maxHp;
            playerStatsText[1].text = "" + unitStats.atk;
            playerStatsText[2].text = "" + unitStats.def;
            playerStatsText[3].text = "" + unitStats.spd;
            playerStatsText[4].text = "" + unitStats.lck;
        }
        else
        {
            foreach (var text in playerStatsText)
            {
                text.text = "";
            }

            pHighlight.enabled = false;
        }
    }
Пример #2
0
    IEnumerator MoveUnits()
    {
        while (!turnOver)
        {
            FEHostileUnit stats = units[currentUnit];
            if (units[currentUnit].fade == null && units[currentUnit] != null)
            {
                FEFriendlyUnit playerStats = GameObject.Find("unit").GetComponent <FEFriendlyUnit>();
                Vector3        position    = stats.gameObject.transform.position;
                Vector3        playerPos   = GameObject.Find("unit").transform.position;

                bool       attack = false;
                GameObject player = null;
                foreach (var block in stats.blocking)
                {
                    if (block.GetComponent <EnemyBlock>().canAttack)
                    {
                        attack = true;
                        player = block.GetComponent <EnemyBlock>().player;
                    }
                }

                if (attack)
                {
                    int accuracy = 69;

                    playerStats = player.GetComponent <FEFriendlyUnit>();
                    int playerChance = accuracy + playerStats.skl * 2 + playerStats.lck / 2;
                    int chance       = accuracy + stats.skl * 2 + stats.lck / 2;

                    bool playerHit = (Random.Range(0, 100) <= playerChance);
                    bool hit       = (Random.Range(0, 100) <= chance);

                    GetComponent <AudioSource>().PlayOneShot(hitSound);

                    yield return(StartCoroutine("AttackAnimation"));

                    if (hit)
                    {
                        bool crit     = (Random.Range(0, 100) <= stats.lck);
                        bool outSpeed = (stats.GetCurrentSpd() > (playerStats.GetCurrentSpd() + 5));
                        int  damage   = stats.atk - playerStats.def;

                        if (damage <= 1)
                        {
                            damage = 1;
                        }

                        if (outSpeed)
                        {
                            damage *= 2;
                        }

                        if (crit)
                        {
                            GetComponent <AudioSource>().PlayOneShot(critSound);
                            damage *= 3;
                        }

                        player.GetComponent <FEFriendlyUnit>().SendMessage("TakeDamage", damage);
                        if (damage >= playerStats.GetCurrentHP())
                        {
                            player = null;
                        }
                    }

                    if (playerHit && player != null)
                    {
                        bool crit     = (Random.Range(0, 100) <= playerStats.lck);
                        bool outSpeed = (playerStats.GetCurrentSpd() > (stats.GetCurrentSpd() + 5));
                        int  damage   = playerStats.atk - stats.def;

                        if (damage <= 1)
                        {
                            damage = 1;
                        }

                        if (outSpeed)
                        {
                            damage *= 2;
                        }

                        if (crit)
                        {
                            damage *= 3;
                        }

                        units[currentUnit].SendMessage("TakeDamage", damage);
                    }

                    unitMoves = 0;
                    currentUnit++;
                    if (currentUnit >= units.Length)
                    {
                        turnOver = true;
                        break;
                    }
                }
                else if (unitMoves < stats.mov && tempCounter == 0)
                {
                    if (playerPos.y > position.y)
                    {
                        // Player north
                        if (!stats.blocked[0])
                        {
                            position.y += movSpeed;
                        }
                        else if (playerPos.x > position.x && !stats.blocked[2])
                        {
                            position.x += movSpeed;
                        }
                        else if (playerPos.x < position.x && !stats.blocked[3])
                        {
                            position.x -= movSpeed;
                        }
                        else if (!stats.blocked[1])
                        {
                            position.y -= movSpeed;
                        }
                    }
                    else if (playerPos.y < position.y)
                    {
                        // Player south
                        if (!stats.blocked[1])
                        {
                            position.y -= movSpeed;
                        }
                        else if (playerPos.x > position.x && !stats.blocked[2])
                        {
                            position.x += movSpeed;
                        }
                        else if (playerPos.x < position.x && !stats.blocked[3])
                        {
                            position.x -= movSpeed;
                        }
                        else if (!stats.blocked[0])
                        {
                            position.y += movSpeed;
                        }
                    }
                    else if (playerPos.x > position.x)
                    {
                        // Player east
                        if (!stats.blocked[2])
                        {
                            position.x += movSpeed;
                        }
                        else if (playerPos.y > position.y && !stats.blocked[0])
                        {
                            position.y += movSpeed;
                        }
                        else if (playerPos.y < position.y && !stats.blocked[1])
                        {
                            position.x -= movSpeed;
                        }
                        else if (!stats.blocked[3])
                        {
                            position.x -= movSpeed;
                        }
                    }
                    else if (playerPos.x < position.x)
                    {
                        // Player west
                        if (!stats.blocked[3])
                        {
                            position.x -= movSpeed;
                        }
                        else if (playerPos.y > position.y && !stats.blocked[0])
                        {
                            position.y += movSpeed;
                        }
                        else if (playerPos.y < position.y && !stats.blocked[1])
                        {
                            position.x -= movSpeed;
                        }
                        else if (!stats.blocked[2])
                        {
                            position.x += movSpeed;
                        }
                    }

                    unitMoves++;
                    stats.gameObject.transform.position = position;
                    tempCounter = 7;
                }
                else if (tempCounter > 0)
                {
                    tempCounter--;
                }
                else
                {
                    unitMoves = 0;
                    currentUnit++;
                    if (currentUnit >= units.Length)
                    {
                        turnOver = true;
                        break;
                    }
                }
            }
            else if (units[currentUnit] == null)
            {
                currentUnit++;
            }

            yield return(null);
        }

        StopCoroutine(moveUnits);
        moveUnits = null;
    }