Пример #1
0
    /**
     * Retrieves the balance of the given virtual item.
     *
     * @param item the required virtual item
     * @return the balance of the required virtual item
     */
    public int getBalance(VirtualItem item){
        SoomlaUtils.LogDebug(mTag, "fetching balance for virtual item with itemId: "
                + item.getItemId());

        String itemId = item.getItemId();
        String key = keyBalance(itemId);
        String val = KeyValueStorage.GetValue(key);

        int balance = 0;
        if (val != null) {
            try
            {
                balance = int.Parse(val);
            }
            catch (Exception e)
            {
                SoomlaUtils.LogError(mTag, "Error casting string to int value: "+val+" "+e.Message);
                return 0;
            }
        }

        SoomlaUtils.LogDebug(mTag, "the balance for " + item.getItemId() + " is " + balance);

        return balance;
    }
Пример #2
0
    /*public static NonConsumableItemsStorage getNonConsumableItemsStorage() {
        return mNonConsumableItemsStorage;
    }*/

    /**
     * Checks whether the given item belongs to <code>VirtualGoodStorage</code> or
     * <code>VirtualCurrencyStorage</code>.
     *
     * @param item the item to check what type of storage it belongs to.
     * @return the type of VirtualItemStorage.
     */
    public static VirtualItemStorage getVirtualItemStorage(VirtualItem item) {
        VirtualItemStorage storage = null;
        if (item is VirtualGood) {
            storage = getVirtualGoodsStorage();
        } else if (item is VirtualCurrency) {
            storage = getVirtualCurrencyStorage();
        }
        return storage;
    }
Пример #3
0
        /**
         * Adds the given amount of items to the storage, and if notify is true
         * posts the change in the balance to the event bus.
         *
         * @param item the required virtual item
         * @param amount the amount of items to add
         * @param notify if true posts balance change event
         * @return new balance
         */
        public int add(VirtualItem item, int amount, bool notify)
        {
            SoomlaUtils.LogDebug(mTag, "adding " + amount + " " + item.getName());

            String itemId = item.getItemId();
            int balance = getBalance(item);
            if (balance < 0) { /* in case the user "adds" a negative value */
            balance = 0;
            amount = 0;
            }
            String balanceStr = (balance + amount).ToString();
            String key = keyBalance(itemId);
            KeyValueStorage.SetValue(key, balanceStr);

            if (notify) {
            postBalanceChangeEvent(item, balance+amount, amount);
            }

            return balance + amount;
        }
Пример #4
0
    /**
     * Sets the balance of the given virtual item to be the given balance, and if notify is true
     * posts the change in the balance to the event bus.
     *
     * @param item the required virtual item
     * @param balance the new balance to be set
     * @param notify if notify is true post balance change event
     * @return the balance of the required virtual item
     */
    public int setBalance(VirtualItem item, int balance, bool notify) {
        SoomlaUtils.LogDebug(mTag, "setting balance " + balance + " to " + item.getName() + ".");

        int oldBalance = getBalance(item);
        if (oldBalance == balance) {
            return balance;
        }

        String itemId = item.getItemId();

        String balanceStr = balance.ToString();
        String key = keyBalance(itemId);

        KeyValueStorage.SetValue(key, balanceStr);

        if (notify) {
            postBalanceChangeEvent(item, balance, 0);
        }

        return balance;
    }
Пример #5
0
 /**
  * Sets the balance of the given virtual item to be the given balance.
  *
  * @param item the required virtual item
  * @param balance the new balance to be set
  * @return the balance of the required virtual item
  */
 public int setBalance(VirtualItem item, int balance) {
     return setBalance(item, balance, true);
 }
Пример #6
0
 /**
  * Posts the given amount changed in the given balance of the given virtual item.
  *
  * @param item virtual item whose balance has changed
  * @param balance the balance that has changed
  * @param amountAdded the amount added to the item's balance
  */
 protected abstract void postBalanceChangeEvent(VirtualItem item, int balance, int amountAdded);
Пример #7
0
 /**
  * Sets the balance of the given virtual item to be the given balance, and if notify is true
  * posts the change in the balance to the event bus.
  *
  * @param item the required virtual item
  * @param balance the new balance to be set
  * @param notify if notify is true post balance change event
  * @return the balance of the required virtual item
  */
 public int setBalance(VirtualItem item, int balance, bool notify)
 {
     return balance;
 }
Пример #8
0
    /**
     * Replaces an old virtual item with a new one by doing the following:
     * 1. Determines the type of the given virtual item.
     * 2. Looks for the given virtual item in the relevant list, according to its type.
     * 3. If found, removes it.
     * 4. Adds the given virtual item.
     *
     * @param virtualItem the virtual item that replaces the old one if exists.
     */
    public static void replaceVirtualItem(VirtualItem virtualItem) {
        mVirtualItems.Add(virtualItem.getItemId(), virtualItem);

        if (virtualItem is VirtualCurrency) {
            for(int i=0; i<mCurrencies.Count; i++) {
                if (mCurrencies[i].getItemId() == virtualItem.getItemId()) {
                    mCurrencies.RemoveAt(i);
                    break;
                }
            }
            mCurrencies.Add((VirtualCurrency)virtualItem);
        }

        if (virtualItem is VirtualCurrencyPack) {
            VirtualCurrencyPack vcp = (VirtualCurrencyPack)virtualItem;
            PurchaseType purchaseType = vcp.GetPurchaseType();
            if (purchaseType is PurchaseWithMarket) {
                mPurchasableItems.Add(((PurchaseWithMarket) purchaseType).getMarketItem()
                        .getProductId(), vcp);
            }

            for(int i=0; i<mCurrencyPacks.Count; i++) {
                if (mCurrencyPacks[i].getItemId() == vcp.getItemId()) {
                    mCurrencyPacks.RemoveAt(i);
                    break;
                }
            }
            mCurrencyPacks.Add(vcp);
        }

        if (virtualItem is VirtualGood) {
            VirtualGood vg = (VirtualGood)virtualItem;

            if (vg is UpgradeVG) {
                List<UpgradeVG> upgrades = mGoodsUpgrades[((UpgradeVG) vg).getGoodItemId()];
                if (upgrades == null) {
                    upgrades = new List<UpgradeVG>();
                    mGoodsUpgrades.Add(((UpgradeVG) vg).getGoodItemId(), upgrades);
                }
                upgrades.Add((UpgradeVG) vg);
            }

            PurchaseType purchaseType = vg.GetPurchaseType();
            if (purchaseType is PurchaseWithMarket) {
                mPurchasableItems.Add(((PurchaseWithMarket) purchaseType).getMarketItem()
                        .getProductId(), vg);
            }

            for(int i=0; i<mGoods.Count; i++) {
                if (mGoods[i].getItemId() == vg.getItemId()) {
                    mGoods.RemoveAt(i);
                    break;
                }
            }
            mGoods.Add(vg);
        }
        /*
        if (virtualItem is NonConsumableItem) {
            NonConsumableItem non = (NonConsumableItem) virtualItem;

            PurchaseType purchaseType = non.GetPurchaseType();
            if (purchaseType is PurchaseWithMarket) {
                mPurchasableItems.Add(((PurchaseWithMarket) purchaseType).getMarketItem()
                        .getProductId(), non);
            }

            for(int i=0; i<mNonConsumables.Count; i++) {
                if (mNonConsumables[i].getItemId() == non.getItemId()) {
                    mNonConsumables.RemoveAt(i);
                    break;
                }
            }
            mNonConsumables.Add(non);
        }*/
    }
Пример #9
0
 /**
  * Adds the given amount of items to the storage.
  *
  * @param item the required virtual item
  * @param amount the amount of items to add
  * @return new balance
  */
 public int add(VirtualItem item, int amount){
     return add(item, amount, true);
 }
Пример #10
0
        private void buildShopLine(VirtualItem item)
        {
            StackPanel stackP = new StackPanel();
            stackP.Orientation = System.Windows.Controls.Orientation.Horizontal;
            stackP.Margin = new Thickness(0, 15, 0, 0);

            StackPanel buttonStack = new StackPanel();
            buttonStack.Orientation = System.Windows.Controls.Orientation.Vertical;

            StackPanel textStack = new StackPanel();
            textStack.Orientation = System.Windows.Controls.Orientation.Vertical;

            stackP.Children.Add(buttonStack);
            stackP.Children.Add(textStack);

            Button buy = new Button();
            buy.Margin = new Thickness(0, 0, 10, 0);
            buy.Click += buyItem;
            buy.Content = "buy";
            buy.CommandParameter = item.getItemId();
            buy.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            buy.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            buttonStack.Children.Add(buy);

            if(item is EquippableVG)
            {
                Button equip = new Button();
                equip.Name = item.getItemId()+"equip";
                equip.Margin = new Thickness(0, 0, 10, 0);
                equip.CommandParameter = item.getItemId();
                equip.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                equip.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                EquippableVG evg = (EquippableVG)item;
                if (StoreInventory.isVirtualGoodEquipped(item.getItemId()))
                {
                    equip.Content = "unequip";
                    equip.Click += unequipItem;
                }
                else
                {
                    equip.Content = "equip";
                    equip.Click += equipItem;
                }
                buttonStack.Children.Add(equip);
            }

            TextBlock balance = new TextBlock();
            balance.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            balance.Margin = new Thickness(0,0,10,0);
            if (!(item is VirtualCurrencyPack) && !(item is NonConsumableItem))
            {
                balance.Text = "balance: "+StoreInventory.getVirtualItemBalance(item.getItemId()).ToString();
            }
            balance.Name = item.getItemId() + "balance";
            textStack.Children.Add(balance);

            TextBlock name = new TextBlock();
            name.Margin = new Thickness(0, 0, 10, 0);
            name.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            name.Text = "id: "+item.getItemId();
            textStack.Children.Add(name);

            TextBlock price = new TextBlock();
            price.Margin = new Thickness(0, 0, 10, 0);
            price.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            TextBlock currency = new TextBlock();
            currency.Margin = new Thickness(0, 0, 10, 0);
            currency.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            if(item is PurchasableVirtualItem)
            {
                PurchasableVirtualItem pvi = (PurchasableVirtualItem)item;
                if(pvi.GetPurchaseType() is PurchaseWithVirtualItem)
                {
                    PurchaseWithVirtualItem purchaseType = (PurchaseWithVirtualItem)pvi.GetPurchaseType();
                    price.Text = "price: "+purchaseType.getAmount().ToString();
                    currency.Text = "currency: "+purchaseType.getTargetItemId();
                }
                if (pvi.GetPurchaseType() is PurchaseWithMarket)
                {
                    PurchaseWithMarket purchaseType = (PurchaseWithMarket)pvi.GetPurchaseType();
                    price.Text = "price: "+purchaseType.getMarketItem().getMarketPrice();
                    
                }

                textStack.Children.Add(price);
                textStack.Children.Add(currency);
            }

            if (item is VirtualCurrencyPack)
            {
                VirtualCurrencyPack vcp = (VirtualCurrencyPack)item;

                TextBlock currencyId = new TextBlock();
                currencyId.Text = "give currency: "+vcp.getCurrencyItemId().ToString();

                TextBlock currencyAmount = new TextBlock();
                currencyAmount.Text = "give amount: "+vcp.getCurrencyAmount().ToString();
                textStack.Children.Add(currencyId);
                textStack.Children.Add(currencyAmount);
            }

            MainStackPanel.Children.Add(stackP);
        }
Пример #11
0
 /**
  * @{inheritDoc}
  */
 protected override void postBalanceChangeEvent(VirtualItem item, int balance, int amountAdded) {
     StoreEvents.GetInstance().PostGoodBalanceChangedEvent((VirtualGood)item,balance, amountAdded);
 }
Пример #12
0
 /**
  * Removes the given amount from the given virtual item's balance, and if notify is true
  * posts the change in the balance to the event bus.
  *
  * @param item is the virtual item to remove the given amount from
  * @param amount is the amount to remove
  * @param notify if notify is true post balance change event
  * @return new balance
  */
 public int remove(VirtualItem item, int amount, bool notify)
 {
     return amount;
 }
Пример #13
0
 /**
  * Retrieves the balance of the given virtual item.
  *
  * @param item the required virtual item
  * @return the balance of the required virtual item
  */
 public int getBalance(VirtualItem item)
 {
     return 0;
 }
Пример #14
0
 /**
  * @{inheritDoc}
  */
 protected override void postBalanceChangeEvent(VirtualItem item, int balance, int amountAdded)
 {
 }
Пример #15
0
 /**
  * Removes the given amount from the given virtual item's balance.
  *
  * @param item is the virtual item to remove the given amount from
  * @param amount is the amount to remove
  * @return new balance
  */
 public int remove(VirtualItem item, int amount){
     return remove(item, amount, true);
 }
Пример #16
0
 /**
  * Replaces the given virtual item, and then saves the store's metadata.
  *
  * @param virtualItem the virtual item to replace
  */
 public static void save(VirtualItem virtualItem) {
     replaceVirtualItem(virtualItem);
     save();
 }
Пример #17
0
    /**
     * Removes the given amount from the given virtual item's balance, and if notify is true
     * posts the change in the balance to the event bus.
     *
     * @param item is the virtual item to remove the given amount from
     * @param amount is the amount to remove
     * @param notify if notify is true post balance change event
     * @return new balance
     */
    public int remove(VirtualItem item, int amount, bool notify){
        SoomlaUtils.LogDebug(mTag, "Removing " + amount + " " + item.getName() + ".");

        String itemId = item.getItemId();
        int balance = getBalance(item) - amount;
        if (balance < 0) {
            balance = 0;
            amount = 0;
        }
        String balanceStr = balance.ToString();
        String key = keyBalance(itemId);
        KeyValueStorage.SetValue(key, balanceStr);

        if (notify) {
            postBalanceChangeEvent(item, balance, -1*amount);
        }

        return balance;
    }
Пример #18
0
 /**
  * @{inheritDoc}
  */
 protected override void postBalanceChangeEvent(VirtualItem item, int balance, int amountAdded)
 {
     BusProvider.Instance.Post(new GoodBalanceChangedEvent((VirtualGood)item,balance, amountAdded));
 }
Пример #19
0
 /**
  * Replaces an old virtual item with a new one by doing the following:
  * 1. Determines the type of the given virtual item.
  * 2. Looks for the given virtual item in the relevant list, according to its type.
  * 3. If found, removes it.
  * 4. Adds the given virtual item.
  *
  * @param virtualItem the virtual item that replaces the old one if exists.
  */
 public static void replaceVirtualItem(VirtualItem virtualItem)
 {
 }