Skip to content

Commit

Permalink
Merge be/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jongmee committed Oct 11, 2024
2 parents 4e14758 + 1b52135 commit e1ad0b3
Show file tree
Hide file tree
Showing 119 changed files with 2,652 additions and 1,734 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Backend-CD-Dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ jobs:
docker run -d -p 8080:8080 --name server \
-e JAVA_OPTS="-XX:InitialRAMPercentage=70.0 -XX:MaxRAMPercentage=70.0" \
-e TZ=Asia/Seoul \
-e SPRING_PROFILES_ACTIVE=local \
-e SPRING_PROFILES_ACTIVE=dev \
${{ secrets.DOCKER_DEV_SERVER_IMAGE }}
4 changes: 2 additions & 2 deletions .github/workflows/Backend-CD-Prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

build:
needs: test
runs-on: cd
runs-on: [cd, app-a]
steps:

- name: Checkout
Expand Down Expand Up @@ -50,7 +50,7 @@ jobs:

deploy:
needs: build
runs-on: cd
runs-on: [cd, app-a]
steps:

- name: Change permission
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/Backend-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
- name: Remove Containers
run: |
docker ps -aq | xargs -r docker rm -vf
docker builder prune
- name: Set up Test MongoDB
working-directory: ./backend/pokerogue/src/main/resources/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ public ApiResponse<List<AbilityResponse>> abilityList() {

@GetMapping("/api/v1/ability2/{id}")
public ApiResponse<AbilityDetailResponse> abilityDetails(@PathVariable("id") String id) {
log.info("---- URI : {}, Param : {}", "/api/v1/ability/{id}", id);
log.info(
"---- URI : {}, Param : {}, ThreadName : {}",
"/api/v1/ability/{id}",
id,
Thread.currentThread().getName()
);

return new ApiResponse<>("특성 정보 불러오기에 성공했습니다.", abilityService.findAbilityDetails(id));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package com.pokerogue.helper.ability.data;

import com.pokerogue.helper.pokemon.data.InMemoryPokemon;
import java.util.List;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

@Getter
@Document(collection = "ability")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Ability {

@Id
Expand All @@ -30,21 +32,15 @@ public class Ability {
private int generation;

@Field("pokemonIds")
private List<Integer> pokemonIds;
private List<String> pokemonIds;

@Field("isBypassFaint")
private Boolean isBypassFaint;

@Field("isIgnorable")
private Boolean isIgnorable;

// Todo: 지우기
private List<InMemoryPokemon> inMemoryPokemons;

public Ability(String id, String name, String description, List<InMemoryPokemon> inMemoryPokemons) {
this.id = id;
this.name = name;
this.description = description;
this.inMemoryPokemons = inMemoryPokemons;
public boolean isPresent() {
return !id.equals("none");
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ public record AbilityDetailResponse(
) {

public static AbilityDetailResponse of(Ability ability, List<AbilityPokemonResponse> pokemons) {
return new AbilityDetailResponse(ability.getName(), ability.getDescription(), pokemons);
return new AbilityDetailResponse(ability.getKoName(), ability.getDescription(), pokemons);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.pokerogue.helper.ability.dto;

import com.pokerogue.helper.pokemon.data.Pokemon;
import java.util.List;

public record AbilityPokemonResponse(
Expand All @@ -9,4 +10,17 @@ public record AbilityPokemonResponse(
String image,
List<AbilityTypeResponse> pokemonTypeResponses
) {
public static AbilityPokemonResponse of(
Pokemon pokemon,
String image,
List<AbilityTypeResponse> pokemonTypeResponses
) {
return new AbilityPokemonResponse(
pokemon.getId(),
(long) pokemon.getPokedexNumber(),
pokemon.getKoName(),
image,
pokemonTypeResponses
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
public record AbilityResponse(String id, String koName, String description) {

public static AbilityResponse from(Ability ability) {
return new AbilityResponse(ability.getId(), ability.getName(), ability.getDescription());
return new AbilityResponse(ability.getId(), ability.getKoName(), ability.getDescription());
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
package com.pokerogue.helper.ability.dto;

import com.pokerogue.helper.type.data.Type;

public record AbilityTypeResponse(String typeLogo, String typeName) {

public static AbilityTypeResponse from(Type type) {
return new AbilityTypeResponse(type.getImage(), type.getKoName());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import com.pokerogue.helper.ability.dto.AbilityPokemonResponse;
import com.pokerogue.helper.ability.dto.AbilityResponse;
import com.pokerogue.helper.ability.dto.AbilityTypeResponse;
import com.pokerogue.helper.ability.repository.InMemoryAbilityRepository;
import com.pokerogue.helper.type.data.Type;
import com.pokerogue.helper.ability.repository.AbilityRepository;
import com.pokerogue.helper.global.exception.ErrorMessage;
import com.pokerogue.helper.global.exception.GlobalCustomException;
import java.util.ArrayList;
import com.pokerogue.helper.pokemon.data.Pokemon;
import com.pokerogue.helper.pokemon.repository.PokemonRepository;
import com.pokerogue.helper.type.data.Type;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -20,43 +21,45 @@
public class AbilityService {

private final S3Service s3Service;
private final InMemoryAbilityRepository inMemoryAbilityRepository;
private final AbilityRepository abilityRepository;
private final PokemonRepository pokemonRepository;

public List<AbilityResponse> findAbilities() {
return inMemoryAbilityRepository.findAll().stream()
return abilityRepository.findAll().stream()
.filter(Ability::isPresent)
.map(AbilityResponse::from)
.toList();
}

public AbilityDetailResponse findAbilityDetails(String id) {
Ability ability = inMemoryAbilityRepository.findById(id)
Ability ability = abilityRepository.findById(id)
.orElseThrow(() -> new GlobalCustomException(ErrorMessage.POKEMON_ABILITY_NOT_FOUND));
List<AbilityPokemonResponse> abilityPokemonResponses = ability.getInMemoryPokemons().stream()
.map(abilityPokemon -> new AbilityPokemonResponse(
abilityPokemon.id(),
Long.parseLong(abilityPokemon.speciesId()),
abilityPokemon.koName(),
s3Service.getPokemonImageFromS3(abilityPokemon.id()),
getAbilityTypeResponses(abilityPokemon.firstType(), abilityPokemon.secondType())
List<String> abilityPokemonIds = ability.getPokemonIds();
List<Pokemon> pokemons = pokemonRepository.findAllById(abilityPokemonIds);
validateExistAllPokemonId(abilityPokemonIds, pokemons);
List<AbilityPokemonResponse> abilityPokemonResponses = pokemons.stream()
.map(pokemon -> AbilityPokemonResponse.of(
pokemon,
s3Service.getPokemonImageFromS3(pokemon.getImageId()),
getAbilityTypeResponses(pokemon.getTypes())
))
.toList();

return AbilityDetailResponse.of(ability, abilityPokemonResponses);
}

private List<AbilityTypeResponse> getAbilityTypeResponses(String firstType, String secondType) {
List<AbilityTypeResponse> abilityTypeResponses = new ArrayList<>();
if (!firstType.equals("Type.undefined") && !firstType.isEmpty()) {
abilityTypeResponses.add(new AbilityTypeResponse(Type.findByEngName(firstType)
.orElseThrow(() -> new GlobalCustomException(ErrorMessage.POKEMON_TYPE_NOT_FOUND)).getImage(),
firstType));
}
if (!secondType.equals("Type.undefined") && !secondType.isEmpty()) {
abilityTypeResponses.add(new AbilityTypeResponse(Type.findByEngName(secondType)
.orElseThrow(() -> new GlobalCustomException(ErrorMessage.POKEMON_TYPE_NOT_FOUND)).getImage(),
secondType));
private static void validateExistAllPokemonId(
List<String> abilityPokemonIds,
List<Pokemon> abilityPokemonResponses
) {
if (abilityPokemonIds.size() != abilityPokemonResponses.size()) {
throw new GlobalCustomException(ErrorMessage.POKEMON_NOT_FOUND);
}
}

return abilityTypeResponses;
private List<AbilityTypeResponse> getAbilityTypeResponses(List<Type> types) {
return types.stream()
.map(AbilityTypeResponse::from)
.toList();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.pokerogue.helper.battle.data;

import com.pokerogue.helper.move.data.MoveCategory;
import com.pokerogue.helper.type.data.Type;

public record BattleMove(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.pokerogue.helper.battle.dto;

import com.pokerogue.helper.move.data.Move;
import com.pokerogue.helper.move.data.MoveCategory;
import com.pokerogue.helper.type.data.Type;

public record BattleResultResponse(
int power,
double multiplier,
Expand All @@ -10,4 +14,20 @@ public record BattleResultResponse(
String moveCategory,
boolean isPreemptive
) {

public static BattleResultResponse from(Move move, double multiplier, double accuracy, boolean isPreemptive) {
Type moveType = move.getType();
MoveCategory moveCategory = move.getMoveCategory();

return new BattleResultResponse(
move.getPower(),
multiplier,
accuracy,
move.getName(),
move.getEffect(),
moveType.getKoName(),
moveCategory.getName(),
isPreemptive
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,8 @@ public double calculateTotalMultiplier(
return BattleMultiplier.DEFAULT_MULTIPLIER.getDoubleValue();
}

Type moveType = Type.valueOf(move.getType().toUpperCase()); // Todo
List<Type> rivalPokemonTypes = rivalPokemon.getTypes()
.stream() // Todo
.map(String::toUpperCase)
.map(Type::valueOf)
.toList();
Type moveType = move.getType();
List<Type> rivalPokemonTypes = rivalPokemon.getTypes();
BattleMultiplier weatherMultiplier = getWeatherMultiplier(weather, moveType);
BattleMultiplier sameTypeBonusMultiplier = getSameTypeBonusMultiplier(moveType, myPokemon);
BattleMultiplier typeMatchingMultiplier = getTypeMatchingMultiplier(moveType, rivalPokemonTypes);
Expand All @@ -63,11 +59,13 @@ private BattleMultiplier getSameTypeBonusMultiplier(Type moveType, Pokemon myPok
}

private BattleMultiplier getTypeMatchingMultiplier(Type moveType, List<Type> rivalPokemonTypes) {
List<BattleMultiplier> typeMatchingMultipliers = typeMultiplierProvider.getAllByTypeMatchings(moveType, rivalPokemonTypes);
List<BattleMultiplier> typeMatchingMultipliers = typeMultiplierProvider.getAllByTypeMatchings(moveType,
rivalPokemonTypes);
return BattleMultiplier.multiply(typeMatchingMultipliers.toArray(EMPTY_BATTLE_MULTIPLIER_ARRAY));
}

private BattleMultiplier applyStrongWindMultiplier(BattleMultiplier totalMultiplier, Type moveType, List<Type> rivalPokemonTypes) {
private BattleMultiplier applyStrongWindMultiplier(BattleMultiplier totalMultiplier, Type moveType,
List<Type> rivalPokemonTypes) {
BattleMultiplier strongWindMultiplier = typeMultiplierProvider.getByStrongWind(moveType, rivalPokemonTypes);
return BattleMultiplier.multiply(totalMultiplier, strongWindMultiplier);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.pokerogue.helper.move.repository.MoveRepository;
import com.pokerogue.helper.pokemon.data.Pokemon;
import com.pokerogue.helper.pokemon.repository.PokemonRepository;
import com.pokerogue.helper.type.data.Type;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -33,21 +32,11 @@ public BattleResultResponse calculateBattleResult(
.orElseThrow(() -> new GlobalCustomException(ErrorMessage.POKEMON_NOT_FOUND));
Move move = moveRepository.findById(myMoveId)
.orElseThrow(() -> new GlobalCustomException(ErrorMessage.MOVE_NOT_FOUND));
Type moveType = Type.valueOf(move.getType().toUpperCase()); // Todo

double finalAccuracy = battleCalculator.calculateAccuracy(move, weather);
double totalMultiplier = battleCalculator.calculateTotalMultiplier(move, weather, rivalPokemon, myPokemon);
boolean isPreemptive = battleCalculator.decidePreemptiveAttack(rivalPokemon, myPokemon);

return new BattleResultResponse(
move.getPower(),
totalMultiplier,
finalAccuracy,
move.getName(),
move.getEffect(),
moveType.getKoName(),
move.getMoveCategory(),
isPreemptive
);
return BattleResultResponse.from(move, totalMultiplier, finalAccuracy, isPreemptive);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.pokerogue.helper.battle.service;

import com.pokerogue.helper.battle.data.TypeMatching;
import com.pokerogue.helper.battle.repository.TypeMatchingRepository;
import com.pokerogue.helper.global.exception.ErrorMessage;
import com.pokerogue.helper.global.exception.GlobalCustomException;
import com.pokerogue.helper.pokemon.data.Pokemon;
import com.pokerogue.helper.type.collection.TypeMatching;
import com.pokerogue.helper.type.data.Type;
import com.pokerogue.helper.type.repository.TypeMatchingRepository;
import java.math.BigDecimal;
import java.util.List;
import lombok.RequiredArgsConstructor;
Expand Down
Loading

0 comments on commit e1ad0b3

Please sign in to comment.