Esempio n. 1
0
        public async void LoadAllDifficultiesAndLevels(bool forceServerRefresh = false)
        {
            this.NotifyLongLoadingStart();

            var difficulties = this.GameProvider.GetDifficulties();
            var levels       = this.GameProvider.GetBaseLevels();
            var serverLevels = await this.GameProvider.GetDlLevelListAsync(forceServerRefresh);



            var terminatedOnV1 = new MigrationManager().GetMQ1PacksCompleted();;

            this.Difficulties = new ObservableCollection <DifficultyPresenter>();
            this.AllPacks     = new ObservableCollection <Pack>();


            //List<DifficultyPresenter> diffs = new List<DifficultyPresenter>();
            //List<Pack> packs = new List<Pack>();

            foreach (var item in difficulties)
            {
                DifficultyPresenter difPresenter = new DifficultyPresenter();
                difPresenter.Id   = item.Id;
                difPresenter.Name = item.Name;

                List <LevelPresenter> presentedLevels = new List <LevelPresenter>();
                var difLevels = levels.Where(m => m.DifficultyId == item.Id);

                foreach (var aBaseLevel in difLevels)
                {
                    Level          aLevel     = this.GameProvider.GetLevel(aBaseLevel.Id);
                    LevelPresenter levPresent = new LevelPresenter();
                    levPresent.Id              = aLevel.Id;
                    levPresent.Number          = aLevel.Val;
                    levPresent.IsLocal         = true;
                    levPresent.PercentProgress = aLevel.Progression;
                    presentedLevels.Add(levPresent);

                    foreach (var p in aLevel.Packs)
                    {
                        this.AllPacks.Add(p);
                    }
                }

                foreach (var serverLevel in serverLevels.Where(m => m.DifficultyId == item.Id)) // Adding sever levels
                {
                    if (!difLevels.Select(m => m.Id).Contains(serverLevel.Id))
                    {
                        LevelPresenter levPresent = new LevelPresenter();
                        levPresent.Id      = serverLevel.Id;
                        levPresent.Number  = serverLevel.Value;
                        levPresent.IsLocal = false;
                        presentedLevels.Add(levPresent);

                        // We update progress percent depending on MovieQuizz1 packs terminated (migration stuff)
                        int nbPacksTerminatedOnV1 = 0;
                        foreach (var aServerPack in serverLevel.Packs)
                        {
                            if (aServerPack.Fextra1.HasValue && terminatedOnV1.Contains(((int)aServerPack.Fextra1.Value)))
                            {
                                nbPacksTerminatedOnV1++;
                                levPresent.PacksIdTerminatedOnV1.Add(aServerPack.Id);
                            }


                            Pack pck = new Pack();
                            pck.Title        = aServerPack.Title;
                            pck.IsRemotePack = true;
                            pck.LevelId      = aServerPack.LevelId;
                            pck.Difficulty   = serverLevel.DifficultyId;
                            for (int i = 0; i < 10; i++)
                            {
                                pck.Medias.Add(new Media()
                                {
                                    IsCompleted = false
                                });
                            }

                            this.AllPacks.Add(pck);
                        }

                        levPresent.PercentProgress = (double)(((double)nbPacksTerminatedOnV1) / serverLevel.Packs.Count);
                    }
                }

                // reorder by value;
                difPresenter.Levels = new ObservableCollection <LevelPresenter>(presentedLevels.OrderBy(m => m.Number));

                this.Difficulties.Add(difPresenter);

                //this.AllPacks = new ObservableCollection<Pack>(packs);
            }


            //this.Difficulties = new ObservableCollection<DifficultyPresenter>(diffs);

            this.NotifyLongLoadingStop();
        }
Esempio n. 2
0
        public async void LoadAllDifficultiesAndLevelsAsync(bool forceServerRefresh = false)
        {
            Debug.WriteLine("LoadAllDifficultiesAndLevelsAsync Started");

            if (isLoadingDifficultiesAndLevel)
            {
                return;
            }

            this.NotifyLongLoadingStart();
            this.isLoadingDifficultiesAndLevel = true;

            try
            {
                List <Difficulty> difficulties = this.GameProvider.GetDifficulties();
                List <BaseLevel>  levels       = this.GameProvider.GetBaseLevels();

                var serverLevels = await this.GameProvider.GetDlLevelListAsync(forceServerRefresh);



                var terminatedOnV1 = new MigrationManager().GetMQ1PacksCompleted();;

                List <DifficultyPresenter> diffs = new List <DifficultyPresenter>();

                foreach (var item in difficulties)
                {
                    DifficultyPresenter difPresenter = new DifficultyPresenter();
                    difPresenter.Id   = item.Id;
                    difPresenter.Name = item.Name;

                    List <LevelPresenter> presentedLevels = new List <LevelPresenter>();
                    var difLevels = levels.Where(m => m.DifficultyId == item.Id);

                    foreach (var aBaseLevel in difLevels)
                    {
                        Level          aLevel     = this.GameProvider.GetLevel(aBaseLevel.Id);
                        LevelPresenter levPresent = new LevelPresenter();
                        levPresent.Id              = aLevel.Id;
                        levPresent.Number          = aLevel.Val;
                        levPresent.IsLocal         = true;
                        levPresent.PercentProgress = aLevel.Progression;


                        for (int i = 0; i < aLevel.Packs.Count && i < 3; i++)
                        {
                            if (i == 0)
                            {
                                levPresent.Title1           = aLevel.Packs[i].Title;
                                levPresent.DifficultyTitle1 = aLevel.Packs[i].Difficulty;
                            }
                            else if (i == 1)
                            {
                                levPresent.Title2           = aLevel.Packs[i].Title;
                                levPresent.DifficultyTitle2 = aLevel.Packs[i].Difficulty;
                            }
                            else if (i == 2)
                            {
                                levPresent.Title3           = aLevel.Packs[i].Title;
                                levPresent.DifficultyTitle3 = aLevel.Packs[i].Difficulty;
                            }
                        }
                        presentedLevels.Add(levPresent);
                    }

                    foreach (var serverLevel in serverLevels.Where(m => m.DifficultyId == item.Id)) // Adding sever levels
                    {
                        if (!difLevels.Select(m => m.Id).Contains(serverLevel.Id))
                        {
                            LevelPresenter levPresent = new LevelPresenter();
                            levPresent.Id      = serverLevel.Id;
                            levPresent.Number  = serverLevel.Value;
                            levPresent.IsLocal = false;
                            presentedLevels.Add(levPresent);

                            // We update progress percent depending on MovieQuizz1 packs terminated (migration stuff)
                            int nbPacksTerminatedOnV1 = 0;
                            foreach (var aServerPack in serverLevel.Packs)
                            {
                                if (aServerPack.Fextra1.HasValue && terminatedOnV1.Contains(((int)aServerPack.Fextra1.Value)))
                                {
                                    nbPacksTerminatedOnV1++;
                                    levPresent.PacksIdTerminatedOnV1.Add(aServerPack.Id);
                                }
                            }

                            levPresent.PercentProgress = (double)(((double)nbPacksTerminatedOnV1) / serverLevel.Packs.Count);

                            for (int i = 0; i < serverLevel.Packs.Count || i < 3; i++)
                            {
                                if (i == 0)
                                {
                                    levPresent.Title1           = serverLevel.Packs[i].Title;
                                    levPresent.DifficultyTitle1 = serverLevel.Packs[i].Difficulty.HasValue ? (double)serverLevel.Packs[i].Difficulty : 1;
                                }
                                else if (i == 1)
                                {
                                    levPresent.Title2           = serverLevel.Packs[i].Title;
                                    levPresent.DifficultyTitle2 = serverLevel.Packs[i].Difficulty.HasValue ? (double)serverLevel.Packs[i].Difficulty : 1;
                                }
                                else if (i == 2)
                                {
                                    levPresent.Title3           = serverLevel.Packs[i].Title;
                                    levPresent.DifficultyTitle3 = serverLevel.Packs[i].Difficulty.HasValue ? (double)serverLevel.Packs[i].Difficulty : 1;
                                }
                            }
                        }
                    }

                    // reorder by value;
                    difPresenter.Levels = new ObservableCollection <LevelPresenter>(presentedLevels.OrderBy(m => m.Number));

                    diffs.Add(difPresenter);
                }


                this.Difficulties = new ObservableCollection <DifficultyPresenter>(diffs);
            }
            catch (Exception e)
            {
                Debug.WriteLine("LoadAllDifficultiesAndLevelsAsync exception : " + e);
            }

            this.isLoadingDifficultiesAndLevel = false;
            this.NotifyLongLoadingStop();
        }