Exemplo n.º 1
0
 public void ExecuteAttack()
 {
     if (fightState == FightFlow.ChooseElements)
     {
         fightState = FightFlow.Attack;
         executeButton.SetActive(false);
     }
 }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        #region Health/SPUpdate

        //set hp
        var temp = hpBar.GetComponent <RectTransform>();
        temp.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, Mathf.Clamp((player.GetComponent <CharacterStats>().healthCurrent *hpBarMaxWidth) / player.GetComponent <CharacterStats>().currentStats.health, 0, 100000));
        hpLabel.text = player.GetComponent <CharacterStats>().healthCurrent.ToString() + "/" + player.GetComponent <CharacterStats>().currentStats.health.ToString();

        //set sp - slime points
        temp = spBar.GetComponent <RectTransform>();
        temp.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, Mathf.Clamp((player.GetComponent <CharacterStats>().slimeCurrent *spBarMaxWidth) / player.GetComponent <CharacterStats>().currentStats.slime, 0, 100000));
        spLabel.text = player.GetComponent <CharacterStats>().slimeCurrent.ToString() + "/" + player.GetComponent <CharacterStats>().currentStats.slime.ToString();

        //error fixing
        try
        {
            if (enemy != null)
            {
                //set enemy hp
                temp = enemyHpBar.GetComponent <RectTransform>();
                temp.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, Mathf.Clamp((enemy.GetHealth() * enemyHpBarMaxWidth) / enemy.GetHealthMax(), 0, 100000));
                enemyHpLabel.text = enemy.GetHealth().ToString() + "/" + enemy.GetHealthMax().ToString();

                //set enemy sp - slime points
                temp = enemySpBar.GetComponent <RectTransform>();
                temp.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, Mathf.Clamp((enemy.GetSP() * spBarMaxWidth) / enemy.GetSPMax(), 0, 100000));
                enemySpLabel.text = enemy.GetSP().ToString() + "/" + enemy.GetSPMax().ToString();
            }
        }
        catch (Exception ex)
        {
            Debug.Log("Enemy not set. Error: " + ex.ToString());
        }

        #endregion

        #region FightFlow

        //continuous label update
        UpdateInfoLabel();

        //fight flow
        switch (fightState)
        {
        case FightFlow.Start:
        {
            ResetFight();

            //label write
            WriteToInfoLabel(string.Format("<color=purple>{0}</color> encountered!", enemy.GetEnemyType()));

            #region UISetUp

            enemyName.text = enemy.GetEnemyName();

            //set element choice slots
            maxElementChoiceSlots = Mathf.Clamp(player.GetComponent <CharacterStats>().currentStats.elementSlots, 0, 7);

            //disable/enable elemental slots
            for (int i = 0; i < elementChoiceSlots.Length; i++)
            {
                //skill[0] dictates the amount of elemental slots a player can have
                if (i < maxElementChoiceSlots)
                {
                    elementChoiceSlots[i].SetActive(true);
                }
                else
                {
                    elementChoiceSlots[i].SetActive(false);
                }
            }

            //set elements available according to lvl 1 skills
            for (int i = 0; i < elementIcons.Length; i++)
            {
                if (player.GetComponent <CharacterSkillTree>().ActiveSkills()[i].CurrentLevel() > 0)
                {
                    elementChoices[i].SetActive(true);
                }
                else
                {
                    elementChoices[i].SetActive(false);
                }
            }

            #endregion

            //move to next phase
            fightState = FightFlow.ChooseElements;

            break;
        }

        case FightFlow.ChooseElements:
        {
            //check death
            if (player.GetComponent <CharacterStats>().healthCurrent <= 0)
            {
                //write death
                WriteToInfoLabel("You're too weak to continue...");

                //advance time
                StoryProgressionManager.AddTime(24);

                //end fight
                fightState = FightFlow.End;
            }

            //enable element choosing
            chooseElements = true;

            //if at least one elements has been chosen
            if (elementChoicesCounter >= maxElementChoiceSlots)
            {
                executeButton.SetActive(true);
            }
            else
            {
                executeButton.SetActive(false);
            }

            break;
        }

        case FightFlow.Attack:
        {
            //disable element choosing
            chooseElements = false;

            //attack
            AttackRoutine();

            //clear element choice slots
            ClearChosenSlots();

            //change phase
            if (enemy.GetHealth() > 0)
            {
                fightState = FightFlow.Defend;
            }
            else
            {
                //end
                fightState = FightFlow.Resolve;
            }

            break;
        }

        case FightFlow.Defend:
        {
            //enemy attack
            DefendRoutine();

            //advance time
            StoryProgressionManager.AddTime(1);

            //check death
            if (player.GetComponent <CharacterStats>().healthCurrent <= 0)
            {
                //write death
                WriteToInfoLabel("You're too weak to continue...");

                //advance time
                StoryProgressionManager.AddTime(24);

                //end fight
                fightState = FightFlow.End;
            }
            else
            {
                //attack again
                fightState = FightFlow.ChooseElements;
            }

            break;
        }

        case FightFlow.Resolve:
        {
            //write exp given
            WriteToInfoLabel(string.Format("Battle end... Obtained <color=yellow>{0}</color> exp.", enemy.GetExp()));

            //give exp
            player.GetComponent <CharacterStats>().GainExp(enemy.GetExp());

            //add enemy to requirements
            StoryProgressionManager.currentRequirementProgress.ChangeRequirementValue(enemy.GetElement(), 1);

            //end
            fightState = FightFlow.End;

            break;
        }

        case FightFlow.End:
        {
            //remove enemy skill effects
            foreach (EnemySkillEffect skillEffect in player.GetComponents <EnemySkillEffect>())
            {
                Destroy(skillEffect);
            }

            //wait for read
            if (!WaitingForRead())
            {
                //check death
                if (player.GetComponent <CharacterStats>().healthCurrent <= 0)
                {
                    player.GetComponent <CharacterStats>().actionPointsCurent = 0;
                }
                else
                {
                    //take ap
                    player.GetComponent <CharacterStats>().actionPointsCurent--;
                }

                fightState = FightFlow.OutsideFight;

                //fade
                GameObject.FindGameObjectWithTag("FadePanel").GetComponent <FadePanel>().Fade(0.5f);
            }

            break;
        }

        case FightFlow.OutsideFight:
        {
            //keep window hidden
            GetComponent <ShowHideWindow>().showHide = false;
            infoLabel.text = "";
            break;
        }
        }

        #endregion
    }
Exemplo n.º 3
0
    // Start is called before the first frame update
    void Start()
    {
        ResetFight();

        fightState = FightFlow.OutsideFight;
    }
Exemplo n.º 4
0
 public void EnemyEscape()
 {
     fightState = FightFlow.End;
 }
Exemplo n.º 5
0
 public void StartFight(Enemy enemySelected)
 {
     enemy = enemySelected;
     enemy.statsCurrent = enemySelected.statsCurrent;
     fightState         = FightFlow.Start;
 }