Esempio n. 1
0
        private void ShowPrize(LootboxEntity currentPrize)
        {
            ShowPrizeComponent prize  = currentPrize.showPrize;
            Transform          parent = uiStorage.resourcesRoot.transform;

            switch (prize.resourceModel.ResourceTypeEnum)
            {
            case ResourceTypeEnum.SoftCurrency:
            {
                var go     = UnityEngine.Object.Instantiate(uiStorage.softCurrencyPrefab, parent);
                var script = go.GetComponent <SoftCurrencyAccrual>();
                SoftCurrencyResourceModel softCurrencyResourceModel =
                    ZeroFormatterSerializer.Deserialize <SoftCurrencyResourceModel>(prize.resourceModel
                                                                                    .SerializedModel);
                script.StartAnimation(softCurrencyResourceModel.Amount);
                particlesColorUpdater.SetStartColor(Color.blue);
                break;
            }

            case ResourceTypeEnum.HardCurrency:
            {
                var go     = UnityEngine.Object.Instantiate(uiStorage.hardCurrencyPrefab, parent);
                var script = go.GetComponent <HardCurrencyAccrual>();
                HardCurrencyResourceModel hardCurrencyResourceModel =
                    ZeroFormatterSerializer.Deserialize <HardCurrencyResourceModel>(prize.resourceModel
                                                                                    .SerializedModel);
                script.SetData(hardCurrencyResourceModel.Amount);

                Color purple = new Color(209, 0, 4);
                particlesColorUpdater.SetStartColor(purple);
                break;
            }

            case ResourceTypeEnum.WarshipPowerPoints:
            {
                var go       = UnityEngine.Object.Instantiate(uiStorage.warshipPowerPointsPrefab, parent);
                var script   = go.GetComponent <WarshipPowerPointsAccrual>();
                var wppModel =
                    ZeroFormatterSerializer.Deserialize <WarshipPowerPointsResourceModel>(prize.resourceModel
                                                                                          .SerializedModel);


                if (wppModel.WarshipTypeEnum == 0)
                {
                    throw new Exception("Не указан тип корабля");
                }

                script.SetData(wppModel);
                Color red = new Color(209, 0, 0);
                particlesColorUpdater.SetStartColor(red);
                break;
            }

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        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);
            }
        }