public NpcModel(string npcName, int npcId) { NpcUser = new NpcUser(); NpcUser.Init(npcName, npcId); NpcMother = new NpcMother(); NpcMother.Init(NpcUser); NpcAlliance = new NpcAlliance(); NpcAlliance.Init(NpcUser); NpcAllianceUser = new NpcAllianceUser(); NpcAllianceUser.Init(NpcUser, NpcAlliance); var teches = new BattleTeches(); teches.CreateStartTeches(); var npcTeches = teches.ConvertToDbTeches(); NpcAllianceTeth = new NpcAllianceTeth { Id = NpcAlliance.Id, Teches = npcTeches }; }
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)); }
/// <summary> /// Предварительные данные должны быть синхронизированны /// </summary> /// <param name="connection"></param> /// <param name="mother"></param> /// <param name="allianceTech"></param> /// <param name="confederationService"></param> /// <param name="storeService"></param> /// <returns></returns> public static Dictionary <UnitType, Dictionary <BattleStatTypes, IBattleStatsDouble> > GetUnitStatsAndMods(IDbConnection connection, UserMothershipDataModel mother, AllianceTechDataModel allianceTech, IConfederationService confederationService, IStoreService storeService) { var boosersMods = GetBoosterBonuses(connection, mother.Id, storeService); var officerBonus = confederationService.GetOfficerBonus(connection, allianceTech.Id); var userTechesService = new BattleTeches(mother.TechProgress); var allianceTechesService = new BattleTeches(allianceTech.Teches); return(GetUnitStatsAndMods(mother.Id, userTechesService, allianceTechesService, officerBonus, boosersMods)); }
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 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 static Dictionary <UnitType, Dictionary <BattleStatTypes, IBattleStatsDouble> > GetUnitStatsAndMods( int userId, BattleTeches userTechs, BattleTeches allianceTeches, IBattleStatsDouble officerBonus, IBattleStatsDouble boosertsSummaryMods) { var key = _stringGetKey(userId); var existData = TmpCache.Get(key); if (existData != null) { return((Dictionary <UnitType, Dictionary <BattleStatTypes, IBattleStatsDouble> >)existData); } boosertsSummaryMods.ConvertPercentToMod(); var dic = new Dictionary <UnitType, Dictionary <BattleStatTypes, IBattleStatsDouble> >(); var unitsStats = UnitHelper.CreateBaseUnitStats(); var userBaseUnitStats = userTechs.GetBaseResultStats(); var userProfileUnitStats = userTechs.GetProfileResultStats(); var allianceBaseUnitStats = allianceTeches.GetBaseResultStats(); var allianceProfileUnitStats = allianceTeches.GetProfileResultStats(); foreach (var unitStats in unitsStats) { var unitTechType = BattleTeches.UnitTypeToTechType(unitStats.Key); var statTypes = new Dictionary <BattleStatTypes, IBattleStatsDouble>(); var userUnitTechStat = userProfileUnitStats[unitTechType]; var allianceUnitTechStat = allianceProfileUnitStats[unitTechType]; var summaryMod = new BattleStatsDouble(0, 0); summaryMod.Add(userBaseUnitStats, false); summaryMod.Add(userUnitTechStat, false); summaryMod.Add(allianceBaseUnitStats, false); summaryMod.Add(allianceUnitTechStat, false); summaryMod.Add(officerBonus, false); summaryMod.Add(boosertsSummaryMods, true); statTypes.Add(BattleStatTypes.UnitStat, unitStats.Value.DoubleStats); statTypes.Add(BattleStatTypes.UserTechMod, userBaseUnitStats); statTypes.Add(BattleStatTypes.UserUnitProfileTechMod, userUnitTechStat); statTypes.Add(BattleStatTypes.AllianceTechMod, allianceBaseUnitStats); statTypes.Add(BattleStatTypes.AllianceUnitProfileTechMod, allianceUnitTechStat); statTypes.Add(BattleStatTypes.OfficerBonus, officerBonus); statTypes.Add(BattleStatTypes.BooserMod, boosertsSummaryMods); statTypes.Add(BattleStatTypes.SummaryMods, summaryMod); dic.Add(unitStats.Key, statTypes); } TmpCache.AddOrUpdate(key, dic, _chacheTime); return(dic); }
public static Dictionary <UnitType, Dictionary <BattleStatTypes, IBattleStatsDouble> > CreateSkagryMods( NpcModel npc) { // todo нужно определить одинаковоые или разные статы var dic = new Dictionary <UnitType, Dictionary <BattleStatTypes, IBattleStatsDouble> >(); //todo будут ли статы отличными. тут хорошее место для применения отличных статов от базы var unitsStats = UnitHelper.CreateBaseUnitStats(); //todo заполняем статы для нпс var npcTeches = new BattleTeches(npc.NpcMother.TechProgress); //todo можно вести свзяь с офицерами и элитными войсками скагри var officerBonus = new BattleStatsDouble(0, 0); // todo можно ввести связь с бустерами игрока, или ввести рандом на понижение сил скагрей var boosertsSummaryMods = new BattleStatsDouble(0, 0); var npcAllianceTeches = new BattleTeches(npc.NpcAllianceTeth.Teches); var userBaseUnitStats = npcTeches.GetBaseResultStats(); var userProfileUnitStats = npcTeches.GetProfileResultStats(); var allianceBaseUnitStats = npcAllianceTeches.GetBaseResultStats(); var allianceProfileUnitStats = npcAllianceTeches.GetProfileResultStats(); foreach (var unitStats in unitsStats) { var unitTechType = BattleTeches.UnitTypeToTechType(unitStats.Key); var statTypes = new Dictionary <BattleStatTypes, IBattleStatsDouble>(); var userUnitTechStat = userProfileUnitStats[unitTechType]; var allianceUnitTechStat = allianceProfileUnitStats[unitTechType]; var summaryMod = new BattleStatsDouble(0, 0); summaryMod.Add(userBaseUnitStats, false); summaryMod.Add(userUnitTechStat, false); summaryMod.Add(allianceBaseUnitStats, false); summaryMod.Add(allianceUnitTechStat, false); summaryMod.Add(officerBonus, false); summaryMod.Add(boosertsSummaryMods, true); statTypes.Add(BattleStatTypes.UnitStat, unitStats.Value.DoubleStats); statTypes.Add(BattleStatTypes.UserTechMod, userBaseUnitStats); statTypes.Add(BattleStatTypes.UserUnitProfileTechMod, userUnitTechStat); statTypes.Add(BattleStatTypes.AllianceTechMod, allianceBaseUnitStats); statTypes.Add(BattleStatTypes.AllianceUnitProfileTechMod, allianceUnitTechStat); statTypes.Add(BattleStatTypes.OfficerBonus, officerBonus); statTypes.Add(BattleStatTypes.BooserMod, boosertsSummaryMods); statTypes.Add(BattleStatTypes.SummaryMods, summaryMod); dic.Add(unitStats.Key, statTypes); } return(dic); }
public AllianceTechesOut(AllianceRoleDataModel userRole, Dictionary <TechType, ItemProgress> dbAllianceTeches) { CanUpgrade = userRole.SetTech; var techService = new BattleTeches(dbAllianceTeches); var teches = techService.GetTeches(false); teches.ForEach(i => { i.Value.Progress.Advanced = i.Value.GetPropertiesView(true); }); Teches = techService.ConvertToTechesOut(true); Teches.ForEach(i => { i.Value.CalcResultPrice(false); }); SetComplexButtonView(); }
private AllianceDataModel _addAlliance(IDbConnection connection, AllianceDataModel dataModel) { AllianceDataModel newAllianceData = null; AllianceUserDataModel newCreatorAllianceUser = null; AllianceTechDataModel newTeches = null; var tech = new BattleTeches(); tech.CreateStartTeches(); var newDbTeches = tech.ConvertToDbTeches().ToSerealizeString(); var al = _aRepo.AddOrUpdate(connection, _aRepo.ConvertToEntity(dataModel)); newAllianceData = _aRepo.ConvertToWorkModel(al); var au = _aUserRepo.AddOrUpdate(connection, new alliance_user { allianceId = al.Id, userId = al.creatorId, roleId = (byte)AllianceRoles.Creator, dateCreate = al.dateCreate }); newCreatorAllianceUser = _aUserRepo.ConvertToWorkModel(au); var teches = _aTechRepo.AddOrUpdate(connection, new alliance_tech { Id = al.Id, techProgress = newDbTeches }); newTeches = _aTechRepo.ConvertToWorkModel(teches); if (newAllianceData == null || newCreatorAllianceUser == null || newTeches == null) { throw new NotImplementedException(); } var lcAllianceData = _aCache.UpdateLocalItem(connection, newAllianceData); _aUserCache.UpdateLocalItem(connection, newCreatorAllianceUser); _aTechCahce.UpdateLocalItem(connection, newTeches); return(lcAllianceData); }
/// <summary> /// Обновляет уровень технологии и баланс алььянса, не делает проверки на разрешение пользователю совершать действие /// </summary> /// <param name="connection"></param> /// <param name="allianceTechType"></param> /// <param name="allianceId"></param> /// <returns></returns> public Dictionary <OldNewAllianceKeys, object> UpdateTech(IDbConnection connection, TechType allianceTechType, int allianceId) { var result = new Dictionary <OldNewAllianceKeys, object>(); var allianceTech = GetAllianceTech(connection, allianceId); var tech = new BattleTeches(allianceTech.Teches).GetTech(allianceTechType); if (tech == null) { throw new NotImplementedException(); } var outTech = tech.ConvertToOutModel(true); outTech.CalcResultPrice(false); var price = outTech.BasePrice.Cc; var alliance = GetAllianceById(connection, allianceId, false); if (price > alliance.Cc) { throw new Exception(Error.NotEnoughCc); } allianceTech.Teches[allianceTechType].Level += 1; var updatedTech = AddOrUpdateTech(connection, allianceTech); alliance.Cc -= (int)Math.Floor(price); AddOrUpdate(connection, alliance); var newTech = new BattleTeches(updatedTech.Teches).GetTech(allianceTechType); newTech.Progress.Advanced = newTech.GetPropertiesView(true); var techOut = newTech.ConvertToOutModel(true); techOut.CalcResultPrice(false); result.Add(OldNewAllianceKeys.NewBalanceCc, alliance.Cc); result.Add(OldNewAllianceKeys.NewTech, techOut); return(result); }
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); }
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 }