Пример #1
0
        public Dictionary <string, IPlanshetViewData> GetMotherEstate(IDbConnection connection, UserDataModel user, bool synchronize = true)
        {
            var userPremium = _storeService.GetPremiumWorkModel(connection, user.Id);
            var mother      = _mothershipService.GetMother(connection, user.Id);

            return(GetMotherEstate(connection, user, userPremium, mother));
        }
        public void PushDemon(IDbConnection connection, IMothershipService motherService, IUMotherJumpService motherJumpService, IStoreService storeService)
        {
            var curTime = UnixTime.UtcNow();

            if (curTime - LAST_DEMON_RUNTIME < MIN_DEMON_DELAY_SECOND)
            {
                return;
            }

            var minItemTime = curTime - MIN_DELAY_TO_UPDATE;

            LAST_DEMON_RUNTIME = curTime;
            var motherIds = motherService.GetAllMothers(connection).Where(i => i.Id > 1000 && i.LastUpgradeProductionTime < minItemTime).Select(i => i.Id).ToList();

            if (!motherIds.Any())
            {
                return;
            }
            foreach (var motherId in motherIds)
            {
                var mother = motherService.GetMother(connection, motherId);
                if (_needUpdate(mother))
                {
                    var prem = storeService.GetPremiumWorkModel(connection, motherId);
                    RunUser(connection, mother, prem, motherService, motherJumpService);
                }
            }

            //Console.WriteLine("_mothershipService.SaveMother");
        }
        public IList <EstateItemOut> GetList(IDbConnection connection, int userId)
        {
            var mother  = _motherService.GetMother(connection, userId);
            var planets = _detailPlanetService.GetUserPlanets(connection, userId);

            return(GetList(connection, mother, planets));
        }
Пример #4
0
        public void ResetMotherResourceById(IDbConnection connection, int userId)
        {
            var res    = StorageResources.InitMotherResources();
            var mother = _mothershipService.GetMother(connection, userId);

            mother.Resources = res;
            _mothershipService.AddOrUpdate(connection, mother);
        }
Пример #5
0
        public void TransPlanetToMother(IDbConnection connection, int sourseId, MaterialResource deltaResourses, int userId, UserPremiumWorkModel userPremium)
        {
            var soursePlanet = _planetService.GetUserPlanet(connection, sourseId, userId);
            var targetMother = _mother.GetMother(connection, userId);

            soursePlanet = _synchronizer.UserPlanet(connection, soursePlanet, userPremium, _planetService);
            targetMother = _synchronizer.UserMothership(connection, targetMother, userPremium, _mother, _motherJumpService);


            var curRes    = soursePlanet.Resources; //_storageResourcesService.Execute(connection, userId, soursePlanet.Resources, sourseId);
            var targetRes = targetMother.Resources; //_storageResourcesService.Execute(connection, userId, targetMother.Resources);

            CalcNewRes(_storage, ref curRes, ref targetRes, deltaResourses, userPremium.IsActive,
                       soursePlanet.BuildStorage.Level);

            soursePlanet.Resources = curRes;
            _planetService.AddOrUpdate(connection, soursePlanet);

            targetMother.Resources = _storageResourcesService.Execute(connection, userId, targetRes);
            _mother.AddOrUpdate(connection, targetMother);
        }
Пример #6
0
        private int _setCompleteJumpAndGetTimeToEnd(IDbConnection connection, UserMotherJumpDataModel mJump)
        {
            var currTime = UnixTime.UtcNow();

            if (mJump.EndTime > currTime)
            {
                return(currTime - mJump.EndTime);
            }

            mJump.Completed = true;
            mJump           = AddOrUpdate(connection, mJump);

            var mother = _mothershipService.GetMother(connection, mJump.MotherId);

            mother.StartSystemId = mJump.TargetSystem;
            _mothershipService.AddOrUpdate(connection, mother);
            return(0);
        }
Пример #7
0
        //item

        public int CreateTaskItem(IDbConnection connection, int currentUserId, string currentUserNickname, TaskFleet inputData)
        {
            var curretnUserPremium = _storeService.GetPremiumWorkModel(connection, currentUserId);
            //todo Check current User fleet

            //todo тип для мазера  byte srcType = 20;

            var isMother = inputData.SourceId == 0;


            var targetPlanet         = _gDetailPlanetService.GetPlanet(connection, inputData.TargetName);
            var targetPlanetGeometry = _geometryPlanetService.GetGeometryPlanetById(connection, targetPlanet.Id);
            var targetPlanetSystem   = _systemService.GetDetailSystemBySystemId(connection, targetPlanetGeometry.SystemId);

            var newTaskItem = new UserTaskDataModel {
                SourceTypeId = (byte)(isMother ? 20 : 0),
                // canselation = false,
                SourceOwnType    = !isMother,
                SourceOwnName    = MapTypes.Mother.ToString(),
                SourceUserId     = currentUserId,
                SourceOwnId      = inputData.SourceId,
                TargetPlanetName = inputData.TargetName,
                DateActivate     = UnixTime.UtcNow(),
                Duration         = 100,
                //sourceFleet = inputData.FixUnitCount(),
                IsAtack            = true,
                IsTransfer         = false,
                TargetPlanetId     = targetPlanet.Id,
                TargetPlanetTypeId = targetPlanetGeometry.TypeId,
                TargetSystemName   = targetPlanetSystem.Name
            };


            //todo  проверить наличие юнитов у пользователя
            if (inputData.IsTransfer)
            {
                newTaskItem.IsAtack    = false;
                newTaskItem.IsTransfer = true;
            }



            if (newTaskItem.SourceOwnType)
            {
                var sourcePlanet = _gDetailPlanetService.GetUserPlanet(connection, inputData.SourceId, currentUserId);
                sourcePlanet = _synchronizer.UserPlanet(connection, sourcePlanet, curretnUserPremium, _gDetailPlanetService);
                var sourcePlanetGeometry = _geometryPlanetService.GetGeometryPlanetById(connection, sourcePlanet.Id);
                var sourcePlanetSystem   =
                    _systemService.GetDetailSystemBySystemId(connection, sourcePlanetGeometry.SystemId);
                var duration =
                    MapDistanceHelper.CalculatePlanetTransferFleet(connection, sourcePlanet.Id, newTaskItem.TargetPlanetId,
                                                                   _mapAdressService, curretnUserPremium.IsActive);

                var baseUnits = sourcePlanet.Hangar;
                inputData.FixUnitCount(sourcePlanet.Hangar);
                var planetFixedUnits = inputData.Units;


                newTaskItem.SourceFleet      = planetFixedUnits;
                newTaskItem.SourceTypeId     = sourcePlanetGeometry.TypeId;
                newTaskItem.SourceOwnName    = sourcePlanet.Name;
                newTaskItem.SourceSystemName = sourcePlanetSystem.Name;
                newTaskItem.Duration         = duration.Sec;

                var calculatedUnitsToSaveToSource = UnitList.CalculateNewUnits(baseUnits, planetFixedUnits, false);
                sourcePlanet.Hangar = calculatedUnitsToSaveToSource;
                _gDetailPlanetService.AddOrUpdate(connection, sourcePlanet);
            }
            else
            {
                var mother = _mothershipService.GetMother(connection, currentUserId);
                mother = _synchronizer.UserMothership(connection, mother, curretnUserPremium, _mothershipService, _motherJumpService);
                var motherSystem = _systemService.GetDetailSystemBySystemId(connection, mother.StartSystemId);
                var duration     =
                    MapDistanceHelper.CalculateMotherTransferFleet(connection, mother.StartSystemId, newTaskItem.TargetPlanetId,
                                                                   _mapAdressService, curretnUserPremium.IsActive);

                var baseUnits = mother.Hangar;
                inputData.FixUnitCount(mother.Hangar);
                var motherfixedUnits = inputData.Units;

                newTaskItem.SourceFleet      = motherfixedUnits;
                newTaskItem.SourceSystemName = motherSystem.Name;
                newTaskItem.Duration         = duration.Sec; //25;


                // почему то небыло указано....
                newTaskItem.SourceTypeId  = 20;
                newTaskItem.SourceOwnName = currentUserNickname;

                //todo calc  оставшихся юнитов
                var calculatedUnitsToSaveToSource = UnitList.CalculateNewUnits(baseUnits, motherfixedUnits, false);
                mother.Hangar = calculatedUnitsToSaveToSource;
                _mothershipService.AddOrUpdate(connection, mother);
            }

            newTaskItem = _uTaskService.AddOrUpdate(connection, newTaskItem);

            var clonedTaskItem = newTaskItem.CloneDeep();
            var userId         = targetPlanet.UserId;

            _synchronizer.GetTaskRunner().OnUserTaskCreated(newTaskItem.CloneDeep(), userId);
            Task.Delay(50).ContinueWith(t => {
                _uTaskService.NotyfyTaskCreated(clonedTaskItem, userId);
            });
            return(newTaskItem.Id);
        }