Ranked done, Shop done and many fixes
This commit is contained in:
@@ -11,6 +11,7 @@ public class ChestOpener : MonoBehaviour
|
||||
|
||||
|
||||
public GameObject chestOpenPopup;
|
||||
public bool active => chestOpenPopup.activeSelf;
|
||||
public Animator chestAnim;
|
||||
public GameObject gemsDrop;
|
||||
public GameObject goldDrop;
|
||||
@@ -24,10 +25,10 @@ public class ChestOpener : MonoBehaviour
|
||||
instance = this;
|
||||
}
|
||||
|
||||
public async void OpenChest(){
|
||||
public async void OpenChest(int minLuck, int maxLuck){
|
||||
chestOpenPopup.SetActive(true);
|
||||
okButton.SetActive(false);
|
||||
int luckiness= Random.Range(0,100);
|
||||
int luckiness= Random.Range(minLuck,maxLuck);
|
||||
List<SkinShopItemData> baseSkins = new List<SkinShopItemData>();
|
||||
List<SkinShopItemData> rareSkins = new List<SkinShopItemData>();
|
||||
List<SkinShopItemData> legendarySkins = new List<SkinShopItemData>();
|
||||
|
||||
@@ -10,7 +10,7 @@ using System.Net;
|
||||
using System.Net.Sockets;
|
||||
public class DBmanager : MonoBehaviour
|
||||
{
|
||||
public static string phpRoot = "http://vps.playpoolstudios.com/upf/";
|
||||
public static string phpRoot = "http://vmi1005083.contaboserver.net/upf/";
|
||||
|
||||
public static string username = null;
|
||||
|
||||
@@ -22,6 +22,7 @@ public class DBmanager : MonoBehaviour
|
||||
private static int trophies = 0;
|
||||
private static int mostTime=0;
|
||||
private static int doubleKills,tripleKills,quadKills,pentaKills = 0;
|
||||
private static DateTime lastCollectedDailyChest;
|
||||
|
||||
private static List<InventoryEntry> inventory;
|
||||
private static List<int> expPassCollected = new List<int>();
|
||||
@@ -39,6 +40,7 @@ public class DBmanager : MonoBehaviour
|
||||
public static int TripleKills => tripleKills;
|
||||
public static int QuadKills => quadKills;
|
||||
public static int PentaKills => pentaKills;
|
||||
public static DateTime LastCollectedDailyChest => lastCollectedDailyChest;
|
||||
public static float Level => level;
|
||||
public static int LevelInt => Mathf.CeilToInt(level);
|
||||
public static List<int> ExpPassCollected => expPassCollected;
|
||||
@@ -218,7 +220,9 @@ public class DBmanager : MonoBehaviour
|
||||
WWWForm form = new WWWForm();
|
||||
form.AddField("name", username);
|
||||
form.AddField("gems", newValue);
|
||||
if (justOffline) { gems = newValue; return; }
|
||||
int oldVal = Gems;
|
||||
gems = newValue;
|
||||
if (justOffline) {return; }
|
||||
using (UnityWebRequest www = UnityWebRequest.Post(phpRoot + "set_gems.php", form))
|
||||
{
|
||||
var operation = www.SendWebRequest();
|
||||
@@ -235,6 +239,7 @@ public class DBmanager : MonoBehaviour
|
||||
{
|
||||
Debug.Log("Response : " + www.downloadHandler.text);
|
||||
Debug.LogWarning("Failed to set gems to " + newValue);
|
||||
gems = oldVal;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,7 +252,9 @@ public class DBmanager : MonoBehaviour
|
||||
WWWForm form = new WWWForm();
|
||||
form.AddField("name", username);
|
||||
form.AddField("metal", newValue);
|
||||
if (justOffline) { metal = newValue; return; }
|
||||
int oldVal = metal;
|
||||
metal = newValue;
|
||||
if (justOffline) { return; }
|
||||
using (UnityWebRequest www = UnityWebRequest.Post(phpRoot + "set_metal.php", form))
|
||||
{
|
||||
var operation = www.SendWebRequest();
|
||||
@@ -265,6 +272,7 @@ public class DBmanager : MonoBehaviour
|
||||
{
|
||||
Debug.Log("Response : " + www.downloadHandler.text);
|
||||
Debug.LogWarning("Failed to set metal to " + newValue);
|
||||
metal = oldVal;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -461,6 +469,40 @@ public class DBmanager : MonoBehaviour
|
||||
OnStateChanged.Invoke();
|
||||
}
|
||||
|
||||
public async static void SetLastCollectedDailyChest(string newValue, bool justOffline = false)
|
||||
{
|
||||
WWWForm form = new WWWForm();
|
||||
form.AddField("name", username);
|
||||
form.AddField("value", newValue);
|
||||
DateTime oldValue = lastCollectedDailyChest;
|
||||
lastCollectedDailyChest = DateTime.Parse(newValue);
|
||||
Debug.Log(newValue + ":"+lastCollectedDailyChest);
|
||||
if (justOffline) { return; }
|
||||
using (UnityWebRequest www = UnityWebRequest.Post(phpRoot + "set_daily_chest_collected.php", form))
|
||||
{
|
||||
var operation = www.SendWebRequest();
|
||||
while (!operation.isDone)
|
||||
{
|
||||
await Task.Yield();
|
||||
}
|
||||
|
||||
if (www.downloadHandler.text == "0")
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
lastCollectedDailyChest = oldValue;
|
||||
Debug.Log("Response : " + www.downloadHandler.text);
|
||||
Debug.LogWarning("Failed to set lastCollectedDailyChest to " + newValue);
|
||||
}
|
||||
}
|
||||
|
||||
GameManager.Refresh();
|
||||
OnStateChanged.Invoke();
|
||||
}
|
||||
|
||||
|
||||
public static void SetExpPassCollected(string rawData, bool justOffline = false)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -132,5 +132,33 @@ public class GameManager : MonoBehaviour
|
||||
public void LoadRanked(){
|
||||
LoadingScreen.instance.LoadLevel("MinigameMatchmaking");
|
||||
}
|
||||
|
||||
|
||||
public void Signout(){
|
||||
PlayerPrefs.DeleteAll();
|
||||
PlayerPrefs.Save();
|
||||
|
||||
LoadingScreen.instance.LoadLevel("Login");
|
||||
}
|
||||
|
||||
public void BuyChest(ChestButton button){
|
||||
if(DBmanager.Gems < button.Price){
|
||||
MessageDialog.instance.ShowDialog("Failed", "Insufficient Gems to complete the purchase");
|
||||
return;
|
||||
}
|
||||
|
||||
DBmanager.SetGems(DBmanager.Gems-button.Price);
|
||||
ChestOpener.instance.OpenChest((int)button.minLuck, (int)button.maxLuck);
|
||||
}
|
||||
|
||||
public void BuyGold(GoldPackButton button){
|
||||
if(DBmanager.Gems < button.Price){
|
||||
MessageDialog.instance.ShowDialog("Failed", "Insufficient Gems to complete the purchase");
|
||||
return;
|
||||
}
|
||||
|
||||
DBmanager.SetGems(DBmanager.Gems-button.Price);
|
||||
DBmanager.SetCoins(DBmanager.Coins + button.Amount);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ public class LoadingScreen : MonoBehaviour
|
||||
CanvasGroup canvasGroup;
|
||||
public Slider loadingProgress;
|
||||
public TMPro.TMP_Text loadingProgressTxt;
|
||||
private static bool loading;
|
||||
public static bool Loading => loading;
|
||||
|
||||
void Awake(){
|
||||
instance =this;
|
||||
@@ -20,10 +22,12 @@ public class LoadingScreen : MonoBehaviour
|
||||
}
|
||||
|
||||
public void LoadLevel(string levelName){
|
||||
if(loading){return;}loading=true;
|
||||
StartCoroutine(loadlLevel(levelName));
|
||||
}
|
||||
|
||||
IEnumerator loadlLevel(string levelName){
|
||||
loading=true;
|
||||
canvasGroup.alpha=0;
|
||||
canvasGroup.blocksRaycasts=true;
|
||||
SetProgress(0);
|
||||
@@ -53,10 +57,11 @@ public class LoadingScreen : MonoBehaviour
|
||||
canvasGroup.alpha-=0.03f;
|
||||
yield return new WaitForFixedUpdate();
|
||||
}
|
||||
loading=false;
|
||||
}
|
||||
|
||||
void SetProgress(float value){
|
||||
loadingProgress.value = value;
|
||||
loadingProgressTxt.text = (int)(value*100) + "%";
|
||||
loadingProgress.value = value;
|
||||
loadingProgressTxt.text = (int)(value*100) + "%";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,6 +81,7 @@ public class LoginManager : MonoBehaviour
|
||||
PlayerPrefs.Save();}
|
||||
DBmanager.username = login_username.text;
|
||||
|
||||
DBmanager.SetLastCollectedDailyChest(www.text.Split('\t')[15],true);
|
||||
DBmanager.SetPentaKills(int.Parse(www.text.Split('\t')[14]),true);
|
||||
DBmanager.SetQuadKills(int.Parse(www.text.Split('\t')[13]),true);
|
||||
DBmanager.SetTripleKills(int.Parse(www.text.Split('\t')[12]),true);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@@ -20,6 +21,7 @@ public class MessageDialog : MonoBehaviour
|
||||
m_instance = this;
|
||||
actionBtn.onClick.AddListener(OnAction);
|
||||
SetActive(false);
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
|
||||
void OnAction(){
|
||||
@@ -28,11 +30,19 @@ public class MessageDialog : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowDialog(string title, string message){
|
||||
public async void ShowDialog(string title, string message){
|
||||
titleTxt.text = title;
|
||||
messageTxt.text = message;
|
||||
|
||||
|
||||
SetActive(true);
|
||||
Canvas.ForceUpdateCanvases();
|
||||
GetComponentInChildren<VerticalLayoutGroup>().enabled=false;
|
||||
GetComponentInChildren<VerticalLayoutGroup>().enabled=true;
|
||||
|
||||
|
||||
|
||||
// messageTxt.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public void SetActive(bool value){
|
||||
|
||||
@@ -6,56 +6,120 @@ using LightReflectiveMirror;
|
||||
public class AutoConnect : MonoBehaviour
|
||||
{
|
||||
public bool isClient;
|
||||
public static bool isRankedServer;
|
||||
public static string serverName;
|
||||
public static int serverPort;
|
||||
public bool isRanked;
|
||||
public LightReflectiveMirrorTransport lrm;
|
||||
public kcp2k.KcpTransport transport;
|
||||
void Start()
|
||||
{
|
||||
if(isRanked){
|
||||
if (isRanked)
|
||||
{
|
||||
|
||||
if(!isRankedServer){
|
||||
lrm.serverListUpdated.AddListener(OnServerListUpdated);
|
||||
StartCoroutine(refreshList());
|
||||
}else{
|
||||
StartCoroutine(startHost());
|
||||
// if(!isRankedServer){
|
||||
// lrm.serverListUpdated.AddListener(OnServerListUpdated);
|
||||
// StartCoroutine(refreshList());
|
||||
// }else{
|
||||
// StartCoroutine(startHost());
|
||||
|
||||
// }
|
||||
string[] args = System.Environment.GetCommandLineArgs();
|
||||
string input = "";
|
||||
for (int i = 0; i < args.Length; i++)
|
||||
{
|
||||
// Debug.Log("ARG " + i + ": " + args[i]);
|
||||
if (args[i] == "-port")
|
||||
{
|
||||
input = args[i + 1];
|
||||
}
|
||||
}
|
||||
|
||||
ushort port = 7777;
|
||||
try
|
||||
{
|
||||
port = ushort.Parse(input);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
}else{
|
||||
if(isClient){
|
||||
|
||||
|
||||
if(!isClient){
|
||||
Debug.Log("Setting port to " + port);
|
||||
transport.Port = port;
|
||||
NetworkManager.singleton.StartServer();
|
||||
}else{
|
||||
NetworkManager.singleton.networkAddress = RegionManager.selectedServer.ip;
|
||||
transport.Port = (ushort)serverPort;
|
||||
NetworkManager.singleton.StartClient();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isClient)
|
||||
{
|
||||
FindObjectOfType<NetworkManager>().networkAddress = RegionManager.selectedServer.ip;
|
||||
FindObjectOfType<NetworkManager>().StartClient();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator startHost(){
|
||||
while(!lrm.isConnectedToRelay){
|
||||
yield return new WaitForSeconds(1);
|
||||
}
|
||||
lrm.serverName = serverName;
|
||||
lrm.isPublicServer=true;
|
||||
NetworkManager.singleton.StartHost();
|
||||
}
|
||||
IEnumerator refreshList(){
|
||||
while(!lrm.isConnectedToRelay){
|
||||
yield return new WaitForSeconds(1);
|
||||
}
|
||||
while(!NetworkManager.singleton.isNetworkActive){
|
||||
yield return new WaitForSeconds(1);
|
||||
lrm.RequestServerList();
|
||||
}
|
||||
}
|
||||
|
||||
void OnServerListUpdated(){
|
||||
Debug.Log("Got new server list of " + lrm.relayServerList.Count);
|
||||
foreach(Room room in lrm.relayServerList){
|
||||
if(room.serverName == serverName){
|
||||
Debug.Log("Found server for me! Joining now");
|
||||
NetworkManager.singleton.networkAddress = room.serverId;
|
||||
NetworkManager.singleton.StartClient();
|
||||
float t;
|
||||
void Update(){
|
||||
if(isRanked && !isClient){
|
||||
//timer
|
||||
t += Time.deltaTime;
|
||||
if(t > 30 && FindObjectsOfType<SpaceshipController>().Length ==0){
|
||||
//No players joined, or they left, gotta close my self
|
||||
t=0;
|
||||
StartCoroutine(CloseRoom());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator CloseRoom(){
|
||||
WWWForm form = new WWWForm();
|
||||
form.AddField("port", serverPort);
|
||||
WWW req = new WWW(DBmanager.phpRoot+"clear_ranked_room.php",form);
|
||||
yield return req;
|
||||
|
||||
Application.Quit();
|
||||
}
|
||||
|
||||
// IEnumerator startHost()
|
||||
// {
|
||||
// while (!lrm.isConnectedToRelay)
|
||||
// {
|
||||
// yield return new WaitForSeconds(1);
|
||||
// }
|
||||
// lrm.serverName = serverName;
|
||||
// lrm.isPublicServer = true;
|
||||
// NetworkManager.singleton.StartHost();
|
||||
// }
|
||||
// IEnumerator refreshList()
|
||||
// {
|
||||
// while (!lrm.isConnectedToRelay)
|
||||
// {
|
||||
// yield return new WaitForSeconds(1);
|
||||
// }
|
||||
// while (!NetworkManager.singleton.isNetworkActive)
|
||||
// {
|
||||
// yield return new WaitForSeconds(1);
|
||||
// lrm.RequestServerList();
|
||||
// }
|
||||
// }
|
||||
|
||||
// void OnServerListUpdated()
|
||||
// {
|
||||
// Debug.Log("Got new server list of " + lrm.relayServerList.Count);
|
||||
// foreach (Room room in lrm.relayServerList)
|
||||
// {
|
||||
// if (room.serverName == serverName)
|
||||
// {
|
||||
// Debug.Log("Found server for me! Joining now");
|
||||
// NetworkManager.singleton.networkAddress = room.serverId;
|
||||
// NetworkManager.singleton.StartClient();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public class Leaderboard : MonoBehaviour
|
||||
{
|
||||
for (int i = 0; i <= players.Length - 2; i++)
|
||||
{
|
||||
if ( (isRanked ? players[i].moonsCollected : players[i].Scores) > (isRanked? players[i+1].moonsCollected : players[i + 1].Scores))
|
||||
if ( (!isRanked ? players[i].moonsCollected : players[i].Scores) > (!isRanked? players[i+1].moonsCollected : players[i + 1].Scores))
|
||||
{
|
||||
temp = players[i + 1];
|
||||
players[i + 1] = players[i];
|
||||
@@ -51,7 +51,7 @@ public class Leaderboard : MonoBehaviour
|
||||
SpaceshipController thisPlayer = players[players.Length-i-1];
|
||||
leaderboardItems[i].gameObject.SetActive(true);
|
||||
leaderboardItems[i].text = (i+1) + ". " +thisPlayer.pname;
|
||||
if(isRanked){
|
||||
if(!isRanked){
|
||||
leaderboardItems[i].transform.GetChild(0).GetComponent<Text>().text = thisPlayer.Scores.ToString();
|
||||
}else{
|
||||
leaderboardItems[i].transform.GetChild(0).GetComponent<Text>().text = (((float)Mathf.Clamp(thisPlayer.moonsCollected,0,30)/ 30f)*100f).ToString("n1") + " %";
|
||||
|
||||
@@ -14,7 +14,6 @@ public class MatchMaker : MonoBehaviour
|
||||
public TMP_Text timerTxt;
|
||||
public Button btn_cancel;
|
||||
float timer;
|
||||
public string serverName;
|
||||
void Start()
|
||||
{
|
||||
if(!DBmanager.LoggedIn){
|
||||
@@ -47,8 +46,6 @@ public class MatchMaker : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool isServer =false;
|
||||
IEnumerator FetchMatchmake(){
|
||||
|
||||
WWWForm form = new WWWForm();
|
||||
@@ -58,19 +55,31 @@ public class MatchMaker : MonoBehaviour
|
||||
WWW req = new WWW(DBmanager.phpRoot+"matchmake.php", form);
|
||||
yield return req;
|
||||
Debug.Log(req.text);
|
||||
if(req.text.Contains(DBmanager.username) && !loadedScene){
|
||||
//Room created!
|
||||
isServer= req.text.Substring(0,DBmanager.username.Length) == DBmanager.username;
|
||||
serverName=req.text;
|
||||
AutoConnect.serverName = serverName;
|
||||
AutoConnect.isRankedServer = isServer;
|
||||
// AutoConnect.isRanked = true;
|
||||
Debug.Log($"Room created! [{req.text}] am I the server? : " + isServer);
|
||||
// if(req.text.Contains(DBmanager.username) && !loadedScene){
|
||||
// int port
|
||||
// //Room created!
|
||||
// // isServer= req.text.Substring(0,DBmanager.username.Length) == DBmanager.username;
|
||||
// // serverName=req.text;
|
||||
// // AutoConnect.serverName = serverName;
|
||||
// // AutoConnect.isRankedServer = isServer;
|
||||
// // AutoConnect.isRanked = true;
|
||||
// Debug.Log($"Room created! [{req.text}] am I the server? : ");
|
||||
|
||||
LoadingScreen.instance.LoadLevel("MinigameRanked");
|
||||
// LoadingScreen.instance.LoadLevel("MinigameRanked");
|
||||
|
||||
// }else{
|
||||
// //Waiting
|
||||
// }
|
||||
|
||||
try{
|
||||
int port = int.Parse(req.text);
|
||||
if(port > 5000){
|
||||
Debug.Log("Got the port, Lets go!");
|
||||
AutoConnect.serverPort = port;
|
||||
LoadingScreen.instance.LoadLevel("MinigameRanked");
|
||||
}
|
||||
}catch{
|
||||
|
||||
}else{
|
||||
//Waiting
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,12 @@ public class MinigameManager : NetworkBehaviour
|
||||
public static MinigameManager instance;
|
||||
public bool isRanked;
|
||||
public bool RankedGameStarted=false;
|
||||
[SyncVar(hook =nameof(OnWinnerChanged))]
|
||||
public int winnerId=-1;
|
||||
[SyncVar]
|
||||
public double startedTime = 0;
|
||||
public GameObject waitingScreen;
|
||||
public RankedGameSummary rankedSummary;
|
||||
public float mapRadius;
|
||||
public int maxMoons, maxStars = 100;
|
||||
public Transform pickupItemsParent;
|
||||
@@ -38,7 +43,13 @@ public class MinigameManager : NetworkBehaviour
|
||||
// if(!DBmanager.LoggedIn){SceneManager.LoadScene(0);} //Signed out, no game for u
|
||||
|
||||
if(isRanked){
|
||||
RankedGameStarted= (FindObjectsOfType<SpaceshipController>().Length >=2);
|
||||
// RankedGameStarted= (FindObjectsOfType<SpaceshipController>().Length >=2);
|
||||
if(!RankedGameStarted && !isServer){
|
||||
SpaceshipController[] players = FindObjectsOfType<SpaceshipController>();
|
||||
if(players.Length >= 2){
|
||||
RankedGameStarted=true;
|
||||
}
|
||||
}
|
||||
waitingScreen.SetActive(!RankedGameStarted);
|
||||
}
|
||||
|
||||
@@ -46,7 +57,51 @@ public class MinigameManager : NetworkBehaviour
|
||||
|
||||
HandlePickupSpawn();
|
||||
KillOutOfBoundsPlayers();
|
||||
if(isRanked){RankedMechanics();}
|
||||
}
|
||||
|
||||
void RankedMechanics(){
|
||||
SpaceshipController[] players = FindObjectsOfType<SpaceshipController>();
|
||||
if(players.Length < 2){
|
||||
//Not enough players
|
||||
}else{
|
||||
if(!RankedGameStarted){
|
||||
startedTime=NetworkTime.time;
|
||||
}
|
||||
RankedGameStarted=true;
|
||||
if(players[0].moonsCollected >= 30){
|
||||
//player 1 has won
|
||||
winnerId = (int)players[0].netId;
|
||||
// players[0].WonRanked();
|
||||
// players[1].LostRanked();
|
||||
}else if(players[1].moonsCollected >= 30){
|
||||
//player 2 has won
|
||||
winnerId = (int)players[1].netId;
|
||||
|
||||
// players[0].WonRanked();
|
||||
// players[1].LostRanked();
|
||||
}
|
||||
}
|
||||
|
||||
if(RankedGameStarted && players.Length < 2){
|
||||
//Forfeited!
|
||||
winnerId = (int)players[0].netId;
|
||||
// players[0].WonRanked();
|
||||
}
|
||||
}
|
||||
|
||||
void OnWinnerChanged(int oldVal, int newVal){
|
||||
if(newVal<= 0){return;}
|
||||
Debug.Log($"{newVal} id won!");
|
||||
SpaceshipController localPlayer = SceneData.localPlayer.GetComponent<SpaceshipController>();
|
||||
if(newVal == localPlayer.netId){
|
||||
//We won
|
||||
localPlayer.CmdWonRanked();
|
||||
Debug.Log("Its Me!, I won!");
|
||||
}else{
|
||||
Debug.Log("Its not me, I lost!");
|
||||
localPlayer.CmdLostRanked();
|
||||
}
|
||||
}
|
||||
|
||||
void KillOutOfBoundsPlayers()
|
||||
|
||||
22
Assets/Game/Scripts/Minigame/RankedGameSummary.cs
Normal file
22
Assets/Game/Scripts/Minigame/RankedGameSummary.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
public class RankedGameSummary : MonoBehaviour
|
||||
{
|
||||
public TMP_Text txtGameOver;
|
||||
public TMP_Text txtTrophies;
|
||||
|
||||
|
||||
public void ShowWin(){
|
||||
txtGameOver.text = "You Won!";
|
||||
txtTrophies.text= "+30";
|
||||
txtTrophies.color = Color.green;
|
||||
}
|
||||
|
||||
public void ShowLoss(){
|
||||
txtGameOver.text = "You Lost!";
|
||||
txtTrophies.text= "-15";
|
||||
txtTrophies.color = Color.red;
|
||||
}
|
||||
}
|
||||
11
Assets/Game/Scripts/Minigame/RankedGameSummary.cs.meta
Normal file
11
Assets/Game/Scripts/Minigame/RankedGameSummary.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 812537ae82c3b8c56ada62732b76a181
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -13,6 +13,7 @@ public class SceneDataHolder : MonoBehaviour
|
||||
public GameObject metalEarnings;
|
||||
public TMP_Text survivalTimeTxt;
|
||||
public TMP_Text mostTimeTxt;
|
||||
public TMP_Text gameOverTxt;
|
||||
public EventTrigger boostBtn;
|
||||
public TMP_Text timerTxt;
|
||||
void Awake()
|
||||
@@ -32,8 +33,12 @@ public class SceneDataHolder : MonoBehaviour
|
||||
xpEarnings.SetActive(xpEarned > 0); metalEarnings.SetActive(metalEarned > 0);
|
||||
xpEarnings.GetComponentInChildren<TMP_Text>().text = xpEarned.ToString();
|
||||
metalEarnings.GetComponentInChildren<TMP_Text>().text = metalEarned.ToString();
|
||||
survivalTimeTxt.text = SceneData.SecondsToText(survivalTime);
|
||||
mostTimeTxt.text = SceneData.SecondsToText(DBmanager.MostTime);
|
||||
if(!MinigameManager.instance.isRanked){
|
||||
survivalTimeTxt.text = SceneData.SecondsToText(survivalTime);
|
||||
mostTimeTxt.text = SceneData.SecondsToText(DBmanager.MostTime);
|
||||
}else{
|
||||
// MinigameManager.instance.rankedSummary.ShowLoss();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,20 +3,21 @@ using UnityEngine;
|
||||
using Mirror;
|
||||
using System.Linq;
|
||||
using UnityEngine.UI;
|
||||
using System.Collections;
|
||||
|
||||
public class SpaceshipController : NetworkBehaviour
|
||||
{
|
||||
public SpriteRenderer playerImg;
|
||||
public SkinsData skins;
|
||||
[SyncVar(hook=nameof(OnSkinChanged))]
|
||||
[SyncVar(hook = nameof(OnSkinChanged))]
|
||||
public string skinName = null;
|
||||
[SyncVar(hook=nameof(OnPnameChanged))]
|
||||
[SyncVar(hook = nameof(OnPnameChanged))]
|
||||
public string pname;
|
||||
[SyncVar(hook=nameof(OnScoresChanged))]
|
||||
[SyncVar(hook = nameof(OnScoresChanged))]
|
||||
public int Scores;
|
||||
[SyncVar(hook=nameof(OnKillsChanged))]
|
||||
[SyncVar(hook = nameof(OnKillsChanged))]
|
||||
public int Kills;
|
||||
[SyncVar(hook=nameof(OnTrailTimeChanged))]
|
||||
[SyncVar(hook = nameof(OnTrailTimeChanged))]
|
||||
public float trailTime;
|
||||
[SyncVar]
|
||||
public int moonsCollected;
|
||||
@@ -25,8 +26,8 @@ public class SpaceshipController : NetworkBehaviour
|
||||
public bool dead;
|
||||
[SyncVar]
|
||||
public float speed;
|
||||
[SyncVar(hook=nameof(OnScaleChanged))]
|
||||
public float scaleMultiplier=1;
|
||||
[SyncVar(hook = nameof(OnScaleChanged))]
|
||||
public float scaleMultiplier = 1;
|
||||
public Text pnameTxt;
|
||||
public Transform body;
|
||||
public TrailMgr trailMgr;
|
||||
@@ -39,87 +40,108 @@ public class SpaceshipController : NetworkBehaviour
|
||||
|
||||
[Header("Client Prediction")]
|
||||
public SortedDictionary<int, StatePayload> serverStateBuffer = new SortedDictionary<int, StatePayload>();
|
||||
public Vector3 DetourError = new Vector3(0,0.2f,0);
|
||||
public Vector3 DetourError = new Vector3(0, 0.2f, 0);
|
||||
public Vector3 Detour = Vector3.zero;
|
||||
public Quaternion RotationDetour = Quaternion.identity;
|
||||
public float DetourCorrectionFactor = 0.5f;
|
||||
public float timeDelayErrorFix = 1f;
|
||||
public bool showDebugHUD = false;
|
||||
|
||||
public float distanceFromCenter= 0;
|
||||
public float distanceFromCenter = 0;
|
||||
|
||||
[Command]
|
||||
void CmdSetPname(string value){
|
||||
void CmdSetPname(string value)
|
||||
{
|
||||
pname = value;
|
||||
}
|
||||
void OnPnameChanged(string oldName, string newName){
|
||||
void OnPnameChanged(string oldName, string newName)
|
||||
{
|
||||
pnameTxt.text = newName;
|
||||
}
|
||||
|
||||
[Command]
|
||||
void CmdSetSkin(string newSkin){
|
||||
void CmdSetSkin(string newSkin)
|
||||
{
|
||||
skinName = newSkin;
|
||||
}
|
||||
|
||||
void OnSkinChanged(string oldSkin, string newSkin){
|
||||
void OnSkinChanged(string oldSkin, string newSkin)
|
||||
{
|
||||
ChangeSkin(newSkin);
|
||||
}
|
||||
|
||||
void ChangeSkin(string name){
|
||||
Sprite newSprite = SkinManagerHelper.getSkinSprite(name,skins);
|
||||
void ChangeSkin(string name)
|
||||
{
|
||||
Sprite newSprite = SkinManagerHelper.getSkinSprite(name, skins);
|
||||
playerImg.sprite = newSprite;
|
||||
}
|
||||
|
||||
|
||||
void OnScoresChanged(int oldScores, int newScores){
|
||||
Debug.Log($"Add scores { newScores - oldScores}, (total: {newScores})");
|
||||
void OnScoresChanged(int oldScores, int newScores)
|
||||
{
|
||||
Debug.Log($"Add scores {newScores - oldScores}, (total: {newScores})");
|
||||
}
|
||||
|
||||
void OnTrailTimeChanged(float oldValue, float newValue){
|
||||
void OnTrailTimeChanged(float oldValue, float newValue)
|
||||
{
|
||||
trailMgr.trail.time = newValue;
|
||||
}
|
||||
|
||||
void OnBoostDown(){
|
||||
if(isLocalPlayer){
|
||||
if(isServer){
|
||||
boosting=true;
|
||||
}else{
|
||||
void OnBoostDown()
|
||||
{
|
||||
if (isLocalPlayer)
|
||||
{
|
||||
if (isServer)
|
||||
{
|
||||
boosting = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
CmdSetBoosting(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnBoostUp(){
|
||||
if(isLocalPlayer){
|
||||
if(isServer){
|
||||
boosting=false;
|
||||
}else{
|
||||
void OnBoostUp()
|
||||
{
|
||||
if (isLocalPlayer)
|
||||
{
|
||||
if (isServer)
|
||||
{
|
||||
boosting = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
CmdSetBoosting(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnScaleChanged(float oldScale, float newScale){
|
||||
if(isLocalPlayer){
|
||||
SceneData.holder.boostBtn.gameObject.SetActive(newScale>1);
|
||||
void OnScaleChanged(float oldScale, float newScale)
|
||||
{
|
||||
if (isLocalPlayer)
|
||||
{
|
||||
SceneData.holder.boostBtn.gameObject.SetActive(newScale > 1);
|
||||
}
|
||||
}
|
||||
|
||||
[Command]
|
||||
void CmdSetBoosting(bool value){
|
||||
boosting=value;
|
||||
void CmdSetBoosting(bool value)
|
||||
{
|
||||
boosting = value;
|
||||
}
|
||||
[SyncVar]
|
||||
double startedTime = 0;
|
||||
|
||||
void ResetStats(){
|
||||
void ResetStats()
|
||||
{
|
||||
startedXp = DBmanager.Xp;
|
||||
startedMetal = DBmanager.Metal;
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
scaleMultiplier=1;
|
||||
scaleMultiplier = 1;
|
||||
if (isLocalPlayer)
|
||||
{
|
||||
ResetStats();
|
||||
@@ -130,17 +152,25 @@ public class SpaceshipController : NetworkBehaviour
|
||||
SceneData.OnBoostDown.AddListener(OnBoostDown);
|
||||
SceneData.OnBoostUp.AddListener(OnBoostUp);
|
||||
//Set username
|
||||
if(isServer){pname=myName;}else{
|
||||
if (isServer) { pname = myName; }
|
||||
else
|
||||
{
|
||||
CmdSetPname(myName);
|
||||
}
|
||||
|
||||
//Set Skin
|
||||
if(!DBmanager.SkinsPurchased.Contains(SkinShopManager.GetEquipedSkin())){
|
||||
if (!DBmanager.SkinsPurchased.Contains(SkinShopManager.GetEquipedSkin()))
|
||||
{
|
||||
//False skin purchase
|
||||
}else{
|
||||
if(isServer){
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isServer)
|
||||
{
|
||||
skinName = SkinShopManager.GetEquipedSkin();
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
CmdSetSkin(SkinShopManager.GetEquipedSkin());
|
||||
}
|
||||
}
|
||||
@@ -162,27 +192,29 @@ public class SpaceshipController : NetworkBehaviour
|
||||
int lastClientUpdateTime = 0;
|
||||
void FixedUpdate()
|
||||
{
|
||||
if(MinigameManager.instance.isRanked && !MinigameManager.instance.RankedGameStarted){return;}
|
||||
if (MinigameManager.instance.isRanked && !MinigameManager.instance.RankedGameStarted) { return; }
|
||||
distanceFromCenter = Vector3.Distance(transform.position, Vector3.zero);
|
||||
pnameTxt.rectTransform.rotation = Quaternion.Euler(Vector3.zero);
|
||||
|
||||
//Update size of trail and spaceship
|
||||
transform.localScale = Vector3.Lerp(transform.localScale,new Vector3(scaleMultiplier,scaleMultiplier,scaleMultiplier),0.1f);
|
||||
trailMgr.trail.startWidth = Mathf.Lerp(trailMgr.trail.startWidth,scaleMultiplier,0.1f);
|
||||
transform.localScale = Vector3.Lerp(transform.localScale, new Vector3(scaleMultiplier, scaleMultiplier, scaleMultiplier), 0.1f);
|
||||
trailMgr.trail.startWidth = Mathf.Lerp(trailMgr.trail.startWidth, scaleMultiplier, 0.1f);
|
||||
|
||||
if(dead){return;}
|
||||
if (dead) { return; }
|
||||
|
||||
if (isLocalPlayer)
|
||||
{
|
||||
joyInput = joystick.input;
|
||||
|
||||
//Cheats => TODO: Remove this
|
||||
if(Input.GetKeyDown(KeyCode.F)){
|
||||
if (Input.GetKeyDown(KeyCode.F))
|
||||
{
|
||||
CmdCheatKills();
|
||||
}
|
||||
// Debug.Log(startedTime-NetworkTime.time);
|
||||
double survivalTime = (startedTime ==0) ? 0 :NetworkTime.time - startedTime;
|
||||
if(DBmanager.MostTime < (int)survivalTime){
|
||||
double survivalTime = (startedTime == 0) ? 0 : NetworkTime.time - ((MinigameManager.instance.isRanked)? MinigameManager.instance.startedTime :startedTime);
|
||||
if (DBmanager.MostTime < (int)survivalTime)
|
||||
{
|
||||
DBmanager.SetMostTime((int)survivalTime);
|
||||
}
|
||||
SceneData.SetTimerTxt(survivalTime);
|
||||
@@ -197,15 +229,19 @@ public class SpaceshipController : NetworkBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
if(isServer){
|
||||
if (isServer)
|
||||
{
|
||||
//boost check
|
||||
if(boosting && scaleMultiplier > 1){
|
||||
speed= movingSpeed*2;
|
||||
scaleMultiplier-=Time.deltaTime;
|
||||
|
||||
if(scaleMultiplier<1){scaleMultiplier=1;} //Clamp in case gets lower
|
||||
}else{
|
||||
speed=movingSpeed;
|
||||
if (boosting && scaleMultiplier > 1)
|
||||
{
|
||||
speed = movingSpeed * 2;
|
||||
scaleMultiplier -= Time.deltaTime;
|
||||
|
||||
if (scaleMultiplier < 1) { scaleMultiplier = 1; } //Clamp in case gets lower
|
||||
}
|
||||
else
|
||||
{
|
||||
speed = movingSpeed;
|
||||
}
|
||||
}
|
||||
///Diff = rot1 . rot2
|
||||
@@ -221,15 +257,16 @@ public class SpaceshipController : NetworkBehaviour
|
||||
{
|
||||
Vector3 newPosition = body.position + Detour;
|
||||
Quaternion newRotation = body.rotation * RotationDetour;
|
||||
if(Detour.magnitude > 0.5f){
|
||||
trailMgr.trail.emitting =false;
|
||||
if (Detour.magnitude > 0.5f)
|
||||
{
|
||||
trailMgr.trail.emitting = false;
|
||||
}
|
||||
body.position = Vector3.Lerp(body.position, newPosition, (Mathf.Abs(Detour.magnitude) > 0.2f) ? DetourCorrectionFactor * 2 * Detour.magnitude : DetourCorrectionFactor);
|
||||
body.position = Vector3.Lerp(body.position, newPosition, (Mathf.Abs(Detour.magnitude) > 0.2f) ? DetourCorrectionFactor * 2 * Detour.magnitude : DetourCorrectionFactor);
|
||||
Detour = newPosition - body.position;
|
||||
body.rotation = Quaternion.Lerp(body.rotation, newRotation, DetourCorrectionFactor * ((joystick.touchDown) ? 0.1f : 1));
|
||||
RotationDetour = Quaternion.Inverse(transform.rotation) * newRotation;
|
||||
|
||||
trailMgr.trail.emitting=true;
|
||||
trailMgr.trail.emitting = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,7 +295,9 @@ public class SpaceshipController : NetworkBehaviour
|
||||
}
|
||||
RpcUpdatePosition(joyInput, transform.position, transform.rotation, timeInMillis);
|
||||
RpcUpdateTrail(trailMgr.positions);
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
transform.position = Vector3.Lerp(transform.position, targetPosition, 0.1f);
|
||||
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, 0.1f);
|
||||
}
|
||||
@@ -266,7 +305,7 @@ public class SpaceshipController : NetworkBehaviour
|
||||
|
||||
Vector3 targetPosition;
|
||||
Quaternion targetRotation;
|
||||
|
||||
|
||||
|
||||
void Turn(Vector2 input)
|
||||
{
|
||||
@@ -298,7 +337,7 @@ public class SpaceshipController : NetworkBehaviour
|
||||
payloadToCompare = lastServerState;
|
||||
if (lastServerState.Time < time)
|
||||
{
|
||||
// Debug.Log("Server doesn't have that data yet\nYou asked for " + time + " best I can do is " + lastServerState.Time);
|
||||
// Debug.Log("Server doesn't have that data yet\nYou asked for " + time + " best I can do is " + lastServerState.Time);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -327,7 +366,7 @@ public class SpaceshipController : NetworkBehaviour
|
||||
}
|
||||
else
|
||||
{
|
||||
// Debug.Log($"RB : {positionDiff.magnitude} [{timeDiff}ms]");
|
||||
// Debug.Log($"RB : {positionDiff.magnitude} [{timeDiff}ms]");
|
||||
RpcRubberBand(joyInput, serverStateBuffer.Values.Last().Position, serverStateBuffer.Values.Last().Rotation, trailMgr.positions, timeInMillis);
|
||||
}
|
||||
|
||||
@@ -336,21 +375,21 @@ public class SpaceshipController : NetworkBehaviour
|
||||
[ClientRpc]
|
||||
void RpcUpdatePosition(Vector2 input, Vector3 position, Quaternion rotation, double sentTime)
|
||||
{
|
||||
if(isLocalPlayer || isServer){return;}
|
||||
if (isLocalPlayer || isServer) { return; }
|
||||
double delay = (timeInMillis - sentTime) * timeDelayErrorFix;
|
||||
int numberOfFrames = (int)((float)(delay/1000f) *50f);
|
||||
|
||||
int numberOfFrames = (int)((float)(delay / 1000f) * 50f);
|
||||
|
||||
Quaternion newRotation = rotation;
|
||||
Vector3 direction = (rotation * Vector3.forward).normalized;
|
||||
Vector3 newPosition = position + ((direction * speed) * numberOfFrames);
|
||||
|
||||
|
||||
for (int i = 0; i < numberOfFrames; i++)
|
||||
{
|
||||
newRotation = Quaternion.Lerp(newRotation, getTurnAngle(input), turningSmoothFactor * input.magnitude);
|
||||
}
|
||||
|
||||
targetPosition = newPosition - DetourError;
|
||||
|
||||
|
||||
targetRotation = newRotation;
|
||||
}
|
||||
double lastRubberBandTime = 0;
|
||||
@@ -363,12 +402,12 @@ public class SpaceshipController : NetworkBehaviour
|
||||
if (sentTime < lastRubberBandTime) { Debug.Log("Old rubber band rpc, ignoree..."); return; }
|
||||
//Lag comprehension
|
||||
double delay = (timeInMillis - sentTime) * timeDelayErrorFix;
|
||||
int numberOfFrames = (int)((float)(delay/1000f) * 50f);
|
||||
|
||||
int numberOfFrames = (int)((float)(delay / 1000f) * 50f);
|
||||
|
||||
Quaternion newRotation = rotation;
|
||||
Vector3 direction = (rotation * Vector3.forward).normalized;
|
||||
Vector3 newPosition = position + ((direction * speed) * numberOfFrames);
|
||||
|
||||
|
||||
for (int i = 0; i < numberOfFrames; i++)
|
||||
{
|
||||
newRotation = Quaternion.Lerp(newRotation, getTurnAngle(input), turningSmoothFactor * input.magnitude);
|
||||
@@ -402,12 +441,13 @@ public class SpaceshipController : NetworkBehaviour
|
||||
RotationDetour = Quaternion.Inverse(transform.rotation) * newRotation;
|
||||
lastRubberBandTime = sentTime;
|
||||
|
||||
// Debug.Log($"Rubber banded (Detour of pos:{Detour}, rotation: {RotationDetour}) you to {transform.position}, @ {sentTime} (delay: {delay}");
|
||||
// Debug.Log($"Rubber banded (Detour of pos:{Detour}, rotation: {RotationDetour}) you to {transform.position}, @ {sentTime} (delay: {delay}");
|
||||
}
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
void RpcUpdateTrail(Vector3[] positions){
|
||||
void RpcUpdateTrail(Vector3[] positions)
|
||||
{
|
||||
//trailMgr.trail.SetPositions(positions);
|
||||
}
|
||||
|
||||
@@ -438,15 +478,18 @@ public class SpaceshipController : NetworkBehaviour
|
||||
{
|
||||
body = transform;
|
||||
}
|
||||
if(trailMgr==null){
|
||||
if (trailMgr == null)
|
||||
{
|
||||
trailMgr = GetComponent<TrailMgr>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void TrailCollided(Collider2D hit){
|
||||
if(!isServer){
|
||||
public void TrailCollided(Collider2D hit)
|
||||
{
|
||||
if (!isServer)
|
||||
{
|
||||
Debug.Log("Got hit : " + hit.name);
|
||||
// Debug.Log("This cannot run on client, That's illegal!"); // <-- What this log says
|
||||
return;
|
||||
@@ -454,55 +497,64 @@ public class SpaceshipController : NetworkBehaviour
|
||||
|
||||
SpaceshipController deadPlayer = hit.GetComponent<SpaceshipController>();
|
||||
Debug.Log("got hit by player? : " + deadPlayer != null);
|
||||
if(deadPlayer!=null && !deadPlayer.dead){ // <-- okay we killed someone | KILLCODE
|
||||
if (deadPlayer != null && !deadPlayer.dead && (NetworkTime.time- deadPlayer.startedTime) > 5)
|
||||
{ // <-- okay we killed someone | KILLCODE
|
||||
deadPlayer.Die(pname);
|
||||
Debug.Log($"{pname} killed {deadPlayer.pname}");
|
||||
OnKill();
|
||||
OnKill();
|
||||
}
|
||||
}
|
||||
|
||||
void OnKill(){
|
||||
void OnKill()
|
||||
{
|
||||
Kills++;
|
||||
Scores+= 10; //TODO: Need to change Scores on kills?
|
||||
scaleMultiplier+=0.05f;
|
||||
OnScaleChanged(scaleMultiplier,scaleMultiplier);
|
||||
Scores += 10; //TODO: Need to change Scores on kills?
|
||||
scaleMultiplier += 0.05f;
|
||||
OnScaleChanged(scaleMultiplier, scaleMultiplier);
|
||||
IncreaseTrail(trailIncrementRate);
|
||||
RpcOnKill();
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
void RpcOnKill(){
|
||||
|
||||
void RpcOnKill()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void OnKillsChanged(int oldVal, int newVal){
|
||||
if(isLocalPlayer){
|
||||
void OnKillsChanged(int oldVal, int newVal)
|
||||
{
|
||||
if (isLocalPlayer)
|
||||
{
|
||||
Debug.Log("Show kills for " + newVal);
|
||||
KillText.Show(newVal);
|
||||
}
|
||||
}
|
||||
|
||||
void IncreaseTrail(float rate){
|
||||
trailTime = trailMgr.trail.time+ rate;
|
||||
void IncreaseTrail(float rate)
|
||||
{
|
||||
trailTime = trailMgr.trail.time + rate;
|
||||
trailMgr.trail.time = trailTime;
|
||||
Debug.Log("Increasing trail of" + pname);
|
||||
}
|
||||
|
||||
[Command]
|
||||
void CmdCheatKills(){
|
||||
void CmdCheatKills()
|
||||
{
|
||||
OnKill();
|
||||
}
|
||||
|
||||
public void CollectPickup(PickupItem.PickupType type){
|
||||
if(!isServer){Debug.Log("Server function ran on client. That's illegal!");} // <-- What this log says
|
||||
switch(type){
|
||||
public void CollectPickup(PickupItem.PickupType type)
|
||||
{
|
||||
if (!isServer) { Debug.Log("Server function ran on client. That's illegal!"); } // <-- What this log says
|
||||
switch (type)
|
||||
{
|
||||
case PickupItem.PickupType.Moon:
|
||||
IncreaseTrail(trailIncrementRate);
|
||||
moonsCollected++;
|
||||
break;
|
||||
|
||||
|
||||
case PickupItem.PickupType.Star:
|
||||
IncreaseTrail(trailIncrementRate/2f);
|
||||
IncreaseTrail(trailIncrementRate / 2f);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -510,24 +562,27 @@ public class SpaceshipController : NetworkBehaviour
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
void RpcCollectPickup(PickupItem.PickupType type){
|
||||
if(isLocalPlayer){
|
||||
MinigameManager.instance.GainMetals((type==PickupItem.PickupType.Star) ? 10 : 30);
|
||||
void RpcCollectPickup(PickupItem.PickupType type)
|
||||
{
|
||||
if (isLocalPlayer)
|
||||
{
|
||||
MinigameManager.instance.GainMetals((type == PickupItem.PickupType.Star) ? 2 : 5);
|
||||
}
|
||||
}
|
||||
|
||||
public void Die(string killer){
|
||||
|
||||
public void Die(string killer)
|
||||
{
|
||||
|
||||
MinigameManager.instance.SpawnLeftoverPickups(transform.position, Scores);
|
||||
Debug.Log($"Sending death signal to {pname} by {killer}");
|
||||
|
||||
//Handle Respawning
|
||||
OnScaleChanged(scaleMultiplier,1);
|
||||
scaleMultiplier=1;
|
||||
dead=true;
|
||||
Scores=0;
|
||||
Kills=0;
|
||||
startedTime=NetworkTime.time;
|
||||
OnScaleChanged(scaleMultiplier, 1);
|
||||
scaleMultiplier = 1;
|
||||
dead = true;
|
||||
Scores = 0;
|
||||
Kills = 0;
|
||||
startedTime = NetworkTime.time;
|
||||
trailTime = 1;
|
||||
trailMgr.trail.time = trailTime;
|
||||
RpcDie(killer);
|
||||
@@ -538,59 +593,153 @@ public class SpaceshipController : NetworkBehaviour
|
||||
private int startedXp;
|
||||
private int startedMetal;
|
||||
|
||||
bool RewardedRankedMetal =false;
|
||||
|
||||
[ClientRpc]
|
||||
public void RpcDie(string killer){
|
||||
public void RpcDie(string killer)
|
||||
{
|
||||
Debug.Log($"{killer} killed {pname} : isItMe? -> {isLocalPlayer}");
|
||||
KillfeedMgr.instance.AddNewEntry($"<b>{pname}</b> was killed by <b>{killer}</b>");
|
||||
gameObject.SetActive(false);
|
||||
if(isLocalPlayer){
|
||||
if (isLocalPlayer)
|
||||
{
|
||||
//TODO: Death message goes here
|
||||
SceneData.holder.ShowDeadscreen(DBmanager.Xp - startedXp, DBmanager.Metal - startedMetal, NetworkTime.time - startedTime);
|
||||
if (MinigameManager.instance.isRanked)
|
||||
{
|
||||
// MinigameManager.instance.rankedSummary.ShowLoss();
|
||||
// StartCoroutine(ShowRankedResults());
|
||||
if(MinigameManager.instance.winnerId<=0){
|
||||
Debug.LogError("Winner ID not synced yet");
|
||||
}
|
||||
if (MinigameManager.instance.winnerId != netId)
|
||||
{
|
||||
//LOSER!
|
||||
MinigameManager.instance.rankedSummary.ShowLoss();
|
||||
}
|
||||
else
|
||||
{
|
||||
MinigameManager.instance.rankedSummary.ShowWin();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Respawn(Vector3 respawnPoint){
|
||||
IEnumerator ShowRankedResults()
|
||||
{
|
||||
while (MinigameManager.instance.winnerId <= 0)
|
||||
{
|
||||
yield return new WaitForFixedUpdate();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void Respawn(Vector3 respawnPoint)
|
||||
{
|
||||
Debug.Log("Respawning " + pname);
|
||||
|
||||
if(isServer){
|
||||
if (isServer)
|
||||
{
|
||||
respawn(respawnPoint);
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
CmdRespawn(respawnPoint);
|
||||
}
|
||||
}
|
||||
|
||||
[Command]
|
||||
void CmdRespawn(Vector3 respawnPoint){
|
||||
void CmdRespawn(Vector3 respawnPoint)
|
||||
{
|
||||
respawn(respawnPoint);
|
||||
}
|
||||
|
||||
public void respawn(Vector3 respawnPoint){
|
||||
dead=false;
|
||||
trailMgr.trail.emitting =false;
|
||||
public void respawn(Vector3 respawnPoint)
|
||||
{
|
||||
dead = false;
|
||||
trailMgr.trail.emitting = false;
|
||||
trailMgr.trail.Clear();
|
||||
RpcRespawn(respawnPoint);
|
||||
transform.position = respawnPoint;
|
||||
trailMgr.trail.emitting=true;
|
||||
trailMgr.trail.emitting = true;
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
public void RpcRespawn(Vector3 respawnPoint){
|
||||
|
||||
GetComponent<NetworkTrail>().enableValidation=false;
|
||||
public void RpcRespawn(Vector3 respawnPoint)
|
||||
{
|
||||
|
||||
GetComponent<NetworkTrail>().enableValidation = false;
|
||||
trailMgr.trail.Clear();
|
||||
trailMgr.positions = new Vector3[0];
|
||||
trailMgr.trail.emitting = false;
|
||||
transform.position = respawnPoint;
|
||||
trailMgr.trail.emitting=true;
|
||||
GetComponent<NetworkTrail>().enableValidation=true;
|
||||
trailMgr.trail.emitting = true;
|
||||
GetComponent<NetworkTrail>().enableValidation = true;
|
||||
gameObject.SetActive(true);
|
||||
|
||||
if(isLocalPlayer){
|
||||
if (isLocalPlayer)
|
||||
{
|
||||
SceneData.holder.deadScreen.SetActive(false);
|
||||
ResetStats();
|
||||
}
|
||||
}
|
||||
[Command]
|
||||
public void CmdWonRanked(){
|
||||
WonRanked();
|
||||
}
|
||||
|
||||
[Command]
|
||||
public void CmdLostRanked(){
|
||||
LostRanked();
|
||||
}
|
||||
public void WonRanked()
|
||||
{
|
||||
if (!isServer)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RpcWonRanked();
|
||||
Die("server");
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
void RpcWonRanked()
|
||||
{
|
||||
if (isLocalPlayer)
|
||||
{
|
||||
DBmanager.SetMetal(DBmanager.Metal+500);
|
||||
MinigameManager.instance.rankedSummary.ShowWin();
|
||||
//Add trophies
|
||||
DBmanager.SetTrophies(DBmanager.Trophies + 30);
|
||||
}
|
||||
}
|
||||
|
||||
public void LostRanked()
|
||||
{
|
||||
if (!isServer)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
RpcLostRanked();
|
||||
Die("server");
|
||||
}
|
||||
|
||||
void RpcLostRanked()
|
||||
{
|
||||
if (isLocalPlayer)
|
||||
{
|
||||
DBmanager.SetMetal(DBmanager.Metal+250);
|
||||
|
||||
MinigameManager.instance.rankedSummary.ShowLoss();
|
||||
DBmanager.SetTrophies(Mathf.Clamp(DBmanager.Trophies - 15, 0, int.MaxValue));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -19,6 +19,11 @@ public class RegionManager : MonoBehaviour
|
||||
UpdateSelectedRegion();
|
||||
|
||||
foreach(RegionServerData server in servers){
|
||||
if(PlayerPrefs.HasKey("regionOverride")){
|
||||
if(PlayerPrefs.GetString("regionOverride") == server.name){
|
||||
selectedServer = server;
|
||||
}
|
||||
}
|
||||
server.btn_select.onClick.AddListener(()=>{SetRegionOverride(server.name);});
|
||||
}
|
||||
btn_auto.onClick.AddListener(()=>{ SetRegionOverride(""); });
|
||||
|
||||
8
Assets/Game/Scripts/Shop.meta
Normal file
8
Assets/Game/Scripts/Shop.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f3f4943072bf1ac4d8c69666654fc1f4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
84
Assets/Game/Scripts/Shop/ChestButton.cs
Normal file
84
Assets/Game/Scripts/Shop/ChestButton.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
public class ChestButton : MonoBehaviour
|
||||
{
|
||||
public bool IsSpecial = false;
|
||||
public bool readFromTexts;
|
||||
public TMP_Text txtPrice;
|
||||
public TMP_Text txtChestName;
|
||||
public string ChestName => txtChestName.text;
|
||||
public int Price;
|
||||
public float minLuck = 0;
|
||||
public float maxLuck = 100;
|
||||
public Button btnInfo;
|
||||
[TextArea]
|
||||
public string infoTxt;
|
||||
|
||||
void Start()
|
||||
{
|
||||
btnInfo.onClick.AddListener(OnClickedInfo);
|
||||
|
||||
if(!IsSpecial)GetComponent<Button>().onClick.AddListener(OnClick);
|
||||
}
|
||||
|
||||
void OnClickedInfo()
|
||||
{
|
||||
MessageDialog.instance.ShowDialog(ChestName, $"This chest will drop following items.\n\n{getItemsProbability()}");
|
||||
}
|
||||
|
||||
void OnClick(){
|
||||
if(DBmanager.Gems < Price){
|
||||
MessageDialog.instance.ShowDialog("Failed","Insufficient Gems to complete the Purchase!");
|
||||
return;
|
||||
}
|
||||
|
||||
DBmanager.SetGems(DBmanager.Gems - Price);
|
||||
ChestOpener.instance.OpenChest((int)minLuck, (int)maxLuck);
|
||||
}
|
||||
|
||||
public string getItemsProbability()
|
||||
{
|
||||
string items = "Gold";
|
||||
|
||||
if (maxLuck > 50)
|
||||
{
|
||||
float probability = ((maxLuck - 50f) / (maxLuck - minLuck)) * 100f;
|
||||
items += $"\nGems : {probability.ToString("n1")}%";
|
||||
}
|
||||
|
||||
if (maxLuck > 70)
|
||||
{
|
||||
//some skins
|
||||
float probability = ((maxLuck - 70f) / (maxLuck - minLuck)) * 100f;
|
||||
items += $"\nCommon Skin : {probability.ToString("n1")}%";
|
||||
}
|
||||
if (maxLuck > 85)
|
||||
{
|
||||
float probability = ((maxLuck - 85f) / (maxLuck - minLuck)) * 100f;
|
||||
items += $"\nRare Skin : {probability.ToString("n1")}%";
|
||||
}
|
||||
if (maxLuck > 95)
|
||||
{
|
||||
float probability = ((maxLuck - 95f) / (maxLuck - minLuck)) * 100f;
|
||||
items += $"\nLegendary Skin : {probability.ToString("n1")}%";
|
||||
}
|
||||
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
void OnValidate()
|
||||
{
|
||||
infoTxt = getItemsProbability();
|
||||
|
||||
if (!readFromTexts) { return; }
|
||||
|
||||
if (txtPrice != null)
|
||||
{
|
||||
Price = int.Parse(txtPrice.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Game/Scripts/Shop/ChestButton.cs.meta
Normal file
11
Assets/Game/Scripts/Shop/ChestButton.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3a00d06b92d7a4dd78fab8529a589430
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
34
Assets/Game/Scripts/Shop/GoldPackButton.cs
Normal file
34
Assets/Game/Scripts/Shop/GoldPackButton.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class GoldPackButton : MonoBehaviour
|
||||
{
|
||||
public bool autoReadFromText = true;
|
||||
public TMP_Text txtAmount;
|
||||
public TMP_Text txtPrice;
|
||||
public int Amount;
|
||||
public int Price;
|
||||
void Start()
|
||||
{
|
||||
GetComponent<Button>().onClick.AddListener(()=>{GameManager.instance.BuyGold(this);});
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void OnValidate() {
|
||||
if(!autoReadFromText){return;}
|
||||
if(txtAmount!=null){
|
||||
Amount = int.Parse(txtAmount.text.Replace(",",""));
|
||||
}
|
||||
if(txtPrice!=null){
|
||||
Price = int.Parse(txtPrice.text.Replace(",",""));
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Game/Scripts/Shop/GoldPackButton.cs.meta
Normal file
11
Assets/Game/Scripts/Shop/GoldPackButton.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5cf2108220cbbf8449f5acdb4be74f69
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
90
Assets/Game/Scripts/Shop/SpecialChest.cs
Normal file
90
Assets/Game/Scripts/Shop/SpecialChest.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using UnityEngine.UI;
|
||||
public class SpecialChest : MonoBehaviour
|
||||
{
|
||||
public int quantity=3;
|
||||
public DateTime lastCollectedTime;
|
||||
public ChestButton chestButton;
|
||||
public TMP_Text txtTimeLeft;
|
||||
public Button button;
|
||||
void Start(){
|
||||
button.onClick.AddListener(OnClicked);
|
||||
StartCoroutine(LoadData());
|
||||
}
|
||||
DateTime specialChestExpire=DateTime.MinValue;
|
||||
float t =30;
|
||||
IEnumerator LoadData(){
|
||||
WWW storeData = new WWW(DBmanager.phpRoot + "get_store_data.php");
|
||||
yield return storeData;
|
||||
|
||||
Debug.Log(storeData.text + " => " + DBmanager.LastCollectedDailyChest);
|
||||
specialChestExpire= DateTime.Parse(storeData.text);
|
||||
}
|
||||
void Update()
|
||||
{
|
||||
|
||||
if(t < 30){
|
||||
t +=Time.deltaTime;
|
||||
}else{
|
||||
t=0;
|
||||
UpdateStat();
|
||||
}
|
||||
|
||||
// if((DateTime.Now - DBmanager.LastCollectedDailyChest).TotalHours > 24){
|
||||
// button.interactable = true;
|
||||
// txtTimeLeft.text = "Ready";
|
||||
// }else{
|
||||
// button.interactable = false;
|
||||
// // txtTimeLeft.text = SceneData.SecondsToText((DateTime.Now - DBmanager.LastCollectedDailyChest).Seconds);
|
||||
// txtTimeLeft.text = MinutesToText((24*60)-(DateTime.Now - DBmanager.LastCollectedDailyChest).TotalMinutes);
|
||||
// // Debug.Log(DateTime.Now + "-" + DBmanager.LastCollectedDailyChest + " = " + (DateTime.Now - DBmanager.LastCollectedDailyChest));
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
public async void UpdateStat(){
|
||||
if(specialChestExpire == DateTime.MinValue){ chestButton.gameObject.SetActive(false);}
|
||||
DateTime nowTime = await DBmanager.GetNetworkTime();
|
||||
if(specialChestExpire < nowTime){
|
||||
chestButton.gameObject.SetActive(false);
|
||||
}else if(DBmanager.LastCollectedDailyChest == specialChestExpire){
|
||||
chestButton.gameObject.SetActive(false);
|
||||
}else{
|
||||
//Set the timer
|
||||
chestButton.gameObject.SetActive(true);
|
||||
txtTimeLeft.text = MinutesToText(specialChestExpire.Subtract(nowTime).TotalMinutes);
|
||||
}
|
||||
}
|
||||
|
||||
void OnClicked(){
|
||||
// gameObject.SetActive(false);
|
||||
if(DBmanager.Gems < chestButton.Price){
|
||||
MessageDialog.instance.ShowDialog("Failed","Insufficient Gems to complete the Purchase!");
|
||||
return;
|
||||
}
|
||||
DBmanager.SetGems(DBmanager.Gems - chestButton.Price);
|
||||
DBmanager.SetLastCollectedDailyChest(specialChestExpire.ToString("yyyy-MM-dd HH:mm:ss"));
|
||||
UpdateStat();
|
||||
StartCoroutine(StartChestList());
|
||||
}
|
||||
|
||||
IEnumerator StartChestList(){
|
||||
for(int i=0; i< quantity; i++){
|
||||
ChestOpener.instance.OpenChest((int)chestButton.minLuck, (int)chestButton.maxLuck);
|
||||
while(ChestOpener.instance.active){
|
||||
yield return new WaitForEndOfFrame();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static string MinutesToText(double minutes){
|
||||
int mins = ((int)(minutes % 60));
|
||||
int hours = Mathf.FloorToInt((float)(minutes/60));
|
||||
return hours + "h "+ mins.ToString("0") + "m";
|
||||
}
|
||||
}
|
||||
11
Assets/Game/Scripts/Shop/SpecialChest.cs.meta
Normal file
11
Assets/Game/Scripts/Shop/SpecialChest.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b15c5b3b610c912db8c1355f50b9f3d8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -107,7 +107,7 @@ public class XpPass : MonoBehaviour
|
||||
DBmanager.SetGems(DBmanager.Gems + reward.amount);
|
||||
}else if(reward.rewardType == XpRewardType.Chest){
|
||||
// StartCoroutine(destroyTimer(Instantiate(chestPrefab, chestSpawnParent),5));
|
||||
ChestOpener.instance.OpenChest();
|
||||
ChestOpener.instance.OpenChest(0,100);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user