Search in sources :

Example 1 with UpgradeVG

use of com.soomla.store.domain.virtualGoods.UpgradeVG in project android-store by soomla.

the class StoreInventory method removeUpgrades.

/**
 * Removes all upgrades from the virtual good with the given <code>goodItemId</code>.
 *
 * @param goodItemId id of the virtual good we want to remove all upgrades from
 * @throws VirtualItemNotFoundException
 */
public static void removeUpgrades(String goodItemId) throws VirtualItemNotFoundException {
    List<UpgradeVG> upgrades = StoreInfo.getGoodUpgrades(goodItemId);
    for (UpgradeVG upgrade : upgrades) {
        StorageManager.getVirtualGoodsStorage().remove(upgrade.getItemId(), 1, true);
    }
    VirtualGood good = (VirtualGood) StoreInfo.getVirtualItem(goodItemId);
    StorageManager.getVirtualGoodsStorage().removeUpgrades(good.getItemId());
}
Also used : VirtualGood(com.soomla.store.domain.virtualGoods.VirtualGood) UpgradeVG(com.soomla.store.domain.virtualGoods.UpgradeVG)

Example 2 with UpgradeVG

use of com.soomla.store.domain.virtualGoods.UpgradeVG in project android-store by soomla.

the class StoreInventory method forceUpgrade.

/**
 * Upgrades the good with the given <code>upgradeItemId</code> for FREE (you are GIVING him/her
 * the upgrade). In case that the good is not an upgradeable item, an error message will be
 * produced. <code>forceUpgrade()</code> is different than <code>upgradeVirtualGood()<code>
 * because <code>forceUpgrade()</code> is a FREE upgrade.
 *
 * @param upgradeItemId id of the virtual good who we want to force an upgrade upon
 * @throws VirtualItemNotFoundException
 */
public static void forceUpgrade(String upgradeItemId) throws VirtualItemNotFoundException {
    try {
        UpgradeVG upgradeVG = (UpgradeVG) StoreInfo.getVirtualItem(upgradeItemId);
        upgradeVG.give(1);
    } catch (ClassCastException ex) {
        SoomlaUtils.LogError("SOOMLA StoreInventory", "The given itemId was of a non UpgradeVG VirtualItem. Can't force it.");
    }
}
Also used : UpgradeVG(com.soomla.store.domain.virtualGoods.UpgradeVG)

Example 3 with UpgradeVG

use of com.soomla.store.domain.virtualGoods.UpgradeVG in project android-store by soomla.

the class StoreInventory method upgradeVirtualGood.

/**
 * Upgrades the virtual good with the given <code>goodItemId</code> by doing the following:
 * 1. Checks if the good is currently upgraded or if this is the first time being upgraded.
 * 2. If the good is currently upgraded, upgrades to the next upgrade in the series, or in
 *    other words, <code>buy()</code>s the next upgrade. In case there are no more upgrades
 *    available(meaning the current upgrade is the last available), the function returns.
 * 3. If the good has never been upgraded before, the function upgrades it to the first
 *    available upgrade, or in other words, <code>buy()</code>s the first upgrade in the series.
 *
 * @param goodItemId the id of the virtual good to be upgraded
 * @throws VirtualItemNotFoundException
 * @throws InsufficientFundsException
 */
public static void upgradeVirtualGood(String goodItemId) throws VirtualItemNotFoundException, InsufficientFundsException {
    VirtualGood good = (VirtualGood) StoreInfo.getVirtualItem(goodItemId);
    String upgradeVGItemId = StorageManager.getVirtualGoodsStorage().getCurrentUpgrade(good.getItemId());
    UpgradeVG upgradeVG = null;
    try {
        upgradeVG = (UpgradeVG) StoreInfo.getVirtualItem(upgradeVGItemId);
    } catch (VirtualItemNotFoundException e) {
        SoomlaUtils.LogDebug("SOOMLA StoreInventory", "This is BAD! Can't find the current upgrade (" + upgradeVGItemId + ") of: " + good.getItemId());
    }
    if (upgradeVG != null) {
        String nextItemId = upgradeVG.getNextItemId();
        if (TextUtils.isEmpty(nextItemId)) {
            return;
        }
        UpgradeVG vgu = (UpgradeVG) StoreInfo.getVirtualItem(nextItemId);
        vgu.buy("");
    } else {
        UpgradeVG first = StoreInfo.getGoodFirstUpgrade(goodItemId);
        if (first != null) {
            first.buy("");
        }
    }
}
Also used : VirtualGood(com.soomla.store.domain.virtualGoods.VirtualGood) UpgradeVG(com.soomla.store.domain.virtualGoods.UpgradeVG) VirtualItemNotFoundException(com.soomla.store.exceptions.VirtualItemNotFoundException)

Example 4 with UpgradeVG

use of com.soomla.store.domain.virtualGoods.UpgradeVG in project android-store by soomla.

the class StoreInfo method initializeWithStoreAssets.

/**
 * Initializes from <code>IStoreAssets</code>.
 * This happens only once - when the game is loaded for the first time.
 *
 * @param storeAssets game economy
 */
private static void initializeWithStoreAssets(IStoreAssets storeAssets) {
    // fall-back here if the json doesn't exist,
    // we load the store from the given {@link IStoreAssets}.
    mCurrencies = new LinkedList<VirtualCurrency>(Arrays.asList(storeAssets.getCurrencies()));
    mCurrencyPacks = new LinkedList<VirtualCurrencyPack>(Arrays.asList(storeAssets.getCurrencyPacks()));
    mGoods = new LinkedList<VirtualGood>(Arrays.asList(storeAssets.getGoods()));
    mCategories = new LinkedList<VirtualCategory>(Arrays.asList(storeAssets.getCategories()));
    mVirtualItems = new HashMap<String, VirtualItem>();
    mPurchasableItems = new HashMap<String, PurchasableVirtualItem>();
    mGoodsCategories = new HashMap<String, VirtualCategory>();
    mGoodsUpgrades = new HashMap<String, List<UpgradeVG>>();
    for (VirtualCurrency vi : mCurrencies) {
        mVirtualItems.put(vi.getItemId(), vi);
    }
    for (VirtualCurrencyPack vi : mCurrencyPacks) {
        mVirtualItems.put(vi.getItemId(), vi);
        PurchaseType purchaseType = vi.getPurchaseType();
        if (purchaseType instanceof PurchaseWithMarket) {
            mPurchasableItems.put(((PurchaseWithMarket) purchaseType).getMarketItem().getProductId(), vi);
        }
    }
    for (VirtualGood vi : mGoods) {
        mVirtualItems.put(vi.getItemId(), vi);
        if (vi instanceof UpgradeVG) {
            List<UpgradeVG> upgrades = mGoodsUpgrades.get(((UpgradeVG) vi).getGoodItemId());
            if (upgrades == null) {
                upgrades = new ArrayList<UpgradeVG>();
                mGoodsUpgrades.put(((UpgradeVG) vi).getGoodItemId(), upgrades);
            }
            upgrades.add((UpgradeVG) vi);
        }
        PurchaseType purchaseType = vi.getPurchaseType();
        if (purchaseType instanceof PurchaseWithMarket) {
            mPurchasableItems.put(((PurchaseWithMarket) purchaseType).getMarketItem().getProductId(), vi);
        }
    }
    for (VirtualCategory category : mCategories) {
        for (String goodItemId : category.getGoodsItemIds()) {
            mGoodsCategories.put(goodItemId, category);
        }
    }
    // Remove this code when no longer needed.
    if (mNonConsumableMigrationNeeded) {
        SoomlaUtils.LogDebug(TAG, "NonConsumables balance migration is required. Doing it now.");
        nonConsBalancesToLTVGs();
    }
    save();
}
Also used : VirtualGood(com.soomla.store.domain.virtualGoods.VirtualGood) PurchasableVirtualItem(com.soomla.store.domain.PurchasableVirtualItem) UpgradeVG(com.soomla.store.domain.virtualGoods.UpgradeVG) PurchaseType(com.soomla.store.purchaseTypes.PurchaseType) VirtualCurrencyPack(com.soomla.store.domain.virtualCurrencies.VirtualCurrencyPack) VirtualCategory(com.soomla.store.domain.VirtualCategory) VirtualItem(com.soomla.store.domain.VirtualItem) PurchaseWithVirtualItem(com.soomla.store.purchaseTypes.PurchaseWithVirtualItem) PurchasableVirtualItem(com.soomla.store.domain.PurchasableVirtualItem) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) PurchaseWithMarket(com.soomla.store.purchaseTypes.PurchaseWithMarket) VirtualCurrency(com.soomla.store.domain.virtualCurrencies.VirtualCurrency)

Example 5 with UpgradeVG

use of com.soomla.store.domain.virtualGoods.UpgradeVG in project android-store by soomla.

the class StoreInfo method toJSONObject.

/**
 * Converts <code>StoreInfo</code> to a <code>JSONObject</code>.
 *
 * @return a <code>JSONObject</code> representation of <code>StoreInfo</code>.
 */
public static JSONObject toJSONObject() {
    JSONArray currencies = new JSONArray();
    for (VirtualCurrency c : mCurrencies) {
        currencies.put(c.toJSONObject());
    }
    JSONArray currencyPacks = new JSONArray();
    for (VirtualCurrencyPack pack : mCurrencyPacks) {
        currencyPacks.put(pack.toJSONObject());
    }
    JSONObject goods = new JSONObject();
    JSONArray suGoods = new JSONArray();
    JSONArray ltGoods = new JSONArray();
    JSONArray eqGoods = new JSONArray();
    JSONArray paGoods = new JSONArray();
    JSONArray upGoods = new JSONArray();
    for (VirtualGood good : mGoods) {
        if (good instanceof SingleUseVG) {
            suGoods.put(good.toJSONObject());
        } else if (good instanceof UpgradeVG) {
            upGoods.put(good.toJSONObject());
        } else if (good instanceof EquippableVG) {
            eqGoods.put(good.toJSONObject());
        } else if (good instanceof SingleUsePackVG) {
            paGoods.put(good.toJSONObject());
        } else if (good instanceof LifetimeVG) {
            ltGoods.put(good.toJSONObject());
        }
    }
    JSONArray categories = new JSONArray();
    for (VirtualCategory cat : mCategories) {
        categories.put(cat.toJSONObject());
    }
    JSONObject jsonObject = new JSONObject();
    try {
        goods.put(StoreJSONConsts.STORE_GOODS_SU, suGoods);
        goods.put(StoreJSONConsts.STORE_GOODS_LT, ltGoods);
        goods.put(StoreJSONConsts.STORE_GOODS_EQ, eqGoods);
        goods.put(StoreJSONConsts.STORE_GOODS_PA, paGoods);
        goods.put(StoreJSONConsts.STORE_GOODS_UP, upGoods);
        jsonObject.put(StoreJSONConsts.STORE_CATEGORIES, categories);
        jsonObject.put(StoreJSONConsts.STORE_CURRENCIES, currencies);
        jsonObject.put(StoreJSONConsts.STORE_GOODS, goods);
        jsonObject.put(StoreJSONConsts.STORE_CURRENCYPACKS, currencyPacks);
    } catch (JSONException e) {
        SoomlaUtils.LogError(TAG, "An error occurred while generating JSON object.");
    }
    return jsonObject;
}
Also used : VirtualGood(com.soomla.store.domain.virtualGoods.VirtualGood) UpgradeVG(com.soomla.store.domain.virtualGoods.UpgradeVG) LifetimeVG(com.soomla.store.domain.virtualGoods.LifetimeVG) VirtualCategory(com.soomla.store.domain.VirtualCategory) JSONObject(org.json.JSONObject) SingleUseVG(com.soomla.store.domain.virtualGoods.SingleUseVG) JSONArray(org.json.JSONArray) VirtualCurrencyPack(com.soomla.store.domain.virtualCurrencies.VirtualCurrencyPack) JSONException(org.json.JSONException) EquippableVG(com.soomla.store.domain.virtualGoods.EquippableVG) SingleUsePackVG(com.soomla.store.domain.virtualGoods.SingleUsePackVG) VirtualCurrency(com.soomla.store.domain.virtualCurrencies.VirtualCurrency)

Aggregations

UpgradeVG (com.soomla.store.domain.virtualGoods.UpgradeVG)11 VirtualGood (com.soomla.store.domain.virtualGoods.VirtualGood)8 VirtualItemNotFoundException (com.soomla.store.exceptions.VirtualItemNotFoundException)5 VirtualCurrency (com.soomla.store.domain.virtualCurrencies.VirtualCurrency)4 VirtualCurrencyPack (com.soomla.store.domain.virtualCurrencies.VirtualCurrencyPack)4 PurchasableVirtualItem (com.soomla.store.domain.PurchasableVirtualItem)3 VirtualCategory (com.soomla.store.domain.VirtualCategory)3 VirtualItem (com.soomla.store.domain.VirtualItem)3 EquippableVG (com.soomla.store.domain.virtualGoods.EquippableVG)3 PurchaseType (com.soomla.store.purchaseTypes.PurchaseType)3 PurchaseWithMarket (com.soomla.store.purchaseTypes.PurchaseWithMarket)3 LifetimeVG (com.soomla.store.domain.virtualGoods.LifetimeVG)2 SingleUsePackVG (com.soomla.store.domain.virtualGoods.SingleUsePackVG)2 SingleUseVG (com.soomla.store.domain.virtualGoods.SingleUseVG)2 PurchaseWithVirtualItem (com.soomla.store.purchaseTypes.PurchaseWithVirtualItem)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2