rematch complete
This commit is contained in:
+127
-18
@@ -1,9 +1,13 @@
|
||||
using UnityEngine;
|
||||
using Mirror;
|
||||
using UnityEngine.EventSystems;
|
||||
using System.Collections;
|
||||
public class NetPlayer : NetworkBehaviour
|
||||
{
|
||||
|
||||
[SyncVar]
|
||||
public int userId;
|
||||
|
||||
[SyncVar]
|
||||
public Team myTeam;
|
||||
// set the team to red if there are no other players, if not set blue
|
||||
@@ -17,16 +21,37 @@ public class NetPlayer : NetworkBehaviour
|
||||
//Without cupid, set the team to red
|
||||
bool cloneWorkspace = LoginManager.EditorWorkspaceLooksLikeClone();
|
||||
SetMyTeam(cloneWorkspace ? Team.Red : Team.Blue);
|
||||
SetMyData(cloneWorkspace ? 0: 1 );
|
||||
|
||||
}else{
|
||||
SetMyTeam(GameManager.MyTeam);
|
||||
SetMyData(GameManager.MyTeam == Team.Red ? GameManager.RedPlayer.UserId : GameManager.BluePlayer.UserId);
|
||||
}
|
||||
#else
|
||||
SetMyTeam(GameManager.MyTeam);
|
||||
SetMyData(GameManager.MyTeam == Team.Red ? GameManager.RedPlayer.UserId : GameManager.BluePlayer.UserId);
|
||||
#endif
|
||||
TeamSpecificEffects.instance.SetTeamSpecificEffects(myTeam);
|
||||
}
|
||||
|
||||
void SetMyData(int uid){
|
||||
if(isServer){
|
||||
setMyData(uid);
|
||||
}else{
|
||||
CmdSetMyData(uid);
|
||||
setMyData(uid);
|
||||
}
|
||||
}
|
||||
|
||||
void setMyData(int uid){
|
||||
userId= uid;
|
||||
}
|
||||
|
||||
[Command]
|
||||
void CmdSetMyData(int uid){
|
||||
userId=uid;
|
||||
}
|
||||
|
||||
void SetMyTeam(Team team){
|
||||
if(isServer){
|
||||
setMyTeam(team);
|
||||
@@ -47,10 +72,18 @@ public class NetPlayer : NetworkBehaviour
|
||||
setMyTeam(team);
|
||||
|
||||
Logger.Log($"Client {netId} set team to {team}");
|
||||
if(team == Team.Red){
|
||||
RedPlayer = this;
|
||||
}else{
|
||||
BluePlayer = this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static NetPlayer localPlayer;
|
||||
|
||||
public static NetPlayer RedPlayer;
|
||||
public static NetPlayer BluePlayer;
|
||||
public static Vector2 curPosition;
|
||||
public Vector2 startPosition;
|
||||
public float curPuckPullForce;
|
||||
@@ -248,35 +281,111 @@ public class NetPlayer : NetworkBehaviour
|
||||
}
|
||||
|
||||
|
||||
public void AcceptRematch(float betRc){
|
||||
public void AcceptRematch( int betRcCoins){
|
||||
if(isServer){
|
||||
OnRematchAccepted(betRc);
|
||||
RpcAcceptRematch(betRc);
|
||||
OnRematchAcceptedServer(betRcCoins);
|
||||
}else{
|
||||
CmdAcceptRematch(betRc);
|
||||
CmdAcceptRematch(betRcCoins);
|
||||
}
|
||||
}
|
||||
|
||||
[Command]
|
||||
void CmdAcceptRematch(float betRc){
|
||||
OnRematchAccepted(betRc);
|
||||
RpcAcceptRematch(betRc);
|
||||
void CmdAcceptRematch(int betRcCoins){
|
||||
OnRematchAcceptedServer(betRcCoins);
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
void RpcAcceptRematch(float betRc){
|
||||
OnRematchAccepted(betRc);
|
||||
}
|
||||
void OnRematchAcceptedServer(int betRcCoins ){
|
||||
if(!isServer){ return; }
|
||||
|
||||
void OnRematchAccepted(float betRc){
|
||||
//Implement here
|
||||
|
||||
if(betRc == 0){
|
||||
//Cancel signal
|
||||
GameOverCanvas.instance.OnRematchCancelled();
|
||||
if(betRcCoins <= 0){
|
||||
OnRematchCancelledServer();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
GameManager.DedicatedRematchResult resp = GameManager.RequestDedicatedRematch(RedPlayer.userId, BluePlayer.userId, betRcCoins);
|
||||
if(resp.Success && resp.Response != null){
|
||||
string matchmadeResponseString = JsonUtility.ToJson(resp.Response);
|
||||
RpcRematchConfirmed(matchmadeResponseString);
|
||||
Logger.Log("Rematch was confirmed, closing in 5 secs. new room :");
|
||||
Logger.Log(matchmadeResponseString);
|
||||
StartCoroutine(CoroutineOnRematchConfirmedServer());
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator CoroutineOnRematchConfirmedServer(){
|
||||
yield return new WaitForSeconds(5f);
|
||||
Logger.Log("Exiting for rematch.");
|
||||
GameManager.ReportDedicatedMatchRoomClosed();
|
||||
Application.Quit();
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
void RpcRematchConfirmed(string matchmadeResponseString){
|
||||
if (string.IsNullOrEmpty(matchmadeResponseString))
|
||||
return;
|
||||
|
||||
MatchmadeResponse env = JsonUtility.FromJson<MatchmadeResponse>(matchmadeResponseString);
|
||||
if (env == null || !env.ok)
|
||||
return;
|
||||
|
||||
Team? teamHint = LoginManager.MatchYourTeam;
|
||||
if (!teamHint.HasValue)
|
||||
teamHint = GameManager.MyTeam;
|
||||
|
||||
int userId = localPlayer != null ? localPlayer.userId : (LoginManager.CurrentUser != null ? LoginManager.CurrentUser.id : 0);
|
||||
|
||||
MatchmadeTeamPayload branch = MatchmadeResponse.SelectTeamPayload(env, userId, teamHint);
|
||||
if (branch == null || !MatchmadeResponse.TryResolveMyAndOpponent(env, branch, userId, out MatchmadePlayer myPlayer, out MatchmadePlayer opponentPlayer))
|
||||
{
|
||||
Debug.LogWarning("RpcRematchConfirmed: could not resolve roster for rematch UI");
|
||||
return;
|
||||
}
|
||||
|
||||
string yt = (branch.your_team ?? "").Trim().ToLowerInvariant();
|
||||
Team myTeam = yt == "blue" ? Team.Blue : Team.Red;
|
||||
|
||||
if (myTeam == Team.Red)
|
||||
{
|
||||
GameManager.RedPlayer = myPlayer;
|
||||
GameManager.BluePlayer = opponentPlayer;
|
||||
}
|
||||
else
|
||||
{
|
||||
GameManager.BluePlayer = myPlayer;
|
||||
GameManager.RedPlayer = opponentPlayer;
|
||||
}
|
||||
GameManager.MyTeam = myTeam;
|
||||
|
||||
int rcPrizeCoins = env.rc_prize > 0 ? env.rc_prize : branch.rc_prize;
|
||||
GameManager.MatchRcPrizeCoins = rcPrizeCoins;
|
||||
|
||||
if (LevelLoadManager.instance != null)
|
||||
LevelLoadManager.instance.SetupMatchMade(myTeam, myPlayer, opponentPlayer, CoinHelper.FormatString(rcPrizeCoins) + " RC");
|
||||
|
||||
GameManager.ConfigureDedicatedMatchReporting(branch.match_id);
|
||||
Cupid.RoomPort = branch.Port;
|
||||
LoginManager.SetMatchYourTeam(branch.your_team);
|
||||
|
||||
GameManager.instance.StopClient();
|
||||
LevelLoadManager.LoadLevel("Game");
|
||||
}
|
||||
|
||||
void OnRematchCancelledServer(){
|
||||
if(!isServer){ return; }
|
||||
|
||||
RpcCancelRematch();
|
||||
if(!isServerOnly){
|
||||
CancelRematch();
|
||||
}
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
void RpcCancelRematch(){
|
||||
CancelRematch();
|
||||
}
|
||||
|
||||
void CancelRematch(){
|
||||
GameOverCanvas.instance.OnRematchCancelled();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user