public override List <BuildItemUnitView> GetPlanetBuildList(GDetailPlanetDataModel planet,
                                                             UserPremiumWorkModel userPremium)
 {
     return(new List <BuildItemUnitView>
     {
         _turels.GetViewModel(planet.Turels, userPremium.IsActive)
     });
 }
 private static void SetUnitUpgradeInHangarUnit(UserPremiumWorkModel userPremium, int shipyardlevel,
                                                ref Dictionary <UnitType, HangarUnitsOut> outUnits, Dictionary <UnitType, TurnedUnit> unitsProgress)
 {
     foreach (var i in unitsProgress)
     {
         outUnits[i.Key].Progress = CalculateUnitProgress(i.Value,
                                                          UnitHelper.GetBaseUnit(i.Key).BasePrice.TimeProduction, shipyardlevel, userPremium,
                                                          outUnits[i.Key].Count ?? 0);
     }
 }
 public override List <BuildItemUnitView> GetPlanetBuildList(GDetailPlanetDataModel planet,
                                                             UserPremiumWorkModel userPremium)
 {
     return(new List <BuildItemUnitView>
     {
         _storage.GetViewModel(planet.BuildStorage, userPremium.IsActive, planet.Resources),
         _extractionModule.GetViewModel(planet.BuildExtractionModule, userPremium.IsActive,
                                        StorageResources.StorageProportion(planet.ExtractionProportin)),
         _energyConverter.GetViewModel(planet.BuildEnergyConverter, userPremium.IsActive)
     });
 }
 public override List <BuildItemUnitView> GetMotherBuildList(UserMothershipDataModel mother,
                                                             UserPremiumWorkModel userPremium)
 {
     return(new List <BuildItemUnitView>
     {
         _storage.GetMotherViewModel(userPremium.IsActive, mother.Resources),
         _extractionModule.GetMotherViewModel(userPremium.IsActive,
                                              StorageResources.StorageProportion(mother.ExtractionProportin)),
         _energyConverter.GetMotherViewModel(userPremium.IsActive)
     });
 }
        private static Dictionary <UnitType, HangarUnitsOut> GetherMotherUnits(UserMothershipDataModel mother,
                                                                               UserPremiumWorkModel userPremium)
        {
            var outUnits = UnitList.ConvertToHangar(mother.Hangar);

            if (mother.UnitProgress == null || !mother.UnitProgress.Any())
            {
                return(outUnits);
            }
            SetUnitUpgradeInHangarUnit(userPremium, 1, ref outUnits, mother.UnitProgress);
            return(outUnits);
        }
        public override List <BuildItemUnitView> GetPlanetBuildList(GDetailPlanetDataModel planet,
                                                                    UserPremiumWorkModel userPremium)
        {
            var shipyardColletion = new List <BuildItemUnitView>
            {
                _spaceShipyard.GetViewModel(planet.BuildSpaceShipyard, userPremium.IsActive)
            };
            var builds = Unit.GetBuildItemUnitViewList(planet.Hangar, planet.UnitProgress, planet.BuildSpaceShipyard, userPremium, OwnType.Planet);

            shipyardColletion.AddRange(builds);
            return(shipyardColletion);
        }
Esempio n. 7
0
        public bool CalculateTechProgreses(Dictionary <TechType, Tech> teches, UserPremiumWorkModel premium)
        {
            var hasChange = false;
            var col       = teches.Select(techItem => techItem.Value)
                            .Where(tech =>
                                   tech.Progress != null && tech.Progress.IsProgress == true && tech.Progress.CheckProgressIsDone());

            foreach (var tech in col)
            {
                ItemProgress.ProgressUpdateComplite(tech.Progress);
                hasChange = true;
            }
            return(hasChange);
        }
        public override List <BuildItemUnitView> GetMotherBuildList(UserMothershipDataModel mother,
                                                                    UserPremiumWorkModel userPremium)
        {
            var teches    = new BattleTeches(mother.TechProgress);
            var techesOut = teches.ConvertToTechesOut(false);


            var propertiesView = teches.CreateBuildItemTechData(false);
            var result         = new List <BuildItemUnitView>();

            techesOut.ForEach(i =>
            {
                var techOut = techesOut[i.Value.TechType];
                techOut.CalcResultPrice(userPremium.IsActive);
                var model = new BuildItemUnitView
                {
                    Progress      = i.Value.Progress,
                    TranslateName = i.Value.Text.Name,
                    NativeName    = i.Value.TechType.ToString(),
                    IconSelf      = i.Value.SpriteImages.Icon,
                    Info          = new BuildDropItemInfo
                    {
                        Description = i.Value.Text.Description,
                        DropImage   = i.Value.SpriteImages.Detail,
                        Data        = propertiesView[i.Value.TechType]
                    },
                    Update = new BuildDropItemUpdate
                    {
                        Properties    = propertiesView[i.Value.TechType].Properties.Select(p => p.Value).ToList(),
                        Price         = i.Value.BasePrice,
                        IsUnitUpgrade = false
                    },
                    IsBuildItem  = false,
                    AdvancedData = new Dictionary <string, object>
                    {
                        { "TechOut", techOut }
                    }
                };
                model.SetComplexButtonView();
                if (!techOut.Disabled)
                {
                    model.Update.SetButtons(true);
                }


                result.Add(model);
            });
            return(result);
        }
        public Dictionary <UnitType, HangarUnitsOut> GetherHangarUnits(object own, UserPremiumWorkModel userPremium,
                                                                       OwnType ownType)
        {
            switch (ownType)
            {
            case OwnType.Mother:
                return(GetherMotherUnits((UserMothershipDataModel)own, userPremium));

            case OwnType.Planet:
                return(GetherPlanetUnits((GDetailPlanetDataModel)own, userPremium));

            default:
                throw new ArgumentOutOfRangeException(nameof(ownType), ownType, null);
            }
        }
        private static Dictionary <UnitType, HangarUnitsOut> GetherPlanetUnits(GDetailPlanetDataModel planet,
                                                                               UserPremiumWorkModel userPremium)
        {
            var shipyardlevel = 1;
            var shipyard      = planet.BuildSpaceShipyard;

            if (shipyard?.Level != null)
            {
                shipyardlevel = (int)shipyard.Level;
            }
            var outUnits = UnitList.ConvertToHangar(planet.Hangar);

            if (planet.UnitProgress == null || !planet.UnitProgress.Any())
            {
                return(outUnits);
            }
            SetUnitUpgradeInHangarUnit(userPremium, shipyardlevel, ref outUnits, planet.UnitProgress);
            return(outUnits);
        }
Esempio n. 11
0
        private static int CalcUnitDurationRemainTime(TurnedUnit tu, int baseTimeProduction, int buildLevel,
                                                      UserPremiumWorkModel userPremium, double?remainToComplete = null)
        {
            double rem;

            var modifedTime = CalculateTimeProduction(baseTimeProduction, userPremium.IsActive, buildLevel);


            if (remainToComplete == null)
            {
                rem = tu.TotalCount - tu.ReadyUnits;
            }
            else
            {
                rem = (double)remainToComplete;
            }


            if (!userPremium.IsActive)
            {
                if (buildLevel == 1)
                {
                    return((int)Math.Ceiling(baseTimeProduction * rem));
                }

                return((int)Math.Ceiling(modifedTime * rem));
            }

            var premiumRemainDuration = userPremium.EndTime - tu.DateLastUpgrade;
            var premiumUnitCount      = premiumRemainDuration / modifedTime;

            if (premiumUnitCount >= rem)
            {
                return((int)Math.Ceiling(modifedTime * rem));
            }
            var deltaUnit = rem - premiumUnitCount;

            return((int)Math.Ceiling((modifedTime * premiumUnitCount) + (deltaUnit * baseTimeProduction)));
        }
        public void PushDemon(IDbConnection connection, IGDetailPlanetService planetService, IStoreService storeService)
        {
            var curTime = UnixTime.UtcNow();

            if (curTime - LAST_DEMON_RUNTIME < MIN_DEMON_DELAY_SECOND)
            {
                return;
            }
            var unsortedPlanets = planetService.GetAllUsersPlanets(connection);

            if (!unsortedPlanets.Any())
            {
                return;
            }
            LAST_DEMON_RUNTIME = curTime;
            var minItemTime = curTime - MIN_DELAY_TO_UPDATE;
            var planets     = unsortedPlanets.Where(i => i.LastUpgradeProductionTime < minItemTime).OrderBy(i => i.UserId);
            UserPremiumWorkModel userPremium = null;

            foreach (var planet in planets)
            {
                if (!_needUpdate(planet))
                {
                    continue;
                }

                if (userPremium == null)
                {
                    userPremium = storeService.GetPremiumWorkModel(connection, planet.UserId);
                }
                if (userPremium.UserId != planet.UserId)
                {
                    userPremium = storeService.GetPremiumWorkModel(connection, planet.UserId);
                }
                FixProgreses(planet, userPremium);
                planetService.AddOrUpdate(connection, planet);
            }
        }
Esempio n. 13
0
        private static ItemProgress CalculateUnitProgress(TurnedUnit turnedUnit, int baseTimeProduction, int builLevel,
                                                          UserPremiumWorkModel userPremium, int hangarCount)
        {
            var remainToComplete = turnedUnit.TotalCount - turnedUnit.ReadyUnits;

            int?duration = null;

            if (remainToComplete > 0)
            {
                duration = CalcUnitDurationRemainTime(turnedUnit, baseTimeProduction, builLevel, userPremium,
                                                      remainToComplete);
            }

            return(new ItemProgress
            {
                Advanced = turnedUnit,
                StartTime = UnixTime.UtcNow(),
                Duration = duration,
                IsProgress = (duration != null),
                Level = hangarCount,
                RemainToComplete = remainToComplete
            });
        }
        public PlanshetViewData GetMotherCollection(IDbConnection connection, UserDataModel user, UserPremiumWorkModel userPremium, UserMothershipDataModel own, bool synchronize = true)
        {
            var mother = own;

            if (synchronize)
            {
                mother = _synchronizer.UserMothership(connection, mother, userPremium, _mothershipService, _motherJumpService);
            }
            var motherPlanshet = _getMotherCollection(GetMotherBuildList(mother, userPremium));

            motherPlanshet.IsMother = true;
            return(motherPlanshet);
        }
 public UserMothershipDataModel UserMothership(IDbConnection connection, UserMothershipDataModel mother, UserPremiumWorkModel userPremium, IMothershipService motherService, IUMotherJumpService motherJump)
 {
     return(_motherRunner.RunUser(connection, mother, userPremium, motherService, motherJump));
 }
 public abstract List <BuildItemUnitView> GetMotherBuildList(UserMothershipDataModel mother,
                                                             UserPremiumWorkModel userPremium);
        public PlanshetViewData GetCollection(IDbConnection connection, UserDataModel user, UserPremiumWorkModel currentUserPremium, object dataModel, OwnType ownType, bool synchronize = true)
        {
            switch (ownType)
            {
            case OwnType.Mother:
                return(GetMotherCollection(connection, user, currentUserPremium, (UserMothershipDataModel)dataModel,
                                           synchronize));

            case OwnType.Planet:
                return(GetPlanetCollection(connection, user, currentUserPremium, (GDetailPlanetDataModel)dataModel,
                                           synchronize));

            default:
                throw new ArgumentOutOfRangeException(nameof(ownType), ownType, null);
            }
        }
        public PlanshetViewData GetPlanetCollection(IDbConnection connection, UserDataModel user, UserPremiumWorkModel userPremium, GDetailPlanetDataModel own, bool synchronize = true)
        {
            var planet = own;

            if (synchronize)
            {
                planet = _synchronizer.UserPlanet(connection, own, userPremium, _gDetailPlanetService);
            }
            var planetPlanshet = _getPlanetCollection(GetPlanetBuildList(planet, userPremium));

            planetPlanshet.IsMother = false;
            return(planetPlanshet);
        }
 public abstract List <BuildItemUnitView> GetPlanetBuildList(GDetailPlanetDataModel planet,
                                                             UserPremiumWorkModel userPremium);
Esempio n. 20
0
        public Dictionary <string, IPlanshetViewData> GetEstate(IDbConnection connection, UserDataModel user, UserPremiumWorkModel userPremium, object own, OwnType ownType, bool synchronize = true)
        {
            switch (ownType)
            {
            case OwnType.Mother:
                return(GetMotherEstate(connection, user, userPremium, (UserMothershipDataModel)own, synchronize));

            case OwnType.Planet:
                return(GetPlanetEstate(connection, user, userPremium, (GDetailPlanetDataModel)own, synchronize));

            default:
                throw new ArgumentOutOfRangeException(nameof(ownType), ownType, null);
            }
        }
Esempio n. 21
0
        public Dictionary <string, object> InitUser(IDbConnection connection, ClaimsPrincipal pricipalUser, IServiceProvider resolver)
        {
            if (pricipalUser == null)
            {
                throw new NullReferenceException(nameof(pricipalUser));
            }
            var allianceService   = resolver.GetService <IAllianceService>();
            var sectorService     = resolver.GetService <IGSectorsService>();
            var estateListService = resolver.GetService <IEstateListService>();
            var systemService     = resolver.GetService <ISystemService>();
            var localizer         = resolver.GetService <ILocalizerService>();

            var tmpUser = _gameUserService.GetCurrentGameUser(connection, pricipalUser);

            if (tmpUser == null)
            {
                throw new NullReferenceException(nameof(tmpUser));
            }
            var gameUser      = _gameUserService.UpdateUserOnlineStatus(connection, tmpUser, true);
            var userChest     = _storeService.GetChestUser(connection, gameUser.Id);
            var balanceData   = (UchBalanceCcData)userChest.ActivatedItemsView[ProductTypeIds.Cc].Data;
            var up            = (UchPremiumData)userChest.ActivatedItemsView[ProductTypeIds.Premium].Data;
            var userPremiumWm = new UserPremiumWorkModel(up.Premium);

            var motherData = _mothershipService.GetMother(connection, gameUser.Id);
            var mother     =
                _synchronizer.UserMothership(connection, motherData, userPremiumWm, _mothershipService, _motherJumpService);

            var planetsData = _detailPlanetService.GetUserPlanets(connection, gameUser.Id);

            if (planetsData != null && planetsData.Any())
            {
                planetsData = _synchronizer.UserPlanets(connection, planetsData, userPremiumWm, _detailPlanetService);
            }
            _synchronizer.RunUserTasks(connection, gameUser.Id);

            var sectors      = sectorService.GetInitSectors(connection);
            var allianceUser = allianceService.GetAllianceUserByUserId(connection, gameUser.Id);
            var alliance     = allianceService.Initial(connection, allianceUser, _gameUserService);
            var personalInfo =
                _gameUserService.GetUserPlanshetProfile(connection, allianceUser.UserId, allianceUser.AllianceId, alliance, true);
            // обновляет пользователя в дб обект юзер обновляет по ссылке
            var myAlliance     = (TabMyAllianceOut)alliance.Bodys[1].TemplateData;
            var connectionUser = _gameUserService.SetConnectionUser(connection, gameUser, allianceUser, myAlliance.Name);
            //btns
            var units = HangarUnitsOut.EmptyHangar();
            var keys  = units.Keys.ToList();

            var systemGeometry = systemService.GetSystemGeometryViewData(connection, mother.StartSystemId);
            var motherEstates  = GetMotherEstate(connection, gameUser, userPremiumWm, mother, false);

            var toggleBtns = new List <IButtonsView>
            {
                ButtonsView.HangarToggle()
            };

            var leftNavBtns = new List <IButtonsView>
            {
                ButtonsView.LefMenuNavAlliance(),
                ButtonsView.LefMenuNavConfederation(),
                ButtonsView.LefMenuNavJournal(),
                ButtonsView.LefMenuNavChannels()
            };
            var mapControllBtns = MapInfoService.MapControllButtons(_localizer);
            var hangarBtns      = keys.Select(key => units[key]).Select(ButtonsView.HangarListBtns).ToList();
            //var storageModel = new StorageResources();
            //storageModel.InitializeField();

            var btns = new Dictionary <string, IReadOnlyList <IButtonsView> >
            {
                { "toggleBtns", toggleBtns },
                { "leftNavBtns", leftNavBtns },
                { "mapControllBtns", mapControllBtns },
                { "hangarBtns", hangarBtns }
            };
            var alianceNames = allianceService.GetAllianceNames(connection, false);


            var result = new Dictionary <string, object>
            {
                { localizer.TranslationKey, localizer.GetGameTranslate() },
                { ResourcesView.ViewKey, ResourcesView.GetInitList(balanceData.BalanceCc.Quantity) },
                { MapTypes.Sector.ToString(), sectors },
                { ButtonsView.BaseBtnsKey, btns },
                //todo data incorrect

                { UchView.ViewKey, userChest },
                { EstateItemOut.ViewKey, estateListService.GetList(connection, gameUser.Id) },
                { ConnectionUser.ViewKey, connectionUser },

                { alliance.UniqueId, alliance },
                { UserProfileInfo.AvatarViewKey, personalInfo },
                { EstateViewKey, motherEstates },
                { AllianceOut.AllianceNamesKey, alianceNames },
                { Planetoids.ViewKey, systemGeometry }
            };

            return(result);
        }
 public GDetailPlanetDataModel UserPlanet(IDbConnection connection, GDetailPlanetDataModel planet, UserPremiumWorkModel userPremium, IGDetailPlanetService planetService)
 {
     return(_planetRunner.RunSinglePlanet(connection, planet, userPremium, planetService));
 }
Esempio n. 23
0
 public ItemProgress FixMotherItemProgress(UnitType unitType, UserMothershipDataModel mother,
                                           UserPremiumWorkModel userPremium)
 {
     return(FixItemProgress(unitType, mother.Hangar, mother.UnitProgress, userPremium));
 }
Esempio n. 24
0
        public ItemProgress FixItemProgress(UnitType unitType, object modelData, OwnType ownType, UserPremiumWorkModel userPremium)
        {
            switch (ownType)
            {
            case OwnType.Mother:
                return(FixMotherItemProgress(unitType, (UserMothershipDataModel)modelData, userPremium));

            case OwnType.Planet:
                return(FixPlanetItemProgress(unitType, (GDetailPlanetDataModel)modelData, userPremium));

            default:
                throw new ArgumentOutOfRangeException(nameof(ownType), ownType, null);
            }
        }
 public IList <GDetailPlanetDataModel> UserPlanets(IDbConnection connection, IList <GDetailPlanetDataModel> planets, UserPremiumWorkModel userPremium, IGDetailPlanetService planetService)
 {
     return(_planetRunner.RunPlanets(connection, planets, userPremium, planetService));
 }
Esempio n. 26
0
        public void TransMotherToPlanet(IDbConnection connection, int targetId, MaterialResource deltaResourses, int userId, UserPremiumWorkModel userPremium)
        {
            var sourseMother = _mother.GetMother(connection, userId);
            var targetPlanet = _planetService.GetUserPlanet(connection, targetId, userId);

            sourseMother = _synchronizer.UserMothership(connection, sourseMother, userPremium, _mother, _motherJumpService);
            targetPlanet = _synchronizer.UserPlanet(connection, targetPlanet, userPremium, _planetService);


            var curRes    = sourseMother.Resources; // _storageResourcesService.Execute(connection, userId, sourseMother.Resources);
            var targetRes = targetPlanet.Resources; //_storageResourcesService.Execute(connection, userId, targetPlanet.Resources, targetId);

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


            sourseMother.Resources = curRes;
            _mother.AddOrUpdate(connection, sourseMother);

            targetPlanet.Resources = _storageResourcesService.Execute(connection, userId, targetRes, targetId);
            _planetService.AddOrUpdate(connection, targetPlanet);
        }
Esempio n. 27
0
 public ItemProgress FixPlanetItemProgress(UnitType unitType, GDetailPlanetDataModel planet,
                                           UserPremiumWorkModel userPremium)
 {
     return(FixItemProgress(unitType, planet.Hangar, planet.UnitProgress, userPremium,
                            planet.BuildSpaceShipyard));
 }
Esempio n. 28
0
        public Dictionary <string, IPlanshetViewData> GetPlanetEstate(IDbConnection connection, UserDataModel user, UserPremiumWorkModel userPremium, GDetailPlanetDataModel own, bool synchronize = true)
        {
            var planet = own;

            if (synchronize)
            {
                planet = _synchronizer.UserPlanet(connection, own, userPremium, _detailPlanetService);
            }

            var ic           = _industrialComplex.GetPlanetCollection(connection, user, userPremium, planet, false);
            var shipyard     = _shipyard.GetPlanetCollection(connection, user, userPremium, planet, false);
            var commandCentr = _commandCenter.GetPlanetCollection(connection, user, userPremium, planet, false);

            return(new Dictionary <string, IPlanshetViewData>
            {
                { ic.UniqueId, ic },
                { shipyard.UniqueId, shipyard },
                { commandCentr.UniqueId, commandCentr }
            });
        }
Esempio n. 29
0
        private static ItemProgress FixItemProgress(UnitType unitType, Dictionary <UnitType, int> hangarUnits,
                                                    Dictionary <UnitType, TurnedUnit> progessUnits, UserPremiumWorkModel userPremium,
                                                    ItemProgress buildSpaceShipyard = null)
        {
            if (!hangarUnits.ContainsKey(unitType))
            {
                throw new Exception(Error.UnitNameNotExist);
            }

            var unitCount = hangarUnits[unitType];

            var hasProgress    = progessUnits.Any();
            var unitExist      = (hasProgress && progessUnits.ContainsKey(unitType));
            var unitInTurn     = (unitExist && (progessUnits[unitType].TotalCount - progessUnits[unitType].ReadyUnits) > 0);
            var unitInProgress = (hasProgress && unitExist && unitInTurn);

            if (!unitInProgress)
            {
                return new ItemProgress
                       {
                           Level      = unitCount,
                           IsProgress = false
                       }
            }
            ;

            var shipyardLevel = 1;

            if (buildSpaceShipyard != null && buildSpaceShipyard.Level != null && buildSpaceShipyard.Level != 0)
            {
                shipyardLevel = (int)buildSpaceShipyard.Level;
            }
            var timeProduction = UnitHelper.GetBaseUnit(unitType).BasePrice.TimeProduction;

            return(CalculateUnitProgress(progessUnits[unitType], timeProduction, shipyardLevel, userPremium, unitCount));
        }
    }
Esempio n. 30
0
        public Dictionary <string, IPlanshetViewData> GetMotherEstate(IDbConnection connection, UserDataModel user, UserPremiumWorkModel userPremium, UserMothershipDataModel own, bool synchronize = true)
        {
            var mother = own;

            if (synchronize)
            {
                mother = _synchronizer.UserMothership(connection, own, userPremium, _mothershipService, _motherJumpService);
            }
            var ic         = _industrialComplex.GetMotherCollection(connection, user, userPremium, mother, false);
            var shipyard   = _shipyard.GetMotherCollection(connection, user, userPremium, mother, false);
            var laboratory = _laboratory.GetMotherCollection(connection, user, userPremium, mother, false);

            return(new Dictionary <string, IPlanshetViewData>
            {
                { ic.UniqueId, ic },
                { shipyard.UniqueId, shipyard },
                { laboratory.UniqueId, laboratory }
            });
        }