DO-70 [Feat] 타임아웃 30초 멀티플레이 처리
This commit is contained in:
parent
d906bc234f
commit
54fece46ca
@ -18,6 +18,7 @@
|
|||||||
ExitRoom, // 자신이 방을 빠져 나왔을 때
|
ExitRoom, // 자신이 방을 빠져 나왔을 때
|
||||||
EndGame, // 상대방이 접속을 끊거나 방을 나갔을 때
|
EndGame, // 상대방이 접속을 끊거나 방을 나갔을 때
|
||||||
DoSurrender, // 상대방이 항복했을 때
|
DoSurrender, // 상대방이 항복했을 때
|
||||||
SurrenderConfirmed // 항복 요청이 성공적으로 전송되었을 때
|
SurrenderConfirmed, // 항복 요청이 성공적으로 전송되었을 때
|
||||||
|
ReceiveTimeout // 상대방이 타임 아웃일 때
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -177,7 +177,7 @@ public class MultiPlayerState: BasePlayerState
|
|||||||
gameLogic.UpdateForbiddenMoves();
|
gameLogic.UpdateForbiddenMoves();
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
// gameLogic.currentTurn = _playerType;
|
gameLogic.currentTurn = _playerType;
|
||||||
// gameLogic.stoneController.OnStoneClickedDelegate = (row, col) =>
|
// gameLogic.stoneController.OnStoneClickedDelegate = (row, col) =>
|
||||||
// {
|
// {
|
||||||
// HandleMove(gameLogic, row, col);
|
// HandleMove(gameLogic, row, col);
|
||||||
@ -277,19 +277,41 @@ public class GameLogic : MonoBehaviour
|
|||||||
this.fioTimer.InitTimer();
|
this.fioTimer.InitTimer();
|
||||||
//timer 시간초과시 진행 함수
|
//timer 시간초과시 진행 함수
|
||||||
this.fioTimer.OnTimeout = () =>
|
this.fioTimer.OnTimeout = () =>
|
||||||
|
{
|
||||||
|
if (gameType == Enums.GameType.MultiPlay)
|
||||||
|
{
|
||||||
|
// 현재 턴의 플레이어가 로컬(유저)인지 확인
|
||||||
|
bool isCurrentPlayerLocal = (currentTurn == Enums.PlayerType.PlayerA && firstPlayerState is PlayerState) ||
|
||||||
|
(currentTurn == Enums.PlayerType.PlayerB && secondPlayerState is PlayerState);
|
||||||
|
|
||||||
|
if (isCurrentPlayerLocal) // 내가 타임 오버일 때
|
||||||
|
{
|
||||||
|
_multiplayManager?.SendTimeout();
|
||||||
|
GameManager.Instance.panelManager.OpenEffectPanel(Enums.GameResult.Lose);
|
||||||
|
EndGame(Enums.GameResult.Lose);
|
||||||
|
}
|
||||||
|
else // 로컬에서 자신의 타이머 기준으로 상대방이 타임 오버일 때
|
||||||
|
{
|
||||||
|
// TODO: 컨펌 패널 OK 버튼 삭제?
|
||||||
|
GameManager.Instance.panelManager.OpenConfirmPanel("상대방의 응답을 기다리는 중입니다",
|
||||||
|
() => { } );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if (currentTurn == Enums.PlayerType.PlayerA)
|
if (currentTurn == Enums.PlayerType.PlayerA)
|
||||||
{
|
{
|
||||||
GameManager.Instance.panelManager.OpenConfirmPanel($"Game Over: {Enums.PlayerType.PlayerB} Win",
|
GameManager.Instance.panelManager.OpenConfirmPanel($"Game Over: {Enums.PlayerType.PlayerB} Win",
|
||||||
() =>{});
|
() => { });
|
||||||
EndGame(Enums.GameResult.Lose);
|
EndGame(Enums.GameResult.Lose);
|
||||||
}
|
}
|
||||||
else if (currentTurn == Enums.PlayerType.PlayerB)
|
else if (currentTurn == Enums.PlayerType.PlayerB)
|
||||||
{
|
{
|
||||||
GameManager.Instance.panelManager.OpenConfirmPanel($"Game Over: {Enums.PlayerType.PlayerA} Win",
|
GameManager.Instance.panelManager.OpenConfirmPanel($"Game Over: {Enums.PlayerType.PlayerA} Win",
|
||||||
() =>{});
|
() => { });
|
||||||
EndGame(Enums.GameResult.Win);
|
EndGame(Enums.GameResult.Win);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -462,6 +484,14 @@ public class GameLogic : MonoBehaviour
|
|||||||
EndGame(Enums.GameResult.Lose);
|
EndGame(Enums.GameResult.Lose);
|
||||||
});
|
});
|
||||||
break;
|
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");
|
ReplayManager.Instance.InitReplayData(UserManager.Instance.Nickname,"nicknameB");
|
||||||
|
|
||||||
|
@ -90,6 +90,7 @@ public class MultiplayManager : IDisposable
|
|||||||
_socket.On("doOpponent", DoOpponent);
|
_socket.On("doOpponent", DoOpponent);
|
||||||
_socket.On("doSurrender", DoSurrender);
|
_socket.On("doSurrender", DoSurrender);
|
||||||
_socket.On("surrenderConfirmed", SurrenderConfirmed);
|
_socket.On("surrenderConfirmed", SurrenderConfirmed);
|
||||||
|
_socket.On("receiveTimeout", ReceiveTimeout);
|
||||||
|
|
||||||
_socket.Connect();
|
_socket.Connect();
|
||||||
}
|
}
|
||||||
@ -218,6 +219,30 @@ public class MultiplayManager : IDisposable
|
|||||||
_onMultiplayStateChanged?.Invoke(Constants.MultiplayManagerState.SurrenderConfirmed, data.message);
|
_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 Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
if (_socket != null)
|
if (_socket != null)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user