test week rc
This commit is contained in:
@@ -808,8 +808,37 @@ public class GameManager : NetworkBehaviour
|
||||
// LevelLoadManager.LoadLevel("MainMenu");
|
||||
}
|
||||
|
||||
|
||||
bool _thirdPlayerLeaveTriggered;
|
||||
|
||||
/// <summary>
|
||||
/// Called when the local client spawns into a match. If three <see cref="NetPlayer"/> instances exist
|
||||
/// (matchmaker sent an extra client into a full room), disconnect and return to the main menu.
|
||||
/// </summary>
|
||||
public void OnLocalPlayerJoinedMatch()
|
||||
{
|
||||
if (!isClient || _thirdPlayerLeaveTriggered)
|
||||
return;
|
||||
StartCoroutine(CoLeaveIfThirdPlayer());
|
||||
}
|
||||
|
||||
IEnumerator CoLeaveIfThirdPlayer()
|
||||
{
|
||||
const int maxFrames = 30;
|
||||
for (int i = 0; i < maxFrames; i++)
|
||||
{
|
||||
yield return null;
|
||||
if (FindObjectsByType<NetPlayer>(FindObjectsSortMode.None).Length >= 3)
|
||||
{
|
||||
_thirdPlayerLeaveTriggered = true;
|
||||
Logger.Log("Third player in a 2-player match (matchmaker bug); leaving to main menu.");
|
||||
if (LevelLoadManager.instance != null)
|
||||
LevelLoadManager.instance.Leave();
|
||||
else
|
||||
LevelLoadManager.LoadLevel("MainMenu");
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void StopClient(){
|
||||
try{
|
||||
|
||||
@@ -46,6 +46,7 @@ public class GameOverCanvas : MonoBehaviour
|
||||
const int MinimumRematchRcCoins = 20;
|
||||
|
||||
[Header("Bet Limit")]
|
||||
public TMP_Text txtRcBalance;
|
||||
public TMP_Text txtBetLimitWarning;
|
||||
public CanvasGroup betLimitAdjustPanel;
|
||||
//minVal: 2, max Val 500, when its 500, show ∞ on the text
|
||||
@@ -59,6 +60,8 @@ public class GameOverCanvas : MonoBehaviour
|
||||
const int BetLimitMax = 500;
|
||||
const int BetLimitUnlimited = 500;
|
||||
|
||||
int rematchOpponentBetLimitCoins = BetLimitUnlimited;
|
||||
|
||||
[Header("Rematch panel")]
|
||||
public CanvasGroup rematchPanel;
|
||||
public RectTransform rematchPopup;
|
||||
@@ -130,6 +133,38 @@ public class GameOverCanvas : MonoBehaviour
|
||||
return PlayerPrefs.GetInt(PersonalBetLimitPrefsKey, BetLimitUnlimited);
|
||||
}
|
||||
|
||||
static int EffectiveBetLimitCap(int limitCoins) =>
|
||||
limitCoins >= BetLimitUnlimited ? int.MaxValue : limitCoins;
|
||||
|
||||
int GetRematchMaxBetCoins()
|
||||
{
|
||||
int maxBet = Mathf.Min(
|
||||
EffectiveBetLimitCap(rematchOpponentBetLimitCoins),
|
||||
GetRcCoins(LevelLoadManager.myPlayer),
|
||||
GetRcCoins(LevelLoadManager.opponentPlayer));
|
||||
return Mathf.Max(0, maxBet);
|
||||
}
|
||||
|
||||
void ApplyRematchBetSliderLimits()
|
||||
{
|
||||
if (betSlider == null)
|
||||
return;
|
||||
|
||||
int maxBet = GetRematchMaxBetCoins();
|
||||
betSlider.maxValue = maxBet;
|
||||
if (maxBet <= 0)
|
||||
{
|
||||
betSlider.minValue = 0;
|
||||
betSlider.value = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
betSlider.minValue = Mathf.Clamp(maxBet / 10f, 5, 10000);
|
||||
betSlider.value = Mathf.Clamp(maxBet / 2, betSlider.minValue, maxBet);
|
||||
}
|
||||
OnBetSliderValueChanged(betSlider.value);
|
||||
}
|
||||
|
||||
static void SetPersonalBetLimit(int limitCoins)
|
||||
{
|
||||
limitCoins = Mathf.Clamp(limitCoins, BetLimitMin, BetLimitMax);
|
||||
@@ -221,13 +256,16 @@ public class GameOverCanvas : MonoBehaviour
|
||||
void OnBtnRematchClicked(){
|
||||
if (!BothPlayersHaveMinimumRematchRc())
|
||||
return;
|
||||
if (txtBetLimitWarning != null)
|
||||
txtBetLimitWarning.gameObject.SetActive(false);
|
||||
NetPlayer.localPlayer.RequestRematch();
|
||||
SetRematchPendingState(true);
|
||||
}
|
||||
|
||||
public void OnRematchRequested(){
|
||||
public void OnRematchRequested(int opponentMaxBetLimitCoins){
|
||||
rematchOpponentBetLimitCoins = opponentMaxBetLimitCoins;
|
||||
if(winningTeam == myTeam){
|
||||
//Only i can initiate the rematch, so here we go
|
||||
//Only the loser can initiate the rematch; winner sets the stake
|
||||
ShowRematchPanel();
|
||||
}else{
|
||||
rematchWarningLoser.text = "Waiting for opponent to accept";
|
||||
@@ -378,6 +416,7 @@ public class GameOverCanvas : MonoBehaviour
|
||||
}
|
||||
|
||||
UpdateRematchAvailability();
|
||||
ApplyRcBalancesToUi(null);
|
||||
|
||||
StartCoroutine(CoroutineShow());
|
||||
|
||||
@@ -461,11 +500,8 @@ public class GameOverCanvas : MonoBehaviour
|
||||
|
||||
public void ShowRematchPanel(){
|
||||
SetRematchPendingState(true);
|
||||
ApplyRematchBetSliderLimits();
|
||||
StartCoroutine(CoroutineShowRematchPanel());
|
||||
|
||||
betSlider.maxValue = (LevelLoadManager.myPlayer.rc < LevelLoadManager.opponentPlayer.rc) ? LevelLoadManager.myPlayer.rc : LevelLoadManager.opponentPlayer.rc;
|
||||
betSlider.value = betSlider.maxValue / 2;
|
||||
betSlider.minValue = Mathf.Clamp(betSlider.maxValue /10f,5,10000);
|
||||
}
|
||||
|
||||
IEnumerator CoroutineShowRematchPanel(){
|
||||
@@ -528,9 +564,15 @@ public class GameOverCanvas : MonoBehaviour
|
||||
txtMyRCBalance.text = myText;
|
||||
if (txtOpponentRCBalance != null)
|
||||
txtOpponentRCBalance.text = oppText;
|
||||
if (txtRcBalance != null)
|
||||
txtRcBalance.text = loadingPlaceholder ?? (my != null ? CoinHelper.FormatString((int)my.rc) + " RC" : "0.0 RC");
|
||||
|
||||
if (loadingPlaceholder == null)
|
||||
{
|
||||
UpdateRematchAvailability();
|
||||
if (rematchPanel != null && rematchPanel.alpha > 0.01f)
|
||||
ApplyRematchBetSliderLimits();
|
||||
}
|
||||
}
|
||||
|
||||
static int GetRcCoins(MatchmadePlayer player) =>
|
||||
|
||||
@@ -36,6 +36,9 @@ public class NetPlayer : NetworkBehaviour
|
||||
SetMyData(GameManager.MyTeam == Team.Red ? GameManager.RedPlayer.UserId : GameManager.BluePlayer.UserId);
|
||||
#endif
|
||||
TeamSpecificEffects.instance.SetTeamSpecificEffects(myTeam);
|
||||
|
||||
if (GameManager.instance != null)
|
||||
GameManager.instance.OnLocalPlayerJoinedMatch();
|
||||
}
|
||||
|
||||
void SetMyData(int uid){
|
||||
@@ -419,29 +422,30 @@ public class NetPlayer : NetworkBehaviour
|
||||
/// Request a rematch with the opponent.
|
||||
/// </summary>
|
||||
public void RequestRematch(){
|
||||
int maxBetLimitCoins = GameOverCanvas.GetPersonalBetLimit();
|
||||
if(isServer){
|
||||
GameOverCanvas.instance.OnRematchRequested();
|
||||
RpcRequestRematch();
|
||||
GameOverCanvas.instance.OnRematchRequested(maxBetLimitCoins);
|
||||
RpcRequestRematch(maxBetLimitCoins);
|
||||
}else{
|
||||
CmdRequestRematch();
|
||||
CmdRequestRematch(maxBetLimitCoins);
|
||||
}
|
||||
}
|
||||
|
||||
[Command]
|
||||
void CmdRequestRematch(){
|
||||
Logger.Log("Rematch requested");
|
||||
void CmdRequestRematch(int maxBetLimitCoins){
|
||||
Logger.Log("Rematch requested, max bet limit coins: " + maxBetLimitCoins);
|
||||
|
||||
if(isServerOnly){
|
||||
//server
|
||||
}else{
|
||||
GameOverCanvas.instance.OnRematchRequested();
|
||||
GameOverCanvas.instance.OnRematchRequested(maxBetLimitCoins);
|
||||
}
|
||||
RpcRequestRematch();
|
||||
RpcRequestRematch(maxBetLimitCoins);
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
void RpcRequestRematch(){
|
||||
GameOverCanvas.instance.OnRematchRequested();
|
||||
void RpcRequestRematch(int maxBetLimitCoins){
|
||||
GameOverCanvas.instance.OnRematchRequested(maxBetLimitCoins);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user