Ranked done, Shop done and many fixes

This commit is contained in:
Sewmina
2022-09-20 00:16:35 +05:30
parent 4194d2decc
commit f4e5b60bbf
166 changed files with 15171 additions and 1586 deletions

View 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);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3a00d06b92d7a4dd78fab8529a589430
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View 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(",",""));
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5cf2108220cbbf8449f5acdb4be74f69
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View 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";
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b15c5b3b610c912db8c1355f50b9f3d8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: