예제 #1
0
        public async Task <BattleResult> Battle(Guid firstPokemonId, Guid secondPokemonId, CancellationToken cancellationToken = default)
        {
            // get pokemon data
            var firstPokemon = await _pokemonService.Get(firstPokemonId, cancellationToken);

            var secondPokemon = await _pokemonService.Get(secondPokemonId, cancellationToken);

            // Determine attack for turn based battle
            var attackerId = GetFirstAttacker(firstPokemon, secondPokemon);

            _logger.LogInformation("Getting first attacker");
            _logger.LogDebug($"First attacker is pokemon: {attackerId}");
            _logger.LogInformation("Battle is starting");

            // Do special attack and special defense moves first - Get remaining health
            firstPokemon.BaseStats.HealthPoints  = firstPokemon.BaseStats.HealthPoints + firstPokemon.BaseStats.SpecialDefense - secondPokemon.BaseStats.SpecialAttack;
            secondPokemon.BaseStats.HealthPoints = secondPokemon.BaseStats.HealthPoints + secondPokemon.BaseStats.SpecialDefense - firstPokemon.BaseStats.SpecialAttack;

            _logger.LogDebug($"Health points of pokemons are: firstPokemon: {firstPokemon.BaseStats.HealthPoints} secondPokemon: {secondPokemon.BaseStats.HealthPoints}");

            if (firstPokemon.BaseStats.HealthPoints < 0 || secondPokemon.BaseStats.HealthPoints < 0)
            {
                return(GetBattleResult(firstPokemon, secondPokemon));
            }

            DoBattle(attackerId, firstPokemon, secondPokemon);

            return(GetBattleResult(firstPokemon, secondPokemon));
        }
예제 #2
0
        public async Task CatchPokemon(Guid pokemonId, Guid trainerId, CancellationToken cancellationToken = default)
        {
            var pokemon = await _pokemonService.Get(pokemonId, cancellationToken);

            var pokemonEntity = _mapper.Map <Pokemon>(pokemon);

            if (pokemonEntity.Trainer != null)
            {
                throw new CatchPokemonException("Pokemon already has a trainer");
            }

            if (_chanceGenerator.getChance(2) != 0)
            {
                throw new CatchPokemonException("Unfortunately pokemon dodged your pokeball");
            }

            pokemonEntity.TrainerId = trainerId;

            await _pokeRepository.Update(pokemonEntity, cancellationToken);
        }
 public async Task <IActionResult> Get(Guid id, CancellationToken cancellationToken = default)
 {
     return(Ok(await _pokemonService.Get(id, cancellationToken)));
 }
예제 #4
0
 public async Task <IEnumerable <Pokemon> > Get()
 {
     return(await _pokemonService.Get());
 }
예제 #5
0
 public PokemonModel GetPokemon(long id)
 {
     return(service.Get(id));
 }