Ejemplo n.º 1
0
    public void Update()
    {
        switch (state)
        {
        case State.WaitingForPlayer:
            // Player Turn

            if (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.W))
            {
                // Select Target Up
                SetSelectedTargetCharacterBattle(
                    GetNextCharacterBattle(selectedTargetCharacterBattle.GetLanePosition(), true, false));
            }

            if (Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown(KeyCode.S))
            {
                // Select Target Down
                SetSelectedTargetCharacterBattle(
                    GetNextCharacterBattle(selectedTargetCharacterBattle.GetLanePosition(), false, false));
            }

            if (Input.GetKeyDown(KeyCode.Space))
            {
                // Attack
                state = State.Busy;
                SetCamera(selectedTargetCharacterBattle.GetPosition() + new Vector3(-5f, 0), 30f);
                activeCharacterBattle.AttackTarget(selectedTargetCharacterBattle.GetPosition(), () =>
                {
                    SoundManager.PlaySound(SoundManager.Sound.CharacterHit);
                    int damageBase = activeCharacterBattle.GetAttack();
                    int damageMin  = (int)(damageBase * 0.8f);
                    int damageMax  = (int)(damageBase * 1.2f);
                    selectedTargetCharacterBattle.Damage(activeCharacterBattle,
                                                         UnityEngine.Random.Range(damageMin, damageMax));
                    UtilsClass.ShakeCamera(.75f, .1f);
                    if (selectedTargetCharacterBattle.IsDead())
                    {
                        TestEvilMonsterKilled();
                    }
                }, () =>
                {
                    ResetCamera();
                    activeCharacterBattle.SlideBack(() => FunctionTimer.Create(ChooseNextActiveCharacter, .2f));
                });
            }

            if (Input.GetKeyDown(KeyCode.R))
            {
                // Special
                if (activeCharacterBattle.TrySpendSpecial())
                {
                    // Spend Special
                    switch (activeCharacterBattle.GetCharacterType())
                    {
                    default:
                    case Character.Type.Player:
                        state = State.Busy;
                        SetCamera(selectedTargetCharacterBattle.GetPosition() + new Vector3(-5f, 0), 30f);
                        Vector3 slideToPosition =
                            selectedTargetCharacterBattle.GetPosition() + new Vector3(-8f, 0);
                        activeCharacterBattle.SlideToPosition(slideToPosition, () =>
                        {
                            activeCharacterBattle.PlayAnim(
                                UnitAnim.GetUnitAnim("dSwordShield_SpartanKickRight"), (UnitAnim u) =>
                            {
                                ResetCamera();
                                activeCharacterBattle.SlideBack(() =>
                                                                FunctionTimer.Create(ChooseNextActiveCharacter, .2f));
                            }, (string trigger) =>
                            {
                                // Massive Single Enemy Damage
                                SoundManager.PlaySound(SoundManager.Sound.CharacterHit);
                                UtilsClass.ShakeCamera(2f, .15f);
                                int damageAmount = 100;
                                selectedTargetCharacterBattle.Damage(activeCharacterBattle, damageAmount);
                                if (selectedTargetCharacterBattle.IsDead())
                                {
                                    TestEvilMonsterKilled();
                                }
                            });
                        });
                        break;

                    case Character.Type.Tank:
                        state = State.Busy;
                        activeCharacterBattle.SlideToPosition(
                            GetPosition(LanePosition.Middle, false) + new Vector3(-15, 0), () =>
                        {
                            activeCharacterBattle.PlayAnim(UnitAnim.GetUnitAnim("dDagger_GroundPound"),
                                                           (UnitAnim u) =>
                            {
                                activeCharacterBattle.SlideBack(() =>
                                                                FunctionTimer.Create(ChooseNextActiveCharacter, .2f));
                            }, (string trigger) =>
                            {
                                // Damage All Enemies
                                SoundManager.PlaySound(SoundManager.Sound.GroundPound);
                                UtilsClass.ShakeCamera(2f, .15f);
                                int damageAmount = 30;
                                List <CharacterBattle> characterBattleList =
                                    GetAliveTeamCharacterBattleList(false);
                                foreach (CharacterBattle characterBattle in characterBattleList)
                                {
                                    characterBattle.Damage(activeCharacterBattle, damageAmount);
                                }

                                if (selectedTargetCharacterBattle.IsDead())
                                {
                                    TestEvilMonsterKilled();
                                }
                            });
                        });
                        break;

                    case Character.Type.Healer:
                        state = State.Busy;
                        SetCamera(activeCharacterBattle.GetPosition(), 30f);
                        activeCharacterBattle.PlayAnim(UnitAnim.GetUnitAnim("dBareHands_Victory"),
                                                       (UnitAnim u) =>
                        {
                            activeCharacterBattle.PlayIdleAnim();
                            ResetCamera();
                            FunctionTimer.Create(ChooseNextActiveCharacter, .2f);
                        }, (string trigger) => { });

                        FunctionTimer.Create(() =>
                        {
                            // Heal all
                            SoundManager.PlaySound(SoundManager.Sound.Heal);
                            List <CharacterBattle> characterBattleList = GetAliveTeamCharacterBattleList(true);
                            foreach (CharacterBattle characterBattle in characterBattleList)
                            {
                                characterBattle.Heal(50);
                            }
                        }, 1.2f);
                        break;
                    }
                }
            }

            if (Input.GetKeyDown(KeyCode.T))
            {
                // Heal
                if (GameData.TrySpendHealthPotion())
                {
                    state = State.Busy;
                    activeCharacterBattle.Heal(100);
                    FunctionTimer.Create(ChooseNextActiveCharacter, .2f);
                }
            }

            break;

        case State.Busy:
            break;
        }
    }