public ExtractedGame(IGameExtractor extractor)
        {
            MoveList          = extractor.ExtractMoves();
            Abilities         = extractor.ExtractAbilities();
            PokemonList       = extractor.ExtractPokemon();
            GiftPokemonList   = extractor.ExtractGiftPokemon();
            ItemList          = extractor.ExtractItems();
            OverworldItemList = extractor.ExtractOverworldItems();
            Pokemarts         = extractor.ExtractPokemarts().OrderBy(m => m.FirstItemIndex).ToArray();
            TrainerPools      = extractor.ExtractPools(PokemonList, MoveList);

            ValidMoves   = MoveList.Where(m => m.MoveIndex != 0 && m.MoveIndex != 355).ToArray();
            ValidPokemon = PokemonList.Where(p => !RandomizerConstants.SpecialPokemon.Contains(p.Index)).ToArray();
            ValidItems   = ItemList.Where(i => !RandomizerConstants.InvalidItemList.Contains(i.Index)).ToArray();
            NonKeyItems  = ValidItems.Where(i => i.BagSlot != BagSlots.KeyItems && i.BagSlot != BagSlots.None).ToArray();
            TMs          = ItemList.Where(i => i is TM).Select(i => i as TM).ToArray();

            if (extractor is XDExtractor xd)
            {
                isXD       = true;
                TutorMoves = xd.ExtractTutorMoves();
            }
            else
            {
                isXD       = false;
                TutorMoves = Array.Empty <TutorMove>();
            }
        }
Beispiel #2
0
        public PokemonRegionViewModel(INavigationService navigationService, IAPIService apiService, IGruposRegionRepository gruposRegionRepository,
                                      IGrupoPokemonsRepository grupoPokemonsRepository)
            : base(navigationService)
        {
            _apiService              = apiService;
            _navigationService       = navigationService;
            _gruposRegionRepository  = gruposRegionRepository;
            _grupoPokemonsRepository = grupoPokemonsRepository;

            #region Commands Logic

            CancelCreation = new Command(async() =>
            {
                await _navigationService.GoBackAsync();
            });

            SaveGroup = new Command(async() =>
            {
                try
                {
                    UserDialogs.Instance.ShowLoading(null, MaskType.None);


                    //validate pokemons number
                    if (PokemonsCounter < 3 || PokemonsCounter > 6)
                    {
                        UserDialogs.Instance.HideLoading();

                        await App.Current.MainPage.DisplayAlert("Error",
                                                                "You must add at min. 3 pokemons or max. 6 pokemons", "ok");
                        return;
                    }

                    var result1 = false;
                    var result2 = false;
                    if (CrossConnectivity.Current.IsConnected)
                    {
                        if (IsCreate)
                        {
                            //Create Group group first
                            var group = new GruposRegion
                            {
                                GrupoId            = await _gruposRegionRepository.GetLastID() + 1,
                                GrupoName          = GroupName,
                                GrupoTipo          = GroupType,
                                PokedexDescription = PokedexDescription,
                                Image         = "",
                                Region        = PokedexInfo.FirstOrDefault().name,
                                UserId        = await SecureStorage.GetAsync("UserId"),
                                Token         = Convert.ToBase64String(Guid.NewGuid().ToByteArray()),
                                GrupoIdFather = null
                            };

                            result1 = await _gruposRegionRepository.SaveData(group);

                            if (result1)
                            {
                                //then we add pokemons related
                                var data = PokemonList.Where(x => x.IsSelected).Select(x =>
                                                                                       new GrupoPokemons
                                {
                                    GroupId = group.GrupoId,
                                    Pokemon = x.name
                                });

                                result2 = await _grupoPokemonsRepository.SaveDataRange(data);
                            }

                            if (result1 && result2)
                            {
                                await App.Current.MainPage.DisplayAlert("Success",
                                                                        "Your group was created successfully", "ok");

                                var navigationParams = new NavigationParameters();
                                navigationParams.Add("RegionName", group.Region);
                                await navigationService.GoBackAsync(navigationParams);
                            }
                            else
                            {
                                UserDialogs.Instance.HideLoading();

                                ErrorAlert();
                                await navigationService.GoBackAsync();
                            }
                        }
                        else
                        {
                            GruposRegion.GrupoName          = GroupName;
                            GruposRegion.GrupoTipo          = GroupType;
                            GruposRegion.PokedexDescription = PokedexDescription;

                            result1 = await _gruposRegionRepository.UpdateData(GruposRegion);

                            if (result1)
                            {
                                //then we add pokemons related and delete pokemons non related

                                var oldValues = (await _grupoPokemonsRepository.GetDataByGrupoId(GruposRegion.GrupoId)).ToList();

                                var data = PokemonList.Where(x => x.IsSelected).Select(x =>
                                                                                       new GrupoPokemons
                                {
                                    GroupId = GruposRegion.GrupoId,
                                    Pokemon = x.name
                                });

                                //if old data does not appear, it means it was no unselected
                                foreach (var item in oldValues)
                                {
                                    if (!data.Select(x => x.Pokemon).Contains(item.Pokemon))
                                    {
                                        await _grupoPokemonsRepository.DeleteData(item.Id, string.Empty, string.Empty);
                                    }
                                }

                                //if new data does not appear, it means it must be added

                                foreach (var item in data)
                                {
                                    if (!oldValues.Select(x => x.Pokemon).Contains(item.Pokemon))
                                    {
                                        item.Id = await _gruposRegionRepository.GetLastID() + 1;
                                        await _grupoPokemonsRepository.SaveData(item);
                                    }
                                }

                                result2 = true;
                            }

                            if (result1 && result2)
                            {
                                UserDialogs.Instance.HideLoading();

                                await App.Current.MainPage.DisplayAlert("Success",
                                                                        "Your group was modified successfully", "ok");

                                var navigationParams = new NavigationParameters();
                                navigationParams.Add("GrupoId", GruposRegion.GrupoId);
                                await navigationService.GoBackAsync(navigationParams);
                            }
                            else
                            {
                                UserDialogs.Instance.HideLoading();

                                ErrorAlert();
                                await navigationService.GoBackAsync();
                            }
                        }
                    }
                    else
                    {
                        NoInternetAlert();
                    }
                }
                catch (Exception ex)
                {
                    ErrorAlert();
                    await navigationService.GoBackAsync();
                }
            });
            #endregion
        }