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); }
public ResourceModel Map(PurchaseModel purchaseModel) { ResourceModel resourceModel = new ResourceModel(); switch (purchaseModel.productModel.ResourceTypeEnum) { case ResourceTypeEnum.WarshipPowerPoints: WarshipPowerPointsProductModel wppModel = purchaseModel.productModel; resourceModel.ResourceTypeEnum = ResourceTypeEnum.WarshipPowerPoints; if (wppModel.WarshipTypeEnum == 0) { throw new Exception("В модели продукта не указан тип корабля"); } resourceModel.SerializedModel = ZeroFormatterSerializer.Serialize( new WarshipPowerPointsResourceModel() { WarshipId = wppModel.WarshipId, WarshipSkinName = null, StartValue = wppModel.SupportClientModel.StartValue, FinishValue = wppModel.SupportClientModel.StartValue + wppModel.Increment, MaxValueForLevel = wppModel.SupportClientModel.MaxValueForLevel, WarshipTypeEnum = wppModel.WarshipTypeEnum }); break; case ResourceTypeEnum.SoftCurrency: SoftCurrencyProductModel softModel = purchaseModel.productModel; resourceModel.ResourceTypeEnum = ResourceTypeEnum.SoftCurrency; resourceModel.SerializedModel = ZeroFormatterSerializer.Serialize( new SoftCurrencyResourceModel() { Amount = softModel.Amount }); break; case ResourceTypeEnum.HardCurrency: HardCurrencyProductModel hardModel = purchaseModel.productModel; resourceModel.ResourceTypeEnum = ResourceTypeEnum.HardCurrency; resourceModel.SerializedModel = ZeroFormatterSerializer.Serialize( new HardCurrencyResourceModel() { Amount = hardModel.Amount }); break; default: throw new ArgumentOutOfRangeException(); } return(resourceModel); }
public List <Increment> Create(ProductModel productModel) { List <Increment> increments = new List <Increment>(); WarshipPowerPointsProductModel model = productModel; Console.WriteLine(model.WarshipId); Increment increment = new Increment { IncrementTypeId = IncrementTypeEnum.WarshipPowerPoints, Amount = model.Increment, WarshipId = model.WarshipId }; increments.Add(increment); return(increments); }
private void FillData(GameObject powerPointsContent, ProductModel productModel) { WarshipPowerPointsProductModel model = productModel; int increment = model.Increment; var costModel = ZeroFormatterSerializer.Deserialize <InGameCurrencyCostModel>(productModel.CostModel .SerializedCostModel); //установить картинку корабля Image image = powerPointsContent.transform.Find("Image_WarshipPowerPointsItem/Image_WarshipPreview") .GetComponent <Image>(); image.sprite = Resources.Load <Sprite>(productModel.PreviewImagePath); //установить текущее кол-во очков силы корабля Text text = powerPointsContent.transform.Find("Image_WarshipPowerPointsItem/Empty_PowerValueRoot/Text") .GetComponent <Text>(); string text1 = $"{model.SupportClientModel.StartValue}/{model.SupportClientModel.MaxValueForLevel}"; // log.Debug("текущее кол-во очков силы корабля "+text1); text.text = text1; //установить значение слайдера Slider slider = powerPointsContent.transform .Find("Image_WarshipPowerPointsItem/Empty_PowerValueRoot/Slider").GetComponent <Slider>(); slider.value = 1f * model.SupportClientModel.StartValue / model.SupportClientModel.MaxValueForLevel; // log.Debug($"slider.value = {slider.value}"); //установить прибавляемое кол-во очков силы Text wppIncrementText = powerPointsContent.transform .Find("Image_WarshipPowerPointsItem/Text_Increment").GetComponent <Text>(); wppIncrementText.text = "+" + (increment); //установить описание Text description = powerPointsContent.transform.Find("Text_WarshipDescription").GetComponent <Text>(); description.text = $"Power points: {increment}. Collect power points to activate improvements for the spacecraft."; //установить цену Text cost = powerPointsContent.transform.Find("Button_Buy/Text_Cost").GetComponent <Text>(); cost.text = costModel.Cost.ToString(CultureInfo.InvariantCulture); //TODO сделать установку типа валюты }
/// <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 void Spawn(PurchaseModel purchaseModel, GameObject sectionGameObject, ProductClickHandlerScript productClickHandlerScript) { WarshipPowerPointsProductModel model = purchaseModel.productModel; int increment = model.Increment; InGameCurrencyCostModel costModel = ZeroFormatterSerializer.Deserialize <InGameCurrencyCostModel>(purchaseModel.productModel.CostModel .SerializedCostModel); //Создать объект на сцене GameObject wppPrefab = Resources.Load <GameObject>("Prefabs/LobbyShop/Image_WarshipPowerPointsItem"); GameObject wppGo = Object.Instantiate(wppPrefab, sectionGameObject.transform, false); //Установить название обьекта wppGo.name += " " + increment; //Заполнить картинку Image itemPreview = wppGo.transform.Find("Image_WarshipPreview") .GetComponentInChildren <Image>(); itemPreview.sprite = Resources.Load <Sprite>("SkinPreview/" + purchaseModel.productModel.PreviewImagePath); //Заполнить текущий показатель силы Text currentPowerValue = wppGo.transform.Find("Empty_PowerValueRoot/Text").GetComponent <Text>(); currentPowerValue.text = $"{model.SupportClientModel.StartValue}/{model.SupportClientModel.MaxValueForLevel}"; //Установить значение слайдера Slider slider = wppGo.transform.Find("Empty_PowerValueRoot/Slider").GetComponent <Slider>(); slider.value = 1f * model.SupportClientModel.StartValue / model.SupportClientModel.MaxValueForLevel; //Заполнить прибавку к очкам силы Text incrementText = wppGo.transform.Find("Text").GetComponent <Text>(); // log.Debug($"increment = "+increment); incrementText.text = $"+{increment}"; //Заполнить цену Text itemCost = wppGo.transform.Find("Image_Cost/Text_Amount").GetComponent <Text>(); itemCost.text = costModel.Cost.ToString(CultureInfo.InvariantCulture); var darkLayer = wppGo.transform.Find("Image_Disabled").gameObject; darkLayer.SetActive(purchaseModel.productModel.IsDisabled); var boughtText = wppGo.transform.Find("Image_Cost/Text_Bought").gameObject; boughtText.SetActive(purchaseModel.productModel.IsDisabled); var costText = wppGo.transform.Find("Image_Cost/Text_Amount").gameObject; costText.SetActive(!purchaseModel.productModel.IsDisabled); if (dictionary.ContainsKey(purchaseModel.productModel.Id)) { dictionary.Remove(purchaseModel.productModel.Id); } dictionary.Add(purchaseModel.productModel.Id, new StubWppUi() { boughtText = boughtText, costText = costText, darkLayer = darkLayer }); //Установить обработчик нажатия Button itemButton = wppGo.GetComponent <Button>(); itemButton.onClick.RemoveAllListeners(); itemButton.onClick.AddListener(() => { productClickHandlerScript.Product_OnClick(purchaseModel); }); }