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 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 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); }
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(); }
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); }
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 }