示例#1
0
    public void UpdateUI()
    {
        //FOE


        foeHPSlider.minValue = 0;
        foeHPSlider.maxValue = foePokemon.HP;
        //foeHPSlider.value = foePokemon.currentHP;

        if (foeHPSlider.value != foePokemon.currentHP)
        {
            foeHPSlider.value = Mathf.RoundToInt(foeHPSlider.value + Mathf.Sign(foePokemon.currentHP - foeHPSlider.value));

            if (Mathf.Abs(foePokemon.currentHP - foeHPSlider.value) < 3)
            {
                foeHPSlider.value = foePokemon.currentHP;
            }
        }

        float foeHPRatio = foeHPSlider.value / foePokemon.HP;

        if (foeHPRatio > .5f)
        {
            foeHPSliderBar.color = HPSliderBarColors[0];
        }
        else if (foeHPRatio > .2f)
        {
            foeHPSliderBar.color = HPSliderBarColors[1];
        }
        else
        {
            foeHPSliderBar.color = HPSliderBarColors[2];
        }

        if (!foePokemon.CheckForDeath())
        {
            foeNameText.text  = foePokemon.GetName();
            foeLevelText.text = "Lv" + foePokemon.level;
            foeSprite.sprite  = foePokemon.GetFrontSprite();

            if (!foePokemon.gender.Equals(Gender.NONE))
            {
                foeGenderSprite.enabled = true; foeGenderSprite.sprite = genderSprites[(int)foePokemon.gender];
            }
            else
            {
                foeGenderSprite.enabled = false;
            }

            if (!foePokemon.status.Equals(Status.NONE))
            {
                foeStatusSprite.enabled = true; foeStatusSprite.sprite = statusSprites[(int)foePokemon.status];
            }
            else
            {
                foeStatusSprite.enabled = false;
            }
        }

        //ALLY

        allyHealthText.text = allyPokemon.currentHP + "/" + allyPokemon.HP;


        allyHPSlider.minValue = 0;
        allyHPSlider.maxValue = allyPokemon.HP;
        //allyHPSlider.value = allyPokemon.currentHP;

        if (allyHPSlider.value != allyPokemon.currentHP)
        {
            allyHPSlider.value = allyHPSlider.value + Mathf.Sign(allyPokemon.currentHP - allyHPSlider.value);

            if (Mathf.Abs(allyPokemon.currentHP - allyHPSlider.value) < 3)
            {
                allyHPSlider.value = allyPokemon.currentHP;
            }
        }

        float allyHPRatio = allyHPSlider.value / allyPokemon.HP;

        if (allyHPRatio > .5f)
        {
            allyHPSliderBar.color = HPSliderBarColors[0];
        }
        else if (allyHPRatio > .2f)
        {
            allyHPSliderBar.color = HPSliderBarColors[1];
        }
        else
        {
            allyHPSliderBar.color = HPSliderBarColors[2];
        }

        if (!allyPokemon.CheckForDeath())
        {
            allyNameText.text  = allyPokemon.GetName();
            allyLevelText.text = "Lv" + allyPokemon.level;

            allySprite.sprite = allyPokemon.GetBackSprite();

            if (!allyPokemon.gender.Equals(Gender.NONE))
            {
                allyGenderSprite.enabled = true; allyGenderSprite.sprite = genderSprites[(int)allyPokemon.gender];
            }
            else
            {
                allyGenderSprite.enabled = false;
            }

            if (!allyPokemon.status.Equals(Status.NONE))
            {
                allyStatusSprite.enabled = true; allyStatusSprite.sprite = statusSprites[(int)allyPokemon.status];
            }
            else
            {
                allyStatusSprite.enabled = false;
            }

            allyXPSlider.minValue = allyPokemon.GetXPMin();
            allyXPSlider.maxValue = allyPokemon.GetXPMax();
            allyXPSlider.value    = allyPokemon.XP;
        }
    }
示例#2
0
    IEnumerator BattleHandler()
    {
        allyPokemon        = Player.instance.party.GetFirstNonFaintedPokemon();
        allyHPSlider.value = allyPokemon.HP;
        dialogueManager.ClearDialogue();

        dialogueManager.AddDialogue("Foe " + foePokemon.GetName() + " wants to battle!");

        allyParent.transform.localPosition = new Vector3(600, -32, 0);

        dialogueManager.DisplayNextSentence();

        foePokemonParent.transform.localPosition = Vector3.zero;

        for (int i = 600; i >= 0; i -= 10)
        {
            foeParent.transform.localPosition = new Vector3(-i, 96, 0);
            yield return(null);
        }

        bool partyDead = false;

        while (Player.instance.party.HasUsablePokemon() && !foePokemon.CheckForDeath())
        {
            bool allyDied = false;
            bool foeDied  = false;

            allyParent.transform.localPosition = new Vector3(600, -32, 0);
            allyPokemon = Player.instance.party.GetFirstNonFaintedPokemon();
            dialogueManager.AddDialogue("Go, " + allyPokemon.GetName() + "!");

            yield return(dialogueManager.WaitForCaughtUpText());

            allyPokemonParent.transform.localPosition = Vector3.zero;

            for (int i = 500; i >= 0; i -= 10)
            {
                allyParent.transform.localPosition = new Vector3(i, -32, 0);
                yield return(null);
            }

            while (!allyPokemon.CheckForDeath() && !foePokemon.CheckForDeath())
            {
                int foeRand  = Random.Range(0, foePokemon.GetNumberOfMoves());
                int allyRand = Random.Range(0, allyPokemon.GetNumberOfMoves());

                Pokemon fasterPokemon;
                Pokemon slowerPokemon;

                if (allyPokemon.speed > foePokemon.speed)
                {
                    fasterPokemon = allyPokemon;
                    slowerPokemon = foePokemon;
                }
                else
                {
                    fasterPokemon = foePokemon;
                    slowerPokemon = allyPokemon;
                }

                yield return(StartCoroutine(SingleAttack(fasterPokemon, slowerPokemon, foeRand)));



                int check = CheckIfEitherPokemonDied();

                if (check != 0)
                {
                    allyDied = (check == 1);
                    foeDied  = (check == 2);
                    break;
                }

                yield return(StartCoroutine(SingleAttack(slowerPokemon, fasterPokemon, allyRand)));

                check = CheckIfEitherPokemonDied();

                if (check != 0)
                {
                    allyDied = (check == 1);
                    foeDied  = (check == 2);
                    break;
                }
            }

            if (foeDied)
            {
                int exp = ExperienceCalculation(allyPokemon, foePokemon);

                yield return(StartCoroutine(dialogueManager.WaitForCaughtUpTextAndInput()));

                for (int i = 0; i < 150; i += 10)
                {
                    foePokemonParent.transform.localPosition = new Vector3(0, -i, 0);
                    yield return(null);
                }

                dialogueManager.AddDialogue(foePokemon.GetName() + " fainted!");
                yield return(StartCoroutine(dialogueManager.WaitForCaughtUpTextAndInput()));

                dialogueManager.AddDialogue(allyPokemon.GetName() + " gained " + exp + " experience points!");
                yield return(StartCoroutine(dialogueManager.WaitForCaughtUpTextAndInput()));

                allyPokemon.ModXP(exp);
                yield return(StartCoroutine(WaitForBarsToLoad()));

                break;
            }

            if (allyDied)
            {
                yield return(StartCoroutine(dialogueManager.WaitForCaughtUpTextAndInput()));

                for (int i = 0; i < 150; i += 10)
                {
                    allyPokemonParent.transform.localPosition = new Vector3(0, -i, 0);
                    yield return(null);
                }

                dialogueManager.AddDialogue(allyPokemon.GetName() + " fainted!");
                yield return(StartCoroutine(dialogueManager.WaitForCaughtUpTextAndInput()));

                if (!Player.instance.party.HasUsablePokemon())
                {
                    partyDead = true;
                }
            }
        }

        if (partyDead)
        {
            dialogueManager.AddDialogue(Player.instance.name + " is out of usable Pokemon!");
            dialogueManager.AddDialogue(Player.instance.name + " blacked out!");
            yield return(StartCoroutine(dialogueManager.WaitForCaughtUpTextAndInput()));
        }

        //dialogueManager.AddDialogue("BATTLE OVER");

        PokemonGameManager.instance.EndBattle();
    }