bots added
This commit is contained in:
@@ -17,7 +17,7 @@ public class AccountSettings : MonoBehaviour
|
||||
public TMP_InputField usernameInput;
|
||||
public TMP_InputField passwordInput;
|
||||
public Button btn_link_register;
|
||||
|
||||
public GameObject loadingScreen;
|
||||
void Awake(){
|
||||
btn_link.onClick.AddListener(OnLink);
|
||||
btn_link_register.onClick.AddListener(OnLinkReg);
|
||||
@@ -62,10 +62,16 @@ public class AccountSettings : MonoBehaviour
|
||||
}
|
||||
|
||||
string results= await DBmanager.LinkAccount(usernameInput.text, passwordInput.text);
|
||||
HandleResult(results,usernameInput.text, passwordInput.text);
|
||||
}
|
||||
|
||||
public void GoogleLogin(){
|
||||
GoogleLoginManager googleLogin= GetComponent<GoogleLoginManager>();
|
||||
googleLogin.SignInWithGoogle();
|
||||
}
|
||||
|
||||
void HandleResult(string results,string username,string password){
|
||||
if(results == "0"){
|
||||
PlayerPrefs.SetString("username", usernameInput.text);
|
||||
PlayerPrefs.SetString("password", passwordInput.text);
|
||||
PlayerPrefs.Save();
|
||||
MessageDialog.instance.ShowQuestion("Link Successful!", "Your Account has been successfully linked.\n\nThe game needs to be restarted.\nPress Yes to restart",OnYes:()=>{SceneManager.LoadScene("Login");}, OnNo:()=>{}, onlyYes:true);
|
||||
}else{
|
||||
int level = -1;
|
||||
@@ -83,6 +89,14 @@ public class AccountSettings : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public async void GoogleSignComplete(){
|
||||
loadingScreen.SetActive(true);
|
||||
|
||||
string results= await DBmanager.LinkAccount(GoogleLoginManager.loggedEmail+"#0",GoogleLoginManager.loggedEmail+"#0");
|
||||
HandleResult(results,GoogleLoginManager.loggedEmail+"#0",GoogleLoginManager.loggedEmail+"#0");
|
||||
loadingScreen.SetActive(false);
|
||||
}
|
||||
|
||||
public async void OnMerge(){
|
||||
PlayerPrefs.SetString("username", usernameInput.text);
|
||||
PlayerPrefs.SetString("password", passwordInput.text);
|
||||
|
||||
@@ -7,12 +7,6 @@ public class CameraFrameRate : MonoBehaviour
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
Application.targetFrameRate = 60;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
// Application.targetFrameRate = 60;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ using UnityEngine.Events;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine.Monetization;
|
||||
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
@@ -57,7 +56,7 @@ public class GameManager : MonoBehaviour
|
||||
{
|
||||
foreach (TMP_Text usernameTxt in usernameTxts)
|
||||
{
|
||||
usernameTxt.text = DBmanager.username;
|
||||
usernameTxt.text = DBmanager.displayName;
|
||||
}
|
||||
RefreshData();
|
||||
}
|
||||
|
||||
88
Assets/Game/Scripts/GoogleLoginManager.cs
Normal file
88
Assets/Game/Scripts/GoogleLoginManager.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Firebase;
|
||||
using Firebase.Auth;
|
||||
using Google;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class GoogleLoginManager : MonoBehaviour {
|
||||
public string webClientId = "871331112347-3qpmns59teudhm5qugl4kiau6eo1efm2.apps.googleusercontent.com";
|
||||
private FirebaseAuth auth;
|
||||
private GoogleSignInConfiguration config;
|
||||
public NewLoginManager loginManager;
|
||||
public AccountSettings accountSettings;
|
||||
|
||||
void Awake(){
|
||||
config = new GoogleSignInConfiguration{WebClientId=webClientId, RequestEmail=true, RequestIdToken=true};
|
||||
CheckFirebaseDependencies();
|
||||
}
|
||||
|
||||
void CheckFirebaseDependencies(){
|
||||
FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task=>{
|
||||
if(task.IsCompleted){
|
||||
if(task.Result == DependencyStatus.Available){
|
||||
auth = FirebaseAuth.DefaultInstance;
|
||||
}else{
|
||||
Debug.Log("googlesign:Firebase Deps missing, " + task.Result.ToString());
|
||||
}
|
||||
}else{
|
||||
Debug.Log("googlesign:Dependency test not completed " + task.Exception.Message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void SignInWithGoogle(){OnSignIn();}
|
||||
public void SignOutFromGoogle(){OnSignOut();}
|
||||
|
||||
private void OnSignIn(){
|
||||
GoogleSignIn.Configuration = config;
|
||||
GoogleSignIn.Configuration.UseGameSignIn = false;
|
||||
GoogleSignIn.Configuration.RequestIdToken = true;
|
||||
Debug.Log("googlesign:Call Signin");
|
||||
|
||||
GoogleSignIn.DefaultInstance.SignIn().ContinueWith(AuthDone);
|
||||
}
|
||||
private void OnSignOut(){
|
||||
GoogleSignIn.DefaultInstance.SignOut();
|
||||
}
|
||||
public void OnDisconnect(){
|
||||
GoogleSignIn.DefaultInstance.Disconnect();
|
||||
}
|
||||
|
||||
public static string loggedEmail;
|
||||
void AuthDone(Task<GoogleSignInUser> task){
|
||||
if(task.IsFaulted){
|
||||
using(IEnumerator<Exception> enumerator = task.Exception.InnerExceptions.GetEnumerator()){
|
||||
if(enumerator.MoveNext()){
|
||||
GoogleSignIn.SignInException error = (GoogleSignIn.SignInException)enumerator.Current;
|
||||
Debug.Log("googlesign:Got error: " + error.Status + " " + error.Message);
|
||||
}else{
|
||||
Debug.Log("googlesign:Unexpected Exception : " + task.Exception);
|
||||
}
|
||||
}
|
||||
}else if(task.IsCanceled){
|
||||
Debug.Log("googlesign:User aborted");
|
||||
}else{
|
||||
Debug.Log("googlesign:User logged");
|
||||
Debug.Log($"user={task.Result.DisplayName}, email={task.Result.Email}");
|
||||
loggedEmail = task.Result.Email;
|
||||
StartCoroutine(OnSignDone(task.Result.DisplayName));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator OnSignDone(string displayName){
|
||||
PlayerPrefs.SetString("displayname", displayName);
|
||||
PlayerPrefs.Save();
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
|
||||
if(loginManager != null){loginManager.OnGoogleSignComplete();}
|
||||
|
||||
if(accountSettings != null){
|
||||
accountSettings.GoogleSignComplete();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Game/Scripts/GoogleLoginManager.cs.meta
Normal file
11
Assets/Game/Scripts/GoogleLoginManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8b3ee20f1f11fbc4ab7e3f45169de9ae
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -6,7 +6,7 @@ using UnityEngine.SceneManagement;
|
||||
|
||||
public class MaintainceChecker : MonoBehaviour
|
||||
{
|
||||
public static int version = 32;
|
||||
public static int version = 44;
|
||||
public static MaintainceChecker instance;
|
||||
public int checkInterval = 30;
|
||||
float t;
|
||||
@@ -51,7 +51,7 @@ public class MaintainceChecker : MonoBehaviour
|
||||
}
|
||||
|
||||
if(_item[0]=="version"){
|
||||
if(int.Parse(_item[1]) != version){
|
||||
if(int.Parse(_item[1]) > version){
|
||||
LoadingScreen.instance.LoadLevel("Update");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,16 +70,14 @@ public class AutoConnect : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
if(isClient){
|
||||
Application.targetFrameRate = 60;
|
||||
}
|
||||
|
||||
}
|
||||
float t;
|
||||
void Update(){
|
||||
if(isRanked && !isClient){
|
||||
//timer
|
||||
t += Time.deltaTime;
|
||||
if(t > 30 && FindObjectsOfType<SpaceshipController>().Length ==0){
|
||||
if(t > 120 && FindObjectsOfType<SpaceshipController>().Length ==0){
|
||||
//No players joined, or they left, gotta close my self
|
||||
t=0;
|
||||
StartCoroutine(CloseRoom());
|
||||
|
||||
8
Assets/Game/Scripts/Minigame/Bot.meta
Normal file
8
Assets/Game/Scripts/Minigame/Bot.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f522e3acf074f94397f9617e03a3459
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
267
Assets/Game/Scripts/Minigame/Bot/SpaceshipNetworkBot.cs
Normal file
267
Assets/Game/Scripts/Minigame/Bot/SpaceshipNetworkBot.cs
Normal file
@@ -0,0 +1,267 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Mirror;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
public class SpaceshipNetworkBot : NetworkBehaviour
|
||||
{
|
||||
|
||||
public string[] Names;
|
||||
[SyncVar (hook = nameof(OnPnameChanged))]
|
||||
public string pname;
|
||||
public Text nameTxt;
|
||||
public float movingSpeed;
|
||||
public Transform curTarget;
|
||||
public TrailMgrBot trailMgr;
|
||||
public GameObject DeathEffect;
|
||||
public LayerMask pickupsLayer;
|
||||
[SyncVar]
|
||||
public int Scores = 0;
|
||||
public float up;
|
||||
|
||||
void OnPnameChanged(string oldName, string newName){
|
||||
nameTxt.text = newName;
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
nameTxt.text = pname;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate()
|
||||
{
|
||||
if(!isServer){return;}
|
||||
HandleMovement();
|
||||
CheckForPickups();
|
||||
ChangeName();
|
||||
}
|
||||
|
||||
float nameChangeTimer = 1000;
|
||||
float nameChangeTime = 0;
|
||||
void ChangeName(){
|
||||
nameChangeTimer+=Time.deltaTime;
|
||||
|
||||
if(nameChangeTimer > nameChangeTime){
|
||||
nameChangeTimer = 0;
|
||||
nameChangeTime = Random.Range(1000, 2000);
|
||||
pname = BotsHiveMind.LeaseName(pname.Length > 0 ? pname : null);
|
||||
nameTxt.text = pname;
|
||||
}
|
||||
}
|
||||
|
||||
void CheckForPickups(){
|
||||
Collider2D[] hits = Physics2D.OverlapCircleAll(transform.position, 3, pickupsLayer);
|
||||
foreach(Collider2D hit in hits){
|
||||
if(hit!=null ){
|
||||
// Debug.Log(hit.name);
|
||||
PickupItem pickupItem = hit.GetComponent<PickupItem>();
|
||||
if(pickupItem !=null && pickupItem.active){
|
||||
pickupItem.active=false;
|
||||
pickupItem.Deactivate(transform);
|
||||
CollectPickup(pickupItem.type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Update(){
|
||||
nameTxt.rectTransform.rotation = Quaternion.Euler(Vector3.zero);
|
||||
}
|
||||
float swayTimer = 0;
|
||||
void HandleMovement(){
|
||||
CheckAndUpdateTarget();
|
||||
|
||||
Vector3 targ = curTarget.position;
|
||||
if(isHunting){
|
||||
targ+=(curTarget.up * 8);
|
||||
if(swayTimer < 10){
|
||||
targ+=(curTarget.right * 8);
|
||||
}else{
|
||||
targ-=(curTarget.right * 8);
|
||||
}
|
||||
swayTimer += Time.deltaTime;
|
||||
if(swayTimer > 20){
|
||||
swayTimer=0;
|
||||
}
|
||||
}
|
||||
targ.z = 0f;
|
||||
|
||||
Vector3 objectPos = transform.position;
|
||||
targ.x = targ.x - objectPos.x;
|
||||
targ.y = targ.y - objectPos.y;
|
||||
|
||||
float angle = Mathf.Atan2(targ.y, targ.x) * Mathf.Rad2Deg + up;
|
||||
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(new Vector3(0, 0, angle)), 0.05f);
|
||||
transform.position += transform.up * movingSpeed;
|
||||
}
|
||||
float t2 =0;
|
||||
bool isHunting=false;
|
||||
void CheckAndUpdateTarget(){
|
||||
bool skip = false;
|
||||
if(curTarget != null){
|
||||
if(curTarget.gameObject.activeSelf){
|
||||
if(t2 < 5){
|
||||
t2+=Time.deltaTime;
|
||||
}else{
|
||||
if(Vector3.Distance(transform.position, curTarget.position) < 7){
|
||||
skip = true;
|
||||
}
|
||||
t2=0;
|
||||
}
|
||||
if(!skip){return;}
|
||||
}
|
||||
}
|
||||
SpaceshipController[] players = FindObjectsOfType<SpaceshipController>();
|
||||
foreach(SpaceshipController player in players){
|
||||
if(BotsHiveMind.LeasePlayer(player, this)){
|
||||
curTarget = player.transform;
|
||||
isHunting=true;
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
bool foundItem = false;
|
||||
while(!foundItem){
|
||||
List<PickupItem> randomSet= MinigameManager.instance.pickupItems[Random.Range(1,MinigameManager.instance.pickupItems.Length)].Active;
|
||||
PickupItem randomPickup = randomSet[Random.Range(0,randomSet.Count)];
|
||||
if(Vector3.Distance(Vector3.zero, randomPickup.transform.position) < MinigameManager.instance.mapRadius){
|
||||
curTarget = randomPickup.transform;
|
||||
foundItem=true;
|
||||
isHunting=false;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void TrailCollided(Collider2D hit){
|
||||
if(!isServer){return;}
|
||||
SpaceshipController deadPlayer = hit.GetComponent<SpaceshipController>();
|
||||
// Debug.Log("got hit by player? : " + (deadPlayer != null));
|
||||
if (deadPlayer != null && !deadPlayer.dead && (NetworkTime.time - deadPlayer.startedTime) > 5)
|
||||
{ // <-- okay we killed someone | KILLCODE
|
||||
// deadPlayer.RpcShowDeathEffect(deadPlayer.transform.position);
|
||||
deadPlayer.Die(pname);
|
||||
if(BotsHiveMind.Leased.ContainsKey(deadPlayer)){
|
||||
if(BotsHiveMind.Leased[deadPlayer] == this){
|
||||
curTarget=null;
|
||||
isHunting=false;
|
||||
}
|
||||
}
|
||||
Debug.Log($"{pname} killed {deadPlayer.pname}");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
SpaceshipNetworkBot deadBot = hit.GetComponent<SpaceshipNetworkBot>();
|
||||
// Debug.Log("got hit by bot? : " + (deadPlayer != deadBot));
|
||||
|
||||
if(deadBot != null){
|
||||
deadBot.Die();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
[SyncVar (hook = nameof(OnTrailTimeChanged))]
|
||||
private float m_trailTime;
|
||||
public float maxTrailTime;
|
||||
public float minTrailTime;
|
||||
public float trailIncrementRate = 0.1f;
|
||||
public float trailTime{get{return m_trailTime;} set{
|
||||
m_trailTime = Mathf.Clamp(value, minTrailTime,maxTrailTime);
|
||||
trailMgr.trail.time = m_trailTime;
|
||||
}}
|
||||
|
||||
void OnTrailTimeChanged(float oldTime, float newTime){
|
||||
trailMgr.trail.time = newTime;
|
||||
}
|
||||
|
||||
|
||||
public void CollectPickup(PickupItem.PickupType type){
|
||||
trailTime += trailIncrementRate;
|
||||
if(type.ToString().ToLower().Contains("moon")){
|
||||
Scores+=2;
|
||||
|
||||
}else{
|
||||
Scores++;
|
||||
}
|
||||
}
|
||||
|
||||
public void Die(){
|
||||
int leftoverAmount = (int)((float)Scores/4f);
|
||||
Debug.Log("Bot " + pname + " Left " + leftoverAmount + " Stars");
|
||||
MinigameManager.instance.SpawnLeftoverPickups(transform.position, leftoverAmount);
|
||||
|
||||
RpcDie(transform.position);
|
||||
Scores = 0;
|
||||
trailTime = 0;
|
||||
trailMgr.trail.time=0;
|
||||
transform.position = MinigameManager.getRandomPointInCirlce(Vector3.zero, 150);
|
||||
StartCoroutine(die());
|
||||
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
void RpcDie(Vector3 position){
|
||||
EffectPool.Spawn(DeathEffect, position);
|
||||
trailMgr.trail.time=0;
|
||||
trailMgr.trail.enabled=false;
|
||||
StartCoroutine(die());
|
||||
}
|
||||
|
||||
IEnumerator die(){
|
||||
yield return new WaitForSeconds(0.5f);
|
||||
trailTime = 0;
|
||||
trailMgr.trail.enabled =true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static class BotsHiveMind{
|
||||
private static string[] Names= {"Andrew Joe", "Dragon Fire", "Doom Killer", "Ice Killer", "Drake Ronin", "Turbo Skull", "Decay", "Fester Flack", "El Diablo", "Rubble r", "Hank 95", "Zer0", "War-lord",
|
||||
"Wraith", "Knuckles U", "iKill U", "iSteal", "Bull3t", "Tito 97", "Jurgen", "Tobias 37", "Mia M", "Luca 43", "Aditya 101", "Abu B", "Ahmad Cipta", "Harta Ismaya", "Yuda_333"};
|
||||
private static List<string> ActiveNames;
|
||||
private static List<string> PooledNames;
|
||||
|
||||
public static string LeaseName(string borrowedName = null){
|
||||
if(ActiveNames == null) { ActiveNames = new List<string>();}
|
||||
if(PooledNames == null){ PooledNames = new List<string>(Names);}
|
||||
|
||||
//Return borrowed name to the list
|
||||
if(borrowedName!=null){
|
||||
ActiveNames.Remove(borrowedName);
|
||||
PooledNames.Add(borrowedName);
|
||||
}
|
||||
|
||||
//Borrow a new name
|
||||
string chosenName = PooledNames[Random.Range(0,PooledNames.Count)];
|
||||
PooledNames.Remove(chosenName);
|
||||
ActiveNames.Add(chosenName);
|
||||
|
||||
return chosenName;
|
||||
}
|
||||
private static Dictionary<SpaceshipController, SpaceshipNetworkBot> leased = new Dictionary<SpaceshipController, SpaceshipNetworkBot>();
|
||||
|
||||
public static Dictionary<SpaceshipController, SpaceshipNetworkBot> Leased {
|
||||
get{
|
||||
if(leased == null){ leased = new Dictionary<SpaceshipController, SpaceshipNetworkBot>();}
|
||||
|
||||
return leased;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool LeasePlayer(SpaceshipController player, SpaceshipNetworkBot bot){
|
||||
if(leased.ContainsKey(player)){//Player's already leased
|
||||
if(leased[player].curTarget == player.transform){
|
||||
return false;
|
||||
}else{
|
||||
leased.Remove(player);
|
||||
}
|
||||
}
|
||||
|
||||
leased.Add(player,bot);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
11
Assets/Game/Scripts/Minigame/Bot/SpaceshipNetworkBot.cs.meta
Normal file
11
Assets/Game/Scripts/Minigame/Bot/SpaceshipNetworkBot.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a3f87b57754b9a74195eedba04d4f2cb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
57
Assets/Game/Scripts/Minigame/Bot/TrailMgrBot.cs
Normal file
57
Assets/Game/Scripts/Minigame/Bot/TrailMgrBot.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class TrailMgrBot : MonoBehaviour
|
||||
{
|
||||
public SpaceshipNetworkBot controller;
|
||||
public TrailRenderer trail;
|
||||
|
||||
public Vector3[] positions;
|
||||
public Transform trailPoolParent;
|
||||
public GameObject trailColliderObj;
|
||||
public List<GameObject> trailsPool;
|
||||
|
||||
void Start(){
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
// #if PLATFORM_ANDROID
|
||||
if(AutoConnect.instance.isClient){return;}
|
||||
positions = new Vector3[trail.positionCount];
|
||||
int length = trail.GetPositions(positions);
|
||||
if(length > trailsPool.Count){
|
||||
//must create new trails
|
||||
int missingCount = length - trailsPool.Count;
|
||||
for(int i =0; i < missingCount; i++){
|
||||
GameObject newTrail = Instantiate(trailColliderObj, trailPoolParent);
|
||||
// Debug.Log("Spawned new trail obj " + newTrail.name);
|
||||
newTrail.GetComponent<TrailCollider>().trailMgrBot = this;
|
||||
trailsPool.Add(newTrail);
|
||||
}
|
||||
}
|
||||
for(int i =0; i < trailsPool.Count; i++){
|
||||
if(i < length){
|
||||
trailsPool[i].SetActive(true);
|
||||
trailsPool[i].transform.position = positions[i];
|
||||
}else{
|
||||
trailsPool[i].SetActive(false);
|
||||
}
|
||||
}
|
||||
// #endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void OnColliderHit(Collider2D hit){
|
||||
controller.TrailCollided(hit);
|
||||
// Debug.Log("Got hit:" +hit.name);
|
||||
}
|
||||
|
||||
void OnValidate(){
|
||||
if(controller==null){
|
||||
controller = GetComponent<SpaceshipNetworkBot>();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Game/Scripts/Minigame/Bot/TrailMgrBot.cs.meta
Normal file
11
Assets/Game/Scripts/Minigame/Bot/TrailMgrBot.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e9c22b4e5e634f4d80b41390492231e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -16,6 +16,8 @@ public class Leaderboard : MonoBehaviour
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
// if(AutoConnect.instance != null &&!AutoConnect.instance.isClient){return;}
|
||||
if (t < updateInterval)
|
||||
{
|
||||
t += Time.deltaTime;
|
||||
@@ -29,32 +31,43 @@ public class Leaderboard : MonoBehaviour
|
||||
|
||||
public void RefreshLeaderboard()
|
||||
{
|
||||
// Debug.Log("Refrsh leaderboard");
|
||||
SpaceshipController[] players = FindObjectsOfType<SpaceshipController>();
|
||||
SpaceshipNetworkBot[] bots = FindObjectsOfType<SpaceshipNetworkBot>();
|
||||
List<LeaderboardEntry> leaderboard = new List<LeaderboardEntry>();
|
||||
foreach(SpaceshipController player in players){
|
||||
leaderboard.Add(new LeaderboardEntry(player.pname,(isRanked) ? player.moonsCollected : player.Scores));
|
||||
}
|
||||
if(!isRanked){
|
||||
foreach(SpaceshipNetworkBot bot in bots){
|
||||
leaderboard.Add(new LeaderboardEntry(bot.pname, bot.Scores));
|
||||
}
|
||||
}
|
||||
//Simple bubble sort to sort players by score
|
||||
SpaceshipController temp;
|
||||
for (int j = 0; j <= players.Length - 2; j++)
|
||||
LeaderboardEntry temp;
|
||||
for (int j = 0; j <= leaderboard.Count - 2; j++)
|
||||
{
|
||||
for (int i = 0; i <= players.Length - 2; i++)
|
||||
for (int i = 0; i <= leaderboard.Count - 2; i++)
|
||||
{
|
||||
if ( (!isRanked ? players[i].moonsCollected : players[i].Scores) > (!isRanked? players[i+1].moonsCollected : players[i + 1].Scores))
|
||||
if ( leaderboard[i].Score > leaderboard[i+1].Score)
|
||||
{
|
||||
temp = players[i + 1];
|
||||
players[i + 1] = players[i];
|
||||
players[i] = temp;
|
||||
temp = leaderboard[i + 1];
|
||||
leaderboard[i + 1] = leaderboard[i];
|
||||
leaderboard[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Populate leaderboard
|
||||
for(int i =0; i < leaderboardItems.Length; i++){
|
||||
if(i < players.Length){
|
||||
SpaceshipController thisPlayer = players[players.Length-i-1];
|
||||
if(i < leaderboard.Count){
|
||||
LeaderboardEntry thisEntry = leaderboard[leaderboard.Count-i-1];
|
||||
leaderboardItems[i].gameObject.SetActive(true);
|
||||
leaderboardItems[i].text = (i+1) + ". " +thisPlayer.pname;
|
||||
leaderboardItems[i].text = (i+1) + ". " +thisEntry.Name;
|
||||
if(!isRanked){
|
||||
leaderboardItems[i].transform.GetChild(0).GetComponent<Text>().text = thisPlayer.Scores.ToString();
|
||||
leaderboardItems[i].transform.GetChild(0).GetComponent<Text>().text = thisEntry.Score.ToString();
|
||||
}else{
|
||||
leaderboardItems[i].transform.GetChild(0).GetComponent<Text>().text = (((float)Mathf.Clamp(thisPlayer.moonsCollected,0,30)/ 30f)*100f).ToString("n1") + " %";
|
||||
leaderboardItems[i].transform.GetChild(0).GetComponent<Text>().text = (((float)Mathf.Clamp(thisEntry.Score,0,30)/ 30f)*100f).ToString("n1") + " %";
|
||||
}
|
||||
}else{
|
||||
leaderboardItems[i].gameObject.SetActive(false);
|
||||
@@ -62,3 +75,13 @@ public class Leaderboard : MonoBehaviour
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class LeaderboardEntry{
|
||||
public int Score;
|
||||
public string Name;
|
||||
|
||||
public LeaderboardEntry(string _name, int _score){
|
||||
Name = _name;
|
||||
Score= _score;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ public class MatchMaker : MonoBehaviour
|
||||
{
|
||||
public TMP_Text timerTxt;
|
||||
public Button btn_cancel;
|
||||
public TMP_Text playerCountTxt;
|
||||
float timer;
|
||||
void Start()
|
||||
{
|
||||
@@ -23,6 +24,7 @@ public class MatchMaker : MonoBehaviour
|
||||
AudioManager.instnace.SetMusic(2);
|
||||
|
||||
// StartCoroutine(StartMatchmaking());
|
||||
|
||||
}
|
||||
|
||||
private void OnClientConnected()
|
||||
@@ -32,8 +34,13 @@ public class MatchMaker : MonoBehaviour
|
||||
|
||||
// Update is called once per frame
|
||||
float t=0;
|
||||
float t2=100;
|
||||
float connectTimeout = 0;
|
||||
bool loadedScene;
|
||||
|
||||
int sgpPlayers;
|
||||
int euPlayers;
|
||||
int usPlayers;
|
||||
void Update()
|
||||
{
|
||||
timer+=Time.deltaTime;
|
||||
@@ -45,6 +52,38 @@ public class MatchMaker : MonoBehaviour
|
||||
t=0;
|
||||
StartCoroutine(FetchMatchmake());
|
||||
}
|
||||
|
||||
if(t2 < 5){
|
||||
t2+= Time.deltaTime;
|
||||
|
||||
}else{
|
||||
t2 = 0;
|
||||
StartCoroutine(FetchPlayerCount("SGP"));
|
||||
StartCoroutine(FetchPlayerCount("USA"));
|
||||
StartCoroutine(FetchPlayerCount("EU"));
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator FetchPlayerCount(string region){
|
||||
WWWForm form = new WWWForm();
|
||||
form.AddField("region", region);
|
||||
|
||||
WWW req = new WWW(DBmanager.phpRoot+"get_players_online.php", form);
|
||||
yield return req;
|
||||
|
||||
if(region == "SGP"){
|
||||
sgpPlayers = int.Parse(req.text);
|
||||
}else if(region == "USA"){
|
||||
usPlayers = int.Parse(req.text);
|
||||
}else if(region == "EU"){
|
||||
euPlayers = int.Parse(req.text);
|
||||
}
|
||||
|
||||
UpdatePlayerCount();
|
||||
}
|
||||
|
||||
void UpdatePlayerCount(){
|
||||
playerCountTxt.text = $"EU: {euPlayers}\nSGP: {sgpPlayers}\nUSA: {usPlayers}";
|
||||
}
|
||||
|
||||
IEnumerator FetchMatchmake(){
|
||||
|
||||
@@ -30,6 +30,9 @@ public class MinigameManager : NetworkBehaviour
|
||||
public float safeZoneShrinkTime = 30;
|
||||
float safeZoneShrinkSpeed;
|
||||
[SerializeField] private PickupSetting[] PickupItems;
|
||||
public PickupSetting[] pickupItems => PickupItems;
|
||||
public GameObject botPrefab;
|
||||
public List<SpaceshipNetworkBot> bots;
|
||||
// public GameObject starPrefab;
|
||||
// public int maxMoons, maxStars = 100;
|
||||
// public int maxTweps = 2;
|
||||
@@ -56,7 +59,7 @@ public class MinigameManager : NetworkBehaviour
|
||||
Vector2 defaultJoyPos;
|
||||
|
||||
public void SwitchUISides(){
|
||||
if(isRanked){
|
||||
if(false){
|
||||
if(ControlSettings.ControlIsOnRight){
|
||||
RectTransform canvasRect = joystick.root.GetComponent<RectTransform>();
|
||||
joystick.anchorMin = new Vector2(0f,0);
|
||||
@@ -111,6 +114,22 @@ public class MinigameManager : NetworkBehaviour
|
||||
|
||||
void Start(){
|
||||
AudioManager.instnace.SetCustomMusic(musicClips[Random.Range(0,musicClips.Length)]);
|
||||
|
||||
if(!isServer){
|
||||
Application.targetFrameRate = 60;
|
||||
}else{
|
||||
Application.targetFrameRate = 35;
|
||||
}
|
||||
|
||||
if(isServer && !isRanked){
|
||||
bots = new List<SpaceshipNetworkBot>();
|
||||
for(int i =0; i < 5; i++){
|
||||
GameObject newBot = Instantiate(botPrefab, getRandomPointInCirlce(Vector3.zero, 150), Quaternion.identity);
|
||||
bots.Add(newBot.GetComponent<SpaceshipNetworkBot>());
|
||||
newBot.GetComponent<SpaceshipNetworkBot>().pname = newBot.GetComponent<SpaceshipNetworkBot>().Names[i];
|
||||
NetworkServer.Spawn(newBot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
@@ -201,6 +220,24 @@ public class MinigameManager : NetworkBehaviour
|
||||
}
|
||||
|
||||
|
||||
public void EnemyForfeit(){
|
||||
SpaceshipController[] players = FindObjectsOfType<SpaceshipController>();
|
||||
if(players.Length == 1){
|
||||
if(isServer){
|
||||
winnerId = (int)netId;
|
||||
}else{
|
||||
CmdSetWinnerId(netId);
|
||||
}
|
||||
SpaceshipController localPlayer = SceneData.localPlayer.GetComponent<SpaceshipController>();
|
||||
localPlayer.CmdWonRanked();
|
||||
}
|
||||
}
|
||||
|
||||
[Command]
|
||||
void CmdSetWinnerId(uint id){
|
||||
winnerId = (int)id;
|
||||
}
|
||||
|
||||
void OnWinnerChanged(int oldVal, int newVal){
|
||||
if(newVal<= 0){return;}
|
||||
// if(!isLocalPlayer){return;}
|
||||
@@ -209,9 +246,12 @@ public class MinigameManager : NetworkBehaviour
|
||||
if(newVal == localPlayer.netId){
|
||||
//We won
|
||||
localPlayer.CmdWonRanked();
|
||||
localPlayer.WonRanked();
|
||||
|
||||
Debug.Log("Its Me!, I won!");
|
||||
}else{
|
||||
Debug.Log("Its not me, I lost!");
|
||||
localPlayer.LostRanked();
|
||||
localPlayer.CmdLostRanked();
|
||||
}
|
||||
}
|
||||
@@ -239,58 +279,61 @@ public class MinigameManager : NetworkBehaviour
|
||||
}
|
||||
|
||||
float twepTimer = 60;
|
||||
float spawnTimer = 100;
|
||||
void HandlePickupSpawn()
|
||||
{
|
||||
foreach(PickupSetting pickup in PickupItems){
|
||||
int spawnsNeeded = pickup.MaxAmount - pickup.Active.Count;
|
||||
if(spawnsNeeded > 0){
|
||||
SpawnPickups(pickup, spawnsNeeded);
|
||||
if(spawnTimer < 10){
|
||||
spawnTimer += Time.deltaTime;
|
||||
}else{
|
||||
spawnTimer=0;
|
||||
foreach(PickupSetting pickup in PickupItems){
|
||||
int spawnsNeeded = pickup.MaxAmount - pickup.Active.Count;
|
||||
if(spawnsNeeded > 0){
|
||||
SpawnPickups(pickup, spawnsNeeded);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SpawnLeftoverPickups(Vector3 position, int amount)
|
||||
{
|
||||
SpawnStars(amount, focusedPosition: position);
|
||||
SpawnStars(Mathf.Clamp(amount,0,100), focusedPosition: position);
|
||||
}
|
||||
|
||||
void SpawnPickups(PickupSetting pickup, int amount)
|
||||
{
|
||||
for (int i = 0; i < amount; i++)
|
||||
{
|
||||
if(pickup.Timer < pickup.SpawnInterval){
|
||||
pickup.Timer++;
|
||||
}else{
|
||||
Vector3 newPosition = getRandomPositionOnMap();
|
||||
if (pickup.Pooled.Count > 0)
|
||||
{ // <-- Got some in the pool, no need to spawn new
|
||||
PickupItem pickedStar = pickup.Pooled[0];
|
||||
pickedStar.Reposition(newPosition);
|
||||
Vector3 newPosition = getRandomPositionOnMap();
|
||||
// if (pickup.Pooled.Count > 0)
|
||||
if (false)
|
||||
{ // <-- Got some in the pool, no need to spawn new
|
||||
PickupItem pickedStar = pickup.Pooled[0];
|
||||
pickedStar.Reposition(newPosition);
|
||||
|
||||
pickup.Active.Add(pickedStar);
|
||||
pickup.Pooled.RemoveAt(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameObject newStar = Instantiate(pickup.Prefab, pickupItemsParent);
|
||||
NetworkServer.Spawn(newStar);
|
||||
newStar.GetComponent<PickupItem>().Reposition(newPosition);
|
||||
pickup.Active.Add(newStar.GetComponent<PickupItem>());
|
||||
}
|
||||
|
||||
pickup.Timer = 0;
|
||||
pickup.Active.Add(pickedStar);
|
||||
pickup.Pooled.RemoveAt(0);
|
||||
// Debug.Log($"Repositioned {pickup.Prefab.name} {pickup.Active.Count}:{pickup.Pooled.Count}");
|
||||
}
|
||||
else
|
||||
{
|
||||
GameObject newStar = Instantiate(pickup.Prefab, pickupItemsParent);
|
||||
NetworkServer.Spawn(newStar);
|
||||
newStar.GetComponent<PickupItem>().Reposition(newPosition);
|
||||
pickup.Active.Add(newStar.GetComponent<PickupItem>());
|
||||
// Debug.Log($"Spawned {pickup.Prefab.name} {pickup.Active.Count}:{pickup.Pooled.Count}");
|
||||
}
|
||||
}
|
||||
}
|
||||
GameObject RandomStar { get{
|
||||
PickupSetting RandomStar { get{
|
||||
int i = Random.Range(0,5);
|
||||
int c = 0;
|
||||
GameObject selected = null;
|
||||
PickupSetting selected = null;
|
||||
foreach(PickupSetting pickup in PickupItems){
|
||||
if(pickup.Prefab.name.ToLower().Contains("star")){
|
||||
selected = pickup.Prefab;
|
||||
selected = pickup;
|
||||
if(c == i){
|
||||
return pickup.Prefab;
|
||||
return pickup;
|
||||
break;
|
||||
}
|
||||
c++;
|
||||
@@ -302,9 +345,15 @@ public class MinigameManager : NetworkBehaviour
|
||||
void SpawnStars(int amount, Vector3 focusedPosition){
|
||||
for(int i=0; i < amount;i++){
|
||||
Vector3 newPosition = getRandomPointInCirlce((Vector3)focusedPosition, 10);
|
||||
GameObject newStar = Instantiate(RandomStar, pickupItemsParent);
|
||||
if(Vector3.Distance(Vector3.zero, newPosition) > mapRadius){
|
||||
newPosition = focusedPosition;
|
||||
}
|
||||
PickupSetting chosenStar = RandomStar;
|
||||
GameObject newStar = Instantiate(chosenStar.Prefab, pickupItemsParent);
|
||||
NetworkServer.Spawn(newStar);
|
||||
newStar.GetComponent<PickupItem>().Reposition(newPosition);
|
||||
|
||||
chosenStar.Active.Add(newStar.GetComponent<PickupItem>());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,7 +362,7 @@ public class MinigameManager : NetworkBehaviour
|
||||
foreach(PickupSetting pickup in PickupItems){
|
||||
if(item.type == pickup.Type)
|
||||
pickup.Active.Remove(item);
|
||||
pickup.Pooled.Add(item);
|
||||
// pickup.Pooled.Add(item);
|
||||
}
|
||||
}
|
||||
// public void ShowDeathEffect(Vector2 position){
|
||||
@@ -349,8 +398,10 @@ public class MinigameManager : NetworkBehaviour
|
||||
// SetRespawn(SceneData.localPlayer);
|
||||
AdsManager.SetOnInterestitialClosed(()=>{SetRespawn(SceneData.localPlayer);});
|
||||
if(!SceneData.holder.ShowAds()){
|
||||
SetRespawn(SceneData.localPlayer);
|
||||
}
|
||||
|
||||
SetRespawn(SceneData.localPlayer);
|
||||
|
||||
}else{
|
||||
Debug.LogError("You aren't dead, you can't restart unless you are dead.");
|
||||
}
|
||||
|
||||
@@ -59,6 +59,16 @@ public class NetworkTrail : NetworkBehaviour
|
||||
[ClientRpc]
|
||||
void RpcUpdatePositions(Vector3[] Positions){
|
||||
if(!enableValidation){return;}
|
||||
if(timer < 5){
|
||||
timer+=Time.deltaTime;
|
||||
return;
|
||||
}
|
||||
timer=0;
|
||||
if(SceneData.localPlayer == null){return;}
|
||||
if(Vector3.Distance(transform.position, SceneData.localPlayer.transform.position) > MinigameManager.instance.mapRadius/3f){
|
||||
return;
|
||||
}
|
||||
|
||||
positions = Positions;
|
||||
line.positionCount = positions.Length;
|
||||
line.SetPositions(positions);
|
||||
|
||||
@@ -18,15 +18,36 @@ public class PickupItem : NetworkBehaviour
|
||||
position = transform.position;
|
||||
newPosition= transform.position;
|
||||
movementTime = Random.Range(0.7f,1f);
|
||||
|
||||
if(isServer){
|
||||
if(GetComponentInChildren<Animator>()!=null){GetComponentInChildren<Animator>().enabled = false;}
|
||||
}
|
||||
anim = GetComponentInChildren<Animator>();
|
||||
}
|
||||
|
||||
Animator anim;
|
||||
|
||||
Vector3 newPosition;
|
||||
float posTimer = 0;
|
||||
float movementTime = 0;
|
||||
float t2=100;
|
||||
bool PlayerIsClose = false;
|
||||
void Update()
|
||||
{
|
||||
|
||||
// return;
|
||||
if(!isServer){
|
||||
if(t2 < movementTime * 2){
|
||||
t2+=Time.deltaTime;
|
||||
}else{
|
||||
t2=0;
|
||||
if(SceneData.localPlayer != null){
|
||||
PlayerIsClose =(Vector3.Distance(transform.position, SceneData.localPlayer.transform.position) < 20);
|
||||
if(anim!=null){ anim.enabled = PlayerIsClose;}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
if(!PlayerIsClose){return;}
|
||||
// transform.position = Vector3.Lerp(transform.position, new Vector3(position.x + ((radius/2f) * Random.Range(-1f,1f)),position.y + ((radius/2f) * Random.Range(-1f,1f))),0.01f);
|
||||
if(posTimer < movementTime){
|
||||
posTimer+=Time.deltaTime;
|
||||
@@ -38,14 +59,19 @@ public class PickupItem : NetworkBehaviour
|
||||
transform.position = Vector3.Lerp(transform.position, newPosition, 0.008f * movementTime);
|
||||
return;
|
||||
}
|
||||
if(!active){return;}
|
||||
|
||||
// if(!active){return;}
|
||||
return;
|
||||
Collider2D hit = Physics2D.OverlapCircle(transform.position, radius);
|
||||
if(hit!=null && hit.GetComponent<SpaceshipController>()!=null){
|
||||
// Debug.Log(hit.GetComponent<SpaceshipController>().pname +$" collected me at {transform.position}");
|
||||
hit.GetComponent<SpaceshipController>().CollectPickup(type);
|
||||
active=false;
|
||||
Deactivate(hit.transform);
|
||||
if(hit!=null ){
|
||||
if(hit.GetComponent<SpaceshipController>()!=null){
|
||||
hit.GetComponent<SpaceshipController>().CollectPickup(type);
|
||||
active=false;
|
||||
Deactivate(hit.transform);
|
||||
}else if(hit.GetComponent<SpaceshipNetworkBot>()!=null){
|
||||
hit.GetComponent<SpaceshipNetworkBot>().CollectPickup(type);
|
||||
active=false;
|
||||
Deactivate(hit.transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +102,7 @@ public class PickupItem : NetworkBehaviour
|
||||
transform.position = newPosition;
|
||||
position= newPosition;
|
||||
gameObject.SetActive(true);
|
||||
Debug.LogWarning("Repositoning pickup");
|
||||
}
|
||||
|
||||
public void Deactivate(Transform playerPos){
|
||||
@@ -90,15 +117,23 @@ public class PickupItem : NetworkBehaviour
|
||||
void deactivate(Transform playerPos){
|
||||
active=false;
|
||||
// gameObject.SetActive(false);
|
||||
StartCoroutine(MoveToPlayer(playerPos));
|
||||
if(false){
|
||||
gameObject.SetActive(false);
|
||||
SceneData.GameManager.DeactivatePickupItem(this);
|
||||
NetworkServer.Destroy(gameObject);
|
||||
|
||||
}else{
|
||||
StartCoroutine(MoveToPlayer(playerPos));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator MoveToPlayer(Transform position){
|
||||
float speed = 0.01f;
|
||||
float speed = 0.02f;
|
||||
while(Vector3.Distance(position.position, transform.position) > 1f){
|
||||
transform.position = Vector3.Lerp(transform.position, position.position, speed);
|
||||
speed+= 0.01f;
|
||||
yield return new WaitForEndOfFrame();
|
||||
speed+= 0.02f;
|
||||
yield return new WaitForSeconds(0.01f);
|
||||
}
|
||||
if(!isServer){
|
||||
ParticleSystem particle = EffectPool.Spawn(PickupEffect, transform.position).GetComponent<ParticleSystem>();
|
||||
@@ -107,6 +142,9 @@ public class PickupItem : NetworkBehaviour
|
||||
SceneData.GameManager.DeactivatePickupItem(this);
|
||||
|
||||
gameObject.SetActive(false);
|
||||
if(isServer){
|
||||
NetworkServer.Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
[Command]
|
||||
@@ -121,6 +159,7 @@ public class PickupItem : NetworkBehaviour
|
||||
}
|
||||
|
||||
private void OnDrawGizmos() {
|
||||
if(!PlayerIsClose){return;}
|
||||
Gizmos.color = gizmoColor;
|
||||
Gizmos.DrawWireSphere(transform.position,radius);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ public class RankedGameSummary : MonoBehaviour
|
||||
|
||||
|
||||
public void ShowWin(){
|
||||
Debug.Log("You Won");
|
||||
|
||||
VictoryEffect.Play();
|
||||
txtGameOver.text = "You Won!";
|
||||
txtTrophies.text= "+30";
|
||||
@@ -18,6 +20,7 @@ public class RankedGameSummary : MonoBehaviour
|
||||
}
|
||||
|
||||
public void ShowLoss(){
|
||||
Debug.Log("You lost");
|
||||
txtGameOver.text = "You Lost!";
|
||||
txtTrophies.text= "-15";
|
||||
txtTrophies.color = Color.red;
|
||||
|
||||
@@ -4,43 +4,81 @@ using UnityEngine;
|
||||
using TMPro;
|
||||
public class RankedSplash : MonoBehaviour
|
||||
{
|
||||
public static RankedSplash instance;
|
||||
public int playerCountRequired;
|
||||
public TMP_Text statusTxt;
|
||||
public GameObject controlsUI;
|
||||
public float startTimer = 120;
|
||||
|
||||
void Start()
|
||||
{
|
||||
instance = this;
|
||||
statusTxt.text = "Waiting for confirmation";
|
||||
controlsUI.SetActive(false);
|
||||
}
|
||||
bool allConnected= false;
|
||||
string rules = @"1.Last one standing or the first to collect 30 moons wins!
|
||||
string rules = @"1.Last one standing or the first to collect 30 ores wins!
|
||||
2.Stay in safe zone to survive
|
||||
3.Safe-Zone gets shrinked in 5 mins
|
||||
4.Have fun!";
|
||||
void Update()
|
||||
void FixedUpdate()
|
||||
{
|
||||
// if(AutoConnect.instance.isClient){return;}
|
||||
if(MinigameManager.instance ==null){return;}
|
||||
SpaceshipController[] players = FindObjectsOfType<SpaceshipController>();
|
||||
// if(AutoConnect.instance.isClient){return;}
|
||||
if(gameObject.activeSelf){
|
||||
if(startTimer > 0){
|
||||
startTimer-= Time.deltaTime;
|
||||
if(startTimer <= 45 && players.Length == 0){
|
||||
MessageDialog.instance.ShowMessage("Error", "Connection to the server timed out");
|
||||
LoadingScreen.instance.LoadLevel("GameScene");
|
||||
startTimer = -100;
|
||||
}
|
||||
if(startTimer <= 45 && players.Length == 1){
|
||||
Debug.Log("Timed out");
|
||||
|
||||
MinigameManager.instance.EnemyForfeit();
|
||||
players[0].WonRanked();
|
||||
startTimer = -100;
|
||||
|
||||
}
|
||||
}else{
|
||||
if(SceneData.localPlayer.GetComponent<SpaceshipController>().ready){
|
||||
MinigameManager.instance.EnemyForfeit();
|
||||
SceneData.localPlayer.GetComponent<SpaceshipController>().WonRanked();
|
||||
}
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
if(players.Length >= playerCountRequired){
|
||||
if(players.Length >= playerCountRequired && players[0].ready && players[1].ready){
|
||||
//Start the match!
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
if(players.Length >= playerCountRequired && players[0].ready && players[1].ready){
|
||||
//Start the match!
|
||||
gameObject.SetActive(false);
|
||||
controlsUI.SetActive(true);
|
||||
startTimer = -100;
|
||||
}
|
||||
}else if(players.Length == 0){
|
||||
statusTxt.text = "Waiting for server\nTimeout in " + (startTimer).ToString("n0") + " seconds";
|
||||
}
|
||||
|
||||
if(MinigameManager.instance ==null){return;}
|
||||
|
||||
if(!MinigameManager.instance.RankedGameStarted){
|
||||
|
||||
if(!allConnected && players.Length < playerCountRequired){
|
||||
statusTxt.text = "Waiting for opponents to connect";
|
||||
statusTxt.text = "Waiting for opponents to connect\nTimeout in " + (startTimer).ToString("n0") + " seconds";
|
||||
}else{
|
||||
if(!allConnected){
|
||||
allConnected = true;
|
||||
MessageDialog.instance.ShowQuestion("Confirm", $"Click yes to confirm you understand the rules below.\n{rules}", OnAgree, ()=>{}, onlyYes:true);
|
||||
// OnAgree();
|
||||
}
|
||||
|
||||
if(players[0].ready && players[1].ready){
|
||||
if(players.Length > 1 && players[0].ready && players[1].ready){
|
||||
//Start the match!
|
||||
gameObject.SetActive(false);
|
||||
startTimer = -100;
|
||||
}else{
|
||||
statusTxt.text = "Waiting for players to get ready";
|
||||
statusTxt.text = "Waiting for players to get ready\nRemaining " + startTimer.ToString("n0") + " seconds";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ public class SceneDataHolder : MonoBehaviour
|
||||
public Transform trailCollidersParent;
|
||||
[Header("Deadscreen")]
|
||||
public GameObject deadScreen;
|
||||
public GameObject controlsUI;
|
||||
public GameObject xpEarnings;
|
||||
public GameObject metalEarnings;
|
||||
public TMP_Text survivalTimeTxt;
|
||||
@@ -33,6 +34,7 @@ public class SceneDataHolder : MonoBehaviour
|
||||
public void ShowDeadscreen(int xpEarned, int metalEarned, double survivalTime){
|
||||
|
||||
deadScreen.SetActive(true);
|
||||
if(MinigameManager.instance.isRanked){controlsUI.SetActive(false);}
|
||||
xpEarnings.SetActive(xpEarned > 0); metalEarnings.SetActive(metalEarned > 0);
|
||||
xpEarnings.GetComponentInChildren<TMP_Text>().text = xpEarned.ToString();
|
||||
metalEarnings.GetComponentInChildren<TMP_Text>().text = metalEarned.ToString();
|
||||
@@ -52,13 +54,13 @@ public class SceneDataHolder : MonoBehaviour
|
||||
}
|
||||
public bool ShowAds(){
|
||||
|
||||
if(MinigameManager.instance.isRanked){
|
||||
if(AdsManager.instance!=null && (DateTime.Now - lastShownTime).Minutes > 10){
|
||||
// if(MinigameManager.instance.isRanked){
|
||||
// if(AdsManager.instance!=null && (DateTime.Now - lastShownTime).Minutes > 10){
|
||||
AdsManager.instance.ShowInterestitial();
|
||||
lastShownTime = DateTime.Now;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// }
|
||||
// }
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Collections;
|
||||
using CustomExtensions;
|
||||
public class SpaceshipController : NetworkBehaviour
|
||||
{
|
||||
public LayerMask pickupsLayer;
|
||||
[SyncVar]
|
||||
public bool ready;
|
||||
public SpriteRenderer playerImg;
|
||||
@@ -216,7 +217,7 @@ public class SpaceshipController : NetworkBehaviour
|
||||
boosting = value;
|
||||
}
|
||||
[SyncVar]
|
||||
double startedTime = 0;
|
||||
public double startedTime = 0;
|
||||
|
||||
void ResetStats()
|
||||
{
|
||||
@@ -255,7 +256,7 @@ public class SpaceshipController : NetworkBehaviour
|
||||
}
|
||||
if (joystick == null) { joystick = FindObjectOfType<Joystick>(); }
|
||||
FindObjectOfType<CameraFollower>().SetTarget(transform);
|
||||
string myName = PlayerPrefs.GetString("username");
|
||||
string myName = DBmanager.displayName;
|
||||
SceneData.localPlayer = gameObject;
|
||||
SceneData.OnBoostDown.AddListener(OnBoostDown);
|
||||
SceneData.OnBoostUp.AddListener(OnBoostUp);
|
||||
@@ -323,6 +324,11 @@ public class SpaceshipController : NetworkBehaviour
|
||||
long lastTime ;
|
||||
void Update()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
// Debug.Log(FindObjectsOfType<PickupItem>().Length);
|
||||
#endif
|
||||
if (joystick == null) { joystick = FindObjectOfType<Joystick>(); if(joystick==null){return;} }
|
||||
|
||||
if (MinigameManager.instance.isRanked && !MinigameManager.instance.RankedGameStarted) { return; }
|
||||
distanceFromCenter = Vector3.Distance(transform.position, Vector3.zero);
|
||||
pnameTxt.rectTransform.rotation = Quaternion.Euler(Vector3.zero);
|
||||
@@ -355,7 +361,7 @@ public class SpaceshipController : NetworkBehaviour
|
||||
|
||||
body.position = Vector3.Lerp(body.position,targetState.Position,MovementSmoothnessFactor * movingSpeed * Vector2.Distance(targetState.Position, body.position));
|
||||
body.rotation = Quaternion.Lerp(body.rotation, targetState.Rotation,MovementSmoothnessFactor*movingSpeed);
|
||||
Debug.Log(lastTime - currentTick);
|
||||
// Debug.Log(lastTime - currentTick);
|
||||
lastTime = targetState.Tick;
|
||||
CameraFollower.UpdateFrame();
|
||||
}
|
||||
@@ -408,7 +414,9 @@ public class SpaceshipController : NetworkBehaviour
|
||||
// body.rotation = Quaternion.Lerp(body.rotation, targetState.Rotation,MovementSmoothnessFactor*movingSpeed);
|
||||
}else if (isServer){
|
||||
HandleInput(m_Input);
|
||||
RpcUpdateOnClient(body.position, body.rotation, m_Input);
|
||||
// RpcUpdateOnClient(body.position, body.rotation, m_Input);
|
||||
|
||||
CheckForPickups();
|
||||
}else{
|
||||
//client but not localPlayer
|
||||
body.position = targetState.Position;
|
||||
@@ -464,6 +472,21 @@ public class SpaceshipController : NetworkBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
void CheckForPickups(){
|
||||
Collider2D[] hits = Physics2D.OverlapCircleAll(transform.position, 3, pickupsLayer);
|
||||
foreach(Collider2D hit in hits){
|
||||
if(hit!=null ){
|
||||
// Debug.Log(hit.name);
|
||||
PickupItem pickupItem = hit.GetComponent<PickupItem>();
|
||||
if(pickupItem !=null && pickupItem.active){
|
||||
pickupItem.active=false;
|
||||
pickupItem.Deactivate(transform);
|
||||
CollectPickup(pickupItem.type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HandleInput(Vector2 _input){
|
||||
// transform.Translate(transform.forward * _input.y);
|
||||
// transform.Rotate(transform.up * _input.x);
|
||||
@@ -602,6 +625,15 @@ public class SpaceshipController : NetworkBehaviour
|
||||
OnKill();
|
||||
|
||||
}
|
||||
|
||||
SpaceshipNetworkBot deadBot = hit.GetComponent<SpaceshipNetworkBot>();
|
||||
Debug.Log("got hit by bot? : " + (deadPlayer != deadBot));
|
||||
|
||||
if(deadBot != null){
|
||||
deadBot.Die();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
public void ShowDeathEffect(Vector2 position){
|
||||
if(isServer){
|
||||
@@ -749,7 +781,7 @@ public class SpaceshipController : NetworkBehaviour
|
||||
{
|
||||
//TODO: Death message goes here
|
||||
SceneData.holder.ShowDeadscreen(DBmanager.Xp - startedXp, DBmanager.Metal - startedMetal, NetworkTime.time - startedTime);
|
||||
if (MinigameManager.instance.isRanked)
|
||||
if (MinigameManager.instance.isRanked && RankedSplash.instance.gameObject.activeSelf)
|
||||
{
|
||||
// MinigameManager.instance.rankedSummary.ShowLoss();
|
||||
// StartCoroutine(ShowRankedResults());
|
||||
@@ -898,7 +930,7 @@ public class SpaceshipController : NetworkBehaviour
|
||||
RpcLostRanked();
|
||||
Die("server");
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
void RpcLostRanked()
|
||||
{
|
||||
if (isLocalPlayer)
|
||||
|
||||
@@ -6,12 +6,18 @@ public class TrailCollider : MonoBehaviour
|
||||
{
|
||||
public Color gizmoColor = Color.red;
|
||||
public TrailMgr trailMgr;
|
||||
public TrailMgrBot trailMgrBot;
|
||||
public float radius;
|
||||
void Update(){
|
||||
Collider2D hit = Physics2D.OverlapCircle(transform.position, radius);
|
||||
if(hit!=null){
|
||||
if(hit.transform.root == trailMgr.transform){return;} // <-- avoid eating myself
|
||||
trailMgr.OnColliderHit(hit);
|
||||
if(trailMgr != null){
|
||||
if(hit.transform.root == trailMgr.transform){return;} // <-- avoid eating myself
|
||||
trailMgr.OnColliderHit(hit);
|
||||
}else{
|
||||
if(hit.transform.root == trailMgrBot.transform){return;} // <-- avoid eating myself
|
||||
trailMgrBot.OnColliderHit(hit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public class TrailMgr : MonoBehaviour
|
||||
|
||||
public void OnColliderHit(Collider2D hit){
|
||||
controller.TrailCollided(hit);
|
||||
Debug.Log("Got hit:" +hit.name);
|
||||
// Debug.Log("Got hit:" +hit.name);
|
||||
}
|
||||
|
||||
void OnValidate(){
|
||||
|
||||
@@ -12,6 +12,7 @@ public class NewLoginManager : MonoBehaviour
|
||||
public GameObject usernameWarning;
|
||||
public TMP_InputField usernameInput;
|
||||
public Button btn_login;
|
||||
public Button btn_login_google;
|
||||
public TMP_Text statusTxt;
|
||||
public static bool loginSaved {get{return PlayerPrefs.HasKey("username") && PlayerPrefs.HasKey("password");}}
|
||||
public static string savedUsername{get{return (loginSaved)? PlayerPrefs.GetString("username") : "";}}
|
||||
@@ -49,14 +50,30 @@ public class NewLoginManager : MonoBehaviour
|
||||
WWW www = new WWW(DBmanager.phpRoot + "register_instant.php",form);
|
||||
yield return www;
|
||||
|
||||
|
||||
|
||||
OnRegister(www.text);
|
||||
}
|
||||
|
||||
IEnumerator registerGoogle(string email){
|
||||
statusTxt.text = "Registering you in...";
|
||||
WWWForm form = new WWWForm();
|
||||
form.AddField("key", "#2CuV1Bit^S!sW1ZcgRv8BhrO");
|
||||
form.AddField("name", email + "#0");
|
||||
form.AddField("display_name", PlayerPrefs.GetString("displayname"));
|
||||
form.AddField("password", email + "#0");
|
||||
|
||||
WWW www = new WWW(DBmanager.phpRoot + "register.php",form);
|
||||
yield return www;
|
||||
|
||||
PlayerPrefs.SetString("username",email+"#0");
|
||||
PlayerPrefs.SetString("password", email+"#0");
|
||||
PlayerPrefs.Save();
|
||||
|
||||
Login(true);
|
||||
}
|
||||
|
||||
void OnRegister(string id){
|
||||
try{
|
||||
TutorialManager.justRegistered=true;
|
||||
// TutorialManager.justRegistered=true;
|
||||
int new_id = int.Parse(id);
|
||||
PlayerPrefs.SetString("username", usernameInput.text+"#"+ id);
|
||||
PlayerPrefs.SetString("password", id);
|
||||
@@ -72,34 +89,42 @@ public class NewLoginManager : MonoBehaviour
|
||||
|
||||
}
|
||||
|
||||
void Login(){
|
||||
StartCoroutine(login());
|
||||
void Login(bool justRegistered = false){
|
||||
StartCoroutine(login(justRegistered));
|
||||
}
|
||||
|
||||
IEnumerator login(){
|
||||
IEnumerator login(bool googleSigned = false, bool justRegistered = false){
|
||||
statusTxt.text = "Logging you in...";
|
||||
|
||||
WWWForm form = new WWWForm();
|
||||
yield return new WaitForSeconds(1);
|
||||
form.AddField("name", savedUsername);
|
||||
form.AddField("password", savedPassword);
|
||||
form.AddField("google", googleSigned ? 1 : 0);
|
||||
WWW www = new WWW(DBmanager.phpRoot + "login.php",form);
|
||||
|
||||
yield return www;
|
||||
Debug.Log(www.text);
|
||||
|
||||
if(DBmanager.Login(www.text)==0){
|
||||
if(TutorialManager.justRegistered){
|
||||
// SceneManager.LoadScene("MinigameTutorial");
|
||||
LoadingScreen.instance.LoadLevel("MinigameTutorial");
|
||||
|
||||
// SceneManager.LoadScene("GameScene");
|
||||
if(justRegistered){
|
||||
LoadingScreen.instance.LoadLevel("Minigame");
|
||||
}else{
|
||||
// SceneManager.LoadScene("GameScene");
|
||||
LoadingScreen.instance.LoadLevel("GameScene");
|
||||
|
||||
|
||||
}
|
||||
|
||||
// if(TutorialManager.justRegistered){
|
||||
// // SceneManager.LoadScene("MinigameTutorial");
|
||||
// LoadingScreen.instance.LoadLevel("MinigameTutorial");
|
||||
|
||||
// // SceneManager.LoadScene("GameScene");
|
||||
// }else{
|
||||
// // SceneManager.LoadScene("GameScene");
|
||||
// // LoadingScreen.instance.LoadLevel("GameScene");
|
||||
|
||||
|
||||
// }
|
||||
}else{
|
||||
statusTxt.text = "Failed!";
|
||||
|
||||
@@ -112,6 +137,10 @@ public class NewLoginManager : MonoBehaviour
|
||||
MessageDialog.instance.ShowQuestion("Sorry", "Looks like there's been an issue logging you in\nPress yes to close the app and Try again later.", OnYes:()=>{Application.Quit();},onlyYes:true,OnNo:()=>{});
|
||||
}
|
||||
|
||||
public void OnGoogleSignComplete(){
|
||||
StartCoroutine(registerGoogle(GoogleLoginManager.loggedEmail));
|
||||
}
|
||||
|
||||
public void OnUsernameInputChanged(string newValue){
|
||||
btn_login.interactable= (usernameInput.text.Length > 2);
|
||||
usernameWarning.SetActive(usernameInput.text.Length< 2);
|
||||
|
||||
@@ -15,6 +15,14 @@ public class DBmanager : MonoBehaviour
|
||||
public static string phpRoot = "vmi1005083.contaboserver.net/upf/";
|
||||
|
||||
public static string username = null;
|
||||
public static string displayName {get {
|
||||
if(username.Contains("#0")){
|
||||
return PlayerPrefs.GetString("displayname");
|
||||
}else{
|
||||
return username;
|
||||
}
|
||||
}}
|
||||
|
||||
public static int userid=0;
|
||||
|
||||
private static float level = 0;
|
||||
@@ -110,6 +118,9 @@ public class DBmanager : MonoBehaviour
|
||||
DBmanager.SetGems(userData.gems,true);
|
||||
DBmanager.SetCoins(userData.coins,true);
|
||||
DBmanager.SetTweps(userData.tweps,true);
|
||||
|
||||
StartBridge();
|
||||
|
||||
return 0;
|
||||
}catch (Exception e){
|
||||
Debug.LogError("Couldn't parse data into json");
|
||||
@@ -117,6 +128,30 @@ public class DBmanager : MonoBehaviour
|
||||
Debug.LogWarning(jsonData);
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static async void StartBridge(){
|
||||
while(true){
|
||||
|
||||
WWWForm form = new WWWForm();
|
||||
form.AddField("username", username);
|
||||
form.AddField("region", (RegionManager.selectedServer == null) ? "EU" : RegionManager.selectedServer.name);
|
||||
|
||||
using (UnityWebRequest www = UnityWebRequest.Post(phpRoot + "bridge.php", form))
|
||||
{
|
||||
var operation = www.SendWebRequest();
|
||||
while (!operation.isDone)
|
||||
{
|
||||
await Task.Yield();
|
||||
}
|
||||
|
||||
|
||||
Debug.Log("Bridge : " + www.downloadHandler.text);
|
||||
}
|
||||
await Task.Delay(20000);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<string> LinkAccount(string newUsername, string newPassword){
|
||||
@@ -419,7 +454,7 @@ public class DBmanager : MonoBehaviour
|
||||
|
||||
if (www.downloadHandler.text == "0")
|
||||
{
|
||||
metal = newValue;
|
||||
metal = Mathf.Clamp(newValue,0,int.MaxValue);
|
||||
Debug.Log("Metal updated on "+ username);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -53,7 +53,7 @@ public class TradingPost : MonoBehaviour
|
||||
}
|
||||
|
||||
public int Refresh(){
|
||||
if(DBmanager.Coins < 10){
|
||||
if(DBmanager.Metal < 10){
|
||||
warningTxt.text = "You need atleast 10 golds to trade";
|
||||
tradeButton.interactable = false;
|
||||
metalSlider.interactable = false;
|
||||
@@ -78,6 +78,7 @@ public class TradingPost : MonoBehaviour
|
||||
txtMetalAmount.text = metalCount.ToString();
|
||||
|
||||
txtGoldAmount.text = (goldCount).ToString();
|
||||
Debug.Log(building.curLevel);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -27,12 +27,14 @@ public class TutorialManager : MonoBehaviour
|
||||
// btn_skip.onClick.AddListener(OnSkip);
|
||||
|
||||
// justRegistered= true; //for testing purpose
|
||||
if(isMinigame){
|
||||
StartSequence(minigameTutorial);
|
||||
}else if(justRegistered){
|
||||
StartSequence(firstTutorial);
|
||||
justRegistered =false;
|
||||
}
|
||||
|
||||
|
||||
// if(isMinigame){
|
||||
// StartSequence(minigameTutorial);
|
||||
// }else if(justRegistered){
|
||||
// StartSequence(firstTutorial);
|
||||
// justRegistered =false;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user