Exp Pass done
This commit is contained in:
@@ -20,6 +20,7 @@ public class DBmanager : MonoBehaviour
|
||||
private static int gems = 0;
|
||||
private static int metal = 0;
|
||||
private static int oxygen = 0;
|
||||
private static List<int> expPassCollected = new List<int>();
|
||||
public static List<BuildingState> buildingStates = new List<BuildingState>();
|
||||
public static UnityEvent OnStateChanged = new UnityEvent();
|
||||
|
||||
@@ -29,6 +30,8 @@ public class DBmanager : MonoBehaviour
|
||||
public static int Metal => metal;
|
||||
public static int Oxygen => oxygen;
|
||||
public static float Level => level;
|
||||
public static int LevelInt => Mathf.CeilToInt(level);
|
||||
public static List<int> ExpPassCollected => expPassCollected;
|
||||
|
||||
|
||||
public static bool LoggedIn { get { return username != null; } }
|
||||
@@ -252,6 +255,60 @@ public class DBmanager : MonoBehaviour
|
||||
OnStateChanged.Invoke();
|
||||
}
|
||||
|
||||
public static void SetExpPassCollected(string rawData, bool justOffline = false)
|
||||
{
|
||||
string[] data = rawData.Split(',');
|
||||
expPassCollected = new List<int>();
|
||||
foreach(string item in data){
|
||||
try{
|
||||
int itemVal = int.Parse(item);
|
||||
expPassCollected.Add(itemVal);
|
||||
}catch {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
GameManagerInstance.gameManager.RefreshData();
|
||||
OnStateChanged.Invoke();
|
||||
}
|
||||
|
||||
public async static void AddCollectedExpPass(int newPassLevel)
|
||||
{
|
||||
expPassCollected.Add(newPassLevel);
|
||||
string output = "";
|
||||
for(int i =0;i < expPassCollected.Count;i++){
|
||||
output += expPassCollected[i].ToString();
|
||||
if(i < expPassCollected.Count -1){
|
||||
output += ",";
|
||||
}
|
||||
}
|
||||
|
||||
WWWForm form = new WWWForm();
|
||||
form.AddField("name", username);
|
||||
form.AddField("expPass", output);
|
||||
using (UnityWebRequest www = UnityWebRequest.Post(phpRoot + "set_expPassCollected.php", form))
|
||||
{
|
||||
var operation = www.SendWebRequest();
|
||||
while (!operation.isDone)
|
||||
{
|
||||
await Task.Yield();
|
||||
}
|
||||
|
||||
if (www.downloadHandler.text == "0")
|
||||
{
|
||||
Debug.Log("Success updating ExpPassCollected");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Response : " + www.downloadHandler.text);
|
||||
Debug.LogWarning("Failed to set exp_pass_collected to " + output);
|
||||
}
|
||||
}
|
||||
|
||||
GameManagerInstance.gameManager.RefreshData();
|
||||
OnStateChanged.Invoke();
|
||||
}
|
||||
|
||||
public static bool GetBuildingStates(string rawData)
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
64
Assets/Game/Scripts/ExpPass.cs
Normal file
64
Assets/Game/Scripts/ExpPass.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
public class ExpPass : MonoBehaviour
|
||||
{
|
||||
public Transform[] items;
|
||||
public Transform itemsParent;
|
||||
[EasyButtons.Button]
|
||||
void GetItems(){
|
||||
items = new Transform[itemsParent.childCount];
|
||||
for(int i =0; i < items.Length; i++){
|
||||
items[i] = itemsParent.GetChild(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
DBmanager.OnStateChanged.AddListener(RefreshData);
|
||||
RefreshData();
|
||||
}
|
||||
|
||||
void RefreshData(){
|
||||
|
||||
for (int i = 0; i < items.Length; i++){
|
||||
int curIndex = 0;
|
||||
curIndex = i;
|
||||
int expPassLevel = (i +1)* 10;
|
||||
int expPassReward =(i +1) * 5;
|
||||
Transform item = items[i];
|
||||
item.GetChild(1).GetComponent<TMP_Text>().text = "Reach Level " + expPassLevel;
|
||||
Slider slider = item.GetComponentInChildren<Slider>();
|
||||
slider.GetComponentInChildren<TMP_Text>().text = DBmanager.LevelInt + " / " + expPassLevel;
|
||||
slider.minValue=0;
|
||||
slider.maxValue = expPassLevel;
|
||||
slider.value = DBmanager.LevelInt;
|
||||
|
||||
item.GetComponentInChildren<Button>().interactable = expPassLevel <= DBmanager.LevelInt;
|
||||
if(expPassLevel <= DBmanager.LevelInt){
|
||||
item.GetComponentInChildren<Button>().gameObject.SetActive(!DBmanager.ExpPassCollected.Contains(expPassLevel));
|
||||
}
|
||||
item.GetComponentInChildren<Button>()?.onClick.AddListener(()=>{CollectExpPass(curIndex);});
|
||||
// item
|
||||
}
|
||||
}
|
||||
|
||||
void CollectExpPass(int i){
|
||||
Debug.Log("Collecting Exp Pass (index: " +i+ ")");
|
||||
|
||||
int expPassLevel = (i +1)* 10;
|
||||
int expPassReward =(i +1) * 5;
|
||||
|
||||
if(expPassLevel > DBmanager.LevelInt){
|
||||
Debug.LogError("Cannot collect, Not enough XP, This should be illegal");
|
||||
return;
|
||||
}
|
||||
|
||||
DBmanager.AddCollectedExpPass(expPassLevel);
|
||||
DBmanager.SetGems(DBmanager.Gems + expPassReward);
|
||||
items[i].GetComponentInChildren<Button>().gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
11
Assets/Game/Scripts/ExpPass.cs.meta
Normal file
11
Assets/Game/Scripts/ExpPass.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dbc3a35dffa376ad89b61f8432a8e5a8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -86,6 +86,7 @@ public class LoginManager : MonoBehaviour
|
||||
PlayerPrefs.SetString("password", login_password.text);
|
||||
PlayerPrefs.Save();}
|
||||
DBmanager.username = login_username.text;
|
||||
DBmanager.SetExpPassCollected(www.text.Split('\t')[7]);
|
||||
DBmanager.SetXp(int.Parse(www.text.Split('\t')[6]),true);
|
||||
DBmanager.GetBuildingStates(www.text.Split('\t')[5]);
|
||||
DBmanager.SetOxygen(int.Parse(www.text.Split('\t')[4]),true);
|
||||
|
||||
Reference in New Issue
Block a user