practice mode
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user