Beispiel #1
0
    IEnumerator RunSkill(BattleUnit source, BattleUnit target, SkillCalc skill)
    {
        bool canMove = source.teras.OnBeforeMove();

        if (!canMove)
        {
            yield return(ShowStatusChanges(source.teras));

            yield return(source.Hud.UpdateHP());

            yield break;
        }

        skill.UseLeft--;
        yield return(dialogBox.TypeDialog($"{source.teras._baseTeras.Name} used {skill.baseSkill.Name}!"));

        if (CheckAccHit(skill, source.teras, target.teras) == true)
        {
            source.AttackAnim();
            yield return(new WaitForSeconds(1f));

            target.GetHitAnim();

            // Check for status condition
            if (skill.baseSkill.Category == SkillCategory.Status)
            {
                yield return(RunSkillEffects(skill.baseSkill.Effects, source.teras, target.teras, skill.baseSkill.SkillTarget));
            }
            // if its not a damaging move deal damage
            if (skill.baseSkill.Category.CompareTo(SkillCategory.Status) <= 0)
            {
                var damageDetails = target.teras.TakeDamage(skill, source.teras);
                yield return(target.Hud.UpdateHP());

                yield return(ShowDamageDetails(damageDetails));
            }

            if (skill.baseSkill.SecondaryEffects != null && skill.baseSkill.SecondaryEffects.Count > 0 && target.teras.Health > 0)
            {
                foreach (var secondary in skill.baseSkill.SecondaryEffects)
                {
                    var random = UnityEngine.Random.Range(1, 101);
                    if (random <= secondary.Chance)
                    {
                        yield return(RunSkillEffects(secondary, source.teras, target.teras, secondary.Target));
                    }
                }
            }

            // if the opposing teras fainted make battle over event true to end battle
            if (target.teras.Health <= 0)
            {
                yield return(dialogBox.TypeDialog($"{target.teras._baseTeras.Name} fainted!"));

                target.FaintAnim();

                yield return(new WaitForSeconds(2f));

                CheckBattleOver(target);
            }
        }
        else
        {
            yield return(dialogBox.TypeDialog($"{source.teras._baseTeras.Name} missed its attack!"));
        }
    }