Ejemplo n.º 1
0
        public bool Delete(IDbConnection connection, AllianceDataModel alliance)
        {
            if (alliance == null)
            {
                throw new NullReferenceException();
            }
            var confederation = NpcHelper.GetNpcByName(Npc.ConfederationName);

            if (alliance.Id == confederation.NpcAlliance.Id)
            {
                throw new NotImplementedException(nameof(confederation.NpcAlliance.Id));
            }
            var skagry = NpcHelper.GetNpcByName(Npc.SkagyName);

            if (alliance.Id == skagry.NpcAlliance.Id)
            {
                throw new NotImplementedException(nameof(skagry.NpcAlliance.Id));
            }


            var allianceId = alliance.Id;

            DisbandAlliance(connection, alliance.CreatorId, allianceId);
            _aRepo.Delete(connection, allianceId);

            return(_channelService.DeleteAllianceChannel(null, allianceId));
        }
Ejemplo n.º 2
0
        public bool Delete(IDbConnection connection, int allianceId)
        {
            var confederation = NpcHelper.GetNpcByName(Npc.ConfederationName);

            if (allianceId == confederation.NpcAlliance.Id)
            {
                throw new NotImplementedException(nameof(confederation.NpcAlliance.Id));
            }
            var skagry = NpcHelper.GetNpcByName(Npc.SkagyName);

            if (allianceId == skagry.NpcAlliance.Id)
            {
                throw new NotImplementedException(nameof(skagry.NpcAlliance.Id));
            }

            var allaicne = GetAllianceById(connection, allianceId, true);

            return(Delete(connection, allaicne));
        }
        /// <summary>
        ///  Не делает проверки планеты на текущее состояние.
        ///  Если планета уже имеет установленного владельца, проверку нужно делать перед методом
        /// В любом слае  отправляет запрос на обновление планеты, и извлечение альянса
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="planet"></param>
        /// <param name="newOwner"></param>
        /// <param name="allianceService"></param>
        public void UpdatePlanetOwner(IDbConnection connection, GDetailPlanetDataModel planet, int newOwner, IAllianceService allianceService)
        {
            var npc = NpcHelper.GetNpcByName(Npc.SkagyName);

            if (newOwner == npc.NpcUser.Id)
            {
                planet.AllianceId = npc.NpcAlliance.Id;
                planet.UserId     = newOwner;
                AddOrUpdate(connection, planet);
                return;
            }

            var allianceUser = allianceService.GetAllianceUserByUserId(connection, newOwner);

            if (planet.AllianceId != allianceUser.AllianceId)
            {
                planet.AllianceId = allianceUser.AllianceId;
            }
            planet.UserId = newOwner;
            AddOrUpdate(connection, planet);
        }
        private bool CreatePlanetDetails(IDbConnection connection)
        {
            var planets       = _getPlanetCollection(connection);
            var npc           = NpcHelper.GetNpcByName(Npc.SkagyName);
            var detailPlanets = new List <GDetailPlanetDataModel>();

            foreach (var planet in planets)
            {
                var translate = new L10N();
                translate.InitializeField();

                var type          = _gameTypeService.GetGGameType(connection, planet.GameTypeId);
                var typeTranslate = type.Description;
                translate.En.Description = "Unique Description En " + planet.NativeName + " " + " TypeDescription: " +
                                           typeTranslate.En.Description;

                translate.Es.Description = "Unique Description Es " + planet.NativeName + " " + " TypeDescription: " +
                                           typeTranslate.Es.Description;
                translate.Ru.Description = "Unique Description Ru " + planet.NativeName + " " + " TypeDescription: " +
                                           typeTranslate.Ru.Description;
                translate.En.Name = translate.Es.Name = translate.Ru.Name = planet.NativeName;


                var detailPlanet = new GDetailPlanetDataModel
                {
                    Id           = planet.Id,
                    UserId       = npc.NpcUser.Id,
                    AllianceId   = npc.NpcAlliance.Id,
                    Name         = planet.NativeName,
                    Description  = translate,
                    DangerLevel  = 1,
                    LastActive   = DateTime.UtcNow,
                    MoonCount    = GetMoonCount(planet.SystemPosition),
                    UnitProgress = new Dictionary <UnitType, TurnedUnit>()
                };

                _iOwnProgressInitializer.SetInitialPlanetBuilds(detailPlanet, npc.NpcUser.Id);
                _iOwnProgressInitializer.SetInitialHangarAndResource(connection, detailPlanet);

                detailPlanets.Add(detailPlanet);
            }

            #region for  Delete

            //for (int p = 0; p < planets.Count; p++)
            //{

            //    var planet = planets[p];
            //    var system = detailSystems.First(i => i.Id == planet.SystemId);
            //    var systemName = system.Name;
            //    //var planetName = systemName + "-"+ planet.SystemPosition;


            //    var translate = new L10N();
            //    translate.InitializeField();

            //    var type = await _gameTypeService.GetGGameTypeAsync(planet.GameTypeId);
            //    var typeTranslate = type.Description;
            //    translate.En.Description = "Unique Description En " + planet.NativeName + " " + " TypeDescription: " +
            //                               typeTranslate.En.Description;

            //    translate.Es.Description = "Unique Description Es " + planet.NativeName + " " + " TypeDescription: " +
            //                               typeTranslate.Es.Description;
            //    translate.Ru.Description = "Unique Description Ru " + planet.NativeName + " " + " TypeDescription: " +
            //                               typeTranslate.Ru.Description;
            //    translate.En.Name = translate.Es.Name = translate.Ru.Name = planet.NativeName;


            //    var detailPlanet = new GDetailPlanetDataModel
            //    {
            //        Id = planet.Id,
            //        UserId = npc.NpcUser.Id,
            //        AllianceId = npc.NpcAlliance.Id,
            //        Name = planet.NativeName,
            //        Description = translate,
            //        DangerLevel = (byte)Rand.Next(0, 10),
            //        LastActive = DateTime.UtcNow,
            //        MoonCount = GetMoonCount(planet.SystemPosition)

            //    };

            //    _iOwnProgressInitializer.SetInitialPlanetBuilds(detailPlanet, npc.NpcUser.Id);
            //    _iOwnProgressInitializer.SetInitialHangarAndResource(detailPlanet);

            //    detailPlanets.Add(detailPlanet);
            //}

            #endregion

            var suc = _gDetailPlanetService.AddOrUpdateDetailPlanetList(connection, detailPlanets).Any();
            return(true);
        }
Ejemplo n.º 5
0
        public void RunTaskItem(IDbConnection connection, int taskId)
        {
            if (taskId == 0)
            {
                return;
            }
            var taskItem = _uTaskService.GetByTaskId(connection, taskId, true);

            if (taskItem == null)
            {
                _demonLog.CrateAndSave("UserTaskDataModel", "TaskRunner.RunTaskItem.taskItemIsNull", new { TaskId = taskId }, taskId);

                return;
            }

            if (taskItem.TaskEnd)
            {
                return;
            }
            lock (_runTaskItemLocker)
            {
                var currUtcTime = DateTime.UtcNow;
                var curTime     = UnixTime.ToTimestamp(currUtcTime);
                var endTime     = taskItem.DateActivate + taskItem.Duration;
                var timers      = TimerExecutor.GetTaskTimersByTaskId(taskItem.Id);
                if (timers.Count > 1)
                {
                    _demonLog.CrateAndSave("UserTaskDataModel", "TaskRunner.RunTaskItem.multipleTimers_", new { TaskId = taskId }, taskId);
                    return;
                }
                var timer = timers.FirstOrDefault();
                if (timer == null)
                {
                    var delay = endTime - curTime;
                    if (delay > 0)
                    {
                        _onUserTaskCreated(delay, taskItem.Id, taskItem.SourceUserId, taskItem.TargetPlanetId);
                        return;
                    }
                }
                else if (!timer.InProgress || timer.IsDisposed)
                {
                    return;
                }

                taskItem = _uTaskService.SetUpdateInProgress(connection, taskItem);

                #region Body

                try
                {
                    var targetPlanetId  = taskItem.TargetPlanetId;
                    var targetPlanetSrc = _gDetailPlanetService.GetPlanet(connection, targetPlanetId);

                    var defenderUser    = _gameUserService.GetGameUser(connection, targetPlanetSrc.UserId);
                    var defendorPremium = _storeService.GetPremiumWorkModel(connection, defenderUser.Id);
                    var defendorPlanet  = _planetRunner.RunSinglePlanet(connection, targetPlanetSrc, defendorPremium, _gDetailPlanetService);


                    //result.TimeOver = true;
                    //var user = taskItem.user;
                    UserDataModel sourceUser = null;
                    var           npc        = NpcHelper.GetNpcByName(Npc.SkagyName);
                    if (taskItem.SourceUserId == defenderUser.Id)
                    {
                        taskItem.IsAtack    = false;
                        taskItem.IsTransfer = true;
                        sourceUser          = defenderUser;
                    }
                    else
                    {
                        taskItem.IsAtack    = true;
                        taskItem.IsTransfer = false;
                        if (taskItem.SourceUserId == npc.NpcUser.Id)
                        {
                            sourceUser = npc.NpcUser;
                        }
                        else
                        {
                            sourceUser = _gameUserService.GetGameUser(connection, taskItem.SourceUserId);
                        }
                    }

                    #region IsAtack

                    if (taskItem.IsAtack)
                    {
                        var atackModel = new TmpAtackModel
                        {
                            TaskItem   = taskItem,
                            SourceUser = new TmpAtackItem
                            {
                                User = sourceUser
                            },
                            DefendorUser = new TmpAtackItem
                            {
                                User    = defenderUser,
                                Premium = defendorPremium
                            },
                            DefendorPlanet = defendorPlanet,
                            Npc            = npc,
                            BattleTime     = curTime,
                            BattleDtTime   = currUtcTime
                        };
                        _atack(connection, atackModel);
                        var ti     = atackModel.TaskItem.CloneDeep();
                        var report = atackModel.ReportDataModel.CloneDeep();
                        int?newTotalWinnerUserCc = atackModel.NewTotalWinnerUserCc;

                        Task.Factory.StartNew(() => { _uTaskService.NotyfyTaskFinished(ti, report, newTotalWinnerUserCc); });

                        return;
                    }

                    #endregion

                    #region IsTransfer

                    defendorPlanet.Hangar = UnitList.CalculateNewUnits(taskItem.SourceFleet, defendorPlanet.Hangar, true);
                    _gDetailPlanetService.AddOrUpdate(connection, defendorPlanet);
                    taskItem.TaskEnd = true;
                    _uTaskService.UnlockUpdateInProgress(connection, taskItem.Id);
                    var updatedTask = _uTaskService.AddOrUpdate(connection, taskItem);

                    Task.Factory.StartNew(() => { _uTaskService.NotyfyTaskFinished(updatedTask); });



                    #endregion
                }
                catch (Exception e)
                {
                    _demonLog.CrateAndSave("UserTaskDataModel", "TaskRunner.RunTaskItem.ExceptionTaskItemData", taskItem, taskItem.Id);
                    _demonLog.CrateAndSave("Exception", "TaskRunner.RunTaskItem.ExceptionData", e, taskItem.Id);
                    _uTaskService.UnlockUpdateInProgress(connection, taskItem.Id);
                    throw;
                }
            }

            #endregion
        }
Ejemplo n.º 6
0
        public PlanetInfoOut GetPlanetInfo(IDbConnection connection, int planetId, int currentUserId)
        {
            var planetGeometry = _geometryPlanetService.GetGeometryPlanetById(connection, planetId);

            if (planetGeometry == null)
            {
                return(null);
            }

            var planetType = _gameTypeService.GetGGameType(connection, planetGeometry.TypeId);

            if (planetType == null)
            {
                return(null);
            }


            var galaxyName = _galaxyService.GetGalaxyById(connection, planetGeometry.GalaxyId, i => i.NativeName);

            if (galaxyName == null)
            {
                return(null);
            }

            var sectorName = _gSectorsService.GetById(connection, planetGeometry.SectorId, i => i.NativeName);

            if (sectorName == null)
            {
                return(null);
            }

            var systemName = _systemService.GetDetailSystemBySystemId(connection, planetGeometry.SystemId, i => i.Name);

            if (systemName == null)
            {
                return(null);
            }


            var planetDetail = _gDetailPlanetService.GetPlanet(connection, planetId);

            if (planetDetail == null)
            {
                return(null);
            }


            var skagry             = NpcHelper.GetNpcByName(Npc.SkagyName);
            var userName           = skagry.NpcUser.Nickname;
            var planetAllianceName = skagry.NpcAlliance.Name;

            if (planetDetail.UserId != skagry.NpcUser.Id)
            {
                userName           = _gameUserService.GetGameUser(connection, planetDetail.UserId, i => i.Nickname);
                planetAllianceName = _allianceService.GetAllianceById(connection, planetDetail.AllianceId, i => i.Name);
            }
            var isCurrentUser = currentUserId == planetDetail.UserId;


            var planetInfo = new PlanetInfoOut
            {
                GalaxyId                 = planetGeometry.GalaxyId,
                GalaxyName               = galaxyName,
                SectorId                 = planetGeometry.SectorId,
                SectorName               = sectorName,
                SystemId                 = planetGeometry.SystemId,
                SystemName               = systemName,
                Id                       = planetGeometry.Id,
                NativeName               = planetDetail.Name,
                TextureTypeId            = planetGeometry.TextureTypeId,
                Owner                    = userName,
                LastActive               = planetDetail.LastActive,
                PlanetReferToCurrentUser = isCurrentUser,
                TypeNativeName           = planetType.Type,
                SubtypeNativeName        = planetType.SubType,
                Description              =
                    L10N.ExecuteTranslateNameOrDescr(planetDetail.Description, false, L10N.GetCurrentCulture()),
                AllianceName = planetAllianceName,
                ChildCount   = planetDetail.MoonCount,
                SpriteImages = new SpriteImages().PlanetImages(planetType.SubType, planetGeometry.TextureTypeId)
            };


            if (string.Equals(planetInfo.SubtypeNativeName, PlanetoidSubTypes.Earth.ToString(),
                              StringComparison.CurrentCultureIgnoreCase))
            {
                planetInfo.SubtypeTranslateName = "translate Earth";
            }
            else if (string.Equals(planetInfo.SubtypeNativeName, PlanetoidSubTypes.Gas.ToString(),
                                   StringComparison.CurrentCultureIgnoreCase))
            {
                planetInfo.SubtypeTranslateName = "translate Gas Gigant";
            }
            else if (string.Equals(planetInfo.SubtypeNativeName, PlanetoidSubTypes.IceGas.ToString(),
                                   StringComparison.CurrentCultureIgnoreCase))
            {
                planetInfo.SubtypeTranslateName = "translate Ice";
            }
            planetInfo.SetComplexButtonView();
            return(planetInfo);
        }
Ejemplo n.º 7
0
        public StarInfoOut GetStarInfo(IDbConnection connection, int starId)
        {
            var system = _systemService.GetSystem(connection, starId, i => i);

            if (system == null)
            {
                return(null);
            }

            var galaxyName = _galaxyService.GetGalaxyById(connection, system.GalaxyId, i => i.NativeName);

            if (galaxyName == null)
            {
                return(null);
            }

            var sectorName = _gSectorsService.GetById(connection, system.SectorId, i => i.NativeName);

            if (sectorName == null)
            {
                return(null);
            }

            var geometryStar = _systemService.GetGeometryStarById(connection, starId, i => i);

            if (geometryStar == null)
            {
                return(null);
            }

            var detailSystem = _systemService.GetDetailSystemBySystemId(connection, starId);

            if (detailSystem == null)
            {
                return(null);
            }

            var planetCountsInSystem = _gDetailPlanetService.GetPlanetCountInSystem(connection, starId);

            if (planetCountsInSystem == 0)
            {
                return(null);
            }


            var npcSkagry       = NpcHelper.GetNpcByName(Npc.SkagyName);
            var npcConfederaion = NpcHelper.GetNpcByName(Npc.ConfederationName);

            var owner        = npcSkagry.NpcUser.Nickname;
            var allianceName = npcSkagry.NpcAlliance.Name;


            if (detailSystem.AllianceId == npcConfederaion.NpcAlliance.Id)
            {
                owner        = npcConfederaion.NpcUser.Nickname;
                allianceName = npcConfederaion.NpcAlliance.Name;
            }
            if (detailSystem.UserName != null && detailSystem.UserName != npcSkagry.NpcUser.Nickname)
            {
                owner = detailSystem.UserName;
                if (detailSystem.AllianceId == npcConfederaion.NpcAlliance.Id)
                {
                    allianceName = npcConfederaion.NpcAlliance.Name;
                }
                else
                {
                    allianceName = _allianceService.GetAllianceById(connection, detailSystem.AllianceId, i => i.Name);
                }
            }

            var systemType = _gameTypeService.GetGGameType(connection, geometryStar.TypeId);
            var starInfo   = new StarInfoOut
            {
                GalaxyId             = system.GalaxyId,
                GalaxyName           = galaxyName,
                SectorId             = system.SectorId,
                SectorName           = sectorName,
                SystemId             = system.Id,
                SystemName           = detailSystem.Name,
                Id                   = system.Id,
                NativeName           = detailSystem.Name,
                TextureTypeId        = geometryStar.TextureTypeId,
                Owner                = owner,
                Bonus                = detailSystem.EnergyBonus,
                TypeNativeName       = systemType.Type,
                SubtypeNativeName    = systemType.SubType,
                SubtypeTranslateName = systemType.SubType,
                Description          =
                    L10N.ExecuteTranslateNameOrDescr(detailSystem.Description, false, L10N.GetCurrentCulture()),
                AllianceName = allianceName,
                ChildCount   = planetCountsInSystem,
                SpriteImages = new SpriteImages().StarImages(systemType.SubType, geometryStar.TextureTypeId)
            };

            starInfo.SetComplexButtonView();

            return(starInfo);
        }