public void UseSkill(int skillID, int enemyIndex)
 {
     if (Player.HasSkill(skillID))
     {
         Skill         skill    = SkillFactory.Instance.FindSkill(skillID);
         BattleFactors playerBF = Player.BattleFactors;
         PlayerSkillEffectStatuses.ForEach(x => x.effector.Use(playerBF, null));
         if (skill.IsAoE)
         {
             var affectedTargets = MonsterBattleFactors.Where(x => x.healthPoint >= 0 && HitCheck(playerBF, x)).ToList();
             skill.Use(playerBF, affectedTargets);
             skill.SkillEffectors.OfType <SustainSkillEffector>().ToList().ForEach(effector =>
             {
                 SkillEffectStatus status = new SkillEffectStatus {
                     effector = effector, remainedRound = effector.SustainRound
                 };
                 if (effector is TargetSpeedPointSkillEffector || effector is TargetStopActionSkillEffector)
                 {
                     foreach (var affectedTarget in affectedTargets)
                     {
                         MonstersSkillEffectStatuses[MonsterBattleFactors.IndexOf(affectedTarget)].Add(status);
                     }
                 }
                 else
                 {
                     PlayerSkillEffectStatuses.Add(status);
                 }
             });
         }
         else
         {
             if (HitCheck(playerBF, MonsterBattleFactors[enemyIndex]))
             {
                 skill.Use(playerBF, new List <BattleFactors> {
                     MonsterBattleFactors[enemyIndex]
                 });
                 skill.SkillEffectors.OfType <SustainSkillEffector>().ToList().ForEach(x =>
                 {
                     SkillEffectStatus status = new SkillEffectStatus {
                         effector = x, remainedRound = x.SustainRound
                     };
                     if (x is TargetSpeedPointSkillEffector || x is TargetStopActionSkillEffector)
                     {
                         MonstersSkillEffectStatuses[enemyIndex].Add(status);
                     }
                     else
                     {
                         PlayerSkillEffectStatuses.Add(status);
                     }
                 });
             }
             else
             {
                 OnMiss?.Invoke(false, 0);
             }
         }
     }
     ProcessTurn();
 }
        public void ProcessTurn()
        {
            OnProcess?.Invoke();
            if (actionAgentList.Count > 0)
            {
                if (actionAgentList[0] == Player)
                {
                    OnPlayerActionRequest?.Invoke();
                    actionAgentList.Remove(Player);
                }
                else
                {
                    int enemyIndex = (int)actionAgentList[0];

                    BattleFactors monsterBF = MonsterBattleFactors[enemyIndex];
                    BattleFactors playerBF  = Player.BattleFactors;
                    PlayerSkillEffectStatuses.ForEach(x => x.effector.Use(playerBF, null));
                    if (HitCheck(monsterBF, playerBF))
                    {
                        Skill skill = Monsters[enemyIndex].Action();
                        if (skill == null)
                        {
                            Player.AbilityFactors.HP -= Math.Max(monsterBF.physicalAttackPoint - playerBF.physicalDefencePoint, 1);
                        }
                        else
                        {
                            skill.Use(monsterBF, new List <BattleFactors> {
                                playerBF
                            });
                            skill.SkillEffectors.OfType <SustainSkillEffector>().ToList().ForEach(x =>
                            {
                                SkillEffectStatus status = new SkillEffectStatus {
                                    effector = x, remainedRound = x.SustainRound
                                };
                                if (x is TargetSpeedPointSkillEffector || x is TargetStopActionSkillEffector)
                                {
                                    PlayerSkillEffectStatuses.Add(status);
                                }
                                else
                                {
                                    MonstersSkillEffectStatuses[enemyIndex].Add(status);
                                }
                            });
                        }
                    }
                    else
                    {
                        OnMiss?.Invoke(true, enemyIndex);
                    }
                    ProcessTurn();
                }
            }
            else
            {
                EndTurn();
            }
        }
 public void EndTurn()
 {
     PlayerSkillEffectStatuses.ForEach(x => x.remainedRound--);
     PlayerSkillEffectStatuses.RemoveAll(x => x.remainedRound < 0);
     for (int i = 0; i < Monsters.Count; i++)
     {
         MonstersSkillEffectStatuses[i].ForEach(effector => effector.remainedRound--);
         MonstersSkillEffectStatuses[i].RemoveAll(effector =>
         {
             effector.effector.End(MonsterBattleFactors[i]);
             return(effector.remainedRound < 0);
         });
     }
     OnEndTurn?.Invoke();
     StartTurn();
 }
        public void NormalAttack(int enemyIndex)
        {
            BattleFactors enemyBF  = MonsterBattleFactors[enemyIndex];
            BattleFactors playerBF = Player.BattleFactors;

            PlayerSkillEffectStatuses.ForEach(x => x.effector.Use(playerBF, null));
            if (HitCheck(playerBF, enemyBF))
            {
                enemyBF.healthPoint -= Math.Max(playerBF.physicalAttackPoint - enemyBF.physicalDefencePoint, 1);
                if (enemyBF.healthPoint <= 0 && actionAgentList.Any(x => x is int && (int)x == enemyIndex))
                {
                    actionAgentList.RemoveAll(x => x is int && (int)x == enemyIndex);
                }
            }
            else
            {
                OnMiss?.Invoke(false, 0);
            }
            ProcessTurn();
        }
        public void StartTurn()
        {
            actionAgentList = new List <object>();

            if (!PlayerSkillEffectStatuses.Any(x => x.effector is TargetStopActionSkillEffector))
            {
                actionAgentList.Add(Player);
            }
            for (int i = 0; i < Monsters.Count; i++)
            {
                if (!MonstersSkillEffectStatuses[i].Any(x => x.effector is TargetStopActionSkillEffector) && MonsterBattleFactors[i].healthPoint > 0)
                {
                    actionAgentList.Add(i);
                }
            }

            actionAgentList.OrderByDescending(x =>
            {
                if (x is Player)
                {
                    BattleFactors playerBF = Player.BattleFactors;
                    PlayerSkillEffectStatuses.ForEach(y => y.effector.Use(playerBF, null));
                    return(playerBF.speedPoint);
                }
                else
                {
                    return(MonsterBattleFactors[(int)x].speedPoint);
                }
            });
            if (MonsterBattleFactors.Any(x => x.healthPoint > 0))
            {
                OnStartTurn?.Invoke();
                ProcessTurn();
            }
            else
            {
                EndBattle();
            }
        }