public async Task BigAccounts(int seedForRandom) { //Arrange string serviceId = "serviceId"; Account originalAccount = await DefaultAccountFactoryService.CreateDefaultAccountAsync(serviceId); int originalAccountRating = originalAccount.GetAccountRating(); int originalAccountSoftCurrency = originalAccount.GetAccountSoftCurrency(); int originalAccountHardCurrency = originalAccount.GetAccountHardCurrency(); //Act AccountDbDto accountDbDto = await AccountDbReaderService.ReadAccountAsync(originalAccount.ServiceId); //Assert Assert.IsNotNull(accountDbDto); Assert.AreEqual(originalAccount.Username, accountDbDto.Username); Assert.AreEqual(originalAccount.ServiceId, accountDbDto.ServiceId); Assert.AreEqual(originalAccountRating, accountDbDto.Rating); Assert.AreEqual(originalAccountSoftCurrency, accountDbDto.SoftCurrency); Assert.AreEqual(originalAccountHardCurrency, accountDbDto.HardCurrency); foreach (var warship in originalAccount.Warships) { WarshipDbDto warshipDbDto = accountDbDto.Warships.Single(w => w.Id == warship.Id); int originalWarshipRating = originalAccount.GetWarshipRating(warship.Id); int originalWarshipPowerPoints = originalAccount.GetWarshipPowerPoints(warship.Id); Assert.AreEqual(originalWarshipRating, warshipDbDto.WarshipRating); Assert.AreEqual(originalWarshipPowerPoints, warshipDbDto.WarshipPowerPoints); } }
public async Task <bool> TryEnqueuePlayerAsync(string playerServiceId, int warshipId) { AccountDbDto accountDbDto = await dbAccountWarshipReaderService.ReadAsync(playerServiceId); if (accountDbDto == null) { return(false); } WarshipDbDto warship = accountDbDto.Warships.SingleOrDefault(dto => dto.Id == warshipId); if (warship == null) { Console.WriteLine("Корабль не принадлежит этому игроку"); return(false); } string warshipSkinName = warship.CurrentSkinType.Name; Console.WriteLine(warshipSkinName); MatchEntryRequest matchEntryRequest = new MatchEntryRequest(playerServiceId, accountDbDto.Id, warship.WarshipType.Name, warship.WarshipPowerLevel, warshipId, DateTime.UtcNow, accountDbDto.Username, warshipSkinName); return(battleRoyaleQueueSingletonServiceService.TryEnqueue(matchEntryRequest)); }
public async Task <AccountDbDto> ReadAsync(string serviceId) { var parameters = new { serviceIdPar = serviceId }; //accountId + account Dictionary <int, AccountDbDto> lookup = new Dictionary <int, AccountDbDto>(); await connection .QueryAsync <AccountDbDto, WarshipDbDto, WarshipType, WarshipCombatRole, WarshipStatistics, AccountDbDto>(sql, (accountDbDto, warshipDbDto, warshipTypeArg, warshipCombatRole, warshipStatistics) => { //Если такого аккаунта ещё не было if (!lookup.TryGetValue(accountDbDto.Id, out AccountDbDto account)) { //Положить аккаунт в словарь lookup.Add(accountDbDto.Id, account = accountDbDto); } //Попытаться достать корабль c таким id из коллекции WarshipDbDto warship = account.Warships .Find(wArg => wArg.Id == warshipDbDto.Id); //Этот корабль уже есть в коллекции? if (warship == null) { warship = warshipDbDto; warship.WarshipType = warshipTypeArg; warship.WarshipRating = warshipStatistics.WarshipRating; warship.WarshipPowerPoints = warshipStatistics.WarshipPowerPoints; warship.WarshipType.WarshipCombatRole = warshipCombatRole; warship.Id = warshipDbDto.Id; warship.WarshipPowerLevel = warshipStatistics.WarshipLevel; warship.WarshipTypeId = warshipDbDto.WarshipTypeId; account.Warships.Add(warship); account.Rating += warship.WarshipRating; } Console.WriteLine(" " + accountDbDto); Console.WriteLine("\t\t " + warshipDbDto); Console.WriteLine("\t\t\t " + warshipStatistics); return(account); }, parameters, splitOn : "Id,WarshipRating"); switch (lookup.Count) { case 0: return(null); case 1: return(lookup.Single().Value); default: throw new Exception($"По serviceId = {serviceId} найдено {lookup.Count} аккаунтов."); } }
public async Task <AccountDbDto> ReadAsync(string playerServiceId) { AccountDbDto accountDbDto = await dbWarshipsStatisticsReader.ReadAsync(playerServiceId); if (accountDbDto == null) { return(null); } // foreach (var warshipDbDto in accountDbDto.Warships) // { // Console.WriteLine("очки силы корабля "+warshipDbDto.WarshipPowerPoints); // } //заполнить список скинов для всех типов кораблей //warshipId, список скинов Dictionary <int, List <SkinType> > skinsDict = await skinsDbReaderService.ReadAsync(accountDbDto.Id); if (skinsDict == null || skinsDict.Count == 0) { throw new Exception("warship has no skin"); } foreach ((int warshipId, List <SkinType> list) in skinsDict) { WarshipDbDto warship = accountDbDto.Warships.Single(warship1 => warship1.Id == warshipId); warship.Skins.AddRange(list); warship.CurrentSkinType = list .Single(skinType => skinType.Id == warship.CurrentSkinTypeId); } foreach (WarshipDbDto warshipDbDto in accountDbDto.Warships) { if (warshipDbDto.WarshipPowerLevel == 0) { throw new Exception("Нулевой уровень " + nameof(AccountDbReaderService)); } if (warshipDbDto.Skins == null || warshipDbDto.Skins.Count == 0) { throw new Exception("Warship have no skins"); } } return(accountDbDto); }
/// <summary> /// Создаёт продукты, которые содержат улучшения для кораблей, которые есть в наличии у аккаунта /// </summary> /// <param name="accountDbDto"></param> /// <returns></returns> public List <ProductModel> CreateWarshipPowerPointProducts(AccountDbDto accountDbDto) { List <TmpWarshipDich> warshipIds = GetWarshipModels(accountDbDto); List <ProductModel> warshipPowerPoints = new List <ProductModel>(); for (int index = 0; index < NumberOfProducts; index++) { int warshipId = warshipIds[index].warshipId; WarshipTypeEnum warshipType = warshipIds[index].warshipType; WarshipDbDto warshipDbDto = accountDbDto.Warships .Single(dto => dto.Id == warshipId); string previewPath = warshipDbDto.WarshipType.Name.ToLower(); ProductModel wpp = factory.Create(140, previewPath, 42, warshipId, warshipType); warshipPowerPoints.Add(wpp); } foreach (var productModel in warshipPowerPoints) { WarshipPowerPointsProductModel model = productModel; } return(warshipPowerPoints); }
public async Task <bool> TryBuyLevel([NotNull] string serviceId, int warshipId) { //Аккаунт существует? AccountDbDto accountDbDto = await accountDbReaderService.ReadAccountAsync(serviceId); if (accountDbDto == null) { throw new Exception("Такого аккаунта не существует"); } //Корабль существует? WarshipDbDto warshipDbDto = accountDbDto.Warships.SingleOrDefault(dto => dto.Id == warshipId); if (warshipDbDto == null) { throw new Exception("Этому аккаунту не принаждлежит этот корабль"); } bool canAPurchaseBeMade = warshipImprovementCostChecker .CanAPurchaseBeMade(accountDbDto.SoftCurrency, warshipDbDto.WarshipPowerLevel, warshipDbDto.WarshipPowerPoints, out var faultReason); if (!canAPurchaseBeMade) { throw new Exception("Невозможно осуществить покупку улучшения для корабля по причине " + faultReason); } WarshipImprovementModel improvementModel = warshipImprovementCostChecker.GetImprovementModel(warshipDbDto.WarshipPowerLevel); Console.WriteLine("текущий wpp " + warshipDbDto.WarshipPowerLevel); //Записать транзакцию Transaction transaction = new Transaction { AccountId = accountDbDto.Id, DateTime = DateTime.UtcNow, TransactionTypeId = TransactionTypeEnum.WarshipImprovement, WasShown = false, Increments = new List <Increment> { new Increment { IncrementTypeId = IncrementTypeEnum.WarshipLevel, Amount = warshipDbDto.WarshipPowerLevel + 1, WarshipId = warshipId } }, Decrements = new List <Decrement> { new Decrement { DecrementTypeId = DecrementTypeEnum.SoftCurrency, Amount = improvementModel.SoftCurrencyCost }, new Decrement { DecrementTypeId = DecrementTypeEnum.WarshipPowerPoints, Amount = improvementModel.PowerPointsCost, WarshipId = warshipDbDto.Id } } }; await dbContext.Transactions.AddAsync(transaction); await dbContext.SaveChangesAsync(); return(true); }
public ResourceModel Create(List <WarshipDbDto> warships) { ResourceTypeEnum resourceTypeEnum = lootboxResourceTypeFactory.CreateResourceType(); switch (resourceTypeEnum) { case ResourceTypeEnum.SoftCurrency: { int amount = random.Next(15, 100); var model = new SoftCurrencyResourceModel() { Amount = amount }; return(new ResourceModel { SerializedModel = ZeroFormatterSerializer.Serialize(model), ResourceTypeEnum = ResourceTypeEnum.SoftCurrency }); } case ResourceTypeEnum.WarshipPowerPoints: { int warshipIndex = random.Next(warships.Count); WarshipDbDto warship = warships[warshipIndex]; int amount = random.Next(2, 15); var model = new WarshipPowerPointsResourceModel(); var test = WarshipPowerScale.GetModel(warship.WarshipPowerLevel); if (test == null) { return(null); } model.MaxValueForLevel = test.PowerPointsCost; model.WarshipSkinName = warship.CurrentSkinType.Name; model.FinishValue = warship.WarshipPowerPoints + amount; model.StartValue = warship.WarshipPowerPoints; model.WarshipId = warship.Id; model.WarshipTypeEnum = warship.WarshipTypeId; warship.WarshipPowerPoints += amount; return(new ResourceModel { SerializedModel = ZeroFormatterSerializer.Serialize(model), ResourceTypeEnum = ResourceTypeEnum.WarshipPowerPoints }); } case ResourceTypeEnum.HardCurrency: { var model = new HardCurrencyResourceModel() { Amount = random.Next(2, 15) }; return(new ResourceModel { SerializedModel = ZeroFormatterSerializer.Serialize(model), ResourceTypeEnum = ResourceTypeEnum.HardCurrency }); } default: throw new Exception("Неизвестный тип подарка " + resourceTypeEnum); } }