diff --git a/ServerlessFunction/buildspec-dev.yml b/ServerlessFunction/buildspec-dev.yml index 78a1275..10571c8 100644 --- a/ServerlessFunction/buildspec-dev.yml +++ b/ServerlessFunction/buildspec-dev.yml @@ -43,7 +43,10 @@ phases: --capabilities CAPABILITY_IAM CAPABILITY_AUTO_EXPAND \ --no-confirm-changeset \ --no-fail-on-empty-changeset \ - --parameter-overrides Environment=$ENVIRONMENT + --parameter-overrides \ + Environment=$ENVIRONMENT \ + ExistingCognitoUserPoolId=ap-northeast-2_ezDwzFCzR \ + ExistingCognitoClientId=4ns077jcr1pkue2vvisr6qdpu5 - echo "Deployment completed on $(date)" cache: diff --git a/ServerlessFunction/buildspec-prod.yml b/ServerlessFunction/buildspec-prod.yml index 0aa8378..6b8ed3e 100644 --- a/ServerlessFunction/buildspec-prod.yml +++ b/ServerlessFunction/buildspec-prod.yml @@ -43,7 +43,10 @@ phases: --capabilities CAPABILITY_IAM CAPABILITY_AUTO_EXPAND \ --no-confirm-changeset \ --no-fail-on-empty-changeset \ - --parameter-overrides Environment=$ENVIRONMENT + --parameter-overrides \ + Environment=$ENVIRONMENT \ + ExistingCognitoUserPoolId=ap-northeast-2_ezDwzFCzR \ + ExistingCognitoClientId=4ns077jcr1pkue2vvisr6qdpu5 - echo "Deployment completed on $(date)" cache: diff --git a/ServerlessFunction/buildspec-test.yml b/ServerlessFunction/buildspec-test.yml index b74b041..e00db1d 100644 --- a/ServerlessFunction/buildspec-test.yml +++ b/ServerlessFunction/buildspec-test.yml @@ -43,7 +43,7 @@ phases: --capabilities CAPABILITY_IAM CAPABILITY_AUTO_EXPAND \ --no-confirm-changeset \ --no-fail-on-empty-changeset \ - --parameter-overrides Environment=$ENVIRONMENT + --parameter-overrides Environment=$ENVIRONMENT ExistingCognitoUserPoolId=ap-northeast-2_ezDwzFCzR ExistingCognitoClientId=4ns077jcr1pkue2vvisr6qdpu5 - echo "Deployment completed on $(date)" cache: diff --git a/ServerlessFunction/src/main/java/com/mzc/secondproject/serverless/domain/chatting/model/GameSettings.java b/ServerlessFunction/src/main/java/com/mzc/secondproject/serverless/domain/chatting/model/GameSettings.java index d97f2fc..7c2ae72 100644 --- a/ServerlessFunction/src/main/java/com/mzc/secondproject/serverless/domain/chatting/model/GameSettings.java +++ b/ServerlessFunction/src/main/java/com/mzc/secondproject/serverless/domain/chatting/model/GameSettings.java @@ -14,10 +14,13 @@ public class GameSettings { @Builder.Default private Integer maxRounds = 5; - + @Builder.Default private Integer roundTimeLimit = 60; - + + @Builder.Default + private Integer turnTimeLimit = 15; // 끝말잇기용 턴 시간 제한 + @Builder.Default private Boolean autoDeleteOnEnd = false; } diff --git a/ServerlessFunction/src/main/java/com/mzc/secondproject/serverless/domain/chatting/model/WordChainSession.java b/ServerlessFunction/src/main/java/com/mzc/secondproject/serverless/domain/chatting/model/WordChainSession.java index aa4e2c8..62f4948 100644 --- a/ServerlessFunction/src/main/java/com/mzc/secondproject/serverless/domain/chatting/model/WordChainSession.java +++ b/ServerlessFunction/src/main/java/com/mzc/secondproject/serverless/domain/chatting/model/WordChainSession.java @@ -40,6 +40,7 @@ public class WordChainSession { private Character nextLetter; // 다음 사람이 시작해야 할 글자 private Long turnStartTime; private Integer timeLimit; // 현재 라운드 시간 제한 (초) + private Integer baseTurnTimeLimit; // 사용자 설정 기본 턴 시간 (초) // 플레이어 관리 private List players; // 전체 플레이어 (순서대로) @@ -182,10 +183,27 @@ public String getWinner() { /** * 시간 제한 계산 (라운드에 따라 점점 빨라짐) - * Round 1-2: 15초, Round 3-4: 13초, Round 5-6: 11초, Round 7-8: 9초, Round 9+: 8초 + * 기본값 15초에서 시작하여 2라운드마다 2초씩 감소, 최소 8초 */ public static int calculateTimeLimit(int round) { - return Math.max(8, 15 - ((round - 1) / 2) * 2); + return calculateTimeLimit(round, 15); + } + + /** + * 시간 제한 계산 (기본 시간 제한 기준) + * 설정된 기본 시간에서 시작하여 2라운드마다 1초씩 감소, 최소 (baseTimeLimit / 2)초 + */ + public static int calculateTimeLimit(int round, int baseTimeLimit) { + int minTimeLimit = Math.max(5, baseTimeLimit / 2); + return Math.max(minTimeLimit, baseTimeLimit - ((round - 1) / 2)); + } + + /** + * 세션의 기본 시간 제한을 기준으로 다음 라운드 시간 계산 + */ + public int getNextRoundTimeLimit(int nextRound) { + int base = baseTurnTimeLimit != null ? baseTurnTimeLimit : 15; + return calculateTimeLimit(nextRound, base); } /** diff --git a/ServerlessFunction/src/main/java/com/mzc/secondproject/serverless/domain/chatting/service/WordChainService.java b/ServerlessFunction/src/main/java/com/mzc/secondproject/serverless/domain/chatting/service/WordChainService.java index c829846..eb41e15 100644 --- a/ServerlessFunction/src/main/java/com/mzc/secondproject/serverless/domain/chatting/service/WordChainService.java +++ b/ServerlessFunction/src/main/java/com/mzc/secondproject/serverless/domain/chatting/service/WordChainService.java @@ -1,7 +1,10 @@ package com.mzc.secondproject.serverless.domain.chatting.service; +import com.mzc.secondproject.serverless.domain.chatting.model.ChatRoom; import com.mzc.secondproject.serverless.domain.chatting.model.Connection; +import com.mzc.secondproject.serverless.domain.chatting.model.GameSettings; import com.mzc.secondproject.serverless.domain.chatting.model.WordChainSession; +import com.mzc.secondproject.serverless.domain.chatting.repository.ChatRoomRepository; import com.mzc.secondproject.serverless.domain.chatting.repository.ConnectionRepository; import com.mzc.secondproject.serverless.domain.chatting.repository.WordChainSessionRepository; import com.mzc.secondproject.serverless.domain.user.model.User; @@ -29,6 +32,7 @@ public class WordChainService { private final WordChainSessionRepository sessionRepository; private final ConnectionRepository connectionRepository; + private final ChatRoomRepository chatRoomRepository; private final UserRepository userRepository; private final DictionaryService dictionaryService; private final Random random; @@ -36,16 +40,19 @@ public class WordChainService { public WordChainService() { this(new WordChainSessionRepository(), new ConnectionRepository(), + new ChatRoomRepository(), new UserRepository(), new DictionaryService()); } public WordChainService(WordChainSessionRepository sessionRepository, ConnectionRepository connectionRepository, + ChatRoomRepository chatRoomRepository, UserRepository userRepository, DictionaryService dictionaryService) { this.sessionRepository = sessionRepository; this.connectionRepository = connectionRepository; + this.chatRoomRepository = chatRoomRepository; this.userRepository = userRepository; this.dictionaryService = dictionaryService; this.random = new Random(); @@ -67,6 +74,17 @@ public GameStartResult startGame(String roomId, String userId) { return GameStartResult.error("최소 2명 이상 필요합니다."); } + // 방 정보에서 gameSettings 조회 + Optional optRoom = chatRoomRepository.findById(roomId); + int baseTurnTimeLimit = 15; // 기본값 + if (optRoom.isPresent()) { + ChatRoom room = optRoom.get(); + GameSettings settings = room.getGameSettings(); + if (settings != null && settings.getTurnTimeLimit() != null) { + baseTurnTimeLimit = settings.getTurnTimeLimit(); + } + } + // 플레이어 순서 랜덤 셔플 List players = connections.stream() .map(Connection::getUserId) @@ -81,7 +99,7 @@ public GameStartResult startGame(String roomId, String userId) { String sessionId = UUID.randomUUID().toString(); String now = Instant.now().toString(); long currentTime = System.currentTimeMillis(); - int timeLimit = WordChainSession.calculateTimeLimit(1); + int timeLimit = baseTurnTimeLimit; // 사용자 설정 턴 시간 사용 WordChainSession session = WordChainSession.builder() .pk("WORDCHAIN#" + sessionId) @@ -100,6 +118,7 @@ public GameStartResult startGame(String roomId, String userId) { .nextLetter(nextLetter) .turnStartTime(currentTime) .timeLimit(timeLimit) + .baseTurnTimeLimit(baseTurnTimeLimit) .players(players) .activePlayers(new ArrayList<>(players)) .eliminatedPlayers(new ArrayList<>()) @@ -171,7 +190,7 @@ public WordSubmitResult submitWord(String roomId, String userId, String word) { char nextLetter = normalizedWord.charAt(normalizedWord.length() - 1); String nextPlayerId = session.getNextPlayerId(); int nextRound = session.getCurrentRound() + 1; - int nextTimeLimit = WordChainSession.calculateTimeLimit(nextRound); + int nextTimeLimit = session.getNextRoundTimeLimit(nextRound); session.setCurrentRound(nextRound); session.setCurrentWord(normalizedWord); @@ -227,7 +246,7 @@ private WordSubmitResult handleTimeout(WordChainSession session, String userId) // 다음 턴 준비 String nextPlayerId = session.getNextPlayerId(); int nextRound = session.getCurrentRound() + 1; - int nextTimeLimit = WordChainSession.calculateTimeLimit(nextRound); + int nextTimeLimit = session.getNextRoundTimeLimit(nextRound); session.setCurrentRound(nextRound); session.setCurrentPlayerId(nextPlayerId);