private void BuyTimeUpgrade(Upgrade up, bool free, int id) { if (Services.GenerationService.Generators.Contains(id)) { int count = GetSpeedUpgradeLevel(id); //Services.GenerationService.Generators.ApplyTime(id, up.TimeMultiplier); Services.GenerationService.Generators.AddTimeBoost( generatorId: id, boost: BoostInfo.CreateTemp( id: $"upgrade_time_{up.GeneratorIdToUpgrade}_".GuidSuffix(5), value: up.TimeMultiplier)); AddSpeedUpgradeLevel(id, 1); if (!free) { RemoveCost(Services, up.CostType, up.CalculateCost(count)); } } else { //Services.GenerationService.Generators.ApplyTime(id, up.TimeMultiplier); Services.GenerationService.Generators.AddTimeBoost( generatorId: id, boost: BoostInfo.CreateTemp( id: $"upgrade_time_{up.GeneratorIdToUpgrade}_".GuidSuffix(5), value: up.TimeMultiplier)); AddSpeedUpgradeLevel(id, 1); if (!free) { RemoveCost(Services, up.CostType, up.CalculateCost(0)); } } }
private void Reload(double balance) { NameView.text = _upgrade.Names.Length > UpgradeLevel ? _upgrade.Names[UpgradeLevel] : _upgrade.OverflowName; var cost = _upgrade.CalculateCost(UpgradeLevel); var enabledCondition = false; ITransportUnitsService transportService = GameServices.Instance.TransportService; switch (_upgrade.CostType) { case CostType.Balance: if (_upgrade.GeneratorIdToUpgrade != -1) { enabledCondition = balance >= cost && transportService.HasUnits(_upgrade.GeneratorIdToUpgrade); } else { enabledCondition = balance >= cost; } PriceView.text = GameServices.Instance.Currency.CreatePriceString(cost, separateWithEndl: false, separator: " ", useDecimalFormat: true); break; case CostType.Investors: if (_upgrade.GeneratorIdToUpgrade != -1) { enabledCondition = GameServices.Instance.PlayerService.Securities.Value >= cost && transportService.HasUnits(_upgrade.GeneratorIdToUpgrade); } else { enabledCondition = GameServices.Instance.PlayerService.Securities.Value >= cost; } PriceView.text = string.Format("{0} investor(s)", cost); break; case CostType.Coins: { var playerService = GameServices.Instance.PlayerService; if (_upgrade.GeneratorIdToUpgrade != -1) { enabledCondition = playerService.Coins >= cost && transportService.HasUnits(_upgrade.GeneratorIdToUpgrade); } else { enabledCondition = playerService.Coins >= cost; } PriceView.text = string.Format("{0} coin(s)", cost); } break; } RealtimeCost = cost; if (enabledCondition) { BuyButton.interactable = true; PriceView.color = Color.white; UpgradeTextView.color = Color.white; CanBuy = true; } else { BuyButton.interactable = false; PriceView.color = DisabledTextColor; UpgradeTextView.color = DisabledTextColor; CanBuy = false; } }