/** * 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); } }
/** * 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); * }*/ }