Individual upgrades for gold mine
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a74ca5aa1c88e784f8caa5f8fb3cb6c2
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c4e3e3041d1151d48a662a0f0796672e
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 22c0c39bb66984f449489395e7ed3b96
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -5,6 +5,7 @@ public class Building : MonoBehaviour
|
||||
{
|
||||
public BuildingData buildingData;
|
||||
public int curLevel;
|
||||
public int[] additionalLevels;
|
||||
public Outline[] outlines;
|
||||
public bool autoGetOutlines = true;
|
||||
|
||||
@@ -50,10 +51,10 @@ public class Building : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void Upgrade(){
|
||||
public void Upgrade(int newLevel =-1, int cost =-1){
|
||||
if(curLevel >= buildingData.levels.Count-1){Debug.Log("Already max");return;}
|
||||
|
||||
int cost = buildingData.levels[curLevel+1].price;
|
||||
if(cost<0){cost = buildingData.levels[curLevel+1].price;}
|
||||
Debug.Log("Upgrading " + buildingData.buildingName + " for " + cost + " coins");
|
||||
|
||||
switch (curLevel)
|
||||
@@ -64,7 +65,11 @@ public class Building : MonoBehaviour
|
||||
|
||||
|
||||
DBmanager.SetCoins(DBmanager.Coins-cost);
|
||||
Mathf.Clamp(curLevel++,0, buildingData.levels.Count-1);
|
||||
if(newLevel <0){
|
||||
curLevel = Mathf.Clamp(curLevel+1,0, buildingData.levels.Count-1);
|
||||
}else{
|
||||
curLevel = newLevel;
|
||||
}
|
||||
|
||||
DBmanager.UpgradeBuilding(buildingData.buildingName, curLevel);
|
||||
DBmanager.SetXp(DBmanager.Xp + buildingData.levels[curLevel].xpGain);
|
||||
|
||||
@@ -4,6 +4,7 @@ using UnityEngine;
|
||||
|
||||
public class BuildingManager : MonoBehaviour
|
||||
{
|
||||
public static BuildingManager instance;
|
||||
public Building[] buildings;
|
||||
[Button]
|
||||
void GetAllBuildings(){
|
||||
@@ -13,6 +14,7 @@ public class BuildingManager : MonoBehaviour
|
||||
|
||||
void Start()
|
||||
{
|
||||
instance =this;
|
||||
DBmanager.OnStateChanged.AddListener(UpdateBuildings);
|
||||
UpdateBuildings();
|
||||
}
|
||||
@@ -52,4 +54,15 @@ public class BuildingManager : MonoBehaviour
|
||||
public void OnClickBuyBuilding(BuildingData buildingData){
|
||||
DBmanager.AddBuilding(buildingData);
|
||||
}
|
||||
|
||||
|
||||
public Building GetBuildingWithId(string id){
|
||||
foreach(Building building in buildings){
|
||||
if(building.buildingData.buildingName == id){
|
||||
return building;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,8 @@ public class CollectBtn : MonoBehaviour
|
||||
|
||||
void Update()
|
||||
{
|
||||
collectableAmount=((DateTime.UtcNow - lastCollected).TotalSeconds * ((productionRate/60f)/60f));
|
||||
// collectableAmount=((DateTime.UtcNow - lastCollected).TotalSeconds * ((productionRate/60f)/60f));
|
||||
collectableAmount = GetCollectableGold();
|
||||
txt.text = ((int)collectableAmount).ToString();
|
||||
|
||||
btn.interactable = collectableAmount > 1;
|
||||
@@ -35,7 +36,7 @@ public class CollectBtn : MonoBehaviour
|
||||
}
|
||||
|
||||
async void OnClick(){
|
||||
collectableAmount=((DateTime.UtcNow - lastCollected).TotalSeconds * ((productionRate/60f)/60f));
|
||||
collectableAmount= GetCollectableGold();
|
||||
lastCollected = await DBmanager.GetNetworkTime();
|
||||
switch (resourceType){
|
||||
case CollectablesData.ResourceType.Metal:
|
||||
@@ -53,4 +54,17 @@ public class CollectBtn : MonoBehaviour
|
||||
}
|
||||
DBmanager.CollectBuilding(buildingId);
|
||||
}
|
||||
|
||||
double GetCollectableGold(){
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -687,7 +687,6 @@ public class DBmanager : MonoBehaviour
|
||||
OnStateChanged.Invoke();
|
||||
}
|
||||
|
||||
|
||||
public async static Task CollectBuilding(string id)
|
||||
{
|
||||
for (int i = 0; i < buildingStates.Count; i++)
|
||||
|
||||
35
Assets/Game/Scripts/GoldMine.cs
Normal file
35
Assets/Game/Scripts/GoldMine.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class GoldMine : MonoBehaviour
|
||||
{
|
||||
|
||||
void Start()
|
||||
{
|
||||
for(int i=0; i < 9; i++){
|
||||
int l = i+1;
|
||||
int p = GetProductionRateByLevel(l);
|
||||
int c = GetCapacityRateByLevel(l);
|
||||
int L = GetLevelByRates(c,p);
|
||||
Debug.Log($"Level:{L} ,Prod:{p}, Capactiy:{c}");
|
||||
}
|
||||
}
|
||||
//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/3f);
|
||||
return l;
|
||||
}
|
||||
|
||||
public static int GetCapacityRateByLevel(int level){
|
||||
//C = L -3(l - 1)
|
||||
int l = Mathf.CeilToInt((float)level/3f);
|
||||
return level - 3 * (l - 1);
|
||||
}
|
||||
|
||||
public static int GetLevelByRates(int Capacity, int Production){
|
||||
//L = 3P + C -3
|
||||
return (3*Production) + Capacity - 3;
|
||||
}
|
||||
}
|
||||
11
Assets/Game/Scripts/GoldMine.cs.meta
Normal file
11
Assets/Game/Scripts/GoldMine.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 804e326e54bee5f3b9c85505e861b0fb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -249,7 +249,7 @@ public class SpaceshipController : NetworkBehaviour
|
||||
if (boosting && scale > 1)
|
||||
{
|
||||
speed = movingSpeed * 2;
|
||||
DecreaseTrail(Time.deltaTime * 3);
|
||||
DecreaseTrail(Time.deltaTime * 1);
|
||||
// scaleMultiplier -= Time.deltaTime;
|
||||
// if (scaleMultiplier < 1) { scaleMultiplier = 1; } //Clamp in case gets lower
|
||||
}
|
||||
|
||||
@@ -20,6 +20,9 @@ public class SelectedItemMenu : MonoBehaviour
|
||||
|
||||
[Header("upgrade menu")]
|
||||
public GameObject upgradeMenu;
|
||||
public GameObject goldmineUpgradeMenu;
|
||||
public Button btn_gold_prod;
|
||||
public Button btn_gold_cap;
|
||||
public Transform upgrade_statParent;
|
||||
public GameObject[] upgrade_tierIndicators;
|
||||
public TMP_Text upgrade_buildingName;
|
||||
@@ -37,6 +40,9 @@ public class SelectedItemMenu : MonoBehaviour
|
||||
upgradeBtn.onClick.AddListener(OnUpgrade);
|
||||
collectBtn.btn.onClick.AddListener(OnCollect);
|
||||
repairRocketsBtn.onClick.AddListener(OpenSkinMenu);
|
||||
|
||||
btn_gold_cap.onClick.AddListener(OnGoldmineCapUpgrade);
|
||||
btn_gold_prod.onClick.AddListener(OnGoldmineProdUpgrade);
|
||||
}
|
||||
|
||||
void OnSelectionChanged()
|
||||
@@ -80,18 +86,47 @@ public class SelectedItemMenu : MonoBehaviour
|
||||
|
||||
void OnUpgradeMenuClicked()
|
||||
{
|
||||
|
||||
// Debug.Log("Opening Upgrade Menu for : " + Selector.selectedBuilding.buildingData.name);
|
||||
AudioManager.instnace.UIPopup();
|
||||
|
||||
upgradeMenu.SetActive(true);
|
||||
upgrade_buildingName.text = Selector.selectedBuilding.buildingData.buildingName;
|
||||
bool isGoldMine = Selector.selectedBuilding.GetComponent<GoldMine>()!=null;
|
||||
List<BuildingStat> stats = Selector.selectedBuilding.buildingData.levels[Selector.selectedBuilding.curLevel].stats;
|
||||
for (int i = 0; i < upgrade_statParent.childCount; i++)
|
||||
{
|
||||
bool hasDataForThis = i < stats.Count;
|
||||
upgrade_statParent.GetChild(i).gameObject.SetActive(hasDataForThis);
|
||||
if (hasDataForThis)
|
||||
{
|
||||
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(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 (Selector.selectedBuilding.curLevel < Selector.selectedData.levels.Count - 1){
|
||||
upgradeBtn.interactable = true;
|
||||
upgradeBtn.GetComponentInChildren<TMP_Text>().text = "Upgrade";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
for(int i=0; i < upgrade_tierIndicators.Length;i++){
|
||||
upgrade_tierIndicators[i].SetActive( Selector.selectedBuilding.curLevel == i);
|
||||
}
|
||||
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();
|
||||
upgradeBtn.GetComponentInChildren<TMP_Text>().text = Selector.selectedData.levels[Selector.selectedBuilding.curLevel + 1].price.ToString();
|
||||
|
||||
}
|
||||
else
|
||||
@@ -102,18 +137,7 @@ public class SelectedItemMenu : MonoBehaviour
|
||||
Debug.Log("Already max");
|
||||
}
|
||||
|
||||
List<BuildingStat> stats = Selector.selectedBuilding.buildingData.levels[Selector.selectedBuilding.curLevel].stats;
|
||||
for (int i = 0; i < upgrade_statParent.childCount; i++)
|
||||
{
|
||||
bool hasDataForThis = i < stats.Count;
|
||||
upgrade_statParent.GetChild(i).gameObject.SetActive(hasDataForThis);
|
||||
if (hasDataForThis)
|
||||
{
|
||||
upgrade_statParent.GetChild(i).GetChild(0).GetComponent<TMP_Text>().text = stats[i].name;
|
||||
upgrade_statParent.GetChild(i).GetChild(1).GetComponent<TMP_Text>().text = stats[i].value;
|
||||
upgrade_statParent.GetChild(i).GetChild(2).GetComponent<Image>().sprite = stats[i].image;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (upgrade_statParent.childCount < stats.Count)
|
||||
{
|
||||
@@ -123,10 +147,61 @@ public class SelectedItemMenu : MonoBehaviour
|
||||
|
||||
void OnUpgrade()
|
||||
{
|
||||
if(Selector.selectedBuilding.GetComponent<GoldMine>()!=null){
|
||||
AudioManager.instnace.UIPopup();
|
||||
goldmineUpgradeMenu.SetActive(true);
|
||||
int L = Selector.selectedBuilding.curLevel+1;
|
||||
int C = GoldMine.GetCapacityRateByLevel(L);
|
||||
int P = GoldMine.GetProductionRateByLevel(L);
|
||||
//Calculate prices
|
||||
if(P>=3){
|
||||
btn_gold_prod.interactable=false; btn_gold_prod.transform.Find("txt_price").GetComponent<TMP_Text>().text = "Max!";
|
||||
}
|
||||
else{
|
||||
btn_gold_prod.interactable=true; btn_gold_prod.transform.Find("txt_price").GetComponent<TMP_Text>().text = (gold_prod_upgrade_cost * P).ToString();
|
||||
}
|
||||
if(C>=3){
|
||||
btn_gold_cap.interactable=false; btn_gold_cap.transform.Find("txt_price").GetComponent<TMP_Text>().text = "Max!";
|
||||
}
|
||||
else{
|
||||
btn_gold_cap.interactable=true; btn_gold_cap.transform.Find("txt_price").GetComponent<TMP_Text>().text = (gold_cap_upgrade_cost * C).ToString();
|
||||
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
upgradeBtn.interactable= false;
|
||||
Selector.selectedBuilding.Upgrade();
|
||||
OnUpgradeMenuClicked();
|
||||
}
|
||||
int gold_prod_upgrade_cost = 3000;
|
||||
int gold_cap_upgrade_cost = 2500;
|
||||
void OnGoldmineCapUpgrade(){
|
||||
int L = Selector.selectedBuilding.curLevel+1;
|
||||
int C = GoldMine.GetCapacityRateByLevel(L);
|
||||
if(C >=3){return;}
|
||||
int P = GoldMine.GetProductionRateByLevel(L);
|
||||
|
||||
int newLevel = GoldMine.GetLevelByRates(C + 1, P);
|
||||
upgradeBtn.interactable= false;
|
||||
Selector.selectedBuilding.Upgrade(newLevel:newLevel-1, cost: C*gold_cap_upgrade_cost);
|
||||
goldmineUpgradeMenu.SetActive(false);
|
||||
OnUpgradeMenuClicked();
|
||||
}
|
||||
|
||||
void OnGoldmineProdUpgrade(){
|
||||
int L = Selector.selectedBuilding.curLevel+1;
|
||||
int C = GoldMine.GetCapacityRateByLevel(L);
|
||||
int P = GoldMine.GetProductionRateByLevel(L);
|
||||
if(P >=3){return;}
|
||||
int newLevel = GoldMine.GetLevelByRates(C, P+1);
|
||||
upgradeBtn.interactable= false;
|
||||
Selector.selectedBuilding.Upgrade(newLevel:newLevel-1, cost: C*gold_prod_upgrade_cost);
|
||||
|
||||
goldmineUpgradeMenu.SetActive(false);
|
||||
OnUpgradeMenuClicked();
|
||||
}
|
||||
|
||||
void OnInfoClicked()
|
||||
{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ec136755f0c5ccc4b86826353cfa811e
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user