public GoodBalanceChangedEvent(VirtualGood good, int balance, int amountAdded, object sender) : base(sender) { mGood = good; mBalance = balance; mAmountAdded = amountAdded; }
/** * Removes any upgrade associated with the given VirtualGood. * * @param good the virtual good to remove the upgrade from * @param notify if true post event to bus */ public void removeUpgrades(VirtualGood good, bool notify) { SoomlaUtils.LogDebug(mTag, "Removing upgrade information from virtual good: " + good.getName()); String itemId = good.getItemId(); String key = keyGoodUpgrade(itemId); KeyValueStorage.DeleteKeyValue(key); if (notify) { BusProvider.Instance.Post(new GoodUpgradeEvent(good, null)); } }
/** * 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 the current upgrade to the associated <code>VirtualGood</code> (mGood). * * NOTE: This action doesn't check anything! It just assigns the current UpgradeVG to the * associated mGood. * * @param amount is NOT USED HERE! * @return 1 if the user was given the good, 0 otherwise */ public override int give(int amount, bool notify) { SoomlaUtils.LogDebug(TAG, "Assigning " + getName() + " to: " + mGoodItemId); VirtualGood good = null; try { good = (VirtualGood)StoreInfo.getVirtualItem(mGoodItemId); } catch (VirtualItemNotFoundException e) { SoomlaUtils.LogError(TAG, "VirtualGood with itemId: " + mGoodItemId + " doesn't exist! Can't upgrade. " + e.Message); return(0); } StorageManager.getVirtualGoodsStorage().assignCurrentUpgrade(good, this, notify); return(base.give(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()); }
public GoodUpgradeEvent(VirtualGood good, UpgradeVG upgradeVG) : this(good, upgradeVG, null) { }
/** * 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); } }
public void PostGoodUpgradeEvent(VirtualGood good, UpgradeVG upgradeVG) { LogEvent("GoodUpgrade"); if (OnGoodUpgradeEvent != null) { OnGoodUpgradeEvent(good, upgradeVG); } }
/** * Removes any upgrade associated with the given <code>VirtualGood</code>. * * @param good the VirtualGood to remove upgrade from */ public void removeUpgrades(VirtualGood good) { removeUpgrades(good, true); }
/** * 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) { }
/** * Removes any upgrade associated with the given VirtualGood. * * @param good the virtual good to remove the upgrade from * @param notify if true post event to bus */ public void removeUpgrades(VirtualGood good, bool notify) { }
/** * Retrieves the current upgrade for the given virtual good. * * @param good the virtual good to retrieve upgrade for * @return the current upgrade for the given virtual good */ public UpgradeVG getCurrentUpgrade(VirtualGood good) { return null; }
private void UpdateGoodBalance(VirtualGood good, int balance, int amountAdded) { TextBlock balanceText = (TextBlock)MainStackPanel.FindName(good.getItemId() + "balance"); balanceText.Text = "balance: " + balance.ToString(); }
public GoodUpgradeEvent(VirtualGood good, UpgradeVG upgradeVG, object sender) : base(sender) { mGood = good; mUpgradeVG = upgradeVG; }
/** * Retrieves the current upgrade for the given virtual good. * * @param good the virtual good to retrieve upgrade for * @return the current upgrade for the given virtual good */ public UpgradeVG getCurrentUpgrade(VirtualGood good) { SoomlaUtils.LogDebug(mTag, "Fetching upgrade to virtual good: " + good.getName()); String itemId = good.getItemId(); String key = keyGoodUpgrade(itemId); String upItemId = KeyValueStorage.GetValue(key); if (upItemId == null) { SoomlaUtils.LogDebug(mTag, "You tried to fetch the current upgrade of " + good.getName() + " but there's not upgrade to it."); return null; } try { return (UpgradeVG) StoreInfo.getVirtualItem(upItemId); } catch (VirtualItemNotFoundException e) { SoomlaUtils.LogError(mTag, "The current upgrade's itemId from the DB is not found in StoreInfo." + " " + e.Message); } catch (InvalidCastException e) { SoomlaUtils.LogError(mTag, "The current upgrade's itemId from the DB is not an UpgradeVG." + " " + e.Message); } return null; }
public GoodBalanceChangedEvent(VirtualGood good, int balance, int amountAdded) : this(good, balance, amountAdded, null) { }
/** * 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 void PostGoodBalanceChangedEvent(VirtualGood good, int balance, int amountAdded) { LogEvent("GoodBalanceChanged"); if (OnGoodBalanceChangedEvent != null) { OnGoodBalanceChangedEvent(good, balance, amountAdded); } }