Ejemplo n.º 1
0
        private async Task <ShopModel> InitProductCostAsync(ShopModel shopModel)
        {
            log.Debug($"Ожидание инициализации {nameof(purchasingService)}");
            List <RealCurrencyCostModel> realCurrencyProducts = shopModel.GetRealCurrencyProducts();

            purchasingService.StartInitialization(realCurrencyProducts);
            await MyTaskExtensions.WaitUntil(purchasingService.IsStoreInitialized);

            log.Debug($"{nameof(purchasingService)} инициализирован");
            foreach (ProductModel productModel in shopModel.GetAllProducts())
            {
                if (productModel.CostModel.CostTypeEnum == CostTypeEnum.RealCurrency)
                {
                    var realCurrencyCostModel = ZeroFormatterSerializer
                                                .Deserialize <RealCurrencyCostModel>(productModel.CostModel.SerializedCostModel);
                    string productId = realCurrencyCostModel.GoogleProductId;
                    string cost      = null;
                    purchasingService.TryGetProductCostById(productId, ref cost);
                    if (cost == null)
                    {
                        throw new Exception("Не удалось достать цену товара из плагина магазина");
                    }


                    realCurrencyCostModel.CostString           = cost;
                    productModel.CostModel.SerializedCostModel =
                        ZeroFormatterSerializer.Serialize(realCurrencyCostModel);
                }
            }

            return(shopModel);
        }
Ejemplo n.º 2
0
        private async Task <ShopModel> InitWppModel(ShopModel shopModel)
        {
            // log.Debug("Ожидание спавна кораблей");
            await MyTaskExtensions.WaitUntil(lobbyEcsController.IsWarshipsCreationCompleted);

            // log.Debug(lobbyEcsController.GetCountOfSpawnedWarships());
            // log.Debug("Ожидание спавна закончено");
            var products = shopModel.UiSections.Select(section => section.UiItems)
                           .SelectMany(item => item)
                           .SelectMany(item => item)
                           .ToList()
            ;

            // log.Debug("Кол-во продуктов "+products.Count());
            foreach (ProductModel productModel in products)
            {
                if (productModel.ResourceTypeEnum == ResourceTypeEnum.WarshipPowerPoints)
                {
                    // log.Debug("Упаковка вспомогательной информации для продукта с id "+productModel.Id);
                    try
                    {
                        WarshipPowerPointsProductModel model = ZeroFormatterSerializer
                                                               .Deserialize <WarshipPowerPointsProductModel>(productModel.SerializedModel);

                        // log.Debug($"{nameof(model.Increment)} {model.Increment}" +
                        //           $"{nameof(model.WarshipId)} {model.WarshipId}"+
                        //           $"{nameof(model.SupportClientModel)} {model.SupportClientModel}"+
                        //           $"{nameof(model.WarshipTypeEnum)} {model.WarshipTypeEnum}"+
                        //           "");
                        int powerLevel = lobbyEcsController.GetWarshipPowerLevel(model.WarshipTypeEnum);
                        var powerModel = WarshipPowerScale.GetModel(powerLevel);

                        var supportModel = new WppSupportClientModel()
                        {
                            StartValue       = lobbyEcsController.GetWarshipPowerPoints(model.WarshipTypeEnum),
                            WarshipSkinName  = lobbyEcsController.GetSkinName(model.WarshipTypeEnum),
                            MaxValueForLevel = powerModel.PowerPointsCost
                        };

                        model.SupportClientModel = supportModel;

                        productModel.SerializedModel = ZeroFormatterSerializer.Serialize(model);
                    }
                    catch (Exception e)
                    {
                        log.Error(e.Message + " " + e.StackTrace);
                        return(null);
                    }
                }
            }

            return(shopModel);
        }