Exemple #1
0
        public async Task <object> BuildLaboratorySetTechTurn(UnitTurnOut data)
        {
            TechType techType = default(TechType);

            _tryCatch(() =>
            {
                if (data == null)
                {
                    throw new ArgumentNullException(nameof(data), Error.InputDataIncorrect);
                }
                var suc = Enum.TryParse(data.NativeName, out techType);
                if (!suc)
                {
                    throw new ArgumentException(Error.InputDataIncorrect);
                }
            });


            return(await _contextAction(connection =>
            {
                var cr = _getCurrentUser(connection);
                data.UserId = cr.UserId;
                var crPremium = cr.GetPremiumWorkModel(connection, _storeService);
                var mother = _mothershipService.GetMother(connection, cr.UserId);
                mother = _synchronizer.UserMothership(connection, mother, crPremium, _mothershipService, _motherJumpService);
                return _laboratory.SetTechTurn(connection, techType, data, mother, crPremium);
            }));
        }
Exemple #2
0
        private async Task <int> _buildSpaceShipyardSetUnitTurnForCc(UnitTurnOut data, UserPremiumWorkModel userPremium,
                                                                     int useId)
        {
            UnitType unitType = default(UnitType);

            _tryCatch(() =>
            {
                if (!Enum.TryParse(data.NativeName, out unitType))
                {
                    throw new NotImplementedException();
                }
            });

            return(await _contextAction(connection =>
            {
                if (data.OwnId == 0)
                {
                    var mother = _mothershipService.GetMother(connection, useId);
                    mother = _synchronizer.UserMothership(connection, mother, userPremium, _mothershipService,
                                                          _motherJumpService);
                    return _unit.CcUpgraded(connection, useId, unitType, data.Count, mother);
                }
                var planet = _gDetailPlanetService.GetUserPlanet(connection, data.OwnId, useId);
                planet = _synchronizer.UserPlanet(connection, planet, userPremium, _gDetailPlanetService);
                return _unit.CcUpgraded(connection, useId, unitType, data.Count, planet);
            }));
        }
        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);
        }
Exemple #4
0
        /// <summary>
        ///     аналог метода BuildItemUpgrade но для юнитов
        /// </summary>
        /// <param name="data"></param>
        /// <exception cref="ArgumentNullException">Error.ConnectionUserNotExist</exception>
        /// <exception cref="ArgumentNullException">Error.ConnectionUserNotConnected</exception>
        /// <returns>bool || int (new cc)</returns>
        public async Task <object> BuildSpaceShipyardSetUnitTurn(UnitTurnOut data)
        {
            UnitType unitType = default(UnitType);

            _tryCatch(() =>
            {
                if (!Enum.TryParse(data.NativeName, out unitType))
                {
                    throw new NotImplementedException();
                }
            });

            return(await _contextAction <object>(connection =>
            {
                var cr = _getCurrentUser(connection);
                var crPremium = cr.GetPremiumWorkModel(connection, _storeService);
                data.UserId = cr.UserId;
                if (data.ForCc)
                {
                    return _buildSpaceShipyardSetUnitTurnForCc(data, crPremium, cr.UserId);
                }

                if (data.OwnId == 0)
                {
                    var mother = _mothershipService.GetMother(connection, cr.UserId);
                    mother = _synchronizer.UserMothership(connection, mother, crPremium, _mothershipService,
                                                          _motherJumpService);
                    _unit.SetMotherUnitTurn(connection, unitType, data.Count, mother, crPremium);
                    return true;
                }
                var planet = _gDetailPlanetService.GetUserPlanet(connection, data.OwnId, cr.UserId);
                planet = _synchronizer.UserPlanet(connection, planet, crPremium, _gDetailPlanetService);
                _unit.SetPlanetUnitTurn(connection, unitType, data.Count, planet, crPremium);
                return true;
            }));
        }
Exemple #5
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;
            }));
        }