public int BuyGenerator(GeneratorInfo generator, int count, bool isFree = false) { ITransportUnitsService unitService = Services.TransportService; IPlayerService playerService = Services.PlayerService; if (unitService.HasUnits(generator.GeneratorId)) { if (!isFree) { double price = CalculatePrice(count, unitService.GetUnitTotalCount(generator.GeneratorId), generator); if (playerService.IsEnoughCompanyCash(price)) { playerService.RemoveCompanyCash(price); } else { return(0); } } unitService.AddLiveUnits(generator.GeneratorId, count); AddBuyedGeneratorCount(generator, count); GlobalRefs.LevelManager.AddXP(XPSources.BuyGenerator * count); } else { if (!isFree) { double price = CalculatePrice(count, 0, generator); if (playerService.IsEnoughCompanyCash(price)) { playerService.RemoveCompanyCash(price); } else { return(0); } } unitService.AddLiveUnits(generator.GeneratorId, count); AddBuyedGeneratorCount(generator, 1); if (!Convert.ToBoolean(PlayerPrefs.GetInt("UnlockGenerator_" + generator.GeneratorId, 0))) { FacebookEventUtils.LogApplyGeneratorEvent(generator.GeneratorId.ToString()); PlayerPrefs.SetInt("UnlockGenerator_" + generator.GeneratorId, 1); } GlobalRefs.LevelManager.AddXP(XPSources.UnlockGenerator * count); } playerService.CheckNonNegativeCompanyCash(); StatsCollector.Instance[Stats.UNITS_BOUGHT] += count; Player.LegacyPlayerData.Save(); StatsCollector.Instance.Save(); return(unitService.GetUnitTotalCount(generator.GeneratorId)); }
private void UpdatePlanetStateGenerators() { var generatorCollection = Services.ResourceService.Generators.Generators.Values; ITransportUnitsService unitService = Services.TransportService; IPlayerService playerService = Services.PlayerService; foreach (GeneratorData data in generatorCollection) { if (data.Type == GeneratorType.Planet || data.Type == GeneratorType.Normal) { GeneratorInfo info = Generators.GetGeneratorInfo(data.Id); if (!info.IsResearched) { Generators.SetState(info.GeneratorId, GeneratorState.Researchable); } else { bool hasAnyUnits = unitService.HasUnits(info.GeneratorId); bool playerHasCashForUnlock = playerService.IsEnoughCompanyCash(info.Cost); bool noAnyUnits = !hasAnyUnits; if (noAnyUnits && playerHasCashForUnlock) { if (info.IsDependent) { GeneratorInfo dependentInfo = Generators.GetGeneratorInfo(info.RequiredGeneratorId); if (dependentInfo.State == GeneratorState.Active) { Generators.SetState(info.GeneratorId, GeneratorState.Unlockable); } else { Generators.SetState(info.GeneratorId, GeneratorState.Locked); } } else { Generators.SetState(info.GeneratorId, GeneratorState.Unlockable); } } else if (noAnyUnits && !playerHasCashForUnlock) { Generators.SetState(info.GeneratorId, GeneratorState.Locked); } else if (hasAnyUnits) { Generators.SetState(info.GeneratorId, GeneratorState.Active); } } } } }
public double GetSecuritiesCountFromInvestors() { ITransportUnitsService unitService = Services.TransportService; double lifetimeEarnings = Services.PlayerService.LifetimeEarningsInPlanet; double million = Math.Pow(10, 6); if (lifetimeEarnings < million) { return(0.0); } if (false == unitService.HasUnits(2)) { return(0); } double koef = 150.0 * Math.Sqrt(lifetimeEarnings / million); double lifetimeSecurities = Services.PlayerService.LifeTimeSecurities.Value; var result = koef - lifetimeSecurities; return(result > 0 ? result : 0); }
private void BuyFreeGenerators(UpgradeData vm, int id) { ITransportUnitsService transportService = GameServices.Instance.TransportService; if (transportService.HasUnits(id)) { transportService.AddLiveUnits(id, (int)vm.Value); GlobalRefs.LevelManager.AddXP(XPSources.BuyUpgrade); } else { transportService.AddLiveUnits(id, (int)vm.Value); GlobalRefs.LevelManager.AddXP(XPSources.BuyGenerator * 10); } //PlayerData.Investors -= vm.Price; GameServices.Instance.PlayerService.RemoveSecurities(vm.Price(() => { return(BosUtils.GetUpgradePriceMult(ResourceService.Planets.GetPlanet(Planets.CurrentPlanet.Id), vm)); })); GlobalRefs.LevelManager.AddXP(XPSources.BuyUpgrade); }
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; } }