practice mode
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c886581a7bac8f34ba8f7995eb48db02
|
||||
@@ -489,7 +489,7 @@ public class GameManager : NetworkBehaviour
|
||||
SwitchTeams();
|
||||
}
|
||||
|
||||
void SwitchTeams(){
|
||||
public void SwitchTeams(){
|
||||
if(!isServer){
|
||||
Debug.LogWarning("SwitchTeams called on client, skipping");
|
||||
return;
|
||||
@@ -555,7 +555,11 @@ public class GameManager : NetworkBehaviour
|
||||
HandleTurnTimer();
|
||||
|
||||
if(!gameStarted){
|
||||
|
||||
if(GameTutorialManager.tutorialModeEnabled){
|
||||
gameStarted = true;
|
||||
GameCanvas.instance.HideWaitingForOpponentPanel();
|
||||
Logger.Log("Game started On localhost, tutorial mode enabled");
|
||||
}
|
||||
NetPlayer[] players = FindObjectsOfType<NetPlayer>();
|
||||
#if UNITY_EDITOR
|
||||
if(Input.GetKeyDown(KeyCode.Space)){
|
||||
|
||||
@@ -411,9 +411,13 @@ public class GameOverCanvas : MonoBehaviour
|
||||
item.localScale = new Vector3(0, 0, 0);
|
||||
}
|
||||
|
||||
if(winningTeam == myTeam){
|
||||
if (GameTutorialManager.tutorialModeEnabled)
|
||||
rcPrize = 0;
|
||||
else if (winningTeam == myTeam)
|
||||
rcPrize = CoinHelper.Format(GameManager.MatchRcPrizeCoins);
|
||||
}
|
||||
|
||||
if (btnRematch != null)
|
||||
btnRematch.gameObject.SetActive(!GameTutorialManager.tutorialModeEnabled);
|
||||
|
||||
UpdateRematchAvailability();
|
||||
ApplyRcBalancesToUi(null);
|
||||
@@ -452,10 +456,13 @@ public class GameOverCanvas : MonoBehaviour
|
||||
yield return new WaitForSeconds(scaleTime * 0.5f);
|
||||
|
||||
//Rewards
|
||||
float ccReward = GameTutorialManager.tutorialModeEnabled ? 0f : 100f;
|
||||
StartCoroutine(CoroutineSetTextNumber(rcPrize, txtRewardRC, 10, "N1", "+", " RC"));
|
||||
StartCoroutine(CoroutineSetTextNumber(100, txtRewardCC, 100, "N0", "+", " CC"));
|
||||
StartCoroutine(CoroutineSetTextNumber(ccReward, txtRewardCC, 100, "N0", "+", " CC"));
|
||||
|
||||
txtBetRC.text = CoinHelper.FormatString(GameManager.MatchRcPrizeCoins) + " RC";
|
||||
txtBetRC.text = GameTutorialManager.tutorialModeEnabled
|
||||
? "0 RC"
|
||||
: CoinHelper.FormatString(GameManager.MatchRcPrizeCoins) + " RC";
|
||||
|
||||
yield return new WaitForSeconds(1f);
|
||||
|
||||
@@ -586,6 +593,14 @@ public class GameOverCanvas : MonoBehaviour
|
||||
|
||||
void UpdateRematchAvailability()
|
||||
{
|
||||
if (GameTutorialManager.tutorialModeEnabled)
|
||||
{
|
||||
btnRematch.interactable = false;
|
||||
if (rematchWarningLoser != null)
|
||||
rematchWarningLoser.text = "";
|
||||
return;
|
||||
}
|
||||
|
||||
if (winningTeam == myTeam)
|
||||
{
|
||||
btnRematch.interactable = false;
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Mirror;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
public class GameTutorialManager : MonoBehaviour
|
||||
{
|
||||
public const string CpuOpponentName = "CPU";
|
||||
public const string DefaultGameSceneName = "Game";
|
||||
|
||||
public static bool tutorialModeTrigger = false;
|
||||
public bool isTutorial = false;
|
||||
public static bool tutorialModeEnabled = false;
|
||||
|
||||
public AiBotController aiController;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
tutorialModeEnabled = false;
|
||||
if (isTutorial)
|
||||
tutorialModeTrigger = true;
|
||||
|
||||
if (tutorialModeTrigger)
|
||||
tutorialModeEnabled = true;
|
||||
|
||||
tutorialModeTrigger = false;
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
if (tutorialModeEnabled)
|
||||
tutorialModeEnabled = false;
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (tutorialModeEnabled)
|
||||
{
|
||||
NetworkManager.singleton.networkAddress = "localhost";
|
||||
NetworkManager.singleton.StartHost();
|
||||
|
||||
StartCoroutine(SetupAiWhenReady());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Call from the main menu before loading the game scene.</summary>
|
||||
public static void PrepareLaunch(MatchmadePlayer myPlayer, MatchmadePlayer cpuPlayer, Team myTeam = Team.Red)
|
||||
{
|
||||
LoginManager.ClearMatchYourTeam();
|
||||
GameManager.MyTeam = myTeam;
|
||||
GameManager.MatchRcPrizeCoins = 0;
|
||||
GameManager.ConfigureDedicatedMatchReporting(0);
|
||||
|
||||
if (myTeam == Team.Red)
|
||||
{
|
||||
GameManager.RedPlayer = myPlayer;
|
||||
GameManager.BluePlayer = cpuPlayer;
|
||||
}
|
||||
else
|
||||
{
|
||||
GameManager.RedPlayer = cpuPlayer;
|
||||
GameManager.BluePlayer = myPlayer;
|
||||
}
|
||||
|
||||
LevelLoadManager.myPlayer = myPlayer;
|
||||
LevelLoadManager.opponentPlayer = cpuPlayer;
|
||||
if (LevelLoadManager.instance != null)
|
||||
LevelLoadManager.instance.SetupMatchMade(myTeam, myPlayer, cpuPlayer, "0 RC");
|
||||
|
||||
tutorialModeTrigger = true;
|
||||
}
|
||||
|
||||
public static MatchmadePlayer CreateCpuOpponent()
|
||||
{
|
||||
return new MatchmadePlayer
|
||||
{
|
||||
Name = CpuOpponentName,
|
||||
l10_wins = 10,
|
||||
l10_losses = 0
|
||||
};
|
||||
}
|
||||
|
||||
public static MatchmadePlayer CreateMyPlayerFromUser(UserData user)
|
||||
{
|
||||
return new MatchmadePlayer
|
||||
{
|
||||
Name = user.username,
|
||||
UserId = user.id,
|
||||
rc = user.rc
|
||||
};
|
||||
}
|
||||
|
||||
public static IEnumerator CoFetchPlayerL10(MatchmadePlayer player)
|
||||
{
|
||||
if (player == null || player.UserId <= 0)
|
||||
yield break;
|
||||
|
||||
string baseUrl = (GameManager.DedicatedInternalApiBase ?? LoginManager.AuthBaseUrl ?? "").TrimEnd('/');
|
||||
if (string.IsNullOrEmpty(baseUrl))
|
||||
yield break;
|
||||
|
||||
string url = baseUrl + "/players/" + player.UserId + "/l10";
|
||||
using (var req = UnityWebRequest.Get(url))
|
||||
{
|
||||
yield return req.SendWebRequest();
|
||||
if (req.result != UnityWebRequest.Result.Success)
|
||||
{
|
||||
Logger.Log("Tutorial L10 fetch failed: " + req.error + " " + url);
|
||||
yield break;
|
||||
}
|
||||
|
||||
var resp = JsonUtility.FromJson<PlayerL10Response>(req.downloadHandler.text);
|
||||
if (resp != null && resp.ok)
|
||||
{
|
||||
player.l10_wins = resp.l10_wins;
|
||||
player.l10_losses = resp.l10_losses;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
class PlayerL10Response
|
||||
{
|
||||
public bool ok;
|
||||
public int player_id;
|
||||
public int l10_wins;
|
||||
public int l10_losses;
|
||||
}
|
||||
|
||||
IEnumerator SetupAiWhenReady()
|
||||
{
|
||||
float timeout = 5f;
|
||||
while (NetPlayer.localPlayer == null && timeout > 0f)
|
||||
{
|
||||
timeout -= Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
Team playerTeam = NetPlayer.localPlayer != null
|
||||
? NetPlayer.localPlayer.myTeam
|
||||
: GameManager.MyTeam;
|
||||
Team opponentTeam = playerTeam == Team.Red ? Team.Blue : Team.Red;
|
||||
|
||||
if (GameManager.instance.SelectedTeam != playerTeam)
|
||||
GameManager.instance.SwitchTeams();
|
||||
|
||||
aiController.Setup(opponentTeam);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 304204825fc486545a7a9bd7dd232861
|
||||
@@ -4,6 +4,19 @@ using UnityEngine;
|
||||
public class Goal : NetworkBehaviour
|
||||
{
|
||||
public Team team;
|
||||
|
||||
public static Goal RedGoal,BlueGoal;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if(team == Team.Red){
|
||||
RedGoal = this;
|
||||
}else{
|
||||
BlueGoal = this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
if(!isServer){return;}
|
||||
|
||||
@@ -27,9 +27,11 @@ public class MainMenuManager : MonoBehaviour
|
||||
public GameObject withdrawalScreen;
|
||||
[Header("Play")]
|
||||
public Button btnPlay;
|
||||
public Button btnTutorial;
|
||||
public TMP_Text rcPlayText;
|
||||
public TMP_Text entryFeeTxt;
|
||||
public TMP_Text rcPrizeTxt;
|
||||
[SerializeField] string tutorialGameScene = GameTutorialManager.DefaultGameSceneName;
|
||||
|
||||
[Header("Dummy Buy")]
|
||||
public Button btnBuyUsd5;
|
||||
@@ -99,6 +101,8 @@ public class MainMenuManager : MonoBehaviour
|
||||
btnPaste.onClick.AddListener(OnPasteFromClipboard);
|
||||
|
||||
btnPlay.onClick.AddListener(OnPlay);
|
||||
if (btnTutorial != null && btnTutorial != btnPlay)
|
||||
btnTutorial.onClick.AddListener(OnPlayTutorial);
|
||||
|
||||
toggleSfx.onToggleValueChanged.AddListener(OnToggleSfx);
|
||||
toggleMusic.onToggleValueChanged.AddListener(OnToggleMusic);
|
||||
@@ -114,6 +118,8 @@ public class MainMenuManager : MonoBehaviour
|
||||
LoginManager.OnUserDataUpdated -= OnUserUpdated;
|
||||
toggleSfx.onToggleValueChanged.RemoveListener(OnToggleSfx);
|
||||
toggleMusic.onToggleValueChanged.RemoveListener(OnToggleMusic);
|
||||
if (btnTutorial != null && btnTutorial != btnPlay)
|
||||
btnTutorial.onClick.RemoveListener(OnPlayTutorial);
|
||||
}
|
||||
|
||||
void OnToggleSfx(bool isOn)
|
||||
@@ -146,6 +152,32 @@ public class MainMenuManager : MonoBehaviour
|
||||
CupidLobby.instance.Matchmake();
|
||||
}
|
||||
|
||||
public void OnPlayTutorial()
|
||||
{
|
||||
if (LoginManager.CurrentUser == null)
|
||||
{
|
||||
Debug.LogError("Tutorial blocked: user profile not loaded.");
|
||||
return;
|
||||
}
|
||||
if (LevelLoadManager.instance == null)
|
||||
{
|
||||
Debug.LogError("Tutorial blocked: LevelLoadManager is missing.");
|
||||
return;
|
||||
}
|
||||
StartCoroutine(CoLaunchTutorial());
|
||||
}
|
||||
|
||||
IEnumerator CoLaunchTutorial()
|
||||
{
|
||||
MatchmadePlayer myPlayer = GameTutorialManager.CreateMyPlayerFromUser(LoginManager.CurrentUser);
|
||||
MatchmadePlayer cpuPlayer = GameTutorialManager.CreateCpuOpponent();
|
||||
|
||||
yield return GameTutorialManager.CoFetchPlayerL10(myPlayer);
|
||||
|
||||
GameTutorialManager.PrepareLaunch(myPlayer, cpuPlayer);
|
||||
LevelLoadManager.LoadLevel(tutorialGameScene);
|
||||
}
|
||||
|
||||
void OnCryptoAddressChanged(string value)
|
||||
{
|
||||
PlayerPrefs.SetString(CryptoAddressPrefsKey, value ?? string.Empty);
|
||||
|
||||
@@ -39,7 +39,7 @@ public class TutorialManagerMainMenu : MonoBehaviour
|
||||
btnSkip.onClick.AddListener(OnSkip);
|
||||
btnNext2.onClick.AddListener(OnNext2);
|
||||
|
||||
btnFinish.onClick.AddListener(OnTutorialCompleted);
|
||||
btnFinish.onClick.AddListener(OnStartTutorialMatch);
|
||||
|
||||
if(!forceShow){
|
||||
if(PlayerPrefs.HasKey(TUTORIAL_PREF_KEY)){
|
||||
@@ -103,6 +103,13 @@ public class TutorialManagerMainMenu : MonoBehaviour
|
||||
tutorialPanel.SetActive(false);
|
||||
}
|
||||
|
||||
void OnStartTutorialMatch()
|
||||
{
|
||||
OnTutorialCompleted();
|
||||
if (MainMenuManager.instance != null)
|
||||
MainMenuManager.instance.OnPlayTutorial();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if(curScreen < 2){return;}
|
||||
|
||||
Reference in New Issue
Block a user