Ranked done, Shop done and many fixes
This commit is contained in:
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:
|
||||
Reference in New Issue
Block a user