Beispiel #1
0
        public IEnumerator CastSkill(SkillStats skill, Unit caster)
        {
            if (caster.IsPlayer)
            {
                caster.ApplyCost(skill.Cost, skill.CostType);
                ChangeDescription("Using " + skill.NameStr);
            }
            else
            {
                ChangeDescription(caster.NameStr + " uses " + skill.NameStr);
            }
            if (caster.GetStatus() == Constants.StatusTypes.Forget && skill.CostType == Constants.CostTypes.Spell)
            {
                log.Add(caster.NameStr + " forgot how to use spells");
                AdvanceTurn();
            }
            //Guard
            if (skill.SkillType == Constants.SkillTypes.Hidden && skill.BuffType == Constants.BuffTypes.Guard)
            {
                float waitDuration = gameManager.PlayParticle(Constants.SkillTypes.Buff, Constants.MAX_ENEMIES);
                yield return(new WaitForSeconds(waitDuration * 1f));

                DoBuff(skill, caster, caster, true, Constants.MAX_ENEMIES);
            }
            else
            //Find defender(s)
            if (skill.SkillType <= Constants.SkillTypes.Dark || skill.SkillType == Constants.SkillTypes.Hidden)
            {
                float waitDuration;
                //Get Targets
                if (skill.TargetType == Constants.TargetTypes.All && caster.IsPlayer)
                {
                    for (int i = 0; i < monsters.Length; i++)
                    {
                        if (monsters[i].enabled)
                        {
                            waitDuration = gameManager.PlayParticle(skill.SkillType, i);
                            yield return(new WaitForSeconds(waitDuration / 2));

                            DoHit(skill, caster, monsters[i], caster.IsPlayer, i);
                        }
                    }
                }
                else if (skill.TargetType == Constants.TargetTypes.Single && caster.IsPlayer)
                {
                    int targetPos = GetFirstTargetPos();
                    if (targetPos != -1)
                    {
                        waitDuration = gameManager.PlayParticle(skill.SkillType, targetPos);
                        Monster target = GetFirstTarget();
                        yield return(new WaitForSeconds(waitDuration));

                        DoHit(skill, caster, target, caster.IsPlayer, targetPos);
                    }
                }
                else if (!caster.IsPlayer)
                {
                    waitDuration = gameManager.PlayParticle(skill.SkillType, Constants.MAX_ENEMIES);
                    yield return(new WaitForSeconds(waitDuration * 1f));

                    DoHit(skill, caster, player, false, Constants.MAX_ENEMIES);
                }
            }
            else if (skill.SkillType == Constants.SkillTypes.Heal)
            {
                float waitDuration;
                if (skill.TargetType == Constants.TargetTypes.All && !caster.IsPlayer)
                {
                    for (int i = 0; i < monsters.Length; i++)
                    {
                        if (monsters[i].enabled)
                        {
                            waitDuration = gameManager.PlayParticle(skill.SkillType, i);
                            yield return(new WaitForSeconds(waitDuration / 2));

                            DoHeal(skill, caster, monsters[i], caster.IsPlayer, i);
                        }
                    }
                }
                else if (skill.TargetType == Constants.TargetTypes.Single && !caster.IsPlayer)
                {
                    float[] temp = new float[Constants.MAX_ENEMIES];
                    for (int i = 0; i < monsters.Length; i++)
                    {
                        if (monsters[i].enabled)
                        {
                            temp[i] = monsters[i].CurrentHealth;
                        }
                        else
                        {
                            temp[i] = Mathf.Infinity;
                        }
                    }
                    int pos = Array.IndexOf(temp, temp.Min());
                    waitDuration = gameManager.PlayParticle(skill.SkillType, pos);
                    yield return(new WaitForSeconds(waitDuration * 1f));

                    DoHeal(skill, caster, monsters[pos], caster.IsPlayer, pos);
                }
                else
                {
                    waitDuration = gameManager.PlayParticle(skill.SkillType, Constants.MAX_ENEMIES);
                    yield return(new WaitForSeconds(waitDuration * 1f));

                    DoHeal(skill, caster, caster, true, Constants.MAX_ENEMIES);
                }
            }
            else if (skill.SkillType == Constants.SkillTypes.Break)
            {
                float waitDuration;
                if (!caster.IsPlayer)
                {
                    waitDuration = gameManager.PlayParticle(skill.SkillType, Array.IndexOf(monsters, caster));
                    yield return(new WaitForSeconds(waitDuration * 1f));
                }
                else
                {
                    waitDuration = gameManager.PlayParticle(skill.SkillType, Constants.MAX_ENEMIES);
                    yield return(new WaitForSeconds(waitDuration * 1f));
                }
                if (caster.GetStatus() == skill.StatusType)
                {
                    caster.RemoveStatus();
                    log.Add("You broke free from your status affliction");
                }
                else
                {
                    log.Add("You tried to break, but you weren't afflicted by that status");
                }
            }
            else if (skill.SkillType == Constants.SkillTypes.Status || skill.SkillType == Constants.SkillTypes.Blast)
            {
                float waitDuration;
                //Get Targets
                if (skill.TargetType == Constants.TargetTypes.All && caster.IsPlayer)
                {
                    for (int i = 0; i < monsters.Length; i++)
                    {
                        if (monsters[i].enabled)
                        {
                            waitDuration = gameManager.PlayParticle(skill.SkillType, i);
                            yield return(new WaitForSeconds(waitDuration / 2));

                            DoStatus(skill, caster, monsters[i], caster.IsPlayer, i);
                        }
                    }
                }
                else if (skill.TargetType == Constants.TargetTypes.Single && caster.IsPlayer)
                {
                    int targetPos = GetFirstTargetPos();
                    if (targetPos != -1)
                    {
                        waitDuration = gameManager.PlayParticle(skill.SkillType, targetPos);
                        Monster target = GetFirstTarget();
                        yield return(new WaitForSeconds(waitDuration * 1f));

                        DoStatus(skill, caster, target, caster.IsPlayer, targetPos);
                    }
                }
                else if (!caster.IsPlayer)
                {
                    waitDuration = gameManager.PlayParticle(skill.SkillType, Constants.MAX_ENEMIES);
                    yield return(new WaitForSeconds(waitDuration * 1f));

                    DoStatus(skill, caster, player, false, Constants.MAX_ENEMIES);
                }
            }
            else if (skill.SkillType == Constants.SkillTypes.Buff && skill.Power >= 0)
            {
                //Buff
                float waitDuration;
                if (skill.TargetType == Constants.TargetTypes.All && !caster.IsPlayer)
                {
                    for (int i = 0; i < monsters.Length; i++)
                    {
                        if (monsters[i].enabled)
                        {
                            waitDuration = gameManager.PlayParticle(skill.SkillType, i);
                            yield return(new WaitForSeconds(waitDuration / 2));

                            DoBuff(skill, caster, monsters[i], caster.IsPlayer, i);
                        }
                    }
                }
                else if (skill.TargetType == Constants.TargetTypes.Single && !caster.IsPlayer)
                {
                    float[] temp = new float[Constants.MAX_ENEMIES];
                    for (int i = 0; i < monsters.Length; i++)
                    {
                        if (monsters[i].enabled)
                        {
                            temp[i] = monsters[i].CurrentHealth;
                        }
                        else
                        {
                            temp[i] = Mathf.Infinity;
                        }
                    }
                    int pos = Array.IndexOf(temp, temp.Min());
                    waitDuration = gameManager.PlayParticle(skill.SkillType, pos);
                    yield return(new WaitForSeconds(waitDuration * 1f));

                    DoBuff(skill, caster, monsters[pos], caster.IsPlayer, pos);
                }
                else
                {
                    waitDuration = gameManager.PlayParticle(skill.SkillType, Constants.MAX_ENEMIES);
                    yield return(new WaitForSeconds(waitDuration * 1f));

                    DoBuff(skill, caster, caster, true, Constants.MAX_ENEMIES);
                }
            }
            else if (skill.SkillType == Constants.SkillTypes.Buff && skill.Power <= 0)
            {
                //Debuff
                float waitDuration;
                //Get Targets
                if (skill.TargetType == Constants.TargetTypes.All && caster.IsPlayer)
                {
                    for (int i = 0; i < monsters.Length; i++)
                    {
                        if (monsters[i].enabled)
                        {
                            waitDuration = gameManager.PlayParticle(skill.SkillType, i);
                            yield return(new WaitForSeconds(waitDuration / 2));

                            DoBuff(skill, caster, monsters[i], caster.IsPlayer, i);
                        }
                    }
                }
                else if (skill.TargetType == Constants.TargetTypes.Single && caster.IsPlayer)
                {
                    int targetPos = GetFirstTargetPos();
                    if (targetPos != -1)
                    {
                        waitDuration = gameManager.PlayParticle(skill.SkillType, targetPos);
                        Monster target = GetFirstTarget();
                        yield return(new WaitForSeconds(waitDuration * 1f));

                        DoBuff(skill, caster, target, caster.IsPlayer, targetPos);
                    }
                }
                else if (!caster.IsPlayer)
                {
                    waitDuration = gameManager.PlayParticle(skill.SkillType, Constants.MAX_ENEMIES);
                    yield return(new WaitForSeconds(waitDuration * 1f));

                    DoBuff(skill, caster, player, false, Constants.MAX_ENEMIES);
                }
            }
            else
            {
                log.Add("WIP skill");
            }
            ClearDescription();
            if (Turn != Turns.EndGame)
            {
                if (!CheckAlive())
                {
                    yield return(new WaitForSeconds(1f));

                    HideAllHealthBars();
                    rewards.GenerateRewards();
                }
                else
                {
                    if (caster.OneMore)
                    {
                        caster.OneMore = false;
                        HideOneMore();
                        if (!caster.IsPlayer)
                        {
                            MonsterCast((int)Turn - 1);
                        }
                        else
                        {
                            ChangeDescription("Knocked one down! Take another turn");
                        }
                    }
                    else
                    {
                        HideOneMore();
                        yield return(new WaitForSeconds(1f));

                        AdvanceTurn();
                    }
                }
            }
            else
            {
                ChangeDescription("You are Dead");
                yield return(new WaitForSeconds(5f));

                SceneManager.LoadScene(0);
            }
        }