/** * Takes upgrade from the user, or in other words DOWNGRADES the associated * <code>VirtualGood</code> (mGood). * Checks if the current Upgrade is really associated with the <code>VirtualGood</code> and: * * if YES - downgrades to the previous upgrade (or remove upgrades in case of null). * if NO - returns 0 (does nothing). * * @param amount is NOT USED HERE! * @param notify see parent * @return see parent */ public override int take(int amount, bool notify) { VirtualGood good = null; try { good = (VirtualGood)StoreInfo.getVirtualItem(mGoodItemId); } catch (VirtualItemNotFoundException e) { SoomlaUtils.LogError(TAG, "VirtualGood with itemId: " + mGoodItemId + " doesn't exist! Can't downgrade." + " " + e.Message); return(0); } UpgradeVG upgradeVG = StorageManager.getVirtualGoodsStorage().getCurrentUpgrade(good); // Case: Upgrade is not assigned to this Virtual Good if (upgradeVG != this) { SoomlaUtils.LogError(TAG, "You can't take an upgrade that's not currently assigned." + "The UpgradeVG " + getName() + " is not assigned to " + "the VirtualGood: " + good.getName()); return(0); } if (!String.IsNullOrEmpty(mPrevItemId)) { UpgradeVG prevUpgradeVG = null; // Case: downgrade is not possible because previous upgrade does not exist try { prevUpgradeVG = (UpgradeVG)StoreInfo.getVirtualItem(mPrevItemId); } catch (VirtualItemNotFoundException e) { SoomlaUtils.LogError(TAG, "Previous UpgradeVG with itemId: " + mPrevItemId + " doesn't exist! Can't downgrade." + " " + e.Message); return(0); } // Case: downgrade is successful! SoomlaUtils.LogDebug(TAG, "Downgrading " + good.getName() + " to: " + prevUpgradeVG.getName()); StorageManager.getVirtualGoodsStorage().assignCurrentUpgrade(good, prevUpgradeVG, notify); } // Case: first Upgrade in the series - so we downgrade to NO upgrade. else { SoomlaUtils.LogDebug(TAG, "Downgrading " + good.getName() + " to NO-UPGRADE"); StorageManager.getVirtualGoodsStorage().removeUpgrades(good, notify); } return(base.take(amount, notify)); }
/** * 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)); } }
/** * Determines if the user is in a state that allows him/her to buy an <code>UpgradeVG</code> * This method enforces allowing/rejecting of upgrades here so users won't buy them when * they are not supposed to. * If you want to give your users free upgrades, use the <code>give</code> function. * * @return true if can buy, false otherwise */ protected override bool CanBuy() { VirtualGood good = null; try { good = (VirtualGood)StoreInfo.getVirtualItem(mGoodItemId); } catch (VirtualItemNotFoundException e) { SoomlaUtils.LogError(TAG, "VirtualGood with itemId: " + mGoodItemId + " doesn't exist! Returning NO (can't buy)." + " " + e.Message); return(false); } UpgradeVG upgradeVG = StorageManager.getVirtualGoodsStorage().getCurrentUpgrade(good); return(((upgradeVG == null && String.IsNullOrEmpty(mPrevItemId)) || (upgradeVG != null && ((upgradeVG.getNextItemId() == getItemId()) || (upgradeVG.getPrevItemId() == getItemId())))) && base.CanBuy()); }
/** * Assigns a specific upgrade to the given virtual good. * * @param good the virtual good to upgrade * @param upgradeVG the upgrade to assign */ public void assignCurrentUpgrade(VirtualGood good, UpgradeVG upgradeVG) { assignCurrentUpgrade(good, upgradeVG, true); }
public GoodUpgradeEvent(VirtualGood good, UpgradeVG upgradeVG, object sender) : base(sender) { mGood = good; mUpgradeVG = upgradeVG; }
public GoodUpgradeEvent(VirtualGood good, UpgradeVG upgradeVG) : this(good, upgradeVG, null) { }
/** Private functions **/ /** * Transforms given JSONObject to StoreInfo * * @param JSONObject * @throws JSONException */ private static void fromJSONObject(JSONObject JSONObject) { 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>(); if (JSONObject.HasField(StoreJSONConsts.STORE_CURRENCIES)) { JSONObject virtualCurrencies = JSONObject[StoreJSONConsts.STORE_CURRENCIES]; for (int i=0; i<virtualCurrencies.Count; i++){ JSONObject o = virtualCurrencies[i]; VirtualCurrency c = new VirtualCurrency(o); mCurrencies.Add(c); mVirtualItems.Add(c.getItemId(), c); } } if (JSONObject.HasField(StoreJSONConsts.STORE_CURRENCYPACKS)) { JSONObject currencyPacks = JSONObject[StoreJSONConsts.STORE_CURRENCYPACKS]; for (int i=0; i<currencyPacks.Count; i++){ JSONObject o = currencyPacks[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 (JSONObject.HasField(StoreJSONConsts.STORE_GOODS)) { JSONObject virtualGoods = JSONObject[StoreJSONConsts.STORE_GOODS]; if (virtualGoods.HasField(StoreJSONConsts.STORE_GOODS_SU)) { JSONObject suGoods = virtualGoods[StoreJSONConsts.STORE_GOODS_SU]; for (int i=0; i<suGoods.Count; i++){ JSONObject o = suGoods[i]; SingleUseVG g = new SingleUseVG(o); addVG(g); } } if (virtualGoods.HasField(StoreJSONConsts.STORE_GOODS_LT)) { JSONObject ltGoods = virtualGoods[StoreJSONConsts.STORE_GOODS_LT]; for (int i=0; i<ltGoods.Count; i++){ JSONObject o = ltGoods[i]; LifetimeVG g = new LifetimeVG(o); addVG(g); } } if (virtualGoods.HasField(StoreJSONConsts.STORE_GOODS_EQ)) { JSONObject eqGoods = virtualGoods[StoreJSONConsts.STORE_GOODS_EQ]; for (int i=0; i<eqGoods.Count; i++){ JSONObject o = eqGoods[i]; EquippableVG g = new EquippableVG(o); addVG(g); } } if (virtualGoods.HasField(StoreJSONConsts.STORE_GOODS_PA)) { JSONObject paGoods = virtualGoods[StoreJSONConsts.STORE_GOODS_PA]; for (int i=0; i<paGoods.Count; i++){ JSONObject o = paGoods[i]; SingleUsePackVG g = new SingleUsePackVG(o); addVG(g); } } if (virtualGoods.HasField(StoreJSONConsts.STORE_GOODS_UP)) { JSONObject upGoods = virtualGoods[StoreJSONConsts.STORE_GOODS_UP]; for (int i=0; i<upGoods.Count; i++){ JSONObject o = upGoods[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 (JSONObject.HasField(StoreJSONConsts.STORE_CATEGORIES)) { JSONObject virtualCategories = JSONObject[StoreJSONConsts.STORE_CATEGORIES]; for(int i=0; i<virtualCategories.Count; i++){ JSONObject o = virtualCategories[i]; VirtualCategory category = new VirtualCategory(o); mCategories.Add(category); foreach(String goodItemId in category.getGoodsItemIds()) { mGoodsCategories.Add(goodItemId, category); } } } /* if (JSONObject.TryGetValue(StoreJSONConsts.STORE_NONCONSUMABLES, out value)) { JSONObject nonConsumables = JSONObject.Value<JSONObject>(StoreJSONConsts.STORE_NONCONSUMABLES); for (int i=0; i<nonConsumables.Count; i++){ JSONObject o = nonConsumables.Value<JSONObject>(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); } } }*/ }
/** * 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) { }
public void PostGoodUpgradeEvent(VirtualGood good, UpgradeVG upgradeVG) { LogEvent("GoodUpgrade"); if (OnGoodUpgradeEvent != null) { OnGoodUpgradeEvent(good, upgradeVG); } }
public void Prepare(int version, String JsonStoreAssets) { try { SoomlaUtils.LogDebug(TAG,"Prepare :\n"+JsonStoreAssets); mVersion = version; JSONObject jSONObject = new JSONObject(JsonStoreAssets,-10); JSONObject virtualCurrencies = jSONObject[StoreJSONConsts.STORE_CURRENCIES]; mVirtualCurrency = new VirtualCurrency[virtualCurrencies.Count]; for (int i = 0; i < virtualCurrencies.Count; i++) { JSONObject o = virtualCurrencies[i]; VirtualCurrency c = new VirtualCurrency(o); mVirtualCurrency[i] = c; } JSONObject currencyPacks = jSONObject[StoreJSONConsts.STORE_CURRENCYPACKS]; mVirtualCurrencyPack = new VirtualCurrencyPack[currencyPacks.Count]; for (int i = 0; i < currencyPacks.Count; i++) { JSONObject o = currencyPacks[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 JSONObject virtualGoods = jSONObject[StoreJSONConsts.STORE_GOODS]; JSONObject suGoods = virtualGoods[StoreJSONConsts.STORE_GOODS_SU]; JSONObject ltGoods = virtualGoods[StoreJSONConsts.STORE_GOODS_LT]; JSONObject eqGoods = virtualGoods[StoreJSONConsts.STORE_GOODS_EQ]; JSONObject upGoods = virtualGoods[StoreJSONConsts.STORE_GOODS_UP]; JSONObject paGoods = virtualGoods[StoreJSONConsts.STORE_GOODS_PA]; List<VirtualGood> goods = new List<VirtualGood>(); for (int i = 0; i < suGoods.Count; i++) { JSONObject o = suGoods[i]; SingleUseVG g = new SingleUseVG(o); SoomlaUtils.LogDebug(TAG, "SingleUseVG " + g.getItemId()); goods.Add(g); } for (int i = 0; i < ltGoods.Count; i++) { JSONObject o = ltGoods[i]; LifetimeVG g = new LifetimeVG(o); SoomlaUtils.LogDebug(TAG, "LifetimeVG " + g.getItemId()); goods.Add(g); } for (int i = 0; i < eqGoods.Count; i++) { JSONObject o = eqGoods[i]; EquippableVG g = new EquippableVG(o); SoomlaUtils.LogDebug(TAG, "EquippableVG " + g.getItemId()); goods.Add(g); } for (int i = 0; i < paGoods.Count; i++) { JSONObject o = paGoods[i]; SingleUsePackVG g = new SingleUsePackVG(o); SoomlaUtils.LogDebug(TAG, "SingleUsePackVG " + g.getItemId()); goods.Add(g); } for (int i = 0; i < upGoods.Count; i++) { JSONObject o = upGoods[i]; UpgradeVG g = new UpgradeVG(o); SoomlaUtils.LogDebug(TAG, "UpgradeVG " + g.getItemId()); goods.Add(g); } mVirtualGood = new VirtualGood[goods.Count]; for(int i = 0; i < goods.Count; i++) { SoomlaUtils.LogDebug(TAG, "VirtualGood " + goods[i].getItemId()); mVirtualGood[i] = goods[i]; } // categories depend on virtual goods. That's why the have to be initialized after! JSONObject virtualCategories = jSONObject[StoreJSONConsts.STORE_CATEGORIES]; mVirtualCategory = new VirtualCategory[virtualCategories.Count]; for (int i = 0; i < virtualCategories.Count; i++) { JSONObject o = virtualCategories[i]; VirtualCategory category = new VirtualCategory(o); mVirtualCategory[i] = category; } /* JArray nonConsumables = JSONObject.Value<JArray>(StoreJSONConsts.STORE_NONCONSUMABLES); mNonConsumableItem = new NonConsumableItem[nonConsumables.Count]; for (int i = 0; i < nonConsumables.Count; i++) { JSONObject o = nonConsumables.Value<JSONObject>(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); } }
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); } }