103 lines
3.8 KiB
C#
Executable File
103 lines
3.8 KiB
C#
Executable File
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class GoldMine : MonoBehaviour
|
|
{
|
|
public static int LevelsCount => levelsCount;
|
|
public static int levelsCount => Stats.levels.Length;
|
|
public Sprite statIcon;
|
|
public GoldMineData gold_stats;
|
|
public static GoldMineData Stats;
|
|
public GameObject fullFX;
|
|
// static int ProductionMultiplier=50;
|
|
// static int CapacityMultiplier=1000;
|
|
// static int gold_prod_upgrade_cost = 3000;
|
|
// static int gold_cap_upgrade_cost = 2500;
|
|
BuildingData data;
|
|
void Awake()
|
|
{
|
|
Stats = gold_stats;
|
|
data =GetComponent<Building>().buildingData;
|
|
data.levels = new List<BuildingLevel>();
|
|
data.productinoRates = new float[levelsCount*levelsCount];
|
|
Debug.Log($"Gold 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("Gold per hour", (gold_stats.levels[p-1].Production).ToString(),statIcon));
|
|
stats.Add(new BuildingStat("Capacity", (gold_stats.levels[c-1].Capacity).ToString(),statIcon));
|
|
data.levels.Add(new BuildingLevel(l,stats,gold_stats.levels[lvl].costGold,gold_stats.levels[lvl].costMetal));
|
|
data.levels[i].xpGain = (i > 0) ? 150 : 0;
|
|
data.productinoRates[i] = gold_stats.levels[p-1].Production;
|
|
|
|
}
|
|
|
|
}
|
|
float t = 0;
|
|
void Update(){
|
|
if(t < 1){
|
|
t += Time.deltaTime;
|
|
}else{
|
|
t=0;
|
|
|
|
fullFX.SetActive(CollectBtn.isEnergyCapped(data.buildingName));
|
|
}
|
|
}
|
|
//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].costGold;}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].costGold;
|
|
}
|
|
public static int GetMetalCostForProduction(int level){
|
|
int Level = GetProductionRateByLevel(level);
|
|
return Stats.levels[ Level%levelsCount].costMetal;
|
|
}
|
|
public static int GetMetalCostForCapacity(int level){
|
|
int Level = GetCapacityRateByLevel(level);
|
|
return Stats.levels[ Level%levelsCount].costMetal;
|
|
}
|
|
}
|
|
|
|
|
|
[System.Serializable]
|
|
public class GoldMineLevel{
|
|
[SerializeField]public string name {get{return "Level " +Level.ToString();}}
|
|
public int Level = 1;
|
|
public int Production;
|
|
public int Capacity;
|
|
public int costGold;
|
|
public int costMetal;
|
|
} |