UPF/Assets/Game/Scripts/GoldMine.cs
2022-10-15 18:33:26 +05:30

61 lines
2.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GoldMine : MonoBehaviour
{
public static int LevelsCount => levelsCount;
static int levelsCount = 40;
public Sprite statIcon;
static int ProductionMultiplier=50;
static int CapacityMultiplier=1000;
static int gold_prod_upgrade_cost = 3000;
static int gold_cap_upgrade_cost = 2500;
void Awake()
{ BuildingData data =GetComponent<Building>().buildingData;
data.levels = new List<BuildingLevel>();
data.productinoRates = new float[levelsCount*levelsCount];
for(int i=0; i < levelsCount * levelsCount; i++){
int l = i+1;
int p = GetProductionRateByLevel(l);
int c = GetCapacityRateByLevel(l);
int L = GetLevelByRates(c,p);
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));
data.levels.Add(new BuildingLevel(l,stats,l*3000));
data.levels[i].xpGain = (i > 0) ? 150 : 0;
data.productinoRates[i] = p * ProductionMultiplier;
// Debug.Log($"Level:{l},{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/(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 GetCostForProduction(int level){
int Level = GetProductionRateByLevel(level);
return Level*gold_prod_upgrade_cost;
}
public static int GetCostForCapacity(int level){
int Level = GetCapacityRateByLevel(level);
return Level*gold_cap_upgrade_cost;
}
}