void onNotEnoughTargetItem(VirtualItem item) { if (item.ItemId == "seed") { UIServer.main.ShowPage("Store"); } }
public SupplyResponse Put(string id, [FromBody] VirtualItem item) { if (string.IsNullOrWhiteSpace(id) || string.IsNullOrWhiteSpace(item.VirtualItemName) || string.IsNullOrWhiteSpace(item.VirtualItemId)) { return(SupplyResponse.RequiredFieldEmpty()); } var entity = _dbContext.VirtualItem.AsNoTracking().SingleOrDefault(p => p.VirtualItemId.Equals(id)); if (entity == null) { return(Post(item)); } if (entity.VirtualItemId != item.VirtualItemId && _dbContext.VirtualItem.SingleOrDefault(p => p.VirtualItemId == item.VirtualItemId) != null) { return(SupplyResponse.DuplicateEntry("virtual item", item.VirtualItemId)); } item.Id = entity.Id; var entry = _dbContext.Attach(item); //var entry = _dbContext.Entry(entity); //entry.CurrentValues.SetValues(item); entry.State = EntityState.Modified; _dbContext.SaveChanges(); return(Get(item.VirtualItemId)); }
internal static string XmlToString(VirtualItem vi) { StringBuilder sX = new StringBuilder(); XmlWriter xR = CreateWriter(sX); if (!(vi.WriteXML(xR))) { return ""; } return sX.ToString(); }
/** * Buys the virtual item with other virtual items. * * @throws com.soomla.store.exceptions.InsufficientFundsException */ public override void buy(String payload) { SoomlaUtils.LogDebug(TAG, "Trying to buy a " + getAssociatedItem().getName() + " with " + mAmount + " pieces of " + mTargetItemId); VirtualItem item = null; try { item = StoreInfo.getVirtualItem(mTargetItemId); } catch (VirtualItemNotFoundException e) { SoomlaUtils.LogError(TAG, "Target virtual item doesn't exist !" + " " + e.Message); return; } StoreEvents.GetInstance().PostItemPurchaseStartedEvent(getAssociatedItem()); VirtualItemStorage storage = StorageManager.getVirtualItemStorage(item); Debug.Assert(storage != null); int balance = storage.getBalance(item); if (balance < mAmount) { throw new InsufficientFundsException(mTargetItemId); } storage.remove(item, mAmount); getAssociatedItem().give(1); //BusProvider.getInstance().post(new OnItemPurchasedEvent(getAssociatedItem(), payload)); StoreEvents.GetInstance().PostItemPurchasedEvent(getAssociatedItem(), payload); }
/** * 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); }
/** * 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); }
private bool ShouldRealize(VirtualItem item) { var itemStartY = item.Position.y; var itemEndY = item.Position.y - item.ListViewItem.ItemHeight; var clipStart = GetClipStartY(); var clipEndY = GetClipEndY(); bool result; if (clipEndY > itemStartY || clipStart < itemEndY) { result = false; } else { result = true; } if (EnableDebug) { Debug.Log(" ShouldRealize ->" + " name: " + item.ListViewItem.gameObject.name + " index: " + item.Index + " itemStartY: " + itemStartY + " itemEndY: " + itemEndY + " clipStart: " + clipStart + " clipEndY: " + clipEndY + " result: " + result); } return(result); }
// When insufficient funds, page opens shop void onNotEnoughTargetItem(VirtualItem item) { if (item.ItemId == "seed") { UIServer.main.ShowPage("Store"); } StoreInventory.GetItemBalance(item.ID); }
private void RealizeItem(VirtualItem item) { if (item.IsRealized) { return; } item.Realize(); }
private void VisualizeItem(VirtualItem item) { if (!item.IsRealized) { return; } item.Virtualize(); }
/** Setters and Getters */ /** * Retrieves a single <code>VirtualItem</code> that resides in the metadata. * * @param itemId the itemId of the required <code>VirtualItem</code> * @return virtual item for the given <code>itemId</code> * @throws VirtualItemNotFoundException if no <code>VirtualItem</code> with the given * <code>itemId</code> was found. */ public static VirtualItem getVirtualItem(String itemId) { VirtualItem item = mVirtualItems[itemId]; if (item == null) { throw new VirtualItemNotFoundException("itemId", itemId); } return(item); }
public void Give(Reward reward) { VirtualItem item = reward.RelatedItem as VirtualItem; if (item != null) { item.Give(reward.RewardNumber); } else { UnityEngine.Debug.LogWarning("Virtual item's reward item is not a virtual item."); } }
/*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); }
public SupplyResponse Post([FromBody] VirtualItem item) { if (string.IsNullOrWhiteSpace(item.VirtualItemName) || string.IsNullOrWhiteSpace(item.VirtualItemId)) { return(SupplyResponse.RequiredFieldEmpty()); } if (_dbContext.VirtualItem.SingleOrDefault(p => p.VirtualItemId == item.VirtualItemId) != null) { return(SupplyResponse.DuplicateEntry("item", item.VirtualItemId)); } item.Id = 0; _dbContext.VirtualItem.Add(item); _dbContext.SaveChanges(); return(Get(item.VirtualItemId)); }
/// <summary> /// Rebuilds the scroll pane in a coroutine after layout. /// </summary> private System.Collections.IEnumerator DoRebuild() { pending = true; yield return(null); if (!App.IsExiting && scroll != null && itemList != null) { int n = itemList.childCount; float marginX = 0.0f, marginY = 0.0f; bool ice = freezeLayout; GameObject go; components.Clear(); for (int i = 0; i < n; i++) { var transform = itemList.GetChild(i); if (transform != null && (go = transform.gameObject).activeSelf) { var vi = new VirtualItem(transform, go, itemList, ice); float w = vi.size.x, h = vi.size.y; components.Add(vi); if (w > marginX) { marginX = w; } if (h > marginY) { marginY = h; } } } if (realLayout != null) { // Copy the parameters to the virtual layout virtualLayout.minHeight = realLayout.minHeight; virtualLayout.minWidth = realLayout.minWidth; virtualLayout.preferredHeight = realLayout.preferredHeight; virtualLayout.preferredWidth = realLayout.preferredWidth; virtualLayout.flexibleHeight = realLayout.flexibleHeight; virtualLayout.flexibleWidth = realLayout.flexibleWidth; virtualLayout.enabled = true; realLayout.enabled = false; } margin = new Vector2(marginX * 1.5f, marginY * 1.5f); // Calculate the margin UpdateScroll(); } pending = false; }
protected virtual void Init() { if (_inited) { return; } // Will cache exist item later var pendingToCahce = new List <GameObject>(); for (var i = 0; i < transform.childCount; i++) { var child = transform.GetChild(i).gameObject; pendingToCahce.Add(child); } // Create root for scrolling _root = new GameObject("Root").transform; _root.SetParent(transform, false); // Create object pool in root _pool = GameObjectPool.CreateSetScalePool("Pool", _root); pendingToCahce.ForEach(x => { _pool.ReleaseAndRegister(x, ListViewItem.gameObject); }); // Init virtual item record _virtualItems = new ResizableList <VirtualItem>(() => { var item = new VirtualItem(); item.ListViewItem = ListViewItem; item.Index = _virtualItems.Count; item.Parent = _root; item.OnUpdate = OnItemUpdate; item.Pool = _pool; item.LocalPosition = GetItemLocalPosition(ListViewItem, item.Index); return(item); }, VisualizeItem); _inited = true; }
/** * 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); }
/** * 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); }
/** * @{inheritDoc} */ protected override void postBalanceChangeEvent(VirtualItem item, int balance, int amountAdded) { BusProvider.Instance.Post(new GoodBalanceChangedEvent((VirtualGood)item, balance, amountAdded)); }
/// <summary> /// Replaces the given virtual item, and then saves the store's metadata. /// </summary> /// <param name="virtualItem">the virtual item to replace.</param> public static void Save(VirtualItem virtualItem) { replaceVirtualItem(virtualItem); Save(); }
/// <summary> /// Replaces the given virtual item, and then saves the store's metadata /// (if requested). /// </summary> /// <param name="virtualItem">the virtual item to replace.</param> /// <param name="saveToDB">should the virtual item be persisted to local DB</param> public static void Save(VirtualItem virtualItem, bool saveToDB = true) { replaceVirtualItem(virtualItem); if (saveToDB) { Save(); } }
/// <summary> /// 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. /// </summary> /// <param name="virtualItem">the virtual item that replaces the old one if exists.</param> private static void replaceVirtualItem(VirtualItem virtualItem) { VirtualItems.AddOrUpdate(virtualItem.ItemId, virtualItem); if (virtualItem is VirtualCurrency) { for(int i=0; i<Currencies.Count(); i++) { if (Currencies[i].ItemId == virtualItem.ItemId) { Currencies.RemoveAt(i); break; } } Currencies.Add((VirtualCurrency)virtualItem); } if (virtualItem is VirtualCurrencyPack) { VirtualCurrencyPack vcp = (VirtualCurrencyPack)virtualItem; if (vcp.PurchaseType is PurchaseWithMarket) { PurchasableItems.AddOrUpdate(((PurchaseWithMarket) vcp.PurchaseType).MarketItem .ProductId, vcp); } for(int i=0; i<CurrencyPacks.Count(); i++) { if (CurrencyPacks[i].ItemId == vcp.ItemId) { CurrencyPacks.RemoveAt(i); break; } } CurrencyPacks.Add(vcp); } if (virtualItem is VirtualGood) { VirtualGood vg = (VirtualGood)virtualItem; if (vg is UpgradeVG) { List<UpgradeVG> upgrades; if (!GoodsUpgrades.TryGetValue (((UpgradeVG) vg).GoodItemId, out upgrades)) { upgrades = new List<UpgradeVG>(); GoodsUpgrades.Add(((UpgradeVG) vg).ItemId, upgrades); } upgrades.Add((UpgradeVG) vg); } if (vg.PurchaseType is PurchaseWithMarket) { PurchasableItems.AddOrUpdate(((PurchaseWithMarket) vg.PurchaseType).MarketItem .ProductId, vg); } for(int i=0; i<Goods.Count(); i++) { if (Goods[i].ItemId == vg.ItemId) { Goods.RemoveAt(i); break; } } Goods.Add(vg); } }
/** * 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); * }*/ }
private string GetGradeString(VirtualItem item) { return(item.HasUpgrades ? item.CurrentLevel == item.MaxLevel ? "(max level)" : string.Format("(level {0})", item.CurrentLevel) : ""); }
public override string GetPlaylist(MyWebRequest req) { var plugpath = GetPluginFromPath(req.Url); var plugin = _plugins.FirstOrDefault(p => plugpath == p.Id); if (plugin == null) { return("Plugin not found"); } var container = plugin.GetContent(req.Parameters) as IPluginContainer; if (container == null) { return("No data"); } if (req.Parameters.ContainsKey("type")) { Playlist pl = Playlist.CreatePlaylist(req.Parameters["type"], req.Headers["host"], Playlist.ContentType.Plugin); var content = container.Children.Where(c => !_device.Filter.Check(plugin.Id).Check(c.Id).Check()); if (req.Parameters.ContainsKey("sort") && container.CanSorted) { switch (req.Parameters["sort"]) { case "title": content = content.OrderBy(item => item.Title).ToList(); break; case "-title": content = content.OrderByDescending(item => item.Title).ToList(); break; case "id": content = content.OrderBy(item => item.Id).ToList(); break; case "-id": content = content.OrderByDescending(item => item.Id).ToList(); break; default: content = container.OrderBy(req.Parameters["sort"]).ToList(); break; } } foreach (var item in content) { if (item is IPluginContainer) { var it = new VirtualContainer { Title = item.Title, Id = item.Id, Parent = item.Parent, Url = !string.IsNullOrEmpty(item.GetUrl(req.Headers["host"])) ? item.GetUrl(req.Headers["host"]) : string.Format("http://{0}/{1}/?id={2}&type=m3u", req.Headers["host"], plugin.Id, item.Id) }; pl.AddLine(it, true, req.Parameters.ContainsKey("transcode") ? req.Parameters["transcode"] : ""); } else { var it = VirtualItem.Copy(item); it.Url = string.Format("http://{0}/{1}/play?id={2}", req.Headers["host"], plugin.Id, item.Id); pl.AddLine(it, append: req.Parameters.ContainsKey("transcode") ? req.Parameters["transcode"] : ""); } } return(pl.ToString()); } return(GetXDocument(container, plugin.Id, true).ToString()); }
/** * 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(); }
/** * 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)); }
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); }
/** * Takes from your user the given amount of the virtual item with the given <code>itemId</code>. * For example, when your user requests a refund you need to TAKE the item he/she is returning. * * @param itemId id of the virtual item to be taken * @param amount amount of the item to be given * @throws VirtualItemNotFoundException */ public static void takeVirtualItem(String itemId, int amount) { VirtualItem item = StoreInfo.getVirtualItem(itemId); item.take(amount); }
/** VIRTUAL ITEMS **/ /** * Retrieves the balance of the virtual item with the given <code>itemId</code>. * * @param itemId id of the virtual item to be fetched. * @return balance of the virtual item with the given <code>itemId</code>. * @throws VirtualItemNotFoundException */ public static int getVirtualItemBalance(String itemId) { VirtualItem item = StoreInfo.getVirtualItem(itemId); return(StorageManager.getVirtualItemStorage(item).getBalance(item)); }
/** * 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)); }
/** * 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)); }
/** * 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);