public void BuyBuilding(Building building) { if (building == null) { return; } if (!BuildingAvailable(building)) { return; } CurrencyTuple cost = BuildingCost(building); if (!Deduct(cost.Currency, cost.Amount)) { return; } int buildingCount; State.EarnedBuildings.TryGetValue(building, out buildingCount); State.EarnedBuildings[building] = buildingCount + 1; UpdateUnlocks(); OnBuyBuilding.Invoke(); }
public CurrencyTuple BuildingCost(Building building) { int count; if (!State.EarnedBuildings.TryGetValue(building, out count)) { count = 0; } CurrencyTuple currencyTuple = building.Cost; currencyTuple.Amount = (int)currencyTuple.Amount * Mathf.Pow(1 + Config.BuildingCostIncrease, count); return(currencyTuple); }