public static List <Reward> InstantiateRewardsFromServerCommands(List <InboxCommand> eventList) { List <Reward> list = new List <Reward>(); foreach (InboxCommand command in eventList) { if (command.CommandId == InboxCommandIdType.RewardShopProduct) { ProductRewardCollection rewards = null; try { rewards = JsonUtils.Deserialize <ProductRewardCollection>(command.Parameters["RewardCollection"].ToString(), true); } catch (Exception exception) { Debug.Log("Could not parse premium resource from InboxCommand: " + exception.ToString()); return(list); } PremiumProduct product = Service.Binder.ShopService.GetProduct(rewards.Pid); if (product == null) { return(list); } AddRewardsFromProduct(ref list, product); } } return(list); }
public static Reward GetRewardFromProductReward(ProductReward productReward, [Optional, DefaultParameterValue(null)] PremiumProduct product) { Reward reward = new Reward(); string key = productReward.key; int amount = productReward.amount; if (key.Equals("Dragon01")) { key = "Pet001"; amount = 10; } if (key.Equals(ResourceType.Diamond.ToString())) { MathUtil.DistributeValuesIntoChunksInt(amount, 1, ref reward.DiamondDrops); reward.Sprite = (product == null) ? "icon_gem_pile2" : product.GetRewardIcon(key); return(reward); } if (key.Equals(ResourceType.Token.ToString())) { MathUtil.DistributeValuesIntoChunksInt(amount, 1, ref reward.TokenDrops); reward.Sprite = (product == null) ? "icon_token" : product.GetRewardIcon(key); return(reward); } if (App.Binder.ConfigMeta.IsActivePetId(key)) { reward.ChestType = ChestType.NONE; List <string> list = new List <string>(); list.Add("PetBundleSmall"); reward.ShopEntryDrops = list; PetReward item = new PetReward(); item.PetId = key; item.Amount = amount; reward.Pets.Add(item); reward.Sprite = "icon_" + key.ToLower(); return(reward); } if (key.Equals(ShopEntryType.MegaBoxBundle.ToString())) { reward.MegaBoxes = amount; reward.Sprite = "icon_megabox_pile1"; return(reward); } if (key.Equals(BuyableItemType.FrenzyPotion.ToString())) { reward.FrenzyPotions = amount; reward.Sprite = (product == null) ? "icon_bottle_frenzy" : product.GetRewardIcon(key); return(reward); } if (key.Equals(BuyableItemType.RevivePotion.ToString())) { reward.Revives = amount; reward.Sprite = (product == null) ? "icon_bottle_red" : product.GetRewardIcon(key); return(reward); } Debug.LogError("GetRewardFromProductReward::Unsupported resource id: " + key); return(reward); }
internal void initBuyResourceAmounts(PremiumProduct prod) { this.BuyResourceAmounts.Clear(); foreach (ProductReward reward in ConfigShops.GetRewardsFromProduct(prod)) { try { ResourceType key = (ResourceType)((int)Enum.Parse(typeof(ResourceType), reward.key)); this.BuyResourceAmounts.Add(key, (double)reward.amount); } catch (Exception) { Debug.Log("ShopEntry - Can't parse shop product reward. " + reward.key + " is not a ResourceType (Which is fine for now)."); } } }
public static List <ProductReward> GetRewardsFromProduct(PremiumProduct prod) { if (prod.flareProductId == IAP_STARTER_BUNDLE_ID) { Player player = GameLogic.Binder.GameState.Player; List <ProductReward> list = new List <ProductReward>(); ProductReward item = new ProductReward(); item.key = ResourceType.Diamond.ToString(); item.amount = (int)App.Binder.ConfigMeta.STARTER_BUNDLE_DIAMOND_COUNT; list.Add(item); item = new ProductReward(); item.key = ResourceType.Token.ToString(); item.amount = (int)App.Binder.ConfigMeta.TokenBundleSize(player, "TokenBundleDragon"); list.Add(item); item = new ProductReward(); item.key = BuyableItemType.Dragon01.ToString(); item.amount = 1; list.Add(item); return(list); } return(prod.rewards); }
public static void DecoratorPatternTest() { var product1 = new NormalProduct { Price = 100, TaxPercent = 8 }; var discountProduct = new DiscountProduct(product1) { DiscountPercent = 4 }; var product2 = new NormalProduct { Price = 200, TaxPercent = 8 }; var premiumProduct = new PremiumProduct(product2) { PremiumPrice = 25 }; Console.WriteLine($"Total price of product on discount is {discountProduct.CalculateTotalPrice()}"); Console.WriteLine($"Total price of premium product is {premiumProduct.CalculateTotalPrice()}"); }
public static void AddRewardsFromProduct(ref List <Reward> rewards, PremiumProduct product) { ShopEntry shopEntryByFlareProductId = Service.Binder.ShopManager.GetShopEntryByFlareProductId(product.flareProductId); List <ProductReward> rewardsFromProduct = GetRewardsFromProduct(product); for (int i = 0; i < rewardsFromProduct.Count; i++) { ProductReward reward = rewardsFromProduct[i]; string key = reward.key; int amount = reward.amount; Reward item = new Reward(); item.ShopEntryId = product.flareProductId; if (key.Equals(ResourceType.Diamond.ToString())) { item.Sprite = product.GetRewardIcon(key); if (shopEntryByFlareProductId != null) { MathUtil.DistributeValuesIntoChunksInt(amount, shopEntryByFlareProductId.NumBursts, ref item.DiamondDrops); } else { MathUtil.DistributeValuesIntoChunksInt(amount, 1, ref item.DiamondDrops); } } else if (key.Equals(ResourceType.Token.ToString())) { item.Sprite = product.GetRewardIcon(key); if (shopEntryByFlareProductId != null) { MathUtil.DistributeValuesIntoChunksInt(amount, shopEntryByFlareProductId.NumBursts, ref item.TokenDrops); } else { MathUtil.DistributeValuesIntoChunksInt(amount, 1, ref item.TokenDrops); } } else if (key.Equals(BuyableItemType.Dragon01.ToString())) { item.Sprite = (shopEntryByFlareProductId == null) ? product.GetRewardIcon(key) : shopEntryByFlareProductId.Sprite.SpriteId; } else if (App.Binder.ConfigMeta.IsActivePetId(key)) { PetReward reward3 = new PetReward(); reward3.PetId = key; reward3.Amount = amount; item.Pets.Add(reward3); item.Sprite = "icon_" + key.ToLower(); } else if (key.Equals(ShopEntryType.MegaBoxBundle.ToString())) { item.MegaBoxes = amount; item.Sprite = "icon_megabox_pile1"; } else if (key.Equals(BuyableItemType.FrenzyPotion.ToString())) { item.ShopEntryId = null; item.FrenzyPotions = amount; item.Sprite = (product == null) ? "icon_bottle_frenzy" : product.GetRewardIcon(key); } else if (key.Equals(BuyableItemType.RevivePotion.ToString())) { item.ShopEntryId = null; item.Revives = amount; item.Sprite = (product == null) ? "icon_bottle_red" : product.GetRewardIcon(key); } else { Debug.LogError("Unsupported resource id: " + key); } rewards.Add(item); } }
protected override void onPreShow([Optional, DefaultParameterValue(null)] object param) { this.m_inputParameters = (InputParameters)param; if (!string.IsNullOrEmpty(this.m_inputParameters.Headline)) { this.PopupTitle.text = StringExtensions.ToUpperLoca(this.m_inputParameters.Headline); } else { this.PopupTitle.enabled = false; } if (!string.IsNullOrEmpty(this.m_inputParameters.Title)) { this.DividerTitle.text = StringExtensions.ToUpperLoca(this.m_inputParameters.Title); } else { this.DividerTitle.enabled = false; } if (!string.IsNullOrEmpty(this.m_inputParameters.Message)) { this.DescriptionText.enabled = true; this.DescriptionText.text = this.m_inputParameters.Message; } else { this.DescriptionText.enabled = false; } if (this.m_inputParameters.DisposableBackgroundTexture != null) { this.RawBg.enabled = true; this.RawBg.texture = this.m_inputParameters.DisposableBackgroundTexture; float num = ((float)this.m_inputParameters.DisposableBackgroundTexture.width) / ((float)this.m_inputParameters.DisposableBackgroundTexture.height); float newSize = Mathf.Clamp((float)(this.m_defaultWidth / num), (float)200f, (float)1880f); RectTransformExtensions.SetHeight(base.RectTm, newSize); } else { this.RawBg.enabled = false; RectTransformExtensions.SetHeight(base.RectTm, this.m_defaultHeight); } string flareProductIdForPromoSlot = Service.Binder.PromotionManager.GetFlareProductIdForPromoSlot(this.m_inputParameters.Slot); if (!string.IsNullOrEmpty(flareProductIdForPromoSlot)) { ShopEntry shopEntryByFlareProductId = Service.Binder.ShopManager.GetShopEntryByFlareProductId(flareProductIdForPromoSlot); if (shopEntryByFlareProductId != null) { this.m_purchaseController = new ShopPurchaseController(shopEntryByFlareProductId, null, PathToShopType.Vendor, null, new Action <ShopEntry, PurchaseResult>(this.onPurchaseComplete)); this.PurchaseButtonText.text = this.m_purchaseController.getPriceText(1); if (this.m_inputParameters.DisposableBackgroundTexture == null) { base.RewardsGrid.gameObject.SetActive(true); List <Reward> rewards = new List <Reward>(); PremiumProduct prod = Service.Binder.ShopService.GetProduct(flareProductIdForPromoSlot); foreach (ProductReward reward in ConfigShops.GetRewardsFromProduct(prod)) { rewards.Add(ConfigShops.GetRewardFromProductReward(reward, prod)); } base.InitRewardGrid(rewards); } else { base.RewardsGrid.gameObject.SetActive(false); } } } }