/** * Retrieves the current upgrade for the given virtual good. * * @param good the virtual good to retrieve upgrade for * @return the current upgrade for the given virtual good */ public UpgradeVG getCurrentUpgrade(VirtualGood good) { SoomlaUtils.LogDebug(mTag, "Fetching upgrade to virtual good: " + good.getName()); String itemId = good.getItemId(); String key = keyGoodUpgrade(itemId); String upItemId = KeyValueStorage.GetValue(key); if (upItemId == null) { SoomlaUtils.LogDebug(mTag, "You tried to fetch the current upgrade of " + good.getName() + " but there's not upgrade to it."); return(null); } try { return((UpgradeVG)StoreInfo.getVirtualItem(upItemId)); } catch (VirtualItemNotFoundException e) { SoomlaUtils.LogError(mTag, "The current upgrade's itemId from the DB is not found in StoreInfo." + " " + e.Message); } catch (InvalidCastException e) { SoomlaUtils.LogError(mTag, "The current upgrade's itemId from the DB is not an UpgradeVG." + " " + e.Message); } return(null); }
/** * Adds the given virtual good to <code>StoreInfo</code>'s <code>mGoods</code>, * <code>mVirtualItems</code>, and if the good has purchase type <code>PurchaseWithMarket</code> * then it is also added to <code>mPurchasableItems</code>. * * @param g virtual good to be added */ private static void addVG(VirtualGood g) { mGoods.Add(g); mVirtualItems.Add(g.getItemId(), g); PurchaseType purchaseType = g.GetPurchaseType(); if (purchaseType is PurchaseWithMarket) { mPurchasableItems.Add(((PurchaseWithMarket)purchaseType) .getMarketItem().getProductId(), g); } }
/** * Removes any upgrade associated with the given VirtualGood. * * @param good the virtual good to remove the upgrade from * @param notify if true post event to bus */ public void removeUpgrades(VirtualGood good, bool notify) { SoomlaUtils.LogDebug(mTag, "Removing upgrade information from virtual good: " + good.getName()); String itemId = good.getItemId(); String key = keyGoodUpgrade(itemId); KeyValueStorage.DeleteKeyValue(key); if (notify) { BusProvider.Instance.Post(new GoodUpgradeEvent(good, null)); } }
/** * Assigns a specific upgrade to the given virtual good. * * @param good the VirtualGood to upgrade * @param upgradeVG the upgrade to assign * @param notify if true post event to bus */ public void assignCurrentUpgrade(VirtualGood good, UpgradeVG upgradeVG, bool notify) { if (getCurrentUpgrade(good) != null && getCurrentUpgrade(good).getItemId() == upgradeVG.getItemId()) { return; } SoomlaUtils.LogDebug(mTag, "Assigning upgrade " + upgradeVG.getName() + " to virtual good: " + good.getName()); String itemId = good.getItemId(); String key = keyGoodUpgrade(itemId); String upItemId = upgradeVG.getItemId(); KeyValueStorage.SetValue(key, upItemId); if (notify) { BusProvider.Instance.Post(new GoodUpgradeEvent(good, upgradeVG)); } }
/** * Replaces an old virtual item with a new one by doing the following: * 1. Determines the type of the given virtual item. * 2. Looks for the given virtual item in the relevant list, according to its type. * 3. If found, removes it. * 4. Adds the given virtual item. * * @param virtualItem the virtual item that replaces the old one if exists. */ public static void replaceVirtualItem(VirtualItem virtualItem) { mVirtualItems.Add(virtualItem.getItemId(), virtualItem); if (virtualItem is VirtualCurrency) { for (int i = 0; i < mCurrencies.Count; i++) { if (mCurrencies[i].getItemId() == virtualItem.getItemId()) { mCurrencies.RemoveAt(i); break; } } mCurrencies.Add((VirtualCurrency)virtualItem); } if (virtualItem is VirtualCurrencyPack) { VirtualCurrencyPack vcp = (VirtualCurrencyPack)virtualItem; PurchaseType purchaseType = vcp.GetPurchaseType(); if (purchaseType is PurchaseWithMarket) { mPurchasableItems.Add(((PurchaseWithMarket)purchaseType).getMarketItem() .getProductId(), vcp); } for (int i = 0; i < mCurrencyPacks.Count; i++) { if (mCurrencyPacks[i].getItemId() == vcp.getItemId()) { mCurrencyPacks.RemoveAt(i); break; } } mCurrencyPacks.Add(vcp); } if (virtualItem is VirtualGood) { VirtualGood vg = (VirtualGood)virtualItem; if (vg is UpgradeVG) { List <UpgradeVG> upgrades = mGoodsUpgrades[((UpgradeVG)vg).getGoodItemId()]; if (upgrades == null) { upgrades = new List <UpgradeVG>(); mGoodsUpgrades.Add(((UpgradeVG)vg).getGoodItemId(), upgrades); } upgrades.Add((UpgradeVG)vg); } PurchaseType purchaseType = vg.GetPurchaseType(); if (purchaseType is PurchaseWithMarket) { mPurchasableItems.Add(((PurchaseWithMarket)purchaseType).getMarketItem() .getProductId(), vg); } for (int i = 0; i < mGoods.Count; i++) { if (mGoods[i].getItemId() == vg.getItemId()) { mGoods.RemoveAt(i); break; } } mGoods.Add(vg); } /* * if (virtualItem is NonConsumableItem) { * NonConsumableItem non = (NonConsumableItem) virtualItem; * * PurchaseType purchaseType = non.GetPurchaseType(); * if (purchaseType is PurchaseWithMarket) { * mPurchasableItems.Add(((PurchaseWithMarket) purchaseType).getMarketItem() * .getProductId(), non); * } * * for(int i=0; i<mNonConsumables.Count; i++) { * if (mNonConsumables[i].getItemId() == non.getItemId()) { * mNonConsumables.RemoveAt(i); * break; * } * } * mNonConsumables.Add(non); * }*/ }
private void UpdateGoodBalance(VirtualGood good, int balance, int amountAdded) { TextBlock balanceText = (TextBlock)MainStackPanel.FindName(good.getItemId() + "balance"); balanceText.Text = "balance: " + balance.ToString(); }