Merge branch 'main' into DO-46-게임-씬-보조-기능-추가
This commit is contained in:
commit
2f886953c8
@ -19,11 +19,12 @@
|
||||
EndGame, // 상대방이 접속을 끊거나 방을 나갔을 때
|
||||
DoSurrender, // 상대방이 항복했을 때
|
||||
SurrenderConfirmed, // 항복 요청이 성공적으로 전송되었을 때
|
||||
ReceiveDrawRequest,
|
||||
ReceiveDrawRequest,
|
||||
DrawRequestSent,
|
||||
DrawAccepted,
|
||||
DrawConfirmed,
|
||||
DrawRejected,
|
||||
DrawRejectionConfirmed
|
||||
DrawRejectionConfirmed,
|
||||
ReceiveTimeout // 상대방이 타임 아웃일 때
|
||||
};
|
||||
}
|
@ -177,7 +177,7 @@ public class MultiPlayerState: BasePlayerState
|
||||
gameLogic.UpdateForbiddenMoves();
|
||||
#endregion
|
||||
|
||||
// gameLogic.currentTurn = _playerType;
|
||||
gameLogic.currentTurn = _playerType;
|
||||
// gameLogic.stoneController.OnStoneClickedDelegate = (row, col) =>
|
||||
// {
|
||||
// HandleMove(gameLogic, row, col);
|
||||
@ -278,17 +278,24 @@ public class GameLogic : MonoBehaviour
|
||||
//timer 시간초과시 진행 함수
|
||||
this.fioTimer.OnTimeout = () =>
|
||||
{
|
||||
if (currentTurn == Enums.PlayerType.PlayerA)
|
||||
// 현재 턴의 플레이어가 로컬(유저)인지 확인
|
||||
bool isCurrentPlayerLocal = (currentTurn == Enums.PlayerType.PlayerA && firstPlayerState is PlayerState) ||
|
||||
(currentTurn == Enums.PlayerType.PlayerB && secondPlayerState is PlayerState);
|
||||
|
||||
if (isCurrentPlayerLocal) // 내가 타임 오버일 때
|
||||
{
|
||||
GameManager.Instance.panelManager.OpenConfirmPanel($"Game Over: {Enums.PlayerType.PlayerB} Win",
|
||||
() =>{});
|
||||
if (this.gameType == Enums.GameType.MultiPlay) // 멀티플레이인 경우
|
||||
{
|
||||
_multiplayManager?.SendTimeout();
|
||||
}
|
||||
GameManager.Instance.panelManager.OpenEffectPanel(Enums.GameResult.Lose);
|
||||
EndGame(Enums.GameResult.Lose);
|
||||
}
|
||||
else if (currentTurn == Enums.PlayerType.PlayerB)
|
||||
else // 로컬에서 자신의 타이머 기준으로 상대방이 타임 오버일 때
|
||||
{
|
||||
GameManager.Instance.panelManager.OpenConfirmPanel($"Game Over: {Enums.PlayerType.PlayerA} Win",
|
||||
() =>{});
|
||||
EndGame(Enums.GameResult.Win);
|
||||
// TODO: 컨펌 패널 OK 버튼 삭제?
|
||||
GameManager.Instance.panelManager.OpenConfirmPanel("상대방의 응답을 기다리는 중입니다",
|
||||
() => { } );
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -501,6 +508,14 @@ public class GameLogic : MonoBehaviour
|
||||
case Constants.MultiplayManagerState.DrawRejectionConfirmed:
|
||||
Debug.Log("무승부 요청 거부 완료");
|
||||
|
||||
break;
|
||||
case Constants.MultiplayManagerState.ReceiveTimeout:
|
||||
Debug.Log("상대방이 타임 아웃 됨");
|
||||
UnityMainThreadDispatcher.Instance().Enqueue(() =>
|
||||
{
|
||||
GameManager.Instance.panelManager.OpenEffectPanel(Enums.GameResult.Win);
|
||||
EndGame(Enums.GameResult.Win);
|
||||
});
|
||||
break;
|
||||
}
|
||||
ReplayManager.Instance.InitReplayData(UserManager.Instance.Nickname,"nicknameB");
|
||||
|
@ -90,6 +90,7 @@ public class MultiplayManager : IDisposable
|
||||
_socket.On("doOpponent", DoOpponent);
|
||||
_socket.On("doSurrender", DoSurrender);
|
||||
_socket.On("surrenderConfirmed", SurrenderConfirmed);
|
||||
_socket.On("receiveTimeout", ReceiveTimeout);
|
||||
_socket.On("receiveDrawRequest", ReceiveDrawRequest);
|
||||
_socket.On("drawRequestSent", DrawRequestSent);
|
||||
_socket.On("drawAccepted", DrawAccepted);
|
||||
@ -224,6 +225,30 @@ public class MultiplayManager : IDisposable
|
||||
_onMultiplayStateChanged?.Invoke(Constants.MultiplayManagerState.SurrenderConfirmed, data.message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 타임 아웃 요청
|
||||
/// </summary>
|
||||
public void SendTimeout()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_roomId))
|
||||
{
|
||||
Debug.LogError("LeaveRoom 호출 실패: _roomId가 설정되지 않음");
|
||||
return;
|
||||
}
|
||||
_socket.Emit("sendTimeout",new { roomId = _roomId });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 타임 아웃 수신
|
||||
/// </summary>
|
||||
/// <param name="response"></param>
|
||||
private void ReceiveTimeout(SocketIOResponse response)
|
||||
{
|
||||
var data = response.GetValue<MessageData>();
|
||||
|
||||
_onMultiplayStateChanged?.Invoke(Constants.MultiplayManagerState.ReceiveTimeout, data.message);
|
||||
}
|
||||
|
||||
public void RequestDraw()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_roomId))
|
||||
|
@ -227,8 +227,13 @@ public class NetworkManager : Singleton<NetworkManager>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator GetLeaderboard(Action<Scores> success, Action failure)
|
||||
|
||||
public void GetLeaderboard(Action<List<ScoreInfo>> success, Action failure)
|
||||
{
|
||||
StartCoroutine(GetLeaderboardCoroutine(success, failure));
|
||||
}
|
||||
|
||||
public IEnumerator GetLeaderboardCoroutine(Action<List<ScoreInfo>> success, Action failure)
|
||||
{
|
||||
using (UnityWebRequest www =
|
||||
new UnityWebRequest(Constants.ServerURL + "/leaderboard", UnityWebRequest.kHttpVerbGET))
|
||||
@ -256,10 +261,15 @@ public class NetworkManager : Singleton<NetworkManager>
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = www.downloadHandler.text;
|
||||
var scores = JsonUtility.FromJson<Scores>(result);
|
||||
|
||||
success?.Invoke(scores);
|
||||
// 성공적으로 데이터를 받아온 경우
|
||||
string jsonResponse = www.downloadHandler.text; // 응답으로 받은 JSON 데이터
|
||||
|
||||
// JSON을 ScoreInfo 리스트로 파싱
|
||||
ScoreListWrapper wrapper = JsonUtility.FromJson<ScoreListWrapper>(jsonResponse);
|
||||
List<ScoreInfo> leaderboardItems = wrapper.leaderboardDatas;
|
||||
|
||||
// Show 메서드를 통해 데이터를 표시
|
||||
success?.Invoke(leaderboardItems);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -511,36 +521,4 @@ public class NetworkManager : Singleton<NetworkManager>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void GetLeaderboardData(Action<List<ScoreInfo>> success, Action failure)
|
||||
{
|
||||
StartCoroutine(GetLeaderboardDataCoroutine(success, failure));
|
||||
}
|
||||
|
||||
private IEnumerator GetLeaderboardDataCoroutine(Action<List<ScoreInfo>> success, Action failure)
|
||||
{
|
||||
string url = Constants.ServerURL + "/leaderboard/"; // 서버의 리더보드 데이터 URL
|
||||
|
||||
UnityWebRequest www = UnityWebRequest.Get(url); // GET 요청으로 데이터 받기
|
||||
yield return www.SendWebRequest(); // 요청 전송 대기
|
||||
|
||||
// 요청이 실패했을 때
|
||||
if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
|
||||
{
|
||||
Debug.LogError("Error: " + www.error);
|
||||
failure?.Invoke();
|
||||
}
|
||||
else
|
||||
{
|
||||
// 성공적으로 데이터를 받아온 경우
|
||||
string jsonResponse = www.downloadHandler.text; // 응답으로 받은 JSON 데이터
|
||||
|
||||
// JSON을 ScoreInfo 리스트로 파싱
|
||||
ScoreListWrapper wrapper = JsonUtility.FromJson<ScoreListWrapper>(jsonResponse);
|
||||
List<ScoreInfo> leaderboardItems = wrapper.leaderboardDatas;
|
||||
|
||||
// Show 메서드를 통해 데이터를 표시
|
||||
success?.Invoke(leaderboardItems);
|
||||
}
|
||||
}
|
||||
}
|
@ -27,7 +27,7 @@ public class LeaderBoardController : MonoBehaviour
|
||||
if (isLeaderboardLoaded) return; // 이미 리더보드가 로드되었으면 중복 호출 방지
|
||||
|
||||
leaderboardPanel.SetActive(true);
|
||||
NetworkManager.Instance.GetLeaderboardData((leaderboardItems) =>
|
||||
NetworkManager.Instance.GetLeaderboard((leaderboardItems) =>
|
||||
{
|
||||
Show(leaderboardItems);
|
||||
}, () => { });
|
||||
|
Loading…
x
Reference in New Issue
Block a user