public void UpdateMatchDayLineUp()
        {
            OverallLineUp.Clear();

            var goal = this.Squad.Where(x => x.Position == PlayerPosition.GK).OrderByDescending(x => x.OverallRating).FirstOrDefault();

            var defence = this.Squad.Where(x => x.Position == PlayerPosition.RB || x.Position == PlayerPosition.LB || x.Position == PlayerPosition.CB).OrderByDescending(x => x.OverallRating);

            for (int i = 0; i < this.Manager.Formation.Defence - 1; i++)
            {
                OverallLineUp.Add(defence.ElementAtOrDefault(i));
            }

            var midfield = this.Squad.Where(x => x.Position == PlayerPosition.RM || x.Position == PlayerPosition.LM || x.Position == PlayerPosition.CM).OrderByDescending(x => x.OverallRating);

            for (int i = 0; i < this.Manager.Formation.Midfield - 1; i++)
            {
                OverallLineUp.Add(defence.ElementAtOrDefault(i));
            }

            var attack = this.Squad.Where(x => x.Position == PlayerPosition.ST).OrderByDescending(x => x.OverallRating);

            for (int i = 0; i < this.Manager.Formation.Attack - 1; i++)
            {
                OverallLineUp.Add(defence.ElementAtOrDefault(i));
            }

            OverallLineUpRating = (int)OverallLineUp.Select(x => x.OverallRating).Average();
        }
예제 #2
0
        public void UpdateMatchDayLineUp()
        {
            OverallLineUp.Clear();

            var goal     = this.Squad.Where(x => x.Position == PlayerPosition.GK).OrderByDescending(x => x.OverallRating).ToList();
            var defence  = this.Squad.Where(x => x.Position == PlayerPosition.RB || x.Position == PlayerPosition.LB || x.Position == PlayerPosition.CB).OrderByDescending(x => x.OverallRating).ToList();
            var midfield = this.Squad.Where(x => x.Position == PlayerPosition.RM || x.Position == PlayerPosition.LM || x.Position == PlayerPosition.CM).OrderByDescending(x => x.OverallRating).ToList();
            var attack   = this.Squad.Where(x => x.Position == PlayerPosition.ST).OrderByDescending(x => x.OverallRating).ToList();

            OverallLineUp.Add(goal.FirstOrDefault());
            if (goal.FirstOrDefault() != null)
            {
                goal.RemoveAt(0);
            }

            for (int i = 0; i < this.Manager.Formation.Defence; i++)
            {
                if (defence.FirstOrDefault() == null)
                {
                    if (midfield.ElementAtOrDefault(Manager.Formation.Midfield) == null)
                    {
                        OverallLineUp.Add(attack.ElementAtOrDefault(Manager.Formation.Attack));

                        if (attack.ElementAtOrDefault(Manager.Formation.Attack) != null)
                        {
                            attack.RemoveAt(Manager.Formation.Attack);
                        }
                        continue;
                    }

                    OverallLineUp.Add(midfield.ElementAt(Manager.Formation.Midfield));
                    midfield.RemoveAt(Manager.Formation.Midfield);
                    continue;
                }

                OverallLineUp.Add(defence.First());
                defence.RemoveAt(0);
            }

            for (int i = 0; i < this.Manager.Formation.Midfield; i++)
            {
                if (midfield.FirstOrDefault() == null)
                {
                    if (attack.ElementAtOrDefault(Manager.Formation.Attack) == null)
                    {
                        OverallLineUp.Add(defence.FirstOrDefault());

                        if (defence.FirstOrDefault() != null)
                        {
                            defence.RemoveAt(0);
                        }
                        continue;
                    }

                    OverallLineUp.Add(attack.ElementAt(Manager.Formation.Attack));
                    attack.RemoveAt(Manager.Formation.Attack);
                    continue;
                }

                OverallLineUp.Add(midfield.First());
                midfield.RemoveAt(0);
            }

            for (int i = 0; i < this.Manager.Formation.Attack; i++)
            {
                if (attack.FirstOrDefault() == null)
                {
                    if (midfield.FirstOrDefault() == null)
                    {
                        OverallLineUp.Add(defence.FirstOrDefault());
                        if (defence.FirstOrDefault() != null)
                        {
                            defence.RemoveAt(0);
                        }
                        continue;
                    }

                    OverallLineUp.Add(midfield.FirstOrDefault());
                    midfield.RemoveAt(0);
                    continue;
                }

                OverallLineUp.Add(attack.First());
                attack.RemoveAt(0);
            }

            var subs = new List <FootballPlayer>();

            subs.AddRange(midfield);
            subs.AddRange(defence);
            subs.AddRange(attack);
            subs.AddRange(goal);

            for (int i = 0; i < 11; i++)
            {
                if (OverallLineUp[i] == null)
                {
                    OverallLineUp.Remove(null);
                    OverallLineUp.Add(subs.First());
                    subs.RemoveAt(0);
                }
            }

            OverallLineUpRating = (int)OverallLineUp.Select(x => x.OverallRating).Average();
        }