Ejemplo n.º 1
0
    private void ChooseNextActiveCharacter()
    {
        // Choose the next character to act
        if (GetAliveTeamCharacterBattleList(false).Count == 0)
        {
            // Battle Over, Player Wins!
            Debug.Log("Battle Over, Player Wins!");
            // Kill Enemy Character in Overmap
            character.isDead = true;
            // Update Player Team Values
            foreach (CharacterBattle characterBattle in GetTeamCharacterBattleList(true))
            {
                if (Character.IsUniqueCharacterType(characterBattle.GetCharacterType()))
                {
                    // Unique Character
                    Character uniqueCharacter = GameData.GetCharacter(characterBattle.GetCharacterType());
                    if (uniqueCharacter != null)
                    {
                        uniqueCharacter.stats.health = characterBattle.GetHealthAmount();
                        if (uniqueCharacter.isInPlayerTeam)
                        {
                            if (uniqueCharacter.stats.health < 1)
                            {
                                uniqueCharacter.stats.health = 1;
                            }
                        }
                    }
                }
            }

            Debug.Log("GameData.state: " + GameData.state);
            switch (GameData.state)
            {
            case GameData.State.Start:
                break;

            case GameData.State.FightingHurtMeDaddy:
                GameData.state = GameData.State.DefeatedHurtMeDaddy;
                break;

            case GameData.State.FightingHurtMeDaddy_2:
                GameData.state = GameData.State.DefeatedHurtMeDaddy_2;
                break;

            case GameData.State.FightingTank:
                GameData.state = GameData.State.DefeatedTank;
                // Heal Tank
                character.isDead         = false;
                character.isInPlayerTeam = true;
                character.stats.health   = character.stats.healthMax;
                character.subType        = Character.SubType.Tank_Friendly;
                GameData.GetCharacter(Character.Type.Sleezer).subType = Character.SubType.Sleezer_Friendly;
                // Heal Player
                Character uniqueCharacter = GameData.GetCharacter(Character.Type.Player);
                uniqueCharacter.stats.health = uniqueCharacter.stats.healthMax;
                break;

            case GameData.State.FightingTavernAmbush:
                GameData.state = GameData.State.SurvivedTavernAmbush;
                break;

            case GameData.State.FightingEvilMonster_1:
                // Player Lost to Evil Monster
                GameData.GetCharacter(Character.Type.Player).stats.health = 1;
                GameData.GetCharacter(Character.Type.Tank).stats.health   = 1;
                GameData.GetCharacter(Character.Type.Healer).stats.health = 1;
                GameData.state = GameData.State.LostToEvilMonster_1;
                break;

            case GameData.State.FightingEvilMonster_2:
                // Player Lost to Evil Monster
                GameData.state = GameData.State.LostToEvilMonster_2;
                break;

            case GameData.State.FightingEvilMonster_3:
                // Player Defeated Evil Monster
                GameData.state = GameData.State.DefeatedEvilMonster;
                break;
            }

            //SoundManager.PlaySound(SoundManager.Sound.BattleWin);
            FunctionTimer.Create(OvermapHandler.LoadBackToOvermap, .7f);
            return;
        }

        if (GetAliveTeamCharacterBattleList(true).Count == 0)
        {
            // Battle Over, Enemy Wins!
            Debug.Log("#### Battle Over, Enemy Wins!");

            foreach (CharacterBattle characterBattle in GetTeamCharacterBattleList(true))
            {
                if (Character.IsUniqueCharacterType(characterBattle.GetCharacterType()))
                {
                    // Unique Character
                    Character uniqueCharacter = GameData.GetCharacter(characterBattle.GetCharacterType());
                    if (uniqueCharacter != null)
                    {
                        uniqueCharacter.stats.health = characterBattle.GetHealthAmount();
                    }
                }
            }

            FunctionTimer.Create(OvermapHandler.LoadBackToOvermap, .7f);
            return;
        }

        // Choose Next Character
        if (activeCharacterBattle.IsPlayerTeam())
        {
            // Next is Enemy
            List <CharacterBattle> characterBattleList = GetAliveTeamCharacterBattleList(false);
            SetActiveCharacterBattle(
                GetNextCharacterBattle(lastEnemyActiveLanePosition, false, false)
                );
            lastEnemyActiveLanePosition = activeCharacterBattle.GetLanePosition();

            FunctionTimer.Create(() =>
            {
                CharacterBattle aiTargetCharacterBattle =
                    GetAliveTeamCharacterBattleList(true)[Random.Range(0, GetAliveTeamCharacterBattleList(true).Count)];
                SetCamera(aiTargetCharacterBattle.GetPosition() + new Vector3(+5f, 0), 30f);
                activeCharacterBattle.AttackTarget(aiTargetCharacterBattle.GetPosition(), () =>
                {
                    SoundManager.PlaySound(SoundManager.Sound.CharacterHit);
                    int damageBase   = activeCharacterBattle.GetAttack();
                    int damageMin    = (int)(damageBase * 0.8f);
                    int damageMax    = (int)(damageBase * 1.2f);
                    int damageAmount = Random.Range(damageMin, damageMax);
                    int damageChance = 75;
                    if (GetAliveCount(true) == 1)
                    {
                        // Only one character alive on the Players Team
                        CharacterBattle lastSurvivingCharacterBattle = GetAliveTeamCharacterBattleList(true)[0];
                        if (lastSurvivingCharacterBattle.GetHealthAmount() <= damageAmount)
                        {
                            // This hit would kill the last player character, miss
                            damageChance = 0;
                        }
                    }

                    if (Random.Range(0, 100) < damageChance)
                    {
                        // Hit
                        aiTargetCharacterBattle.Damage(activeCharacterBattle, damageAmount);
                        UtilsClass.ShakeCamera(.75f, .1f);
                    }
                    else
                    {
                        // Miss
                        DamagePopup.Create(activeCharacterBattle.GetPosition(), "MISS",
                                           UtilsClass.GetColorFromString("00B4FF"));
                    }
                }, () =>
                {
                    ResetCamera();
                    activeCharacterBattle.SlideBack(() => FunctionTimer.Create(ChooseNextActiveCharacter, .2f));
                });
            }, .3f);
        }
        else
        {
            // Next is player character
            List <CharacterBattle> characterBattleList = GetAliveTeamCharacterBattleList(true);
            //SetActiveCharacterBattle(characterBattleList[Random.Range(0, characterBattleList.Count)]);

            //Debug.Log(lastPlayerActiveLanePosition);
            SetActiveCharacterBattle(
                GetNextCharacterBattle(lastPlayerActiveLanePosition, false, true)
                );
            lastPlayerActiveLanePosition = activeCharacterBattle.GetLanePosition();
            //Debug.Log("2 " + lastPlayerActiveLanePosition);

            activeCharacterBattle.TickSpecialCooldown();

            RefreshSelectedTargetCharacterBattle();
            state = State.WaitingForPlayer;
        }
    }