示例#1
0
        public int UpgradeForCc(IDbConnection connection, GDetailPlanetDataModel planet, int userId, bool premiumIsActive, BuildUpgrade preResult, IServiceProvider resolver)
        {
            var bu = new BuildUpgrade();

            bu.SetData(planet.BuildEnergyConverter, NativeName);
            return(base.UpgradeForCc(connection, planet, userId, premiumIsActive, preResult, CalcCcCurrentPrice(preResult.Progress?.Level ?? 1), resolver));
        }
        //public BuildItemUnitView Upgraded(IGDetailPlanetService planetService, int userId, int planetId,bool premiumIsActive)
        public ItemProgress Upgraded(IDbConnection connection, GDetailPlanetDataModel planet, int userId, bool premiumIsActive, IServiceProvider resolver)
        {
            var bu = new BuildUpgrade();

            bu.SetData(planet.BuildSpaceShipyard, NativeName);
            return(base.Upgraded(connection, planet, bu, resolver));
        }
示例#3
0
        //BuildItemUnitView
        public ItemProgress Upgraded(IDbConnection connection, GDetailPlanetDataModel planet, int userId, bool premiumIsActive, IServiceProvider resolver)
        {
            var bu = new BuildUpgrade();

            bu.SetData(planet.Turels, NativeName);
            if (!bu.IsUpgradeComplite(bu.Progress))
            {
                return(bu.Progress);
            }
            //planetService.SavePlanet();
            bu.Progress = ItemProgress.ProgressUpdateComplite(bu.Progress);
            BuildUpgrade.TransactionBuildUpdate(connection, planet, bu, resolver);
            return(bu.Progress);
        }
        public int UpgradeForCc(IDbConnection connection, GDetailPlanetDataModel planet, int userId, bool premiumIsActive, BuildUpgrade preResult, IServiceProvider resolver)
        {
            var storeService = resolver.GetService <IStoreService>();
            var balanceCc    =
                storeService.BalanceCalcResultCc(connection, userId, CalcCcCurrentPrice(preResult.Progress?.Level ?? 1));

            preResult.Cc       = balanceCc.Quantity;
            preResult.Progress = ItemProgress.ProgressUpdateComplite(preResult.Progress);
            if (preResult.StorageResources == null)
            {
                throw new Exception(Error.UserResourceNotSetInInstance);
            }
            preResult.StorageResources.Max = MaxStorable(preResult.Progress?.Level ?? 1, premiumIsActive);
            BuildUpgrade.TransactionBuildUpdate(connection, planet, preResult, resolver, balanceCc);
            return(preResult.Cc);
        }
        public ItemProgress Upgraded(IDbConnection connection, GDetailPlanetDataModel planet, int userId, bool premiumIsActive, IServiceProvider resolver)
        {
            var progress  = planet.BuildStorage;
            var preResult = new BuildUpgrade(planet.Resources, progress, NativeName);


            //todo  не правильно высчитывается время на азуре из за чего вылетает ошибка при ответе от сервера
            if (!preResult.IsUpgradeComplite(preResult.Progress))
            {
                return(preResult.Progress);
            }

            preResult.Progress             = ItemProgress.ProgressUpdateComplite(preResult.Progress);
            preResult.StorageResources.Max = MaxStorable(preResult.Progress.Level ?? 1, premiumIsActive);
            BuildUpgrade.TransactionBuildUpdate(connection, planet, preResult, resolver);
            return(preResult.Progress);
        }
        public object SetTechTurn(IDbConnection connection, TechType techType, UnitTurnOut input, UserMothershipDataModel mother, UserPremiumWorkModel premium)
        {
            var teches    = new BattleTeches(mother.TechProgress);
            var techesOut = teches.ConvertToTechesOut(false);
            var tech      = techesOut[techType];

            if (tech.Disabled)
            {
                throw new NotImplementedException(Error.TechDisabled);
            }
            tech.CalcResultPrice(premium.IsActive);
            var price = tech.BasePrice;

            if (input.ForCc)
            {
                var cc          = (int)price.Cc;
                var preResultCc = _storeService.BalanceCalcResultCc(connection, input.UserId, cc);
                ItemProgress.ProgressUpdateComplite(tech.Progress);
                mother.TechProgress = teches.ConvertToDbTeches();
                _mothershipService.AddOrUpdate(connection, mother);
                _storeService.AddOrUpdateBalance(connection, preResultCc);
                return(preResultCc.Quantity);
            }
            if (tech.Progress.IsProgress == true)
            {
                throw new Exception(Error.TechInProgress);
            }

            var bu = new BuildUpgrade(mother.Resources, tech.Progress, techType.ToString());

            var newBu = BuildUpgrade.SetUpgrade(bu, price);

            newBu.Progress.StartTime = UnixTime.UtcNow();
            mother.Resources         = newBu.StorageResources;
            tech.Progress.SetFromOther(newBu.Progress);
            mother.TechProgress = teches.ConvertToDbTeches();
            _mothershipService.AddOrUpdate(connection, mother);
            return(true);
        }
示例#7
0
        public ItemProgress Upgraded(IDbConnection connection, GDetailPlanetDataModel planet, int userId, bool premiumIsActive, IServiceProvider resolver)
        {
            var bu = new BuildUpgrade(planet.Resources, planet.BuildEnergyConverter, NativeName);

            return(base.Upgraded(connection, planet, bu, resolver));
        }
 public int UpgradeForCc(IDbConnection connection, GDetailPlanetDataModel planet, int userId, bool premiumIsActive, BuildUpgrade preResult, IServiceProvider resolver)
 {
     return(base.UpgradeForCc(connection, planet, userId, premiumIsActive, preResult,
                              CalcCcCurrentPrice(preResult.Progress?.Level ?? 1), resolver));
 }
示例#9
0
        /// <summary>
        ///     planet builds only!
        /// </summary>
        /// <param name="data"></param>
        /// <param name="buildItemNativeName"></param>
        /// <exception cref="ArgumentNullException">Error.ConnectionUserNotExist</exception>
        /// <exception cref="ArgumentNullException">Error.ConnectionUserNotConnected</exception>
        /// <returns> bool (true - upgrade added and data was changed) || int => wen buy for cc retturn new result cc</returns>
        public async Task <object> BuildItemUpgrade(UnitTurnOut data, string buildItemNativeName)
        {
            BuildNativeNames nativeName = default(BuildNativeNames);

            _tryCatch(() =>
            {
                if (data == null)
                {
                    throw new ArgumentNullException(nameof(data), Error.InputDataIncorrect);
                }
                if (data.OwnId == 0)
                {
                    throw new ArgumentException(Error.InputDataIncorrect);
                }

                var suc = Enum.TryParse(buildItemNativeName, out nativeName);
                if (!suc)
                {
                    throw new ArgumentException(Error.InputDataIncorrect);
                }
            });

            return(await _contextAction <object>(connection =>
            {
                var cr = _getCurrentUser(connection);

                var planet = _gDetailPlanetService.GetUserPlanet(connection, data.OwnId, cr.UserId);
                if (planet == null)
                {
                    throw new ArgumentNullException(Error.PlanetChangeOwner);
                }
                var crPremium = cr.GetPremiumWorkModel(connection, _storeService);
                planet = _synchronizer.UserPlanet(connection, planet, crPremium, _gDetailPlanetService);


                if (nativeName == BuildNativeNames.EnergyConverter)
                {
                    var preResult = new BuildUpgrade(planet.Resources, planet.BuildEnergyConverter,
                                                     BuildNativeNames.EnergyConverter.ToString());


                    //todo  проверить премиум (непонятно что а коммент)
                    if (data.ForCc)
                    {
                        return _energyConverter.UpgradeForCc(connection, planet, cr.UserId, crPremium.IsActive,
                                                             preResult,
                                                             _svp);
                    }

                    var newResult = BuildUpgrade.SetUpgrade(preResult,
                                                            _energyConverter.CalcPrice(preResult.GetLevel(), crPremium.IsActive));
                    if (preResult.Equals(newResult))
                    {
                        return false;
                    }
                    preResult = newResult;
                    preResult.Progress.StartTime = UnixTime.UtcNow();
                    planet.Resources = preResult.StorageResources;
                    planet.BuildEnergyConverter = preResult.Progress;
                }
                else if (nativeName == BuildNativeNames.ExtractionModule)
                {
                    var preResult = new BuildUpgrade(planet.Resources, planet.BuildExtractionModule,
                                                     BuildNativeNames.ExtractionModule.ToString());


                    //todo  проверить премиум (непонятно что а коммент)
                    if (data.ForCc)
                    {
                        return _extractionModule.UpgradeForCc(connection, planet, cr.UserId, crPremium.IsActive, preResult, _svp);
                    }

                    var newResult = BuildUpgrade.SetUpgrade(preResult,
                                                            _extractionModule.CalcPrice(preResult.GetLevel(), crPremium.IsActive));

                    if (preResult.Equals(newResult))
                    {
                        return false;
                    }
                    preResult = newResult;
                    preResult.Progress.StartTime = UnixTime.UtcNow();
                    planet.Resources = preResult.StorageResources;
                    planet.BuildExtractionModule = preResult.Progress;
                }
                else if (nativeName == BuildNativeNames.SpaceShipyard)
                {
                    var preResult = new BuildUpgrade(planet.Resources, planet.BuildSpaceShipyard,
                                                     BuildNativeNames.SpaceShipyard.ToString());

                    //todo  проверить премиум (непонятно что за коммент)
                    if (data.ForCc)
                    {
                        return _spaceShipyard.UpgradeForCc(connection, planet, cr.UserId, crPremium.IsActive, preResult,
                                                           _svp);
                    }

                    var newResult = BuildUpgrade.SetUpgrade(preResult,
                                                            _spaceShipyard.CalcPrice(preResult.GetLevel(), crPremium.IsActive));

                    if (preResult.Equals(newResult))
                    {
                        return false;
                    }
                    preResult = newResult;
                    preResult.Progress.StartTime = UnixTime.UtcNow();
                    planet.Resources = preResult.StorageResources;
                    planet.BuildSpaceShipyard = preResult.Progress;
                }
                else if (nativeName == BuildNativeNames.Storage)
                {
                    var preResult = new BuildUpgrade(planet.Resources, planet.BuildStorage,
                                                     BuildNativeNames.Storage.ToString());


                    if (data.ForCc)
                    {
                        return _storage.UpgradeForCc(connection, planet, cr.UserId, crPremium.IsActive, preResult,
                                                     _svp);
                    }

                    var newResult = BuildUpgrade.SetUpgrade(preResult,
                                                            _storage.CalcPrice(preResult.GetLevel(), crPremium.IsActive));

                    if (preResult.Equals(newResult))
                    {
                        return false;
                    }
                    preResult = newResult;
                    preResult.Progress.StartTime = UnixTime.UtcNow();

                    planet.Resources = preResult.StorageResources;
                    planet.BuildStorage = preResult.Progress;
                }
                else if (nativeName == BuildNativeNames.Turel)
                {
                    var preResult = new BuildUpgrade(planet.Resources, planet.Turels,
                                                     BuildNativeNames.Turel.ToString());


                    if (data.ForCc)
                    {
                        return _turels.UpgradeForCc(connection, planet, cr.UserId, crPremium.IsActive, preResult,
                                                    _svp);
                    }
                    var newResult = BuildUpgrade.SetUpgrade(preResult, _turels.CalcPrice(1, crPremium.IsActive));

                    if (preResult.Equals(newResult))
                    {
                        return false;
                    }
                    preResult = newResult;
                    preResult.Progress.StartTime = UnixTime.UtcNow();

                    planet.Resources = preResult.StorageResources;
                    planet.Turels = preResult.Progress;
                }
                else
                {
                    throw new ArgumentException(Error.InputDataIncorrect);
                }
                _gDetailPlanetService.AddOrUpdate(connection, planet);

                return true;
            }));
        }
示例#10
0
 public int UpgradeForCc(IDbConnection connection, GDetailPlanetDataModel planet, int userId, bool premiumIsActive, BuildUpgrade preResult, IServiceProvider resolver)
 {
     throw new NotImplementedException();
 }