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());
}
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.");
}
}
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("");
}
}
}
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();
}
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;
}
Aggregations