UPF/Assets/Game/Scripts/SolarPanels.cs
2022-11-03 14:55:22 +05:30

82 lines
3.3 KiB
C#

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