public LeagueItemViewModel(GameCore core)
            : base(core)
        {
            Cities = new ObservableCollection<City>();
            TeamViewModels = new ObservableCollection<TeamViewModel>();
            GenerateRandomTeamsViewModel = new GenerateRandomTeamsViewModel(core);
            Reputation = 200;

            GenerateRandomTeamsTogglePopup = new RelayCommand(() =>
            {
                TogglePopup();
            });

            GenerateRandomTeams = new RelayCommand(() =>
            {
                var teams = GenerateRandomTeamsViewModel.GenerateTeams();

                TeamViewModels.Clear();
                TeamViewModels.AddRange(teams.Select(team => team.ToViewModel(core)));
                TeamViewModels.ForEach(vm => vm.Changed += Changed);

                NotifyPropertyChanged("TeamListViewVisibility");
                NotifyPropertyChanged("GenerateRandomTeamsButtonVisibility");
                TogglePopup();
            });

            Reload(core);
        }
        public DraftLotteryViewModel(GameCore core, League league) : base(core)
        {
            ViewHeading = "Draft Lottery";
            this.league = league;
            this.nextPickNumber = 1;

            Teams = new UpdatableObservableCollection<TeamViewModel>(league.Teams.Select(team => team.ToViewModel(core)));

            NextDraw = new RelayCommand(() =>
            {
                var team = Teams.Where(x => x.DraftOrder == 0).GetRandom();

                if (team != null)
                {
                    team.DraftOrder = nextPickNumber;
                    nextPickNumber++;
                    Teams.UpdateCollection();
                }

                if (Teams.All(x => x.DraftOrder > 0))
                {
                    UpdateLeague();
                }
            });
        }
        public CitySourcesViewModel(GameCore core, int numberOfTeams)
            : base(core)
        {
            this.numberOfTeams = numberOfTeams;

            CityCount = new ObservableCollection<Pair<City, int>>();

            SearchAndAddCity = new RelayCommand(() =>
            {
                var city = core.QueryService.GetCity(SearchCityName, SearchNation);
                //var city = core.QueryService.GetCities().FirstOrDefault(x => !string.IsNullOrEmpty(SearchCityName) && x.Name.Contains(SearchCityName));

                if (city != null)
                {
                    var pair = new Pair<City, int>(city, 1);

                    CityCount.Add(pair);
                    SearchCityName = "";
                    NotifyPropertyChanged("SearchCityName");
                    NotifyPropertyChanged("CityCount");
                    NotifyPropertyChanged("TeamCountValidatorText");
                    NotifyPropertyChanged("TeamCountValidatorTextColor");
                }
            });

            AllNations = new ObservableCollection<Nation>(core.QueryService.GetNations());
        }
        public SelectPlayersViewModel(GameCore core) : base(core)
        {
            AutomateSelections = new RelayCommand(() =>
            {
                var draftCards = core.GameState.Leagues.SelectMany(league => league.Teams.SelectMany(team => team.DraftCards));

                double additionalPlayerMultiplier = 1.4f;
                
                int numberOfSeniorPlayersNeeded = Convert.ToInt32(draftCards.Count(x => !x.MaxAge.HasValue) * additionalPlayerMultiplier);
                int numberOfYouthPlayersNeeded = Convert.ToInt32(draftCards.Count(x => x.MaxAge.HasValue) * additionalPlayerMultiplier);

                // Assumed max age value for simplicity
                int maxAge = 19;

                var bestAvailablePlayers = core.QueryService.GetPlayers(passive: false)
                    .OrderByDescending(x => x.CurrentAbility)
                    .Take(numberOfSeniorPlayersNeeded);

                PickedPlayerIds.AddRange(bestAvailablePlayers.Select(x => x.ID));
                PlayersAddedEvent(bestAvailablePlayers);

                var bestAvailableYoungPlayers = core.QueryService.GetPlayers(passive: false, filter: UnpickedPlayerPredicate)
                    .Where(x => x.Age <= maxAge)
                    .OrderByDescending(x => x.CurrentAbility)
                    .Take(numberOfYouthPlayersNeeded);

                PickedPlayerIds.AddRange(bestAvailableYoungPlayers.Select(x => x.ID));
                PlayersAddedEvent(bestAvailableYoungPlayers);
            });

            Reload(core);

            PickedPlayerIds = new List<int>();
        }
 public override void Reload(GameCore core)
 {
     base.Reload(core);
     if (IsLoaded)
     {
         DraftLeagueItems.Clear();
         DraftLeagueItems.AddRange(core.GameState.Leagues.Select(x => x.ToViewModel(core)));
     }
 }
        public PlayerDraftRoundViewModel(GameCore core, League league, int roundNumber)
            : base(core)
        {
            RoundNumber = roundNumber;

            DraftPicks = new UpdatableObservableCollection<DraftCardViewModel>();

            this.league = league;

            InitializeDraftPicks();
        }
        public override void Reload(GameCore core)
        {
            base.Reload(core);

            if (IsLoaded)
            {
                AllNations = new ObservableCollection<Nation>(core.QueryService.GetNations());
            }

            Cities.Clear();
            Cities.AddRange(core.QueryService.GetCities());
        }
        public LeagueSetupMasterViewModel(GameCore core) : base(core)
        {
            LeagueItemViews = new ObservableCollection<LeagueItemViewModel>();

            AddLeague = new RelayCommand(() =>
            {
                var leagueVm = new LeagueItemViewModel(core);
                leagueVm.Changed += UpdateCore;

                LeagueItemViews.Add(leagueVm);
            });
        }
        public GenerateDraftCardViewModel(GameCore core)
            : base(core)
        {
            DraftCards = new ObservableCollection<DraftCardViewModel>();

            NumberOfPlayersPerTeam = 20;
            NumberOfYouthPlayersPerTeam = 14;

            GenerateStandardDraftCards = new RelayCommand(() =>
            {
                GenerateRandomDraftCards(NumberOfPlayersPerTeam, NumberOfYouthPlayersPerTeam);
            }, CanGenerateStandardDraftCards);
        }
예제 #10
0
        private void InitializeGame()
        {
            game = new GameCore();

            game.LoadFailedCallback += () =>
            {
                MessageBox.Show("Could not load data. Ensure that Football Manager 2015 is running and that no Firewall is prevent this application from accessing it.");
            };

            game.LoadCompleteCallback += () =>
            {
                MessageBox.Show("Data has been loaded");
            };
        }
        public override void Reload(GameCore core)
        {
            base.Reload(core);

            AvailablePlayers.Clear();

            if (IsLoaded)
            {
                AvailablePlayers.AddRange(this.core.GameState.DraftPool.AvailablePlayers);
            }

            if (SearchPlayerViewModel != null)
            {
                SearchPlayerViewModel.Reload(core);
            }
        }
        public AbstractViewModel(GameCore core)
        {
            if (core != null && core.IsLoaded)
            {
                this.core = core;

                core.LoadCompleteCallback += () =>
                {
                    Reload(core);
                };
            }

            ViewHeading = "Abstract View";
            ChildViews = new ObservableCollection<AbstractViewModel>();
            SelectedChildView = null;
        }
        public DraftLeagueViewModel(GameCore core, League league)
            : base(core)
        {
            this.league = league;

            var draftLotteryVm = new DraftLotteryViewModel(core, league);

            draftLotteryVm.DraftLotteryComplete += () =>
            {
                var draftedPlayers = core.GameState.Leagues.SelectMany(l => l.Teams.SelectMany(t => t.DraftCards.Select(d => d.Player)));

                var playerDraftVm = new PlayerDraftMasterViewModel(core, league, player => !draftedPlayers.Any(draftedPlayer => draftedPlayer != null && draftedPlayer.ID == player.ID));
                ChildViews.Add(playerDraftVm);
                NotifyPropertyChanged("ChildViews");
            };

            ChildViews.Add(draftLotteryVm);
        }
        public GenerateRandomTeamsViewModel(GameCore core)
            : base(core)
        {
            NumberOfTeams = 20;
            Reputation = 9000;
            StadiumAttendances = 90000;

            generateDraftCardVm = new GenerateDraftCardViewModel(core);
            citySourcesVm = new CitySourcesViewModel(core, NumberOfTeams);

            EditDraftCards = new RelayCommand(() =>
            {
                RightSideViewModel = generateDraftCardVm;
            });

            EditCitySources = new RelayCommand(() =>
            {
                RightSideViewModel = citySourcesVm;
            });
        }
예제 #15
0
        public TeamViewModel(GameCore core) : base(core)
        {
            var selectedManagers = core.GameState.Leagues.SelectMany(x => x.Teams.Select(y => y.Manager));

            var managerList = core.QueryService.GetManagers(manager => !selectedManagers.Contains(manager));

            SearchedManagers = new ObservableCollection<ManagerViewModel>(managerList.Select(x =>
            {
                return new ManagerViewModel(core)
                {
                    ID = x.ID,
                    Name = x.FullName
                };
            }));

            ToggleEditManager = new RelayCommand(() =>
            {
                ToggleEditManagerPopup = !ToggleEditManagerPopup;
            });
        }
        public PlayerDraftMasterViewModel(GameCore core, League league, Func<Player, bool> playerFilter = null)
            : base(core)
        {
            this.league = league;
            this.draftService = new NaiveDraftService();

            Teams = new ObservableCollection<TeamViewModel>();
            DraftRounds = new UpdatableObservableCollection<PlayerDraftRoundViewModel>(new List<PlayerDraftRoundViewModel>());

            IEnumerable<Player> availablePlayers = core.GameState.DraftPool.AvailablePlayers;

            if (playerFilter != null)
            {
                availablePlayers = availablePlayers.Where(playerFilter);
            }

            AvailablePlayers = new ObservableCollection<Player>(availablePlayers);
            ViewHeading = "Player Draft";

            NextPick = new RelayCommand(ProcessNextPick);
            DraftPlayer = new RelayCommand(ProcessDraftPick);
            AutomatePicks = new RelayCommand(() =>
            {
                while (CanDraftPlayer || CanGoToNextPick)
                {
                    if (CanDraftPlayer)
                    {
                        ProcessDraftPick();
                    }
                    if (CanGoToNextPick)
                    {
                        ProcessNextPick();
                    }
                }
            });

            Reload(core);

            ProcessNextPick();
            SelectHumanTeamIfSingle();
        }
        public DraftPoolViewModel(GameCore core)
            : base(core)
        {
            AvailablePlayers = new ObservableCollection<Player>();

            Reload(core);

            AvailablePlayers.CollectionChanged += (sender, e) =>
            {
                if (e.Action == NotifyCollectionChangedAction.Add)
                {
                    foreach (var item in e.NewItems)
                    {
                        this.core.GameState.DraftPool.AvailablePlayers.Add(item as Player);
                    }
                }
            };

            SearchPlayerViewModel = new SelectPlayersViewModel(core);
            SearchPlayerViewModel.PlayersAddedEvent += (players) =>
            {
                AvailablePlayers.AddRange(players);
            };
        }
 public virtual void Reload(GameCore core)
 {
     this.core = core;
 }
 public static DraftCardViewModel ToViewModel(this DraftCard draftCard, GameCore core)
 {
     return new DraftCardViewModel(core)
     {
         RoundNumber = draftCard.Round,
         ContractLength = draftCard.ContractYears,
         MaximumAbility = draftCard.MaxCurrentAbility,
         MaximumAge = draftCard.MaxAge,
         MinimumAbility = draftCard.MinCurrentAbility,
         MinimumAge = draftCard.MinAge,
         WeeklySalary = draftCard.ContractSalary,
         TeamType = draftCard.TeamType,
         Team = draftCard.Team,
         DraftCard = draftCard
     };
 }
 public DraftCardViewModel(GameCore core)
     : base(core)
 {
 }
 public ManagerViewModel(GameCore core)
     : base(core)
 {
 }
 public DraftMasterViewModel(GameCore core)
     : base(core)
 {
     DraftLeagueItems = new ObservableCollection<DraftLeagueViewModel>();
 }
 public static DraftLeagueViewModel ToViewModel(this League league, GameCore core)
 {
     return new DraftLeagueViewModel(core, league);
 }
        public override void Reload(GameCore core)
        {
            base.Reload(core);

            if (IsLoaded)
            {
                Teams.Clear();
                Teams.AddRange(league.Teams.Select(x => x.ToViewModel(core)));

                InitializeDraftRounds();
            }
        }
 public static LeagueItemViewModel ToViewModel(this League league, GameCore core)
 {
     return new LeagueItemViewModel(core)
     {
         Name = league.Name,
         TeamViewModels = new ObservableCollection<TeamViewModel>(league.Teams.Select(x => x.ToViewModel(core)))
     };
 }
예제 #26
0
        public static TeamViewModel ToViewModel(this FMDraft.Library.Entities.Team team, GameCore core)
        {
            var vm = new TeamViewModel(core)
            {
                BackgroundColor = team.BackgroundColor,
                ForegroundColor = team.ForegroundColor,
                City = team.City,
                Name = team.Name,
                DraftOrder = team.DraftOrder,
                Manager = new ManagerViewModel(core)
            };

            if (team.Stadium != null)
            {
                vm.StadiumAttendances = team.Stadium.Attendances;
                vm.StadiumName = team.Stadium.Name;
            }

            if (team.ManagerMode == ManagerMode.CPU && team.Manager != null)
            {
                vm.Manager.Name = team.Manager.FullName;
                vm.Manager.ID = team.Manager.ID;
            }
            
            if (team.ManagerMode == ManagerMode.Player)
            {
                vm.HumanControlled = true;
            }

            if (team.DraftCards != null)
            {
                vm.DraftCards = new ObservableCollection<DraftCardViewModel>(team.DraftCards.Select(x => x.ToViewModel(core)));
                
                vm.DraftCards.CollectionChanged += (sender, e) =>
                {
                    vm.NotifyPropertyChanged("SeniorPlayers");
                    vm.NotifyPropertyChanged("YouthPlayers");
                };
            }

            return vm;
        }