10/24 completed
This commit is contained in:
@@ -54,8 +54,8 @@ public class AccountSettings : MonoBehaviour
|
||||
}
|
||||
|
||||
async void OnLinkReg(){
|
||||
if(usernameInput.text.Length <= 4 || passwordInput.text.Length <= 4){
|
||||
MessageDialog.instance.ShowMessage("Error", "Username and password must have\nmore than 4 characters.");
|
||||
if(usernameInput.text.Length <= 2 || passwordInput.text.Length <= 2){
|
||||
MessageDialog.instance.ShowMessage("Error", "Username and password must have\nmore than 2 characters.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -99,11 +99,11 @@ public class AccountSettings : MonoBehaviour
|
||||
}
|
||||
|
||||
public void ValidateLinkCredentials(){
|
||||
if(usernameInput.text.Length < 4){
|
||||
if(usernameInput.text.Length <=2){
|
||||
btn_link_register.interactable = false;
|
||||
return;
|
||||
}
|
||||
if(passwordInput.text.Length < 4){
|
||||
if(passwordInput.text.Length <=2){
|
||||
btn_link_register.interactable = false;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ public class BuildingManager : MonoBehaviour
|
||||
|
||||
|
||||
public async void UpdateBuildings(){
|
||||
|
||||
//Add default buildings
|
||||
foreach (Building building in buildings){
|
||||
if(!building.gameObject.activeSelf){
|
||||
continue;
|
||||
@@ -65,4 +67,15 @@ public class BuildingManager : MonoBehaviour
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string GetStatValue(Building building, string statName) => GetStatValue(building.buildingData, building.curLevel, statName);
|
||||
public static string GetStatValue(BuildingData buildingData, int curLevel, string statName){
|
||||
foreach(BuildingStat stat in buildingData.levels[curLevel].stats){
|
||||
if(stat.name == statName){
|
||||
return stat.value;
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,14 +36,16 @@ public class CollectBtn : MonoBehaviour
|
||||
}
|
||||
|
||||
public async void OnClick(){
|
||||
collectableAmount= GetCollectableGold();
|
||||
lastCollected = await DBmanager.GetNetworkTime();
|
||||
// lastCollected = await DBmanager.GetNetworkTime();
|
||||
switch (resourceType){
|
||||
case CollectablesData.ResourceType.Metal:
|
||||
collectableAmount= GetCollectableEnergy();
|
||||
DBmanager.SetMetal(DBmanager.Metal + (int)collectableAmount);
|
||||
break;
|
||||
|
||||
case CollectablesData.ResourceType.Gold:
|
||||
collectableAmount= GetCollectableGold();
|
||||
|
||||
DBmanager.SetCoins(DBmanager.Coins + (int)collectableAmount);
|
||||
AudioManager.instnace.CollectGold();
|
||||
break;
|
||||
@@ -53,6 +55,7 @@ public class CollectBtn : MonoBehaviour
|
||||
// break;
|
||||
}
|
||||
DBmanager.CollectBuilding(buildingId);
|
||||
Selector.selectBuilding(null);
|
||||
}
|
||||
|
||||
double GetCollectableGold(){
|
||||
@@ -67,4 +70,17 @@ public class CollectBtn : MonoBehaviour
|
||||
|
||||
return Mathf.Clamp((float)((DateTime.UtcNow - lastCollected).TotalSeconds * ((productionRate/60f)/60f)),0, coinsCap);
|
||||
}
|
||||
|
||||
double GetCollectableEnergy(){
|
||||
Building selectedBuilding = BuildingManager.instance.GetBuildingWithId(buildingId);
|
||||
int coinsCap = 0;
|
||||
foreach(BuildingStat stat in selectedBuilding.buildingData.levels[selectedBuilding.curLevel].stats){
|
||||
if(stat.name == "Capacity"){
|
||||
coinsCap = int.Parse(stat.value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return Mathf.Clamp((float)((DateTime.UtcNow - lastCollected).TotalSeconds * ((productionRate/60f)/60f)),0, coinsCap);
|
||||
}
|
||||
}
|
||||
|
||||
258
Assets/Game/Scripts/DesignLab.cs
Normal file
258
Assets/Game/Scripts/DesignLab.cs
Normal file
@@ -0,0 +1,258 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
public class DesignLab : MonoBehaviour
|
||||
{
|
||||
[Header("Box opening")]
|
||||
|
||||
public Building designLabBuilding;
|
||||
public Button btnCommonBox,btnRareBox,btnEpicBox,btnLegendaryBox;
|
||||
public int[] boxPrices;
|
||||
public GameObject newBoxPanel;
|
||||
public GameObject newSkinPanel;
|
||||
public GameObject goldsPanel;
|
||||
public Button btnOpen;
|
||||
|
||||
public Button[] slips;
|
||||
|
||||
[Header("Blueprints")]
|
||||
public GameObject blueprintsPanel;
|
||||
public GameObject noBlueprintsPanel;
|
||||
public Transform gridParent;
|
||||
public GameObject gridChildPrefab;
|
||||
public Transform selectedCard;
|
||||
public int[] buildGoldPrices,buildMetalPrices;
|
||||
public Button btn_build;
|
||||
|
||||
void Start()
|
||||
{
|
||||
btn_build.onClick.AddListener(OnBuildClicked);
|
||||
|
||||
btnCommonBox.onClick.AddListener(()=>{OnBoxSelected(0);});
|
||||
btnRareBox.onClick.AddListener(()=>{OnBoxSelected(1);});
|
||||
btnEpicBox.onClick.AddListener(()=>{OnBoxSelected(2);});
|
||||
btnLegendaryBox.onClick.AddListener(()=>{OnBoxSelected(3);});
|
||||
|
||||
btnOpen.onClick.AddListener(OnOpen);
|
||||
|
||||
foreach(Button btn in slips){
|
||||
btn.onClick.AddListener(OnSlipSelected);
|
||||
}
|
||||
Refresh();
|
||||
}
|
||||
public int selectedBoxIndex = -1;
|
||||
int selectedBlueprintIndex= 0;
|
||||
void OnBoxSelected(int index){
|
||||
selectedBoxIndex = index;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void Refresh()
|
||||
{
|
||||
RefreshBoxes();
|
||||
RefreshBlueprints();
|
||||
}
|
||||
|
||||
void RefreshBlueprints(){
|
||||
for(int i=0; i < gridParent.childCount; i++){ //PURGE
|
||||
Destroy(gridParent.GetChild(i).gameObject);
|
||||
}
|
||||
|
||||
List<PurchasedSkin> blueprints = DBmanager.Blueprints;
|
||||
if(blueprints.Count <= 0){
|
||||
blueprintsPanel.SetActive(false);
|
||||
noBlueprintsPanel.SetActive(true);
|
||||
return;
|
||||
}
|
||||
blueprintsPanel.SetActive(true);
|
||||
noBlueprintsPanel.SetActive(false);
|
||||
blueprintItems = new List<GameObject>();
|
||||
//Populate
|
||||
for(int i =0; i < blueprints.Count; i++){
|
||||
GameObject newItem = Instantiate(gridChildPrefab, gridParent);
|
||||
SkinShopItemData skinData = SkinShopManager.GetSkinDataByName(blueprints[i].name);
|
||||
newItem.transform.GetComponentInChildren<TMP_Text>().text = SkinShopManager.GetRarityName(skinData.skinType);
|
||||
newItem.transform.GetComponentInChildren<TMP_Text>().color = SkinShopManager.GetRarityColor(skinData.skinType);
|
||||
|
||||
newItem.transform.Find("img_skin").GetComponent<Image>().sprite = skinData.image;
|
||||
newItem.name = blueprints[i].name;
|
||||
int index = i;
|
||||
newItem.GetComponent<Button>().onClick.AddListener(()=>{OnBlueprintItemClicked(index);});
|
||||
|
||||
blueprintItems.Add(newItem);
|
||||
}
|
||||
OnBlueprintItemClicked(selectedBlueprintIndex);
|
||||
|
||||
}
|
||||
List<GameObject> blueprintItems = new List<GameObject>();
|
||||
void RefreshBoxes(){
|
||||
// OnBoxSelected(-1);
|
||||
|
||||
btnCommonBox.transform.GetChild(1).gameObject.SetActive(false);
|
||||
btnRareBox.transform.GetChild(1).gameObject.SetActive(false);
|
||||
btnEpicBox.transform.GetChild(1).gameObject.SetActive(false);
|
||||
btnLegendaryBox.transform.GetChild(1).gameObject.SetActive(false);
|
||||
switch(selectedBoxIndex){
|
||||
case 0:
|
||||
btnCommonBox.transform.GetChild(1).gameObject.SetActive(true);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
btnRareBox.transform.GetChild(1).gameObject.SetActive(true);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
btnEpicBox.transform.GetChild(1).gameObject.SetActive(true);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
btnLegendaryBox.transform.GetChild(1).gameObject.SetActive(true);
|
||||
break;
|
||||
}
|
||||
if(selectedBoxIndex <0 || selectedBoxIndex >= boxPrices.Length){ //Non Selected
|
||||
btnOpen.gameObject.SetActive(false);
|
||||
return;
|
||||
}
|
||||
|
||||
btnOpen.gameObject.SetActive(true);
|
||||
btnOpen.transform.Find("txt_metal").GetComponent<TMP_Text>().text = boxPrices[selectedBoxIndex].ToString();
|
||||
btnOpen.transform.Find("txt_metal").GetComponent<TMP_Text>().color = (DBmanager.Metal >= boxPrices[selectedBoxIndex]) ? Color.white : Color.red;
|
||||
|
||||
btnOpen.interactable = DBmanager.Metal >= boxPrices[selectedBoxIndex] && designLabBuilding.curLevel >= selectedBoxIndex;
|
||||
|
||||
}
|
||||
|
||||
public void Show(){
|
||||
selectedBoxIndex=-1;
|
||||
gameObject.SetActive(true);
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void OnBlueprintItemClicked(int index){
|
||||
selectedBlueprintIndex = index;
|
||||
Debug.Log("selecting item " + index);
|
||||
SkinShopItemData skin = SkinShopManager.GetSkinDataByName(blueprintItems[index].name);
|
||||
selectedCard.Find("img_skin").GetComponent<Image>().sprite = skin.image;
|
||||
|
||||
selectedCard.Find("rate_common").gameObject.SetActive(skin.skinType == SkinType.Base);
|
||||
selectedCard.Find("rate_rare").gameObject.SetActive(skin.skinType == SkinType.Rare);
|
||||
selectedCard.Find("rate_epic").gameObject.SetActive(skin.skinType == SkinType.Epic);
|
||||
selectedCard.Find("rate_legendary").gameObject.SetActive(skin.skinType == SkinType.Legendary);
|
||||
|
||||
RocketLevel stats = SkinShopManager.GetStatsForRarity(skin.skinType)[0];
|
||||
selectedCard.Find("txt_energy").GetChild(0).GetComponent<TMP_Text>().text = stats.moonMultiplier.ToString();
|
||||
selectedCard.Find("txt_speed").GetChild(0).GetComponent<TMP_Text>().text = (stats.speedMultiplier * 100).ToString("n0") + "%";
|
||||
selectedCard.Find("txt_boost").GetChild(0).GetComponent<TMP_Text>().text = (stats.boostConsumption * 100).ToString("n0") + "%";
|
||||
|
||||
int rarityIndex = SkinShopManager.GetRarityIndexFromName(blueprintItems[index].name);
|
||||
btn_build.transform.GetChild(0).Find("txt_metal").GetComponent<TMP_Text>().text = buildMetalPrices[rarityIndex].ToString();
|
||||
btn_build.transform.GetChild(0).Find("txt_metal").gameObject.SetActive(buildMetalPrices[rarityIndex] > 0);
|
||||
btn_build.transform.GetChild(0).Find("txt_gold").GetComponent<TMP_Text>().text = buildGoldPrices[rarityIndex].ToString();
|
||||
btn_build.transform.GetChild(0).Find("txt_gold").gameObject.SetActive(buildGoldPrices[rarityIndex] > 0);
|
||||
|
||||
btn_build.interactable = DBmanager.Coins >= buildGoldPrices[rarityIndex] && DBmanager.Metal >= buildMetalPrices[rarityIndex];
|
||||
}
|
||||
|
||||
|
||||
void OnBuildClicked(){
|
||||
int rarityIndex = SkinShopManager.GetRarityIndexFromName(blueprintItems[selectedBlueprintIndex].name);
|
||||
|
||||
if(DBmanager.Coins >= buildGoldPrices[rarityIndex] && DBmanager.Metal >= buildMetalPrices[rarityIndex]){
|
||||
string message = $@"Are you sure you want to build this skin for {buildGoldPrices[rarityIndex]} Golds
|
||||
and {buildMetalPrices[rarityIndex]} Energy?";
|
||||
MessageDialog.instance.ShowQuestion("Confirm",message, OnYes:OnBuildConfirmed, OnNo:()=>{});
|
||||
}else{
|
||||
MessageDialog.instance.ShowMessage("Error", "Not enough resources to build this blueprint");
|
||||
}
|
||||
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void OnBuildConfirmed(){
|
||||
int rarityIndex = SkinShopManager.GetRarityIndexFromName(blueprintItems[selectedBlueprintIndex].name);
|
||||
|
||||
if(DBmanager.Coins >= buildGoldPrices[rarityIndex] && DBmanager.Metal >= buildMetalPrices[rarityIndex]){
|
||||
DBmanager.SetCoins(DBmanager.Coins - buildGoldPrices[rarityIndex]);
|
||||
DBmanager.SetMetal(DBmanager.Metal - buildMetalPrices[rarityIndex]);
|
||||
DBmanager.BuildBlueprint(blueprintItems[selectedBlueprintIndex].name);
|
||||
AudioManager.instnace.ChestOpen();
|
||||
}else{
|
||||
MessageDialog.instance.ShowMessage("Error", "Not enough resources to build this blueprint");
|
||||
}
|
||||
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void OnOpen(){
|
||||
if(DBmanager.Metal < boxPrices[selectedBoxIndex]){
|
||||
MessageDialog.instance.ShowMessage("Error", "Not enough energy to open this box");
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
AudioManager.instnace.ChestOpen();
|
||||
newBoxPanel.SetActive(true);
|
||||
string rarityName = "Common";
|
||||
if(selectedBoxIndex == 1){
|
||||
rarityName = "Rare";
|
||||
}else if(selectedBoxIndex == 2){
|
||||
rarityName = "Epic";
|
||||
}else if(selectedBoxIndex ==3){
|
||||
rarityName = "Legendary";
|
||||
}
|
||||
newBoxPanel.transform.GetChild(0).GetComponent<TMP_Text>().text = rarityName + " Box";
|
||||
}
|
||||
|
||||
void OnSlipSelected(){
|
||||
int random = Random.Range(0,100);
|
||||
if(random < 20){
|
||||
//Got a skin
|
||||
List<SkinShopItemData> availableSkins = new List<SkinShopItemData>();
|
||||
foreach(SkinShopItemData item in SkinShopManager.SkinsData.skins){
|
||||
if(DBmanager.GetSkinIdByName(item.name) >=0){continue;}
|
||||
if(selectedBoxIndex ==0 && item.skinType == SkinType.Base){
|
||||
availableSkins.Add(item);
|
||||
}else if(selectedBoxIndex ==1 && item.skinType == SkinType.Rare){
|
||||
availableSkins.Add(item);
|
||||
}else if(selectedBoxIndex ==2 && item.skinType == SkinType.Epic){
|
||||
availableSkins.Add(item);
|
||||
}else if(selectedBoxIndex ==3 && item.skinType == SkinType.Legendary){
|
||||
availableSkins.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
if(availableSkins.Count <= 0){
|
||||
Debug.LogError("No skin found to award");
|
||||
AwardGold((int)(boxPrices[selectedBoxIndex] / 4f));
|
||||
}else{
|
||||
AwardSkin(availableSkins[Random.Range(0, availableSkins.Count-1)]);
|
||||
}
|
||||
}else{
|
||||
AwardGold((int)(boxPrices[selectedBoxIndex] / 4f));
|
||||
}
|
||||
newBoxPanel.SetActive(false);
|
||||
AudioManager.instnace.ChestOpen();
|
||||
}
|
||||
|
||||
void AwardSkin(SkinShopItemData skin){
|
||||
newSkinPanel.SetActive(true);
|
||||
newSkinPanel.transform.Find("img_skin").GetComponent<Image>().sprite = skin.image;
|
||||
|
||||
DBmanager.AddSkinBlueprint(skin);
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void AwardGold(int amount){
|
||||
goldsPanel.SetActive(true);
|
||||
goldsPanel.transform.Find("txt_amount").GetComponent<TMP_Text>().text = amount.ToString();
|
||||
|
||||
DBmanager.SetCoins(DBmanager.Coins + amount);
|
||||
Refresh();
|
||||
}
|
||||
|
||||
public void Hide(){
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
11
Assets/Game/Scripts/DesignLab.cs.meta
Normal file
11
Assets/Game/Scripts/DesignLab.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ef88fb813856237feb3de6eee17e302a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -7,6 +7,7 @@ public class LeaderboardItem : MonoBehaviour
|
||||
{
|
||||
public TMP_Text positionTxt;
|
||||
public Image img_place;
|
||||
public Image img_rank;
|
||||
public Sprite[] specialPlaces;
|
||||
public TMP_Text usernameTxt;
|
||||
public TMP_Text trophiesTxt;
|
||||
@@ -22,5 +23,7 @@ public class LeaderboardItem : MonoBehaviour
|
||||
|
||||
usernameTxt.text = data.username;
|
||||
trophiesTxt.text = data.trophies.ToString();
|
||||
|
||||
img_rank.sprite = DBmanager.GetRankForTrophies(data.trophies).image;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ using UnityEngine.SceneManagement;
|
||||
|
||||
public class MaintainceChecker : MonoBehaviour
|
||||
{
|
||||
public static int version = 10;
|
||||
public static int version = 13;
|
||||
public static MaintainceChecker instance;
|
||||
public int checkInterval = 30;
|
||||
float t;
|
||||
|
||||
@@ -6,6 +6,7 @@ public class RocketSkinStats : ScriptableObject
|
||||
public RocketLevel[] baseLevels;
|
||||
public RocketLevel[] commonLevels;
|
||||
public RocketLevel[] rareLevels;
|
||||
public RocketLevel[] epicLevels;
|
||||
public RocketLevel[] legendaryLevels;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ using TMPro;
|
||||
using UnityEngine.UI;
|
||||
public class RocketUpgradePanel : MonoBehaviour
|
||||
{
|
||||
public TMP_Text txtRocketLevel;
|
||||
public TMP_Text txtEnergyGain;
|
||||
public TMP_Text txtSpeed;
|
||||
public TMP_Text txtBoostConsumption;
|
||||
@@ -28,6 +29,8 @@ public class RocketUpgradePanel : MonoBehaviour
|
||||
int curSpeedLevel;
|
||||
int curEnergyLevel;
|
||||
int curBoostLevel;
|
||||
|
||||
public int curRocketLevel => Mathf.Clamp(curSpeedLevel + curEnergyLevel + curBoostLevel+1,1,10);
|
||||
SkinType rarity;
|
||||
public float curSpeed => SkinShopManager.GetStatsForRarity(rarity)[curSpeedLevel].speedMultiplier;
|
||||
public float curEnergy => SkinShopManager.GetStatsForRarity(rarity)[curEnergyLevel].moonMultiplier;
|
||||
@@ -36,6 +39,8 @@ public class RocketUpgradePanel : MonoBehaviour
|
||||
public RocketLevel nextSpeedStats =>SkinShopManager.GetStatsForRarity(rarity)[curSpeedLevel];
|
||||
public RocketLevel nextEnergyStats =>SkinShopManager.GetStatsForRarity(rarity)[curEnergyLevel];
|
||||
public RocketLevel nextBoostStats =>SkinShopManager.GetStatsForRarity(rarity)[curBoostLevel];
|
||||
public RocketLevel nextRocketLevel => (curRocketLevel < 10) ? SkinShopManager.GetPriceForRarity(rarity)[curRocketLevel] : null;
|
||||
|
||||
|
||||
|
||||
public float nextSpeed => SkinShopManager.GetStatsForRarity(rarity)[curSpeedLevel+1].speedMultiplier;
|
||||
@@ -58,35 +63,65 @@ public class RocketUpgradePanel : MonoBehaviour
|
||||
curSpeedLevel = data.speedLevel;
|
||||
curEnergyLevel = data.energyLevel;
|
||||
curBoostLevel = data.boostLevel;
|
||||
|
||||
txtRocketLevel.text = "Level " + curRocketLevel;
|
||||
txtEnergyGain.text = $"{ curEnergy } Per moon";
|
||||
txtSpeed.text = $"{curSpeed*100}%";
|
||||
txtBoostConsumption.text = $"{ curBoost *100}%";
|
||||
int maxLevels =SkinShopManager.GetStatsForRarity(rarity).Length;
|
||||
// int maxleve
|
||||
|
||||
if(curEnergyLevel < maxLevels-1) {txtEnergyGain.text += $" -> <color=green> {nextEnergy}</color>";}
|
||||
if(curSpeedLevel < maxLevels-1) {txtSpeed.text += $" -> <color=green> {nextSpeed*100}%</color>";}
|
||||
if(curBoostLevel < maxLevels-1) {txtBoostConsumption.text += $" -> <color=green> {nextBoost*100}%</color>";}
|
||||
bool boostAvailable = curBoostLevel < maxLevels-1;
|
||||
bool speedAvailable = curSpeedLevel < maxLevels-1;
|
||||
bool energyAvailable = curEnergyLevel < maxLevels-1;
|
||||
|
||||
if(energyAvailable) {txtEnergyGain.text += $" -> <color=green> {nextEnergy}</color>";}
|
||||
if(speedAvailable) {txtSpeed.text += $" -> <color=green> {nextSpeed*100}%</color>";}
|
||||
if(boostAvailable) {txtBoostConsumption.text += $" -> <color=green> {nextBoost*100}%</color>";}
|
||||
|
||||
if(curRocketLevel < 10){
|
||||
txtRocketLevel.text += $" -> <color=green> {curRocketLevel+1}</color>";
|
||||
}else{
|
||||
txtRocketLevel.text += " <color=green> <b> MAX! </b></color>";
|
||||
}
|
||||
|
||||
btn_upgrade_boost.interactable = DBmanager.Coins >= nextBoostStats.goldCost && DBmanager.Metal >= nextBoostStats.metalCost && curBoostLevel < maxLevels-1;
|
||||
btn_upgrade_energy.interactable = DBmanager.Coins >= nextEnergyStats.goldCost && DBmanager.Metal >= nextEnergyStats.metalCost&& curEnergyLevel < maxLevels-1;
|
||||
btn_upgrade_speed.interactable = DBmanager.Coins >= nextSpeedStats.goldCost && DBmanager.Metal >= nextSpeedStats.metalCost&& curSpeedLevel < maxLevels-1;
|
||||
|
||||
if(nextRocketLevel == null){
|
||||
btn_upgrade_boost.interactable = false;
|
||||
btn_upgrade_energy.interactable = false;
|
||||
btn_upgrade_speed.interactable=false;
|
||||
btn_upgrade_boost.transform.GetChild(1).gameObject.SetActive(false);
|
||||
btn_upgrade_energy.transform.GetChild(1).gameObject.SetActive(false);
|
||||
btn_upgrade_speed.transform.GetChild(1).gameObject.SetActive(false);
|
||||
|
||||
btn_upgrade_boost.transform.GetChild(1).GetChild(0).gameObject.SetActive(nextBoostStats.goldCost > 0);
|
||||
btn_upgrade_boost.transform.GetChild(1).GetChild(0).GetComponentInChildren<TMP_Text>().text = nextBoostStats.goldCost.ToString();
|
||||
btn_upgrade_boost.transform.GetChild(1).GetChild(1).gameObject.SetActive(nextBoostStats.metalCost > 0);
|
||||
btn_upgrade_boost.transform.GetChild(1).GetChild(1).GetComponentInChildren<TMP_Text>().text = nextBoostStats.metalCost.ToString();
|
||||
}else{
|
||||
btn_upgrade_boost.interactable = DBmanager.Coins >= nextRocketLevel.goldCost && DBmanager.Metal >= nextRocketLevel.metalCost && curRocketLevel < 10 && boostAvailable && curBoostLevel < maxLevels-1;
|
||||
btn_upgrade_energy.interactable = DBmanager.Coins >= nextRocketLevel.goldCost && DBmanager.Metal >= nextRocketLevel.metalCost&& curRocketLevel < 10&& energyAvailable && curEnergyLevel < maxLevels -1;
|
||||
btn_upgrade_speed.interactable = DBmanager.Coins >= nextRocketLevel.goldCost && DBmanager.Metal >= nextRocketLevel.metalCost&& curRocketLevel < 10&& speedAvailable && curSpeedLevel < maxLevels-1;
|
||||
|
||||
btn_upgrade_boost.GetComponentInChildren<TMP_Text>().text = curBoostLevel < maxLevels-1 ? "Upgrade" : "Max!";
|
||||
btn_upgrade_boost.transform.GetChild(1).gameObject.SetActive(boostAvailable);
|
||||
|
||||
btn_upgrade_speed.transform.GetChild(1).GetChild(0).gameObject.SetActive(nextSpeedStats.goldCost > 0);
|
||||
btn_upgrade_speed.transform.GetChild(1).GetChild(0).GetComponentInChildren<TMP_Text>().text = nextSpeedStats.goldCost.ToString();
|
||||
btn_upgrade_speed.transform.GetChild(1).GetChild(1).gameObject.SetActive(nextSpeedStats.metalCost > 0);
|
||||
btn_upgrade_speed.transform.GetChild(1).GetChild(1).GetComponentInChildren<TMP_Text>().text = nextSpeedStats.metalCost.ToString();
|
||||
btn_upgrade_boost.transform.GetChild(1).GetChild(0).gameObject.SetActive(nextRocketLevel.goldCost > 0);
|
||||
btn_upgrade_boost.transform.GetChild(1).GetChild(0).GetComponentInChildren<TMP_Text>().text = nextRocketLevel.goldCost.ToString();
|
||||
btn_upgrade_boost.transform.GetChild(1).GetChild(1).gameObject.SetActive(nextRocketLevel.metalCost > 0);
|
||||
btn_upgrade_boost.transform.GetChild(1).GetChild(1).GetComponentInChildren<TMP_Text>().text = nextRocketLevel.metalCost.ToString();
|
||||
|
||||
btn_upgrade_energy.transform.GetChild(1).GetChild(0).gameObject.SetActive(nextEnergyStats.goldCost > 0);
|
||||
btn_upgrade_energy.transform.GetChild(1).GetChild(0).GetComponentInChildren<TMP_Text>().text = nextEnergyStats.goldCost.ToString();
|
||||
btn_upgrade_energy.transform.GetChild(1).GetChild(1).gameObject.SetActive(nextEnergyStats.metalCost > 0);
|
||||
btn_upgrade_energy.transform.GetChild(1).GetChild(1).GetComponentInChildren<TMP_Text>().text = nextEnergyStats.metalCost.ToString();
|
||||
btn_upgrade_speed.GetComponentInChildren<TMP_Text>().text = curSpeedLevel < maxLevels-1 ? "Upgrade" : "Max!";
|
||||
btn_upgrade_speed.transform.GetChild(1).gameObject.SetActive(speedAvailable);
|
||||
|
||||
btn_upgrade_speed.transform.GetChild(1).GetChild(0).gameObject.SetActive(nextRocketLevel.goldCost > 0);
|
||||
btn_upgrade_speed.transform.GetChild(1).GetChild(0).GetComponentInChildren<TMP_Text>().text = nextRocketLevel.goldCost.ToString();
|
||||
btn_upgrade_speed.transform.GetChild(1).GetChild(1).gameObject.SetActive(nextRocketLevel.metalCost > 0);
|
||||
btn_upgrade_speed.transform.GetChild(1).GetChild(1).GetComponentInChildren<TMP_Text>().text = nextRocketLevel.metalCost.ToString();
|
||||
|
||||
btn_upgrade_energy.GetComponentInChildren<TMP_Text>().text = curEnergyLevel < maxLevels-1 ? "Upgrade" : "Max!";
|
||||
btn_upgrade_energy.transform.GetChild(1).gameObject.SetActive(energyAvailable);
|
||||
|
||||
btn_upgrade_energy.transform.GetChild(1).GetChild(0).gameObject.SetActive(nextRocketLevel.goldCost > 0);
|
||||
btn_upgrade_energy.transform.GetChild(1).GetChild(0).GetComponentInChildren<TMP_Text>().text = nextRocketLevel.goldCost.ToString();
|
||||
btn_upgrade_energy.transform.GetChild(1).GetChild(1).gameObject.SetActive(nextRocketLevel.metalCost > 0);
|
||||
btn_upgrade_energy.transform.GetChild(1).GetChild(1).GetComponentInChildren<TMP_Text>().text = nextRocketLevel.metalCost.ToString();
|
||||
}
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
@@ -100,7 +135,7 @@ public class RocketUpgradePanel : MonoBehaviour
|
||||
DBmanager.UpgradeRocketSpeed(selectedRocket, nextSpeedStats);
|
||||
SkinShopManager.instance.Populate();
|
||||
// MessageDialog.instance.ShowMessage("Success","Rocket Upgraded Successfully!");
|
||||
AudioManager.instnace.ChestOpen();
|
||||
AudioManager.instnace.CollectPickup();
|
||||
// Hide();
|
||||
Show(selectedRocket);
|
||||
|
||||
@@ -116,7 +151,7 @@ public class RocketUpgradePanel : MonoBehaviour
|
||||
DBmanager.UpgradeRocketBoost(selectedRocket, nextBoostStats);
|
||||
SkinShopManager.instance.Populate();
|
||||
// MessageDialog.instance.ShowMessage("Success","Rocket Upgraded Successfully!");
|
||||
AudioManager.instnace.ChestOpen();
|
||||
AudioManager.instnace.CollectPickup();
|
||||
// Hide();
|
||||
Show(selectedRocket);
|
||||
}
|
||||
@@ -131,7 +166,7 @@ public class RocketUpgradePanel : MonoBehaviour
|
||||
DBmanager.UpgradeRocketEnergy(selectedRocket, nextEnergyStats);
|
||||
SkinShopManager.instance.Populate();
|
||||
// MessageDialog.instance.ShowMessage("Success","Rocket Upgraded Successfully!");
|
||||
AudioManager.instnace.ChestOpen();
|
||||
AudioManager.instnace.CollectPickup();
|
||||
// Hide();
|
||||
Show(selectedRocket);
|
||||
|
||||
|
||||
@@ -6,14 +6,14 @@ using UnityEngine.UI;
|
||||
public class SkinShopItem : MonoBehaviour
|
||||
{
|
||||
public Image spaceshipImg;
|
||||
[Tooltip("In order of: normal, rare, legendary. 3 items required")]
|
||||
[Tooltip("In order of: normal, rare, legendary. 5 items required")]
|
||||
public GameObject[] banners;
|
||||
public Image frame;
|
||||
public bool Available;
|
||||
// public GameObject notPurchasedIndicator;
|
||||
public SkinShopItemData skinData;
|
||||
[Header("Stats")]
|
||||
// public TMP_Text txtLevel;
|
||||
public TMP_Text txtLevel;
|
||||
public TMP_Text txtEnergyGain;
|
||||
public TMP_Text txtSpeed;
|
||||
public TMP_Text txtBoostConsumption;
|
||||
@@ -26,6 +26,8 @@ public class SkinShopItem : MonoBehaviour
|
||||
int curEnergyLevel;
|
||||
int curBoostLevel;
|
||||
|
||||
public int curRocketLevel => Mathf.Clamp(curBoostLevel + curEnergyLevel + curSpeedLevel+1,1,10);
|
||||
|
||||
public void Set(SkinShopItemData data, bool available){
|
||||
skinData = data;
|
||||
// newItem.backgroundImg.color = (skinsData.skins[i].skinType==SkinType.Base) ? basicColor : (skinsData.skins[i].skinType==SkinType.Rare ? rareColor : legendaryColor);
|
||||
@@ -42,7 +44,8 @@ public class SkinShopItem : MonoBehaviour
|
||||
banners[1].SetActive(data.skinType== SkinType.Base);
|
||||
}
|
||||
banners[2].SetActive(data.skinType== SkinType.Rare);
|
||||
banners[3].SetActive(data.skinType== SkinType.Legendary);
|
||||
banners[3].SetActive(data.skinType== SkinType.Epic);
|
||||
banners[4].SetActive(data.skinType== SkinType.Legendary);
|
||||
|
||||
//Level
|
||||
rarity = SkinShopManager.GetRarityFromName(data.name);
|
||||
@@ -53,7 +56,7 @@ public class SkinShopItem : MonoBehaviour
|
||||
curBoostLevel = purchasedSkin.boostLevel;
|
||||
}
|
||||
|
||||
// txtLevel.text = "";
|
||||
txtLevel.text = "Level " +curRocketLevel;
|
||||
|
||||
txtEnergyGain.transform.parent.gameObject.SetActive(available);
|
||||
txtSpeed.transform.parent.gameObject.SetActive(available);
|
||||
|
||||
@@ -9,8 +9,9 @@ public class SkinShopManager : MonoBehaviour
|
||||
{
|
||||
public static SkinShopManager instance;
|
||||
public RocketSkinStats rocketStats;
|
||||
public RocketSkinStats rocketPrices;
|
||||
public static RocketSkinStats RocketStats;
|
||||
public static bool availableToUpgrade;
|
||||
// public static bool availableToUpgrade;
|
||||
public NewSkinDisplay newSkinDisplay;
|
||||
public Building skinShopBuilding;
|
||||
public SkinsData skinsData;
|
||||
@@ -50,8 +51,8 @@ public class SkinShopManager : MonoBehaviour
|
||||
}
|
||||
List<SkinShopItemData> skinsAvailableToPurchase= new List<SkinShopItemData>();
|
||||
public void Populate(){
|
||||
int purchasedFlagships=0;
|
||||
int flagshipsCount=0;
|
||||
// int purchasedFlagships=0;
|
||||
// int flagshipsCount=0;
|
||||
|
||||
//Validate skins list
|
||||
if(DBmanager.SkinsPurchased.Count <=0){
|
||||
@@ -73,22 +74,25 @@ public class SkinShopManager : MonoBehaviour
|
||||
skinShopItems = new List<SkinShopItem>();
|
||||
for(int i=0; i<skinsData.skins.Length;i++){
|
||||
int rarity = getRarityInt(skinsData.skins[i]);
|
||||
bool isAvailable = skinShopBuilding.curLevel >= rarity;
|
||||
if(!isAvailable){continue;}
|
||||
// bool isAvailable = skinShopBuilding.curLevel >= rarity;
|
||||
// if(!isAvailable){continue;}
|
||||
|
||||
|
||||
bool isOwned = DBmanager.GetSkinIdByName(skinsData.skins[i].name) >= 0;
|
||||
|
||||
|
||||
if(skinShopBuilding.curLevel == rarity){
|
||||
flagshipsCount++;
|
||||
if(isOwned){
|
||||
purchasedFlagships++;
|
||||
}
|
||||
}
|
||||
// if(skinShopBuilding.curLevel == rarity){
|
||||
// flagshipsCount++;
|
||||
// if(isOwned){
|
||||
// purchasedFlagships++;
|
||||
// }
|
||||
// }
|
||||
|
||||
if(!isOwned){
|
||||
skinsAvailableToPurchase.Add(skinsData.skins[i]);
|
||||
// skinsAvailableToPurchase.Add(skinsData.skins[i]);
|
||||
}else{
|
||||
if(!DBmanager.GetSkinByName(skinsData.skins[i].name).built){
|
||||
continue;
|
||||
}
|
||||
SkinShopItem newItem = Instantiate(listItemPrefab, listItemsParent).GetComponent<SkinShopItem>();
|
||||
|
||||
newItem.Set(skinsData.skins[i],isOwned);
|
||||
@@ -106,7 +110,7 @@ public class SkinShopManager : MonoBehaviour
|
||||
skinShopItems.Add(newItem);
|
||||
}
|
||||
|
||||
availableToUpgrade = purchasedFlagships >= ((float)flagshipsCount/2f);
|
||||
// availableToUpgrade = purchasedFlagships >= ((float)flagshipsCount/2f);
|
||||
|
||||
SelectItem(selectedSkin,true);
|
||||
}
|
||||
@@ -114,7 +118,8 @@ public class SkinShopManager : MonoBehaviour
|
||||
int getRarityInt(SkinShopItemData skin){
|
||||
int rarity = 0;
|
||||
if(skin.skinType == SkinType.Rare){rarity=1;}
|
||||
if(skin.skinType == SkinType.Legendary){rarity=2;}
|
||||
if(skin.skinType == SkinType.Legendary){rarity=3;}
|
||||
if(skin.skinType == SkinType.Epic){rarity=2;}
|
||||
|
||||
return rarity;
|
||||
}
|
||||
@@ -131,7 +136,7 @@ public class SkinShopManager : MonoBehaviour
|
||||
}
|
||||
if(DBmanager.GetSkinIdByName(data.name)>=0){ // <-- purchased
|
||||
btn_Equip.gameObject.SetActive(true);
|
||||
btn_Upgrade.gameObject.SetActive(true);
|
||||
btn_Upgrade.gameObject.SetActive(getRarityInt(data) <= skinShopBuilding.curLevel);
|
||||
btn_Buy.gameObject.SetActive(false);
|
||||
btn_Equip.interactable = GetEquipedSkin() != data.name; // <-- disable equip button if already equipped
|
||||
}else{
|
||||
@@ -208,8 +213,10 @@ public class SkinShopManager : MonoBehaviour
|
||||
rarityIndex=1;
|
||||
}else if(item.skinType == SkinType.Rare){
|
||||
rarityIndex = 2;
|
||||
}else if(item.skinType == SkinType.Epic){
|
||||
rarityIndex = 3;
|
||||
}else{
|
||||
rarityIndex=3;
|
||||
rarityIndex=4;
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -218,6 +225,18 @@ public class SkinShopManager : MonoBehaviour
|
||||
|
||||
return rarityIndex;
|
||||
}
|
||||
public static SkinShopItemData GetSkinDataByName(string name){
|
||||
int rarityIndex = 0;
|
||||
|
||||
foreach(SkinShopItemData item in SkinsData.skins){
|
||||
if(item.name == name){
|
||||
//this is it
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static SkinType GetRarityFromName(string name){
|
||||
return GetRarityFromIndex(GetRarityIndexFromName(name));
|
||||
@@ -230,6 +249,8 @@ public class SkinShopManager : MonoBehaviour
|
||||
return SkinType.Base;
|
||||
}else if(id==2){
|
||||
return SkinType.Rare;
|
||||
}else if(id ==3){
|
||||
return SkinType.Epic;
|
||||
}else{
|
||||
return SkinType.Legendary;
|
||||
}
|
||||
@@ -254,6 +275,8 @@ public class SkinShopManager : MonoBehaviour
|
||||
return RocketStats.commonLevels;
|
||||
}else if(data.skinType == SkinType.Rare){
|
||||
return RocketStats.rareLevels;
|
||||
}else if(data.skinType == SkinType.Epic){
|
||||
return RocketStats.epicLevels;
|
||||
}else{
|
||||
return RocketStats.legendaryLevels;
|
||||
}
|
||||
@@ -266,14 +289,59 @@ public class SkinShopManager : MonoBehaviour
|
||||
return RocketStats.commonLevels;
|
||||
}else if(data == SkinType.Rare){
|
||||
return RocketStats.rareLevels;
|
||||
}else if(data == SkinType.Epic){
|
||||
return RocketStats.epicLevels;
|
||||
}else{
|
||||
return RocketStats.legendaryLevels;
|
||||
}
|
||||
}
|
||||
public static RocketLevel[] GetPriceForRarity(SkinType data){
|
||||
if(data == SkinType.Default){
|
||||
return instance.rocketPrices.baseLevels;
|
||||
}else if(data == SkinType.Base){
|
||||
return instance.rocketPrices.commonLevels;
|
||||
}else if(data == SkinType.Rare){
|
||||
return instance.rocketPrices.rareLevels;
|
||||
}else if(data == SkinType.Epic){
|
||||
return instance.rocketPrices.epicLevels;
|
||||
}else{
|
||||
return instance.rocketPrices.legendaryLevels;
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetRarityName(SkinType data){
|
||||
if(data == SkinType.Default){
|
||||
return "Basic";
|
||||
}else if(data == SkinType.Base){
|
||||
return "Common";
|
||||
}else if(data == SkinType.Rare){
|
||||
return "Rare";
|
||||
}else if(data == SkinType.Epic){
|
||||
return "Epic";
|
||||
}else{
|
||||
return "Legendary";
|
||||
}
|
||||
}
|
||||
|
||||
public static Color GetRarityColor(SkinType data){
|
||||
if(data == SkinType.Default){
|
||||
return Color.grey;
|
||||
}else if(data == SkinType.Base){
|
||||
return Color.green;
|
||||
|
||||
}else if(data == SkinType.Rare){
|
||||
return Color.blue;
|
||||
|
||||
}else if(data == SkinType.Epic){
|
||||
return Color.magenta;
|
||||
|
||||
}else{
|
||||
return Color.red;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class SkinShopItemData{
|
||||
[Serializable]public class SkinShopItemData{
|
||||
public string name;
|
||||
public Sprite image;
|
||||
public int price_gold,price_metal;
|
||||
@@ -285,7 +353,8 @@ public enum SkinType{
|
||||
Default,
|
||||
Base,
|
||||
Rare,
|
||||
Legendary
|
||||
Legendary,
|
||||
Epic
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
|
||||
@@ -178,6 +178,7 @@ public class SpaceshipController : NetworkBehaviour
|
||||
ResetStats();
|
||||
if(MinigameManager.instance.isRanked){
|
||||
DBmanager.SetMetal(DBmanager.Metal + DBmanager.CurrentRank.energyReward);
|
||||
DBmanager.SetMetal(DBmanager.Metal - DBmanager.CurrentRank.entryFee);
|
||||
}
|
||||
if (joystick == null) { joystick = FindObjectOfType<Joystick>(); }
|
||||
FindObjectOfType<CameraFollower>().SetTarget(transform);
|
||||
@@ -557,7 +558,7 @@ public class SpaceshipController : NetworkBehaviour
|
||||
void OnKill()
|
||||
{
|
||||
Kills++;
|
||||
Scores += 10; //TODO: Need to change Scores on kills?
|
||||
// Scores += 10; //TODO: Need to change Scores on kills?
|
||||
// scaleMultiplier += 0.05f;
|
||||
// OnScaleChanged(scaleMultiplier, scaleMultiplier);
|
||||
IncreaseTrail(trailIncrementRate);
|
||||
@@ -608,10 +609,13 @@ public class SpaceshipController : NetworkBehaviour
|
||||
IncreaseTrail(trailIncrementRate);
|
||||
// scaleMultiplier += 0.05f;
|
||||
moonsCollected++;
|
||||
Scores += 2;
|
||||
break;
|
||||
|
||||
case PickupItem.PickupType.Star:
|
||||
IncreaseTrail(trailIncrementRate / 2f);
|
||||
Scores += 1;
|
||||
|
||||
// scaleMultiplier += 0.025f;
|
||||
|
||||
break;
|
||||
@@ -638,7 +642,7 @@ public class SpaceshipController : NetworkBehaviour
|
||||
public void Die(string killer)
|
||||
{
|
||||
|
||||
MinigameManager.instance.SpawnLeftoverPickups(transform.position, Scores);
|
||||
MinigameManager.instance.SpawnLeftoverPickups(transform.position, (int)((float)Scores/4f));
|
||||
Debug.Log($"Sending death signal to {pname} by {killer}");
|
||||
|
||||
//Handle Respawning
|
||||
|
||||
@@ -31,7 +31,7 @@ public class NewLoginManager : MonoBehaviour
|
||||
}
|
||||
|
||||
public void Register(){
|
||||
if(usernameInput.text.Length >4){
|
||||
if(usernameInput.text.Length >=2){
|
||||
StartCoroutine(register());
|
||||
loadingPanel.SetActive(true);
|
||||
}else{
|
||||
@@ -102,8 +102,8 @@ public class NewLoginManager : MonoBehaviour
|
||||
}
|
||||
|
||||
public void OnUsernameInputChanged(string newValue){
|
||||
btn_login.interactable= (usernameInput.text.Length > 4);
|
||||
usernameWarning.SetActive(usernameInput.text.Length<= 4);
|
||||
btn_login.interactable= (usernameInput.text.Length > 2);
|
||||
usernameWarning.SetActive(usernameInput.text.Length< 2);
|
||||
}
|
||||
|
||||
void OnRegisterButton(){
|
||||
|
||||
@@ -11,28 +11,35 @@ public class SelectedItemMenu : MonoBehaviour
|
||||
public CollectBtn collectBtn;
|
||||
// public Button joinHallBtn;
|
||||
public Button repairRocketsBtn;
|
||||
public Button tradingPostBtn;
|
||||
public Button designLabBtn;
|
||||
|
||||
public TradingPost tradingPost;
|
||||
public DesignLab designLab;
|
||||
|
||||
[Header("info menu")]
|
||||
public GameObject infoMenu;
|
||||
public GameObject[] tierIndicators;
|
||||
public TMP_Text levelTxt;
|
||||
public TMP_Text buildingName;
|
||||
public TMP_Text descriptionTxt;
|
||||
|
||||
[Header("upgrade menu")]
|
||||
public GameObject upgradeMenu;
|
||||
public GameObject goldmineUpgradeMenu;
|
||||
public TMP_Text goldMineUpgradeMenuTitle;
|
||||
public Button btn_gold_prod;
|
||||
public Button btn_gold_cap;
|
||||
|
||||
public Transform upgrade_statParent;
|
||||
public GameObject[] upgrade_tierIndicators;
|
||||
public TMP_Text upgrade_tierTxt;
|
||||
public TMP_Text upgrade_buildingName;
|
||||
public TMP_Text extraDetailsTxt;
|
||||
public Button upgradeBtn;
|
||||
|
||||
[Header("Special buildings")]
|
||||
public BuildingData mainHall;
|
||||
public BuildingData designLabBuilding;
|
||||
public BuildingData rocketRepair;
|
||||
public BuildingData tradePost;
|
||||
|
||||
void Start()
|
||||
{
|
||||
@@ -42,6 +49,8 @@ public class SelectedItemMenu : MonoBehaviour
|
||||
upgradeBtn.onClick.AddListener(OnUpgrade);
|
||||
collectBtn.btn.onClick.AddListener(OnCollect);
|
||||
repairRocketsBtn.onClick.AddListener(OpenSkinMenu);
|
||||
tradingPostBtn.onClick.AddListener(OpenTradingPost);
|
||||
designLabBtn.onClick.AddListener(OpenDesignLab);
|
||||
|
||||
btn_gold_cap.onClick.AddListener(OnGoldmineCapUpgrade);
|
||||
btn_gold_prod.onClick.AddListener(OnGoldmineProdUpgrade);
|
||||
@@ -72,6 +81,8 @@ public class SelectedItemMenu : MonoBehaviour
|
||||
|
||||
// joinHallBtn.gameObject.SetActive((Selector.selectedData == mainHall));
|
||||
repairRocketsBtn.gameObject.SetActive((Selector.selectedData == rocketRepair));
|
||||
tradingPostBtn.gameObject.SetActive((Selector.selectedData == tradePost));
|
||||
designLabBtn.gameObject.SetActive((Selector.selectedData == designLabBuilding));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -95,6 +106,8 @@ public class SelectedItemMenu : MonoBehaviour
|
||||
upgradeMenu.SetActive(true);
|
||||
upgrade_buildingName.text = Selector.selectedBuilding.buildingData.buildingName;
|
||||
bool isGoldMine = Selector.selectedBuilding.GetComponent<GoldMine>()!=null;
|
||||
bool isSolarPanel = Selector.selectedBuilding.GetComponent<SolarPanels>()!=null;
|
||||
|
||||
List<BuildingStat> stats = Selector.selectedBuilding.buildingData.levels[Selector.selectedBuilding.curLevel].stats;
|
||||
for (int i = 0; i < upgrade_statParent.childCount; i++)
|
||||
{
|
||||
@@ -104,50 +117,66 @@ public class SelectedItemMenu : MonoBehaviour
|
||||
{
|
||||
upgrade_statParent.GetChild(i).GetChild(0).GetComponent<TMP_Text>().text = stats[i].name;
|
||||
string nextLevelStat = ((Selector.selectedBuilding.buildingData.levels.Count-1 > Selector.selectedBuilding.curLevel) ? $" <color=green> -> {Selector.selectedBuilding.buildingData.levels[Selector.selectedBuilding.curLevel+1].stats[i].value}</color>" : "");
|
||||
upgrade_statParent.GetChild(i).GetChild(1).GetComponent<TMP_Text>().text = stats[i].value + (isGoldMine? "":nextLevelStat);
|
||||
upgrade_statParent.GetChild(i).GetChild(1).GetComponent<TMP_Text>().text = stats[i].value + (isGoldMine || isSolarPanel? "":nextLevelStat);
|
||||
upgrade_statParent.GetChild(i).GetChild(2).GetComponent<Image>().sprite = stats[i].image;
|
||||
}
|
||||
}
|
||||
|
||||
if(isGoldMine){ //Special path for gold mine
|
||||
for(int i=0; i < upgrade_tierIndicators.Length;i++){ //No rarity tag for you
|
||||
upgrade_tierIndicators[i].SetActive(false);
|
||||
}
|
||||
|
||||
if(isGoldMine || isSolarPanel){ //Special path for gold mine
|
||||
// for(int i=0; i < upgrade_tierIndicators.Length;i++){ //No rarity tag for you
|
||||
// upgrade_tierIndicators[i].SetActive(false);
|
||||
// }
|
||||
upgrade_tierTxt.text = "";
|
||||
if (Selector.selectedBuilding.curLevel < Selector.selectedData.levels.Count - 1){
|
||||
upgradeBtn.interactable = true;
|
||||
upgradeBtn.GetComponentInChildren<TMP_Text>().text = "Upgrade";
|
||||
// upgradeBtn.GetComponentInChildren<TMP_Text>().text = "Upgrade";
|
||||
upgradeBtn.transform.GetChild(1).gameObject.SetActive(false);
|
||||
upgradeBtn.transform.GetChild(2).gameObject.SetActive(false);
|
||||
upgradeBtn.transform.GetChild(3).gameObject.SetActive(true);
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
upgradeBtn.transform.GetChild(3).gameObject.SetActive(false); //Not gold mine, no choice
|
||||
|
||||
for(int i=0; i < upgrade_tierIndicators.Length;i++){
|
||||
upgrade_tierIndicators[i].SetActive( Selector.selectedBuilding.curLevel == i);
|
||||
}
|
||||
upgrade_tierTxt.text = BuildingManager.GetStatValue(Selector.selectedBuilding,"Level");
|
||||
if (Selector.selectedBuilding.curLevel < Selector.selectedData.levels.Count - 1)
|
||||
{
|
||||
upgradeBtn.interactable = (Selector.selectedData.levels[Selector.selectedBuilding.curLevel + 1].price < DBmanager.Coins);
|
||||
upgradeBtn.GetComponentInChildren<TMP_Text>().text = Selector.selectedData.levels[Selector.selectedBuilding.curLevel + 1].price.ToString();
|
||||
int goldPrice = Selector.selectedData.levels[Selector.selectedBuilding.curLevel + 1].price;
|
||||
int metalPrice = Selector.selectedData.levels[Selector.selectedBuilding.curLevel + 1].metal_price;
|
||||
|
||||
upgradeBtn.interactable = goldPrice <= DBmanager.Coins && metalPrice <= DBmanager.Metal;
|
||||
upgradeBtn.transform.GetChild(1).gameObject.SetActive(true);
|
||||
upgradeBtn.transform.GetChild(2).gameObject.SetActive(false);
|
||||
|
||||
upgradeBtn.transform.GetChild(1).GetChild(0).gameObject.SetActive(goldPrice>0);
|
||||
upgradeBtn.transform.GetChild(1).GetChild(0).GetComponentInChildren<TMP_Text>().text = goldPrice.ToString();
|
||||
upgradeBtn.transform.GetChild(1).GetChild(1).gameObject.SetActive(metalPrice>0);
|
||||
upgradeBtn.transform.GetChild(1).GetChild(1).GetComponentInChildren<TMP_Text>().text = metalPrice.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
upgradeBtn.interactable = false;
|
||||
upgradeBtn.GetComponentInChildren<TMP_Text>().text = "MAX!";
|
||||
// upgradeBtn.GetComponentInChildren<TMP_Text>().text = "MAX!";
|
||||
upgradeBtn.transform.GetChild(1).gameObject.SetActive(false);
|
||||
upgradeBtn.transform.GetChild(2).gameObject.SetActive(true);
|
||||
|
||||
|
||||
Debug.Log("Already max");
|
||||
}
|
||||
|
||||
if(Selector.selectedData == rocketRepair){
|
||||
SkinShopManager.instance.Populate();
|
||||
upgradeBtn.interactable= (SkinShopManager.availableToUpgrade);
|
||||
if(!SkinShopManager.availableToUpgrade && Selector.selectedBuilding.curLevel < Selector.selectedData.levels.Count-1){
|
||||
// MessageDialog.instance.ShowMessage("Notice!","You have to purchase half of the best rarity skins available to upgrade");
|
||||
extraDetailsTxt.gameObject.SetActive(true);
|
||||
extraDetailsTxt.text = "You have to purchase half of the best rarity skins available to upgrade";
|
||||
extraDetailsTxt.color = Color.red;
|
||||
}
|
||||
}
|
||||
// if(Selector.selectedData == rocketRepair){
|
||||
// SkinShopManager.instance.Populate();
|
||||
// upgradeBtn.interactable= (SkinShopManager.availableToUpgrade);
|
||||
// if(!SkinShopManager.availableToUpgrade && Selector.selectedBuilding.curLevel < Selector.selectedData.levels.Count-1){
|
||||
// // MessageDialog.instance.ShowMessage("Notice!","You have to purchase half of the best rarity skins available to upgrade");
|
||||
// extraDetailsTxt.gameObject.SetActive(true);
|
||||
// extraDetailsTxt.text = "You have to purchase half of the best rarity skins available to upgrade";
|
||||
// extraDetailsTxt.color = Color.red;
|
||||
// }
|
||||
// }
|
||||
|
||||
if (upgrade_statParent.childCount < stats.Count)
|
||||
{
|
||||
@@ -159,6 +188,7 @@ public class SelectedItemMenu : MonoBehaviour
|
||||
{
|
||||
if(Selector.selectedBuilding.GetComponent<GoldMine>()!=null){
|
||||
AudioManager.instnace.UIPopup();
|
||||
goldMineUpgradeMenuTitle.text = "Upgrade Gold Mine";
|
||||
goldmineUpgradeMenu.SetActive(true);
|
||||
int L = Selector.selectedBuilding.curLevel+1;
|
||||
int C = GoldMine.GetCapacityRateByLevel(L);
|
||||
@@ -202,6 +232,52 @@ public class SelectedItemMenu : MonoBehaviour
|
||||
|
||||
|
||||
return;
|
||||
}else if(Selector.selectedBuilding.GetComponent<SolarPanels>()!=null){
|
||||
AudioManager.instnace.UIPopup();
|
||||
goldmineUpgradeMenu.SetActive(true);
|
||||
goldMineUpgradeMenuTitle.text = "Upgrade Solar Panels";
|
||||
|
||||
int L = Selector.selectedBuilding.curLevel+1;
|
||||
int C = SolarPanels.GetCapacityRateByLevel(L);
|
||||
int P = SolarPanels.GetProductionRateByLevel(L);
|
||||
//Calculate prices
|
||||
int gold_cost_p = SolarPanels.GetGoldCostForProduction(L);
|
||||
int metal_cost_p = SolarPanels.GetMetalCostForProduction(L);
|
||||
|
||||
int gold_cost_c = SolarPanels.GetGoldCostForCapacity(L);
|
||||
int metal_cost_c = SolarPanels.GetMetalCostForCapacity(L);
|
||||
if(P>=SolarPanels.LevelsCount){
|
||||
btn_gold_prod.interactable=false;
|
||||
btn_gold_prod.transform.Find("Price/txt_price").GetComponent<TMP_Text>().text = "Max!";
|
||||
btn_gold_prod.transform.Find("Price/txt_price_metal").gameObject.SetActive(false);
|
||||
btn_gold_prod.transform.Find("Price/txt_price").gameObject.SetActive(true);
|
||||
}
|
||||
else{
|
||||
bool affroadable = DBmanager.Coins >= gold_cost_p && DBmanager.Metal >= metal_cost_p;
|
||||
btn_gold_prod.interactable=affroadable;
|
||||
btn_gold_prod.transform.Find("Price/txt_price").GetComponent<TMP_Text>().text = gold_cost_p.ToString();
|
||||
btn_gold_prod.transform.Find("Price/txt_price_metal").GetComponent<TMP_Text>().text = metal_cost_p.ToString();
|
||||
btn_gold_prod.transform.Find("Price/txt_price").gameObject.SetActive(gold_cost_p>0);
|
||||
btn_gold_prod.transform.Find("Price/txt_price_metal").gameObject.SetActive(metal_cost_p>0);
|
||||
}
|
||||
if(C>=SolarPanels.LevelsCount){
|
||||
btn_gold_cap.interactable = false;
|
||||
btn_gold_cap.transform.Find("Price/txt_price").GetComponent<TMP_Text>().text = "Max!";
|
||||
btn_gold_cap.transform.Find("Price/txt_price_metal").gameObject.SetActive(false);
|
||||
btn_gold_cap.transform.Find("Price/txt_price").gameObject.SetActive(true);
|
||||
}
|
||||
else{
|
||||
bool affroadable = DBmanager.Coins >= gold_cost_c && DBmanager.Metal >= metal_cost_c;
|
||||
btn_gold_cap.interactable=affroadable;
|
||||
btn_gold_cap.transform.Find("Price/txt_price").GetComponent<TMP_Text>().text = gold_cost_c.ToString();
|
||||
btn_gold_cap.transform.Find("Price/txt_price_metal").GetComponent<TMP_Text>().text = metal_cost_c.ToString();
|
||||
btn_gold_cap.transform.Find("Price/txt_price").gameObject.SetActive(gold_cost_c > 0);
|
||||
btn_gold_cap.transform.Find("Price/txt_price_metal").gameObject.SetActive(metal_cost_c > 0);
|
||||
|
||||
|
||||
}
|
||||
return;
|
||||
|
||||
}
|
||||
upgradeBtn.interactable= false;
|
||||
Selector.selectedBuilding.Upgrade();
|
||||
@@ -209,27 +285,51 @@ public class SelectedItemMenu : MonoBehaviour
|
||||
}
|
||||
|
||||
public void OnGoldmineCapUpgrade(){
|
||||
int L = Selector.selectedBuilding.curLevel+1;
|
||||
int C = GoldMine.GetCapacityRateByLevel(L);
|
||||
if(C >=GoldMine.LevelsCount){return;}
|
||||
int P = GoldMine.GetProductionRateByLevel(L);
|
||||
if(Selector.selectedBuilding.GetComponent<GoldMine>()!=null){
|
||||
int L = Selector.selectedBuilding.curLevel+1;
|
||||
int C = GoldMine.GetCapacityRateByLevel(L);
|
||||
if(C >=GoldMine.LevelsCount){return;}
|
||||
int P = GoldMine.GetProductionRateByLevel(L);
|
||||
|
||||
int newLevel = GoldMine.GetLevelByRates(C + 1, P);
|
||||
upgradeBtn.interactable= false;
|
||||
Selector.selectedBuilding.Upgrade(newLevel:newLevel-1, gold_cost:GoldMine.GetGoldCostForCapacity(L), metal_cost: GoldMine.GetMetalCostForCapacity(L) );
|
||||
goldmineUpgradeMenu.SetActive(false);
|
||||
OnUpgradeMenuClicked();
|
||||
int newLevel = GoldMine.GetLevelByRates(C + 1, P);
|
||||
upgradeBtn.interactable= false;
|
||||
Selector.selectedBuilding.Upgrade(newLevel:newLevel-1, gold_cost:GoldMine.GetGoldCostForCapacity(L), metal_cost: GoldMine.GetMetalCostForCapacity(L) );
|
||||
goldmineUpgradeMenu.SetActive(false);
|
||||
OnUpgradeMenuClicked();
|
||||
}else{
|
||||
int L = Selector.selectedBuilding.curLevel+1;
|
||||
int C = SolarPanels.GetCapacityRateByLevel(L);
|
||||
if(C >=SolarPanels.LevelsCount){return;}
|
||||
int P = SolarPanels.GetProductionRateByLevel(L);
|
||||
|
||||
int newLevel = SolarPanels.GetLevelByRates(C + 1, P);
|
||||
upgradeBtn.interactable= false;
|
||||
Selector.selectedBuilding.Upgrade(newLevel:newLevel-1, gold_cost:SolarPanels.GetGoldCostForCapacity(L), metal_cost: SolarPanels.GetMetalCostForCapacity(L) );
|
||||
goldmineUpgradeMenu.SetActive(false);
|
||||
OnUpgradeMenuClicked();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnGoldmineProdUpgrade(){
|
||||
int L = Selector.selectedBuilding.curLevel+1;
|
||||
int C = GoldMine.GetCapacityRateByLevel(L);
|
||||
int P = GoldMine.GetProductionRateByLevel(L);
|
||||
if(P >=GoldMine.LevelsCount){return;}
|
||||
int newLevel = GoldMine.GetLevelByRates(C, P+1);
|
||||
upgradeBtn.interactable= false;
|
||||
Selector.selectedBuilding.Upgrade(newLevel:newLevel-1, gold_cost: GoldMine.GetGoldCostForProduction(L), metal_cost: GoldMine.GetMetalCostForProduction(L));
|
||||
if(Selector.selectedBuilding.GetComponent<GoldMine>()!=null){
|
||||
|
||||
int L = Selector.selectedBuilding.curLevel+1;
|
||||
int C = GoldMine.GetCapacityRateByLevel(L);
|
||||
int P = GoldMine.GetProductionRateByLevel(L);
|
||||
if(P >=GoldMine.LevelsCount){return;}
|
||||
int newLevel = GoldMine.GetLevelByRates(C, P+1);
|
||||
upgradeBtn.interactable= false;
|
||||
Selector.selectedBuilding.Upgrade(newLevel:newLevel-1, gold_cost: GoldMine.GetGoldCostForProduction(L), metal_cost: GoldMine.GetMetalCostForProduction(L));
|
||||
}else{
|
||||
int L = Selector.selectedBuilding.curLevel+1;
|
||||
int C = SolarPanels.GetCapacityRateByLevel(L);
|
||||
int P = SolarPanels.GetProductionRateByLevel(L);
|
||||
if(P >=SolarPanels.LevelsCount){return;}
|
||||
int newLevel = SolarPanels.GetLevelByRates(C, P+1);
|
||||
upgradeBtn.interactable= false;
|
||||
Selector.selectedBuilding.Upgrade(newLevel:newLevel-1, gold_cost: SolarPanels.GetGoldCostForProduction(L), metal_cost: SolarPanels.GetMetalCostForProduction(L));
|
||||
|
||||
}
|
||||
goldmineUpgradeMenu.SetActive(false);
|
||||
OnUpgradeMenuClicked();
|
||||
}
|
||||
@@ -240,9 +340,7 @@ public class SelectedItemMenu : MonoBehaviour
|
||||
|
||||
infoMenu.SetActive(true);
|
||||
buildingName.text = Selector.selectedBuilding.buildingData.buildingName;
|
||||
for(int i=0; i < tierIndicators.Length;i++){
|
||||
tierIndicators[i].SetActive( Selector.selectedBuilding.curLevel == i);
|
||||
}
|
||||
levelTxt.text = BuildingManager.GetStatValue(Selector.selectedBuilding, "Level");
|
||||
descriptionTxt.text = Selector.selectedBuilding.buildingData.description;
|
||||
|
||||
AudioManager.instnace.UIPopup();
|
||||
@@ -251,7 +349,16 @@ public class SelectedItemMenu : MonoBehaviour
|
||||
public void OpenSkinMenu(){
|
||||
SkinShopManager.instance.Show();
|
||||
AudioManager.instnace.UIPopup();
|
||||
}
|
||||
|
||||
public void OpenTradingPost(){
|
||||
tradingPost.Show();
|
||||
AudioManager.instnace.UIPopup();
|
||||
}
|
||||
|
||||
public void OpenDesignLab(){
|
||||
designLab.Show();
|
||||
AudioManager.instnace.UIPopup();
|
||||
}
|
||||
|
||||
void OnCollect(){
|
||||
|
||||
81
Assets/Game/Scripts/SolarPanels.cs
Normal file
81
Assets/Game/Scripts/SolarPanels.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class SolarPanels : MonoBehaviour
|
||||
{
|
||||
public static int LevelsCount => levelsCount;
|
||||
public static int levelsCount => Stats.levels.Length;
|
||||
public Sprite statIcon;
|
||||
public GoldMineData solar_stats;
|
||||
public static GoldMineData Stats;
|
||||
// static int ProductionMultiplier=50;
|
||||
// static int CapacityMultiplier=1000;
|
||||
// static int gold_prod_upgrade_cost = 3000;
|
||||
// static int gold_cap_upgrade_cost = 2500;
|
||||
void Awake()
|
||||
{
|
||||
Stats = solar_stats;
|
||||
BuildingData data =GetComponent<Building>().buildingData;
|
||||
data.levels = new List<BuildingLevel>();
|
||||
data.productinoRates = new float[levelsCount*levelsCount];
|
||||
Debug.Log($"Solar mine levels combos:{levelsCount}");
|
||||
for(int i=0; i < levelsCount * levelsCount; i++){
|
||||
int l = i+1;
|
||||
int lvl = (i%levelsCount);
|
||||
int p = GetProductionRateByLevel(l);
|
||||
int c = GetCapacityRateByLevel(l);
|
||||
int L = GetLevelByRates(c,p);
|
||||
// Debug.Log($"Level:{l},{L},{lvl} ,Prod:{p}, Capactiy:{c}");
|
||||
|
||||
List<BuildingStat> stats = new List<BuildingStat>();
|
||||
// stats.Add(new BuildingStat("Gold per hour", (p * ProductionMultiplier).ToString(),statIcon));
|
||||
// stats.Add(new BuildingStat("Capacity", (c * CapacityMultiplier).ToString(),statIcon));
|
||||
stats.Add(new BuildingStat("Energy per hour", (solar_stats.levels[p-1].Production).ToString(),statIcon));
|
||||
stats.Add(new BuildingStat("Capacity", (solar_stats.levels[c-1].Capacity).ToString(),statIcon));
|
||||
data.levels.Add(new BuildingLevel(l,stats,solar_stats.levels[lvl].costGold,solar_stats.levels[lvl].costMetal));
|
||||
data.levels[i].xpGain = (i > 0) ? 150 : 0;
|
||||
data.productinoRates[i] = solar_stats.levels[p-1].Production;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
//Note for future me: Refer to the sketch you draw on laptop to understand below equations
|
||||
public static int GetProductionRateByLevel(int level){
|
||||
//P = L - C - (2l-3)
|
||||
int l = Mathf.CeilToInt((float)level/(float)levelsCount);
|
||||
return l;
|
||||
}
|
||||
|
||||
public static int GetCapacityRateByLevel(int level){
|
||||
//C = L -3(l - 1)
|
||||
int l = Mathf.CeilToInt((float)level/(float)levelsCount);
|
||||
return level - levelsCount * (l - 1);
|
||||
}
|
||||
|
||||
public static int GetLevelByRates(int Capacity, int Production){
|
||||
//L = 3P + C -3
|
||||
return (levelsCount*Production) + Capacity - levelsCount;
|
||||
}
|
||||
|
||||
public static int GetGoldCostForProduction(int level){
|
||||
int Level = GetProductionRateByLevel(level);
|
||||
int cost = 0;
|
||||
try{cost = Stats.levels[Level%levelsCount].costMetal;}catch{
|
||||
Debug.LogError("Error at receiving gold cost for level " + level);
|
||||
}
|
||||
return cost;
|
||||
}
|
||||
public static int GetGoldCostForCapacity(int level){
|
||||
int Level = GetCapacityRateByLevel(level);
|
||||
return Stats.levels[ Level%levelsCount].costMetal;
|
||||
}
|
||||
public static int GetMetalCostForProduction(int level){
|
||||
int Level = GetProductionRateByLevel(level);
|
||||
return Stats.levels[ Level%levelsCount].costGold;
|
||||
}
|
||||
public static int GetMetalCostForCapacity(int level){
|
||||
int Level = GetCapacityRateByLevel(level);
|
||||
return Stats.levels[ Level%levelsCount].costGold;
|
||||
}
|
||||
}
|
||||
11
Assets/Game/Scripts/SolarPanels.cs.meta
Normal file
11
Assets/Game/Scripts/SolarPanels.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f749ffca00877c84bd7e8c50e80e88c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -63,6 +63,14 @@ public class DBmanager : MonoBehaviour
|
||||
public static List<int> ExpPassCollected => expPassCollected;
|
||||
public static List<InventoryEntry> Inventory => inventory;
|
||||
public static List<PurchasedSkin> SkinsPurchased => skinsPurchased;
|
||||
public static List<PurchasedSkin> Blueprints {get{
|
||||
List<PurchasedSkin> m_blueprints = new List<PurchasedSkin>();
|
||||
foreach(PurchasedSkin skin in SkinsPurchased){
|
||||
if(!skin.built){m_blueprints.Add(skin);}
|
||||
}
|
||||
return m_blueprints;
|
||||
}}
|
||||
|
||||
|
||||
|
||||
public static bool LoggedIn { get { return username != null; } }
|
||||
@@ -132,6 +140,19 @@ public class DBmanager : MonoBehaviour
|
||||
username = null;
|
||||
}
|
||||
|
||||
public static RankLevel GetRankForTrophies(int trophies){
|
||||
RankLevel rank = RankLevels[0];
|
||||
foreach(RankLevel level in RankLevels){
|
||||
if(trophies < level.minimumTrophies){
|
||||
break;
|
||||
}else{
|
||||
rank = level;
|
||||
}
|
||||
}
|
||||
|
||||
return rank;
|
||||
}
|
||||
|
||||
public static async Task<DateTime> GetNetworkTime()
|
||||
{
|
||||
int unixTime = 0;
|
||||
@@ -279,7 +300,7 @@ public class DBmanager : MonoBehaviour
|
||||
WWWForm form = new WWWForm();
|
||||
form.AddField("name", username);
|
||||
form.AddField("coins", newValue);
|
||||
coins = newValue;
|
||||
coins = Mathf.Clamp(newValue,0,int.MaxValue);
|
||||
if (justOffline) { return; }
|
||||
using (UnityWebRequest www = UnityWebRequest.Post(phpRoot + "set_coins.php", form))
|
||||
{
|
||||
@@ -715,6 +736,20 @@ public class DBmanager : MonoBehaviour
|
||||
skinsPurchased.Add(new PurchasedSkin(){name= data.name});
|
||||
UpdatePurchasedSkins();
|
||||
}
|
||||
public static void AddSkinBlueprint(SkinShopItemData data){
|
||||
skinsPurchased.Add(new PurchasedSkin(){name= data.name,built=false});
|
||||
UpdatePurchasedSkins();
|
||||
}
|
||||
|
||||
public static void BuildBlueprint(string name){
|
||||
for(int i=0; i < skinsPurchased.Count; i++){
|
||||
if(skinsPurchased[i].name == name){
|
||||
skinsPurchased[i].built= true;
|
||||
UpdatePurchasedSkins();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async static void UpdatePurchasedSkins(){
|
||||
string output = JsonConvert.SerializeObject(skinsPurchased);
|
||||
@@ -1094,4 +1129,5 @@ public class PurchasedSkin{
|
||||
public int speedLevel;
|
||||
public int boostLevel;
|
||||
public int energyLevel;
|
||||
public bool built=true;
|
||||
}
|
||||
@@ -11,4 +11,13 @@ public class RankLevel{
|
||||
public int energyReward;
|
||||
public Sprite image;
|
||||
public Color color;
|
||||
}
|
||||
|
||||
|
||||
public static class ExtensionMethods
|
||||
{
|
||||
public static int RoundOff (this int i)
|
||||
{
|
||||
return ((int)Mathf.Round((float)i / 10f)) * 10;
|
||||
}
|
||||
}
|
||||
41
Assets/Game/Scripts/TabUI.cs
Normal file
41
Assets/Game/Scripts/TabUI.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class TabUI : MonoBehaviour
|
||||
{
|
||||
public TabUIElement[] elements;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
for(int i =0; i < elements.Length; i++){
|
||||
int index = i;
|
||||
elements[i].tabElement.GetComponent<Button>().onClick.AddListener(()=>{SelectItem(index);});
|
||||
}
|
||||
|
||||
SelectItem(0);
|
||||
}
|
||||
|
||||
public void SelectItem(int index){
|
||||
for(int i=0; i< elements.Length; i++){
|
||||
SetElementFocus(elements[i],i == index);
|
||||
}
|
||||
}
|
||||
|
||||
void SetElementFocus(TabUIElement element, bool value){
|
||||
element.tabElement.GetComponentInChildren<TMP_Text>().color = value ? Color.white : new Color(74f/250f,172f/250f,247f/250f);
|
||||
element.tabElement.transform.GetChild(1).gameObject.SetActive(value);
|
||||
element.panel.SetActive(value);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class TabUIElement{
|
||||
public GameObject tabElement;
|
||||
public GameObject panel;
|
||||
}
|
||||
11
Assets/Game/Scripts/TabUI.cs.meta
Normal file
11
Assets/Game/Scripts/TabUI.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ffb62a8bb7cf38e448889ceb42134195
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
85
Assets/Game/Scripts/TradingPost.cs
Normal file
85
Assets/Game/Scripts/TradingPost.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
public class TradingPost : MonoBehaviour
|
||||
{
|
||||
public Building building;
|
||||
|
||||
public TMP_Text txtMetalAmount;
|
||||
public TMP_Text txtGoldAmount;
|
||||
public Slider metalSlider;
|
||||
// public Slider metalSlider;
|
||||
public TMP_Text warningTxt;
|
||||
public Button tradeButton;
|
||||
void Start()
|
||||
{
|
||||
metalSlider.onValueChanged.AddListener(OnGoldChanged);
|
||||
tradeButton.onClick.AddListener(OnTrade);
|
||||
Refresh();
|
||||
}
|
||||
|
||||
public void Show(){
|
||||
gameObject.SetActive(true);
|
||||
Refresh();
|
||||
}
|
||||
|
||||
public void Hide(){
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
|
||||
int metalCount = 10;
|
||||
public int goldCount => goldPerMetal * metalCount /10;
|
||||
public int goldPerMetal => (int)(float.Parse(building.buildingData.levels[building.curLevel].stats[0].value) * 10);
|
||||
|
||||
void OnGoldChanged(float value){
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void OnTrade(){
|
||||
MessageDialog.instance.ShowQuestion("Are you sure?", $"You are about to trade <b>{metalCount} Energy</b> for <b>{goldCount} Coins</b>", OnYes:OnTradeConfirmed, OnNo:()=>{});
|
||||
}
|
||||
|
||||
void OnTradeConfirmed(){
|
||||
if(Refresh()==1){
|
||||
MessageDialog.instance.ShowMessage("Error", "You need to have atleast 10 golds to trade.");
|
||||
return;
|
||||
}
|
||||
Hide();
|
||||
DBmanager.SetCoins(DBmanager.Coins + goldCount);
|
||||
DBmanager.SetMetal(DBmanager.Metal - metalCount);
|
||||
}
|
||||
|
||||
public int Refresh(){
|
||||
if(DBmanager.Coins < 10){
|
||||
warningTxt.text = "You need atleast 10 golds to trade";
|
||||
tradeButton.interactable = false;
|
||||
metalSlider.interactable = false;
|
||||
txtGoldAmount.text = "0";
|
||||
txtMetalAmount.text = "0";
|
||||
return 1;
|
||||
}
|
||||
tradeButton.interactable = true;
|
||||
metalSlider.interactable = true;
|
||||
warningTxt.text = "";
|
||||
|
||||
float selectedPart = (metalSlider.value/metalSlider.maxValue) * DBmanager.Metal;
|
||||
metalCount = ((int)selectedPart).RoundOff();
|
||||
|
||||
|
||||
if(metalCount > DBmanager.Coins){
|
||||
metalCount -= 10;
|
||||
}
|
||||
if(metalCount <= 0){
|
||||
metalCount =10;
|
||||
}
|
||||
txtMetalAmount.text = metalCount.ToString();
|
||||
|
||||
txtGoldAmount.text = (goldCount).ToString();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Game/Scripts/TradingPost.cs.meta
Normal file
11
Assets/Game/Scripts/TradingPost.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0c6db446da4510207a6e71832aeea483
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user