public BuildUpgrade SetData(StorageResources storageResourses, ItemProgress progress, string nativeName) { StorageResources = storageResourses; Progress = progress; NativeName = nativeName; return(this); }
private static void CalcNewRes(IStorage storage, ref StorageResources sourceRes, ref StorageResources targetRes, MaterialResource delta, bool premium, int?storageLevel = null) { var compareTarget = targetRes.CloneDeep(); sourceRes.Current = storage.CalculateTransferedRes(false, sourceRes.Current, delta, premium, storageLevel); targetRes.Current = storage.CalculateTransferedRes(true, targetRes.Current, delta, premium, storageLevel); if (!sourceRes.IsFull()) { return; } if (targetRes.Current.E - (compareTarget.Current.E + delta.E) > 0) { var overMax = targetRes.Current.E - targetRes.Max.E; sourceRes.Current.E += overMax; targetRes.Current.E -= overMax; } if (targetRes.Current.Ir - (compareTarget.Current.Ir + delta.Ir) > 0) { var overMax = targetRes.Current.Ir - targetRes.Max.Ir; sourceRes.Current.Ir += overMax; targetRes.Current.Ir -= overMax; } if (targetRes.Current.Dm - (compareTarget.Current.Dm + delta.Dm) > 0) { var overMax = targetRes.Current.Dm - targetRes.Max.Dm; sourceRes.Current.Dm += overMax; targetRes.Current.Dm -= overMax; } }
private static async Task <StorageResources> DiscoverStorageResourcesAsync(IAmazonServiceDiscovery discovery, string serviceId) { GetInstanceResponse resourcesResponse; try { resourcesResponse = await discovery.GetInstanceAsync(new GetInstanceRequest() { ServiceId = serviceId, InstanceId = "storageTables", }); } catch (Exception e) { Console.WriteLine(e); throw; } var attributes = resourcesResponse.Instance.Attributes; var storage = new StorageResources() { CountersTable = attributes["counters"], KudosTable = attributes["kudos"], LinkRequestsTable = attributes["linkrequests"], UserIdsTable = attributes["userids"], ChatMessagesTable = attributes["chatmessages"], SentimentSnapshotTable = attributes["sentimentsnapshots"], PaginationTokensTable = attributes["paginationtokens"], SocketSessionsTable = attributes["socketsessions"] }; return(storage); }
public UserMothershipDataModel CreateMother(IDbConnection connection, int userId, int startSystem = 1) { var r = StorageResources.InitMotherResources(); var curMother = GetMother(connection, userId, false); if (curMother != null) { return(curMother); } var teches = new BattleTeches(); teches.CreateStartTeches(); var userTeches = teches.ConvertToDbTeches(); var newMother = new UserMothershipDataModel { Id = userId, StartSystemId = startSystem, Resources = r, Hangar = UnitList.InitUnitsInOwn(), ExtractionProportin = MaterialResource.InitBaseOwnProportion(), UnitProgress = new Dictionary <UnitType, TurnedUnit>(), TechProgress = userTeches }; return(AddOrUpdate(connection, newMother)); }
public BuildItemUnitView GetViewModel(ItemProgress buildProgress, bool premiumIsActive, StorageResources resources = null) { var text = _text; var images = _images; var level = buildProgress?.Level ?? 1; var model = new BuildItemUnitView { TranslateName = text.Name, NativeName = NativeName, IconSelf = images.Icon, Progress = buildProgress, Info = new BuildDropItemInfo { Description = text.Name, DropImage = images.Detail }, Update = new BuildDropItemUpdate { Price = CalcPrice(level, premiumIsActive), Properties = PropertyList(level, premiumIsActive) }, IsBuildItem = true }; model.SetComplexButtonView(); model.Update.SetButtons(); //model.Action.SetButtons(); return(model); }
public BuildItemUnitView GetMotherViewModel(bool premiumIsActive, StorageResources resources = null) { //if (resources == null) throw new Exception(Error.UserResourceNotSetInInstance); var description = new LangField(Resource.MotherEnergyConverter, Resource.MotherEnergyConverterDescription); var images = new SpriteImages().BuildImages(MotherCssNativename); var model = new BuildItemUnitView { TranslateName = description.Name, NativeName = NativeName, IconSelf = images.Icon, Info = new BuildDropItemInfo { Description = description.Name, DropImage = images.Detail }, Action = new BuildDropItemAction { ViewPath = BuildEnergyConverterActions.ViewPath, Data = new BuildEnergyConverterActions { StorageResources = null, ConvertLoses = GameMathStats.BaseConvertLosses } }, IsBuildItem = true }; model.SetComplexButtonView(); model.Action.SetButtons(); return(model); }
public StorageResources Execute(IDbConnection connection, int userId, StorageResources res, int planetId = 0) { var pr = _storeService.GetPremiumWorkModel(connection, userId); if (pr.IsActive) { return(_premiumActive(connection, userId, res, planetId)); } if (!res.NeedFix()) { return(res); } var fixedRes = FixCurrentResources(res); if (planetId == 0) { var updatedMother = _mother.SetNewResources(connection, userId, fixedRes); return(updatedMother.Resources); } var updatedPlanetRes = _planet.SetNewResources(connection, planetId, userId, fixedRes); return(updatedPlanetRes.Resources); }
public UserMothershipDataModel SetNewResources(IDbConnection connection, int userId, StorageResources newResources) { var mother = GetMother(connection, userId, true); mother.Resources = newResources; return(Update(connection, mother)); }
public void ResetMotherResourceById(IDbConnection connection, int userId) { var res = StorageResources.InitMotherResources(); var mother = _mothershipService.GetMother(connection, userId); mother.Resources = res; _mothershipService.AddOrUpdate(connection, mother); }
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) }); }
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 void ResetAllMotherResources(IDbConnection connection) { var res = StorageResources.InitMotherResources(); var mothers = _mothershipService.GetAllMothers(connection); foreach (var mother in mothers) { mother.Resources = res; } _mothershipService.AddOrUpdate(connection, mothers); }
public override int GetHashCode() { unchecked { var hashCode = (StorageResources != null ? StorageResources.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Progress != null ? Progress.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (NativeName != null ? StringComparer.InvariantCulture.GetHashCode(NativeName) : 0); hashCode = (hashCode * 397) ^ Cc; return(hashCode); } }
public BuildItemUnitView GetMotherViewModel(bool premiumIsActive, StorageResources resources = null) { if (resources?.Current == null) { throw new Exception(Error.ProportionNotSetInModel); } var description = new LangField(Resource.MotherExtractionModule, Resource.MotherStorageDescription); var images = new SpriteImages().BuildImages(MotherCssNativename); //todo временно // var power = GetPower(1, premiumIsActive); var power = GetPower(22, premiumIsActive); var extraction = new ExtractionResource(); extraction.SetAndCalcEmpFromProportion(resources.Current, power, BaseProportion.Ir, BaseProportion.Dm); var model = new BuildItemUnitView { TranslateName = description.Name, NativeName = NativeName, IconSelf = images.Icon, Info = new BuildDropItemInfo { Description = description.Name, DropImage = images.Detail }, Action = new BuildDropItemAction { ViewPath = BuildExtractionModuleActions.ViewPath, Data = new BuildExtractionModuleActions { //todo реализовать Power = power, Percent = extraction.ExtractionProportin, ExtractionPerHour = extraction.ExtractionPerHour } }, IsBuildItem = true }; model.SetComplexButtonView(); model.Action.SetButtons(); return(model); }
public IHttpActionResult ObjectToDics() { var s = new StorageResources(); s.InitializeField(); s.Current.Init(100, 200, 300); s.Max.Init(1000, 1500, 1800); var names = new List <string> { "E", "Ir", "Dm" }; var result = names.Select(name => StorageResourceItem.GetItemByName(s, name)).ToList(); return(Json(result)); }
public void Init(NpcUser npc, StorageResources sr = null, Dictionary <UnitType, int> hangar = null, MaterialResource extraction = null) { Id = npc.Id; Resources = sr ?? StorageResources.InitPlanetResources(); Hangar = hangar ?? UnitList.InitUnitsInOwn(true); ExtractionProportin = extraction ?? MaterialResource.InitBaseOwnProportion(); StartSystemId = 1; LastUpgradeProductionTime = 0; LaboratoryProgress = new ItemProgress(); var teches = new BattleTeches(); teches.CreateStartTeches(); TechProgress = teches.ConvertToDbTeches(); }
public BuildItemUnitView GetViewModel(ItemProgress buildProgress, bool premiumIsActive, StorageResources resources = null) { //todo Временный костыль из за не состыковки типов if (resources?.Current == null) { throw new Exception(Error.ProportionNotSetInModel); } var em = Init(buildProgress, premiumIsActive, resources.Current); var model = new BuildItemUnitView { Progress = em.ItemProgress, TranslateName = em.Text.Name, NativeName = NativeName, IconSelf = em.Images.Icon, Info = new BuildDropItemInfo { DropImage = em.Images.Detail, Description = em.Text.Description }, Action = new BuildDropItemAction { ViewPath = BuildExtractionModuleActions.ViewPath, Data = new BuildExtractionModuleActions { Power = em.Power, Percent = em.ExtractionProportin, ExtractionPerHour = em.ExtractionPerHour } }, Update = new BuildDropItemUpdate { Price = em.Cost, Properties = em.Properties }, IsBuildItem = true }; model.SetComplexButtonView(); model.Update.SetButtons(true); model.Action.SetButtons(true); return(model); }
public Storage Init(StorageResources storageResourses, ItemProgress itemProgress, bool premiumIsActive) { if (itemProgress == null) { itemProgress = new ItemProgress { Level = 1 } } ; StorageResources = storageResourses; ItemProgress = itemProgress; Cost = CalcPrice((int)itemProgress.Level, premiumIsActive); Images = _images; Text = _text; Properties = PropertyList((int)itemProgress.Level, premiumIsActive); return(this); }
public BuildItemUnitView GetViewModel(ItemProgress buildProgress, bool premiumIsActive, StorageResources resources = null) { var model = new BuildItemUnitView { Progress = buildProgress, TranslateName = _text.Name, NativeName = NativeName, IconSelf = _images.Icon, Info = GetInfo(), Update = new BuildDropItemUpdate { Price = CalcPrice(premiumIsActive) }, IsBuildItem = true }; model.SetComplexButtonView(); model.Update.SetButtons(); return(model); }
public BuildItemUnitView GetViewModel(ItemProgress buildProgress, bool premiumIsActive, StorageResources resources = null) { var ec = Init(premiumIsActive, buildProgress); var model = new BuildItemUnitView { Progress = ec.ItemProgress, TranslateName = ec.Text.Name, NativeName = NativeName, IconSelf = ec.Images.Icon, Info = new BuildDropItemInfo { Description = ec.Text.Description, DropImage = ec.Images.Detail }, Update = new BuildDropItemUpdate { Properties = ec.Properties, Price = ec.Cost }, Action = new BuildDropItemAction { ViewPath = BuildEnergyConverterActions.ViewPath, Data = new BuildEnergyConverterActions { StorageResources = null, ConvertLoses = ec.Properties[0].CurrentValue } }, IsBuildItem = true }; model.SetComplexButtonView(); model.Update.SetButtons(true); model.Action.SetButtons(true); return(model); }
public BuildItemUnitView GetViewModel(ItemProgress buildProgress, bool premiumIsActive, StorageResources resources = null) { //var res = ToModel<StorageResources>(planet.resources); var storage = Init(resources, buildProgress, premiumIsActive); var model = new BuildItemUnitView { Progress = storage.ItemProgress, TranslateName = storage.Text.Name, NativeName = NativeName, IconSelf = storage.Images.Icon, Info = new BuildDropItemInfo { DropImage = storage.Images.Detail, Description = storage.Text.Description }, Action = new BuildDropItemAction { ViewPath = BuildStorageActions.ViewPath, Data = new BuildStorageActions { StorageResources = storage.StorageResources, Losses = storage.Properties[3].CurrentValue + 1 } }, Update = new BuildDropItemUpdate { Price = storage.Cost, Properties = storage.Properties }, IsBuildItem = true }; SetRequiredButtons(model); model.Update.SetButtons(); return(model); }
public IHttpActionResult Equals() { var src = new StorageResources(); src.InitializeField(); src.Current.E = 10; src.Current.Ir = 15; src.Current.Dm = 100; src.Max.E = 10; src.Max.Ir = 15; src.Max.Dm = 100; var cloneTrue = src.CloneDeep(); var cloneFalse = src.CloneDeep(); cloneFalse.Current.E = 6; var otherTrue = new StorageResources(); otherTrue.InitializeField(); otherTrue.Current.E = 10; otherTrue.Current.Ir = 15; otherTrue.Current.Dm = 100; otherTrue.Max.E = 10; otherTrue.Max.Ir = 15; otherTrue.Max.Dm = 100; var result = new { srcEqcloneTrue = src.Equals(cloneTrue), srcEqcloneFalse = src.Equals(cloneFalse), srcEqotherTrue = src.Equals(otherTrue) }; return(Json(result)); }
public BuildItemUnitView GetMotherViewModel(bool premiumIsActive, StorageResources resources = null) { if (resources == null) { resources = new StorageResources(); resources.InitializeField(); } var description = new LangField(Resource.MotherStorage, Resource.MotherStorageDescription); var images = new SpriteImages().BuildImages(MotherCssNativename); var model = new BuildItemUnitView { TranslateName = description.Name, NativeName = NativeName, IconSelf = images.Icon, Info = new BuildDropItemInfo { Description = description.Name, DropImage = images.Detail }, Action = new BuildDropItemAction { ViewPath = BuildStorageActions.ViewPath, Data = new BuildStorageActions { StorageResources = resources, Losses = GetTransferLossesMod(1, premiumIsActive) } }, IsBuildItem = true }; SetRequiredButtons(model); return(model); }
/// <summary> /// Вычисляет данные для записи нового эллемента очереди юнита на мезере ил планете /// </summary> /// <param name="unitType">Native name Unit</param> /// <param name="count">Желаемое количество для покупки</param> /// <param name="resource">текушие ресурсы пользователя</param> /// <param name="unit">тип юнита который мы покупаем</param> /// <param name="resultPrice">Итоговая стоимость пачки с учетом проверки на нехватку ресурсов</param> /// <param name="unitTurnModel">новый эллемент очереди (еще не просумированный с основной очередью)</param> private static void InitializeUnitTurn(UnitType unitType, int count, StorageResources resource, UnitModel unit, out MaterialResource resultPrice, out TurnedUnit unitTurnModel) { var basePrice = unit.BasePrice; //вычисляем стоимость пачки var price = MaterialResource.CalcUnitsPrice(basePrice, count); int resultCount; //проверяем хватает ли ресурсов if (MaterialResource.EnoughResourses(resource.Current, price)) { resultCount = count; resultPrice = price; } else { var newCount = CalculateMaxCount(basePrice, resource.Current); if (newCount == 0) { throw new Exception(Error.NotEnoughResources); } resultCount = newCount; resultPrice = MaterialResource.CalcUnitsPrice(basePrice, newCount); } //устанавливаем модель var time = UnixTime.UtcNow(); unitTurnModel = new TurnedUnit { TotalCount = resultCount, DateCreate = time, UnitType = unitType, DateLastUpgrade = time }; }
private static StorageResources _callculateNewResources(StorageResources dbRes, EnergyConverterChangeOut clientData, int level) { var toConvert = clientData.ToConvert; var resources = dbRes.ToDictionary(); var current = StorageResources.GetCurrent(resources); var max = StorageResources.GetMax(resources); var srcName = clientData.From; var targetName = clientData.To; var srcCount = current[srcName]; var targetCount = current[targetName]; var targetMax = max[targetName]; if (srcCount < 1) { throw new Exception(Error.NotEnoughResources); } if (targetMax - targetCount < 1) { throw new Exception(Error.TargetResourceIsFull); } var bp = ExtractionModule.BaseProportion.ToDictionary(); double realCount = toConvert; if ((srcCount - toConvert) < 1) { realCount = srcCount; } var loses = 1 - GetEnergyConverterMod(level); var rate = (bp[srcName] / bp[targetName]) * loses; if (rate <= 0) { rate = 1; } var freeTargetRes = targetMax - targetCount; var potentialSourceMax = freeTargetRes / rate; if (potentialSourceMax - realCount < 1) { realCount = potentialSourceMax; } var raealAdedResource = realCount * rate; if (raealAdedResource < 1) { throw new Exception(Error.NotEnoughResources); } var targetSum = targetCount + raealAdedResource; if (targetMax < targetSum) { throw new Exception(Error.MathError); } resources[StorageResources.CurrentKey][srcName] = srcCount - realCount; resources[StorageResources.CurrentKey][targetName] = targetCount + raealAdedResource; return(StorageResources.DictionaryToStorageResources(resources)); }
public GDetailPlanetDataModel SetNewResources(IDbConnection connection, int planetId, int userId, StorageResources newResources) { return(UpdateUserPlanet(connection, planetId, userId, planet => { planet.Resources = newResources; return planet; })); }
private static void FixProgreses(UserMothershipDataModel mother, UserPremiumWorkModel userPremium) { #region Premium var pt = userPremium.TimeLineStatus; #endregion #region CalcResource var lastUpgradeProductionTime = mother.LastUpgradeProductionTime; var beforeResource = mother.Resources.CloneDeep(); var last = pt?.Status?.Last(); var curPrem = (last != null && (bool)last); // var motherExtatracionLevel = 1; var motherExtatracionLevel = 22; StorageResources.CalculateProductionResources(beforeResource, mother.ExtractionProportin, ref lastUpgradeProductionTime, motherExtatracionLevel, curPrem, ExtractionModule.BaseProportion.Ir, ExtractionModule.BaseProportion.Dm, ExtractionModule.GetPower, (res) => { StorageResourcesService.FixCurrentResources(res); } ); if (!mother.Resources.Equals(beforeResource)) { mother.Resources = beforeResource; } #region Laboratory if (mother.TechProgress.Select(i => i.Value).ToList().Any(i => i.IsProgress == true)) { var techService = new BattleTeches(mother.TechProgress); if (techService.CalculateTechProgreses(techService.GetTeches(false), userPremium)) { mother.TechProgress = techService.ConvertToDbTeches(); } } #endregion mother.LastUpgradeProductionTime = lastUpgradeProductionTime; #endregion if (mother.UnitProgress == null || !mother.UnitProgress.Any()) { if (mother.UnitProgress == null) { mother.UnitProgress = new Dictionary <UnitType, TurnedUnit>(); } return; } #region Calc UnitProgress const int shipyardLevel = 1; var pureTurn = mother.UnitProgress; var hangarUnits = mother.Hangar; bool unitInProgress; TurnedUnit.CalculateUserUnits(pt, ref pureTurn, out unitInProgress, ref hangarUnits, shipyardLevel, Unit.CalculateTrickyUnitTimeProduction, (unitType) => UnitHelper.GetBaseUnit(unitType).BasePrice.TimeProduction, Unit.CalculateTimeProduction); mother.UnitProgress = unitInProgress ? pureTurn : new Dictionary <UnitType, TurnedUnit>(); mother.Hangar = hangarUnits; #endregion }
public BuildUpgrade(StorageResources storageResourses, ItemProgress progress, string nativeName) { SetData(storageResourses, progress, nativeName); }
public static StorageResources FixCurrentResources(StorageResources currResources) { currResources.Current = MaterialResource.FixCurrentResources(currResources.Current, currResources.Max); return(currResources); }
private StorageResources _premiumActive(IDbConnection connection, int userId, StorageResources res, int planetId) { var level = 1; var newRes = res.CloneDeep(); if (planetId != 0) { // todo создать генератор всех хранишищ var p = _planet.GetUserPlanet(connection, planetId, userId); if (p.BuildStorage.Level != null) { level = (int)p.BuildStorage.Level; } newRes.Max = Storage.MaxStorable(level, true); if (!res.NeedFix()) { return(newRes); } var fixedPlanetRes = FixCurrentResources(newRes); var updatedPlanetRes = _planet.SetNewResources(connection, planetId, userId, fixedPlanetRes); return(updatedPlanetRes.Resources); } newRes.Max = Storage.MaxMotherStorable(true); if (!res.NeedFix()) { return(newRes); } var fixedMotherRes = FixCurrentResources(newRes); var updatedMother = _mother.SetNewResources(connection, userId, fixedMotherRes); return(updatedMother.Resources); }