/** * Equips the current <code>EquippableVG</code>. * The equipping is done according to the equipping model ('GLOBAL', 'CATEGORY', or 'LOCAL'). * * @param notify if true post event to bus * @throws NotEnoughGoodsException */ public void equip(bool notify) { // only if the user has bought this EquippableVG, the EquippableVG is equipped. if (StorageManager.getVirtualGoodsStorage().getBalance(this) > 0) { if (mEquippingModel == EquippingModel.CATEGORY) { VirtualCategory category = null; try { category = StoreInfo.getCategory(getItemId()); } catch (VirtualItemNotFoundException e) { SoomlaUtils.LogError(TAG, "Tried to unequip all other category VirtualGoods but there was no " + "associated category. virtual good itemId: " + getItemId() + " " + e.Message); return; } foreach (String goodItemId in category.getGoodsItemIds()) { EquippableVG equippableVG = null; try { equippableVG = (EquippableVG)StoreInfo.getVirtualItem(goodItemId); if (equippableVG != null && equippableVG != this) { equippableVG.unequip(notify); } } catch (VirtualItemNotFoundException e) { SoomlaUtils.LogError(TAG, "On equip, couldn't find one of the itemIds " + "in the category. Continuing to the next one. itemId: " + goodItemId + " " + e.Message); } catch (InvalidCastException ex) { SoomlaUtils.LogDebug(TAG, "On equip, an error occurred. It's a debug " + "message b/c the VirtualGood may just not be an EquippableVG. " + "itemId: " + goodItemId + " " + ex.Message); } } } else if (mEquippingModel == EquippingModel.GLOBAL) { foreach (VirtualGood good in StoreInfo.getGoods()) { if (good != this && good is EquippableVG) { ((EquippableVG)good).unequip(notify); } } } StorageManager.getVirtualGoodsStorage().equip(this, notify); } else { throw new NotEnoughGoodsException(getItemId()); } }
/** * Retrieves the <code>VirtualCategory</code> that the virtual good with the given * <code>goodItemId</code> belongs to. * * @param goodItemId the id of the virtual good whose category is to be fetched * @return the virtual category that the good with the given <code>goodItemId</code> belongs to * @throws VirtualItemNotFoundException if the given <code>goodItemId</code> is not found */ public static VirtualCategory getCategory(String goodItemId) { VirtualCategory item = mGoodsCategories[goodItemId]; if (item == null) { throw new VirtualItemNotFoundException("goodItemId", goodItemId); } return(item); }
public MashinRunAssets() { mashinRunCurrency = new VirtualCurrency("Coin", "the currency of the mashin run game" , "com.mashinran.currency"); moneyCategory = new VirtualCategory("money category" , new List <string>(new string[] { mashinRunCurrency.ItemId })); fiatCar = new EquippableVG (EquippableVG.EquippingModel.GLOBAL, "fiat" , "Fiat", "com.mashinrun.fiat", new PurchaseWithVirtualItem (mashinRunCurrency.ItemId , 2000)); volksWagenCar = new EquippableVG (EquippableVG.EquippingModel.GLOBAL, "volksWagen" , "Volks wagen", "com.mashinrun.volkswagen", new PurchaseWithVirtualItem (mashinRunCurrency.ItemId , 0)); sportCar = new EquippableVG( EquippableVG.EquippingModel.GLOBAL, "sportcar" , "Sport car", "com.mashinrun.sportcar", new PurchaseWithVirtualItem (mashinRunCurrency.ItemId, 20000)); beetleCar = new EquippableVG( EquippableVG.EquippingModel.GLOBAL, "beetle" , "Beetle car", "com.mashinrun.beetle", new PurchaseWithVirtualItem (mashinRunCurrency.ItemId, 8000)); twentyThousandCoinsPack = new VirtualCurrencyPack ("Fifty ThousandCoins", "Fifty thousand coins", "twenty_thousand_coins", 20000 , mashinRunCurrency.ItemId, new PurchaseWithMarket (TWENTY_THOUSAND_COINS_PACK_ITEM_ID, 20000)); fiftyThousandCoinsPack = new VirtualCurrencyPack ("Fifty ThousandCoins", "Fifty thousand coins", "fifty_thousand_coins", 50000 , mashinRunCurrency.ItemId, new PurchaseWithMarket (FIFTY_THOUSAND_COINS_PACK_ITEM_ID, 50000)); tenThousandCoinsPack = new VirtualCurrencyPack("Ten ThousandCoins", "Ten thousand coins", "ten_thousand_coins" , 10000 , mashinRunCurrency.ItemId, new PurchaseWithMarket ("com.mashinran.ten_thousand_coins", 10000)); }
private static void fromJSONObject(JSONObject storeJSON) { VirtualItems = new Dictionary<string, VirtualItem> (); PurchasableItems = new Dictionary<string, PurchasableVirtualItem> (); GoodsCategories = new Dictionary<string, VirtualCategory> (); GoodsUpgrades = new Dictionary<string, List<UpgradeVG>> (); CurrencyPacks = new List<VirtualCurrencyPack> (); Goods = new List<VirtualGood> (); Categories = new List<VirtualCategory> (); Currencies = new List<VirtualCurrency> (); if (storeJSON.HasField (StoreJSONConsts.STORE_CURRENCIES)) { List<JSONObject> objs = storeJSON [StoreJSONConsts.STORE_CURRENCIES].list; foreach (JSONObject o in objs) { VirtualCurrency c = new VirtualCurrency (o); Currencies.Add (c); } } if (storeJSON.HasField (StoreJSONConsts.STORE_CURRENCYPACKS)) { List<JSONObject> objs = storeJSON [StoreJSONConsts.STORE_CURRENCYPACKS].list; foreach (JSONObject o in objs) { VirtualCurrencyPack c = new VirtualCurrencyPack (o); CurrencyPacks.Add (c); } } if (storeJSON.HasField (StoreJSONConsts.STORE_GOODS)) { JSONObject goods = storeJSON [StoreJSONConsts.STORE_GOODS]; if (goods.HasField (StoreJSONConsts.STORE_GOODS_SU)) { List<JSONObject> suGoods = goods [StoreJSONConsts.STORE_GOODS_SU].list; foreach (JSONObject o in suGoods) { var c = new SingleUseVG (o); Goods.Add (c); } } if (goods.HasField (StoreJSONConsts.STORE_GOODS_LT)) { List<JSONObject> ltGoods = goods [StoreJSONConsts.STORE_GOODS_LT].list; foreach (JSONObject o in ltGoods) { LifetimeVG c = new LifetimeVG (o); Goods.Add (c); } } if (goods.HasField (StoreJSONConsts.STORE_GOODS_EQ)) { List<JSONObject> eqGoods = goods [StoreJSONConsts.STORE_GOODS_EQ].list; foreach (JSONObject o in eqGoods) { EquippableVG c = new EquippableVG (o); Goods.Add (c); } } if (goods.HasField (StoreJSONConsts.STORE_GOODS_PA)) { List<JSONObject> paGoods = goods [StoreJSONConsts.STORE_GOODS_PA].list; foreach (JSONObject o in paGoods) { SingleUsePackVG c = new SingleUsePackVG (o); Goods.Add (c); } } if (goods.HasField (StoreJSONConsts.STORE_GOODS_UP)) { List<JSONObject> upGoods = goods [StoreJSONConsts.STORE_GOODS_UP].list; foreach (JSONObject o in upGoods) { UpgradeVG c = new UpgradeVG (o); Goods.Add (c); } } } if (storeJSON.HasField(StoreJSONConsts.STORE_CATEGORIES)) { List<JSONObject> categories = storeJSON[StoreJSONConsts.STORE_CATEGORIES].list; foreach (JSONObject o in categories){ VirtualCategory category = new VirtualCategory(o); Categories.Add(category); } } updateAggregatedLists (); }
public void Prepare(int version, String JsonStoreAssets) { try { mVersion = version; JObject JObject = JObject.Parse(JsonStoreAssets); JArray virtualCurrencies = JObject.Value <JArray>(StoreJSONConsts.STORE_CURRENCIES); mVirtualCurrency = new VirtualCurrency[virtualCurrencies.Count]; for (int i = 0; i < virtualCurrencies.Count; i++) { JObject o = virtualCurrencies.Value <JObject>(i); VirtualCurrency c = new VirtualCurrency(o); mVirtualCurrency[i] = c; } JArray currencyPacks = JObject.Value <JArray>(StoreJSONConsts.STORE_CURRENCYPACKS); mVirtualCurrencyPack = new VirtualCurrencyPack[currencyPacks.Count]; for (int i = 0; i < currencyPacks.Count; i++) { JObject o = currencyPacks.Value <JObject>(i); VirtualCurrencyPack pack = new VirtualCurrencyPack(o); mVirtualCurrencyPack[i] = pack; } // The order in which VirtualGoods are created matters! // For example: VGU and VGP depend on other VGs JObject virtualGoods = JObject.Value <JObject>(StoreJSONConsts.STORE_GOODS); JArray suGoods = virtualGoods.Value <JArray>(StoreJSONConsts.STORE_GOODS_SU); JArray ltGoods = virtualGoods.Value <JArray>(StoreJSONConsts.STORE_GOODS_LT); JArray eqGoods = virtualGoods.Value <JArray>(StoreJSONConsts.STORE_GOODS_EQ); JArray upGoods = virtualGoods.Value <JArray>(StoreJSONConsts.STORE_GOODS_UP); JArray paGoods = virtualGoods.Value <JArray>(StoreJSONConsts.STORE_GOODS_PA); List <VirtualGood> goods = new List <VirtualGood>(); for (int i = 0; i < suGoods.Count; i++) { JObject o = suGoods.Value <JObject>(i); SingleUseVG g = new SingleUseVG(o); goods.Add(g); } for (int i = 0; i < ltGoods.Count; i++) { JObject o = ltGoods.Value <JObject>(i); LifetimeVG g = new LifetimeVG(o); goods.Add(g); } for (int i = 0; i < eqGoods.Count; i++) { JObject o = eqGoods.Value <JObject>(i); EquippableVG g = new EquippableVG(o); goods.Add(g); } for (int i = 0; i < paGoods.Count; i++) { JObject o = paGoods.Value <JObject>(i); SingleUsePackVG g = new SingleUsePackVG(o); goods.Add(g); } for (int i = 0; i < upGoods.Count; i++) { JObject o = upGoods.Value <JObject>(i); UpgradeVG g = new UpgradeVG(o); goods.Add(g); } mVirtualGood = new VirtualGood[goods.Count]; for (int i = 0; i < goods.Count; i++) { mVirtualGood[i] = goods[i]; } // categories depend on virtual goods. That's why the have to be initialized after! JArray virtualCategories = JObject.Value <JArray>(StoreJSONConsts.STORE_CATEGORIES); mVirtualCategory = new VirtualCategory[virtualCategories.Count]; for (int i = 0; i < virtualCategories.Count; i++) { JObject o = virtualCategories.Value <JObject>(i); VirtualCategory category = new VirtualCategory(o); mVirtualCategory[i] = category; } JArray nonConsumables = JObject.Value <JArray>(StoreJSONConsts.STORE_NONCONSUMABLES); mNonConsumableItem = new NonConsumableItem[nonConsumables.Count]; for (int i = 0; i < nonConsumables.Count; i++) { JObject o = nonConsumables.Value <JObject>(i); NonConsumableItem non = new NonConsumableItem(o); mNonConsumableItem[i] = non; } } catch (Exception ex) { SoomlaUtils.LogError(TAG, "An error occurred while trying to prepare storeAssets" + ex.Message); } }
/// <summary> /// Creates a final "Characters" category and virtual goods array. /// This should be called after all characters have been added to the list of /// characters, and just before Store.Initialize is called. /// </summary> public void FinalizeCharacterGoods() { CharactersCategory = new VirtualCategory("Characters", m_charCategoryGoodsList); m_virtualGoodsArray = m_virtualGoodsList.ToArray(); }
/** Private functions **/ /** * Transforms given JObject to StoreInfo * * @param JObject * @throws JSONException */ private static void fromJObject(JObject JObject) { mVirtualItems = new Dictionary <String, VirtualItem>(); mPurchasableItems = new Dictionary <String, PurchasableVirtualItem>(); mGoodsCategories = new Dictionary <String, VirtualCategory>(); mGoodsUpgrades = new Dictionary <String, List <UpgradeVG> >(); mCurrencyPacks = new List <VirtualCurrencyPack>(); mGoods = new List <VirtualGood>(); mCategories = new List <VirtualCategory>(); mCurrencies = new List <VirtualCurrency>(); mNonConsumables = new List <NonConsumableItem>(); JToken value; if (JObject.TryGetValue(StoreJSONConsts.STORE_CURRENCIES, out value)) { JArray virtualCurrencies = JObject.Value <JArray>(StoreJSONConsts.STORE_CURRENCIES); for (int i = 0; i < virtualCurrencies.Count; i++) { JObject o = virtualCurrencies.Value <JObject>(i); VirtualCurrency c = new VirtualCurrency(o); mCurrencies.Add(c); mVirtualItems.Add(c.getItemId(), c); } } if (JObject.TryGetValue(StoreJSONConsts.STORE_CURRENCYPACKS, out value)) { JArray currencyPacks = JObject.Value <JArray>(StoreJSONConsts.STORE_CURRENCYPACKS); for (int i = 0; i < currencyPacks.Count; i++) { JObject o = currencyPacks.Value <JObject>(i); VirtualCurrencyPack pack = new VirtualCurrencyPack(o); mCurrencyPacks.Add(pack); mVirtualItems.Add(pack.getItemId(), pack); PurchaseType purchaseType = pack.GetPurchaseType(); if (purchaseType is PurchaseWithMarket) { mPurchasableItems.Add(((PurchaseWithMarket)purchaseType) .getMarketItem().getProductId(), pack); } } } // The order in which VirtualGoods are created matters! // For example: VGU and VGP depend on other VGs if (JObject.TryGetValue(StoreJSONConsts.STORE_GOODS, out value)) { JObject virtualGoods = JObject.Value <JObject>(StoreJSONConsts.STORE_GOODS); JToken valueVg; if (virtualGoods.TryGetValue(StoreJSONConsts.STORE_GOODS_SU, out valueVg)) { JArray suGoods = virtualGoods.Value <JArray>(StoreJSONConsts.STORE_GOODS_SU); for (int i = 0; i < suGoods.Count; i++) { JObject o = suGoods.Value <JObject>(i); SingleUseVG g = new SingleUseVG(o); addVG(g); } } if (virtualGoods.TryGetValue(StoreJSONConsts.STORE_GOODS_LT, out valueVg)) { JArray ltGoods = virtualGoods.Value <JArray>(StoreJSONConsts.STORE_GOODS_LT); for (int i = 0; i < ltGoods.Count; i++) { JObject o = ltGoods.Value <JObject>(i); LifetimeVG g = new LifetimeVG(o); addVG(g); } } if (virtualGoods.TryGetValue(StoreJSONConsts.STORE_GOODS_EQ, out valueVg)) { JArray eqGoods = virtualGoods.Value <JArray>(StoreJSONConsts.STORE_GOODS_EQ); for (int i = 0; i < eqGoods.Count; i++) { JObject o = eqGoods.Value <JObject>(i); EquippableVG g = new EquippableVG(o); addVG(g); } } if (virtualGoods.TryGetValue(StoreJSONConsts.STORE_GOODS_PA, out valueVg)) { JArray paGoods = virtualGoods.Value <JArray>(StoreJSONConsts.STORE_GOODS_PA); for (int i = 0; i < paGoods.Count; i++) { JObject o = paGoods.Value <JObject>(i); SingleUsePackVG g = new SingleUsePackVG(o); addVG(g); } } if (virtualGoods.TryGetValue(StoreJSONConsts.STORE_GOODS_UP, out valueVg)) { JArray upGoods = virtualGoods.Value <JArray>(StoreJSONConsts.STORE_GOODS_UP); for (int i = 0; i < upGoods.Count; i++) { JObject o = upGoods.Value <JObject>(i); UpgradeVG g = new UpgradeVG(o); addVG(g); List <UpgradeVG> upgrades = mGoodsUpgrades[g.getGoodItemId()]; if (upgrades == null) { upgrades = new List <UpgradeVG>(); mGoodsUpgrades.Add(g.getGoodItemId(), upgrades); } upgrades.Add(g); } } } // Categories depend on virtual goods. That's why the have to be initialized after! if (JObject.TryGetValue(StoreJSONConsts.STORE_CATEGORIES, out value)) { JArray virtualCategories = JObject.Value <JArray>(StoreJSONConsts.STORE_CATEGORIES); for (int i = 0; i < virtualCategories.Count; i++) { JObject o = virtualCategories.Value <JObject>(i); VirtualCategory category = new VirtualCategory(o); mCategories.Add(category); foreach (String goodItemId in category.getGoodsItemIds()) { mGoodsCategories.Add(goodItemId, category); } } } if (JObject.TryGetValue(StoreJSONConsts.STORE_NONCONSUMABLES, out value)) { JArray nonConsumables = JObject.Value <JArray>(StoreJSONConsts.STORE_NONCONSUMABLES); for (int i = 0; i < nonConsumables.Count; i++) { JObject o = nonConsumables.Value <JObject>(i); NonConsumableItem non = new NonConsumableItem(o); mNonConsumables.Add(non); mVirtualItems.Add(non.getItemId(), non); PurchaseType purchaseType = non.GetPurchaseType(); if (purchaseType is PurchaseWithMarket) { mPurchasableItems.Add(((PurchaseWithMarket)purchaseType) .getMarketItem().getProductId(), non); } } } }