Exemple #1
0
    //used to switch creatures
    IEnumerator SwitchCreature(Creature newCreature)
    {
        //bool currentCreatureFainted = true;

        if (playerUnit.Creature.HP > 0)
        {
            //currentCreatureFainted = false;
            //call out to your creature Return *friend*
            yield return(dialogueBox.TypeDialog($"Return {playerUnit.Creature.Base.Name}"));

            //SAM - replace below faint animation with return animation - SAM
            playerUnit.BattleFaintAnimation();
            yield return(new WaitForSeconds(2f));
        }

        //send out new creture
        playerUnit.Setup(newCreature);
        //Passing the next creatures moves to the set moves function over the previous
        dialogueBox.SetMoveNames(newCreature.Moves);

        //using string interprilation to bring in game spacific text
        yield return(dialogueBox.TypeDialog($"Go {newCreature.Base.Name}"));

        //if ennemy creature fainted dont allow them a free hit if you swapped creatures
        if (priorState == null)
        {
            state = BattleState.RunningTurn;
        }
        else if (priorState == BattleState.AboutToUse)
        {
            priorState = null;
            StartCoroutine(SendNextTrainerCreature());
        }
    }
Exemple #2
0
    //this will now hold all fainted calculations
    IEnumerator HandleCreatureFainted(BattleUnit faintedUnit)
    {
        yield return(dialogueBox.TypeDialog($"{faintedUnit.Creature.Base.Name} fainted"));

        faintedUnit.BattleFaintAnimation();
        yield return(new WaitForSeconds(2f));

        if (!faintedUnit.IsPlayerUnit)
        {
            //Experiance gain
            int expYield   = faintedUnit.Creature.Base.ExpYield;
            int enemyLevel = faintedUnit.Creature.Level;
            //float trainerBonus = (isTrainerBattle) ? 1.5f : 1f;

            //formula to calculate the experience gain
            int expGain = Mathf.FloorToInt((expYield * enemyLevel /** trainerBonus*/) / 7);
            //this is wehre the experience gain is added to our littel boy
            playerUnit.Creature.Exp += expGain;
            yield return(dialogueBox.TypeDialog($"{playerUnit.Creature.Base.Name} gained {expGain} exp"));

            yield return(playerUnit.Hud.SetExpSmooth());

            //check level up, while incase multiple levels exp is gained at once
            while (playerUnit.Creature.CheckForLevelUp())
            {
                playerUnit.Hud.SetLevel();
                yield return(dialogueBox.TypeDialog($"{playerUnit.Creature.Base.Name} grew to level {playerUnit.Creature.Level}"));

                //try to learn new move
                var newMove = playerUnit.Creature.GetLearnableMoveAtCurrLevel();
                if (newMove != null)
                {
                    if (playerUnit.Creature.Moves.Count < Creature.MaxNumberOfMoves)
                    {
                        // learn the new move
                        playerUnit.Creature.LearnMove(newMove);
                        yield return(dialogueBox.TypeDialog($"{playerUnit.Creature.Base.Name} learned {newMove.Base.Name}"));

                        dialogueBox.SetMoveNames(playerUnit.Creature.Moves);
                    }
                    else
                    {
                        yield return(dialogueBox.TypeDialog($"{playerUnit.Creature.Base.Name} is trying to learn {newMove.Base.Name}"));

                        yield return(dialogueBox.TypeDialog($"but it cannot learn more than {Creature.MaxNumberOfMoves} moves!"));

                        //creature forgets a move and adds new move
                        yield return(ChooseMoveToForget(playerUnit.Creature, newMove.Base));

                        yield return(new WaitUntil(() => state != BattleState.MoveToForget));

                        yield return(new WaitForSeconds(2f));
                    }
                }
                //creature may have gained more xp to just level up
                yield return(playerUnit.Hud.SetExpSmooth(true));
            }

            yield return(new WaitForSeconds(1f));
        }

        CheckForBattleOver(faintedUnit);
    }