Ejemplo n.º 1
0
        public async Task <LootboxModel> CreateLootboxModelAsync([NotNull] string playerServiceId)
        {
            //Достать аккаунт
            AccountDbDto accountDbDto = await accountDbReaderService.ReadAccountAsync(playerServiceId);

            if (accountDbDto == null)
            {
                Console.WriteLine("попытка купить лутбокс для аккаунта, которого не существует.");
                return(null);
            }

            //Ресурсов для покупки хватает?
            if (accountDbDto.LootboxPoints < 100)
            {
                Console.WriteLine("Не хватает ресурсов для покупки лутбокса");
                return(null);
            }

            //Создать лутбокс
            LootboxModel lootboxModel = smallLootboxModelFactory.Create(accountDbDto.Warships);

            //Сохранить лутбокс
            await lootboxDbWriterService.WriteAsync(playerServiceId, lootboxModel);

            return(lootboxModel);
        }
Ejemplo n.º 2
0
        private IEnumerator SetLootboxResources()
        {
            ResourcesAccrualStorage.Instance.SetLootboxNeeded();
            yield return(new WaitUntil(() => LootboxModelDownloader.Instance.IsDownloadingCompleted()));

            LootboxModel lootboxPrize = LootboxModelDownloader.Instance.GetLootboxModel();

            if (lootboxPrize != null)
            {
                var test = lootboxPrize.Prizes;
                ResourcesAccrualStorage.Instance.SetResourcesModels(test);
            }
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <string> > BuyLootbox([FromForm] string playerServiceId)
        {
            if (string.IsNullOrEmpty(playerServiceId))
            {
                return(BadRequest());
            }

            LootboxModel lootboxModel = await lootboxFacadeService.CreateLootboxModelAsync(playerServiceId);

            if (lootboxModel == null)
            {
                return(BadRequest());
            }

            return(lootboxModel.SerializeToBase64String());
        }
Ejemplo n.º 4
0
        public LootboxModel Create(List <WarshipDbDto> warships)
        {
            LootboxModel result = new LootboxModel
            {
                Prizes = new List <ResourceModel>(NumberOfPrizes)
            };

            for (int i = 0; i < NumberOfPrizes; i++)
            {
                ResourceModel prize = lootboxResourcesFactory.Create(warships);
                if (prize != null)
                {
                    result.Prizes.Add(prize);
                }
            }

            return(result);
        }
Ejemplo n.º 5
0
        public RewardsThatHaveNotBeenShown Create(LootboxModel lootboxModel)
        {
            RewardsThatHaveNotBeenShown result = new RewardsThatHaveNotBeenShown();

            foreach (ResourceModel resourceModel in lootboxModel.Prizes)
            {
                if (resourceModel.ResourceTypeEnum == ResourceTypeEnum.HardCurrency)
                {
                    var hardCurrencyResourceModel =
                        ZeroFormatterSerializer.Deserialize <HardCurrencyResourceModel>(resourceModel.SerializedModel);
                    result.HardCurrencyDelta += hardCurrencyResourceModel.Amount;
                }

                if (resourceModel.ResourceTypeEnum == ResourceTypeEnum.SoftCurrency)
                {
                    var softCurrencyResourceModel =
                        ZeroFormatterSerializer.Deserialize <SoftCurrencyResourceModel>(resourceModel.SerializedModel);
                    result.SoftCurrencyDelta += softCurrencyResourceModel.Amount;
                }
            }
            return(result);
        }
Ejemplo n.º 6
0
        public async Task WriteAsync(string playerServiceId, LootboxModel lootboxModel)
        {
            Account account = await dbContext.Accounts
                              .Where(account1 => account1.ServiceId == playerServiceId)
                              .SingleOrDefaultAsync();

            List <Increment> increments = new List <Increment>();

            foreach (ResourceModel prize in lootboxModel.Prizes)
            {
                Increment increment = new Increment();
                switch (prize.ResourceTypeEnum)
                {
                case ResourceTypeEnum.SoftCurrency:
                {
                    increment.IncrementTypeId = IncrementTypeEnum.SoftCurrency;
                    int amount = ZeroFormatterSerializer
                                 .Deserialize <SoftCurrencyResourceModel>(prize.SerializedModel).Amount;
                    increment.Amount = amount;
                    break;
                }

                case ResourceTypeEnum.HardCurrency:
                {
                    increment.IncrementTypeId = IncrementTypeEnum.HardCurrency;
                    int amount = ZeroFormatterSerializer
                                 .Deserialize <HardCurrencyResourceModel>(prize.SerializedModel).Amount;
                    increment.Amount = amount;
                    break;
                }

                case ResourceTypeEnum.WarshipPowerPoints:
                {
                    var model = ZeroFormatterSerializer
                                .Deserialize <WarshipPowerPointsResourceModel>(prize.SerializedModel);
                    if (model.WarshipId != null)
                    {
                        increment.IncrementTypeId = IncrementTypeEnum.WarshipPowerPoints;
                        increment.Amount          = model.FinishValue - model.StartValue;
                        increment.WarshipId       = model.WarshipId;
                    }
                    else
                    {
                        throw new NullReferenceException("warshipId");
                    }
                    break;
                }

                default:
                    throw new ArgumentOutOfRangeException();
                }

                increments.Add(increment);
            }


            Transaction transaction = new Transaction
            {
                AccountId         = account.Id,
                DateTime          = DateTime.UtcNow,
                TransactionTypeId = TransactionTypeEnum.LootboxOpening,
                Decrements        = new List <Decrement>
                {
                    new Decrement
                    {
                        Amount          = 100,
                        DecrementTypeId = DecrementTypeEnum.LootboxPoints
                    }
                },
                Increments = increments,
                WasShown   = false
            };

            await dbContext.Transactions.AddAsync(transaction);

            await dbContext.SaveChangesAsync();
        }