예제 #1
0
        public IActionResult Catch(int encounterId)
        {
            Encounter encounter = GameState.Encounters.FirstOrDefault(_encounter => _encounter.ID == encounterId);

            Local  local  = Locals.FindOneByID(encounter.LocalID);
            Player player = Players.FindOneByID(encounter.PlayerID);

            if (local != null && player != null)
            {
                bool caught = PokemonEncounter.TryCatch(encounter.PokemonEncountered);

                if (caught)
                {
                    PokedexPokemon pokemonCaught = player.Pokedex.Pokemons.FirstOrDefault(pokedexPokemon => pokedexPokemon.PokemonID == encounter.PokemonEncountered.LocalPokemon.PokemonID && pokedexPokemon.Enabled);

                    if (pokemonCaught == null)
                    {
                        pokemonCaught                 = new PokedexPokemon();
                        pokemonCaught.PokemonID       = encounter.PokemonEncountered.LocalPokemon.PokemonID;
                        pokemonCaught.EncountersCount = 1;
                        pokemonCaught.Level           = encounter.PokemonEncountered.Level;
                    }
                    else
                    {
                        pokemonCaught.Level           = encounter.PokemonEncountered.Level;
                        pokemonCaught.EncountersCount = pokemonCaught.EncountersCount + 1;
                    }

                    pokemonCaught.Catched = true;
                    pokemonCaught.Enabled = true;

                    if (!encounter.PokemonAlreadyCaught)
                    {
                        pokemonCaught = Pokedexes.AddPokemon(pokemonCaught, player.Pokedex);
                    }
                    else
                    {
                        pokemonCaught = Pokedexes.UpdatePokemon(pokemonCaught, player.Pokedex);
                    }

                    if (!player.CatchedAnyPokemon())
                    {
                        player.MainPokedexPokemonID = pokemonCaught.ID;
                        Players.Update(player);
                    }
                }

                dynamic response = new ExpandoObject();
                response.caught = caught;

                GameState.Encounters.Remove(encounter);

                return(Ok(response));
            }

            return(BadRequest());
        }
예제 #2
0
        private void ButtonRegister_Click(object sender, RoutedEventArgs e)
        {
            PokedexPokemon pokemonCaught = PokemonAlreadyCaught();

            if (pokemonCaught == null)
            {
                pokemonCaught                 = new PokedexPokemon();
                pokemonCaught.PokemonID       = PokemonEncountered.LocalPokemon.PokemonID;
                pokemonCaught.EncountersCount = 1;
                pokemonCaught.Level           = PokemonEncountered.Level;
            }
            else
            {
                MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure you want to replace your " + PokemonEncountered.LocalPokemon.Pokemon.Name + " (lvl. " + PokemonEncountered.Level + ") with this one?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (messageBoxResult == MessageBoxResult.Yes)
                {
                    pokemonCaught.Level = PokemonEncountered.Level;
                }

                pokemonCaught.EncountersCount = pokemonCaught.EncountersCount + 1;
            }

            pokemonCaught.Nickname = TextBoxPokemonNickname.Text;
            pokemonCaught.Notes    = TextBoxPokemonNotes.Text;
            pokemonCaught.Catched  = true;
            pokemonCaught.Enabled  = true;

            try {
                if (PokemonAlreadyCaught() == null)
                {
                    pokemonCaught = Pokedexes.AddPokemon(pokemonCaught, Session.Player.Pokedex);
                }
                else
                {
                    pokemonCaught = Pokedexes.UpdatePokemon(pokemonCaught, Session.Player.Pokedex);
                }

                // If is the first pokemon set as main
                if (Session.Player.Pokedex.Pokemons.Count == 0)
                {
                    Session.Player.MainPokedexPokemonID = pokemonCaught.ID;
                    Players.UpdatePlayer(Session.Player);
                }

                Session.UpdatePlayer();
                Close();
            } catch {
                MessageBox.Show("An error has occurred, please try again later.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }