public void Add(IShopItem item) { if (ValidateInternalCollection()) { _items.Add(item); } }
public void SetShopItem(int itemIndex, IShopItem item, IShopManager shop) { itemImage.sprite = item.GetItemSprite(); currencyImage.sprite = item.GetCurrencySprite(); nameLabel.text = item.GetName(); costLabel.text = item.GetCost().ToString("n0"); button.onClick.AddListener(delegate { shop.BuyItem(itemIndex); }); }
public void SetItem(IShopItem item, float price) { currentItem = item; currentPrice = price; this.price.text = "£ " + price.ToString("0.00"); name.text = currentItem.Name; icon.sprite = currentItem.Icon; }
/// <summary> /// Construct the order /// </summary> public Order(IShopItem orderedItem, Common.GameLogicTime time) { serialNumber = s_IssueSerialNumber(); orderState = OrderState.kPlaced; placedTime = new Common.GameLogicTime(time.elapsedUnits); orderedShopItem = orderedItem; orderItem = null; }
private void OnItemPurchased(IShopItem shopItem) { if (_item != null) { if (shopItem.ItemId == _item.ItemId) { UpdateButtonView(); } } }
public bool Contains(IShopItem item) { if (ValidateInternalCollection()) { return(_items.Contains(item)); } else { return(false); } }
public void addNewItem(IShopItem item) { try { validator.validate(item); compressor.compress(item); items.Add(item); } catch (Exception e) { Console.WriteLine($"Failed to add an image with message: {e.Message}"); } }
protected virtual void Validate(IShopItem shopItem, IShopItemGroup group) { if (shopItem == null) { throw new NullReferenceException("shopItem should be not null"); } else if (group == null) { throw new NullReferenceException("group should be not null"); } }
public OrderDetail(IShopItem Item, int Quantity) { _record = new OrderDetailRecord() { DetailType = Item.ItemType, ContentId = Item.ContentItem != null ? Item.ContentItem.Id : 0, SKU = Item.SKU, Designation = Item.Designation, Description = Item.Description, UnitPrice = Item.GetUnitPrice(Quantity), Quantity = Quantity }; }
private async Task <string> processOrder(Utxos utxo, ITransaction txinfo, IShopItem mainItem) { var amountOfTokens = (int)((mainItem.Price / (utxo.Value / neblio.FromSatToMainRatio)) * mainItem.Lot); if (amountOfTokens != 0) { try { var meta = new Dictionary <string, string>(); meta.Add("Token Order", "true"); meta.Add("PaymentTxId", utxo.Txid); var sutxs = await NeblioTransactionHelpers.FindUtxoForMintNFT(Address, TokenId, amountOfTokens - 1); if (sutxs.Count != 0) { var sendutxos = new List <string>(); foreach (var s in sutxs) { sendutxos.Add(s.Txid + ":" + s.Index); } var dto = new SendTokenTxData() { Amount = amountOfTokens, Id = TokenId, Metadata = meta, Password = string.Empty, // shop must be unlocked SenderAddress = Address, ReceiverAddress = txinfo.From[0], sendUtxo = sendutxos, NeblUtxo = utxo.Txid, UseRPCPrimarily = false }; var resp = await NeblioTransactionHelpers.SendNTP1TokenAPI(dto, isItMintNFT : true); return(resp); } } catch (Exception ex) { log.Error("Cannot send ordered tokens!", ex); } } return(string.Empty); }
public void ToggleShoppingList() { List <GameObject> itemList = new List <GameObject>(); int i = 0; foreach (GameObject item in shopItemPrefabs) { ShopItemLabel label = Instantiate(shopItemLabelPrefab); IShopItem shopItem = item.GetComponent <IShopItem>(); label.SetShopItem(i++, shopItem, this); itemList.Add(label.gameObject); } hud.ToggleMenu(Menu.Shop, itemList); sound.PlayDrawerClip(); }
public override bool Execute(IServerConnection server, IPlayer p, params string[] args) { string cmd = String.Join(" ", args, 1, args.Length - 1); IShop shop = p.GetCurrentShop(); if (shop == null) { p.Error("R:Shop.NotInside"); return(false); } if (!shop.IsOpen()) { p.Error("R:Shop.Closed", shop.ShopOpensAt, shop.ShopClosesAt); return(false); } GroupCollection groups = CommandMatch(p, cmd); if (groups == null) { p.Error(CommandUsage); return(false); } int amount = Convert.ToInt32(groups["amount"].Value); int itemid = Convert.ToInt32(groups["itemid"].Value); IShopItem shopItem = (from item in shop.ShopItems where item.ItemID == itemid select item).FirstOrDefault(); if (shopItem == null) { p.Error("R:Shop.OutOfStock"); return(false); } if (shopItem.StockAmount < amount) { p.Error("R:Shop.ShortStock", shopItem.StockAmount, shopItem.ItemName); return(false); } int price = Program.Config.ShopHandlers[shopItem.HandlerName].EvaluateBuy(server, p, shopItem, amount); if (price > p.zCoins) { p.Error("R:Shop.OutOfCoins", price); return(false); } return(Program.Config.ShopHandlers[shopItem.HandlerName].ItemBought(server, p, shopItem, amount, price)); }
public void SetItem(IShopItem item, float price, int quantity) { currentItem = item; currentPrice = price; currentQuantity = quantity; if (currentQuantity == 0) { Debug.LogWarning("Quantity is 0 but SetItem() was called."); } this.price.text = "£ " + price.ToString("0.00"); this.quantity.transform.parent.gameObject.SetActive(currentQuantity > 1); this.quantity.text = quantity.ToString(); name.text = currentItem.Name; icon.sprite = currentItem.Icon; }
static public void BuyItem(DigPlayer player, string itemName, int amount = 1) { InventoryItem item = ItemManager.GetItemFromName(itemName); IShopItem shopItem = ItemManager.GetShopItemByName(itemName); if (item != null && shopItem != null) { int totalItemPrice = shopItem.BuyPrice * amount; if (player.digMoney >= totalItemPrice) { player.digMoney -= totalItemPrice; player.Inventory.AddItem(new InventoryItem(item), amount); player.Player.Reply("You bought " + amount + " " + itemName + "!"); } else { if (amount == 1) { player.Player.Reply("You need " + totalItemPrice + " money to buy that item."); } else { player.Player.Reply("You need " + totalItemPrice + " money, " + shopItem.BuyPrice + " each, to buy those items."); } } } else { if (itemName != "") { player.Player.Reply("That item does not exist."); } player.Player.Reply("You can buy these items:"); List <InventoryItem> shopItems = ItemManager.GetBuyableItems(); string temp = ""; foreach (InventoryItem oitem in shopItems) { temp += oitem.Name + (shopItems.Last().Name.Equals(oitem.Name) ? "" : ", "); } player.Player.Send(temp); } }
public void UseItem(Player player, IShopItem item) { switch (item.Name) { case "Elixer": player.FleeChance += 20; break; case "Potion of Health": Heal(player); break; case "Power Up": player.Weapon.Damage += 15; break; } player._inventory.Remove(item); }
public IShopItem[] RandomGenerateShopItems(ShopTypes shopType, int minItems, int maxItems) { IItem[] itemPool = GenerateItemPool(shopType); int totalItemsGenerated = rand.Next(minItems, maxItems); IDictionary <IItem, int> itemsAndStockQuantity = GetItemAndStockOfItemPool(itemPool, totalItemsGenerated); IShopItem[] shopItems = new IShopItem[itemsAndStockQuantity.Count]; int counter = 0; foreach (KeyValuePair <IItem, int> itemAndStockQuantity in itemsAndStockQuantity) { int itemPrice = GetItemPrice(itemAndStockQuantity.Key); shopItems[counter] = new ShopItem(itemAndStockQuantity.Key, itemPrice, itemAndStockQuantity.Value); ++counter; } return(shopItems); }
static public void SellItem(DigPlayer player, string itemName, int amount = 1) { InventoryItem item = ItemManager.GetItemFromName(itemName); if (item != null) { IShopItem shopItem = ItemManager.GetShopItemByName(itemName); if (shopItem != null) { int itemSellPrice = shopItem.SellPrice; if (player.Inventory.Contains(item) && player.Inventory.GetItemCount(item) >= amount) { if (player.Inventory.RemoveItem(item, amount)) { player.digMoney += itemSellPrice * amount; string prefix = (amount > 1 ? "Items" : "Item"); player.Player.Reply(prefix + " sold! You received " + (itemSellPrice * amount) + " money."); } else { player.Player.Reply("Internal error, try doing that again."); } } else { player.Player.Reply("You do not have enough of that item."); } } else { player.Player.Reply("You can't sell that item."); } } else { if (itemName != "") { player.Player.Reply("That item does not exist."); } } }
private void OnCoinUpgradePurchased(IShopItem data) { if (Data != null && (Data.Id == data.ItemId)) { GameObject prefab = GameServices.Instance.ResourceService.Prefabs.GetPrefab("coins"); GameObject instance = Instantiate <GameObject>(prefab); instance.transform.SetParent(buyButton.transform, false); instance.transform.localPosition = new Vector3(0, 0, -1); instance.transform.localScale = Vector3.one; instance.transform.localRotation = Quaternion.Euler(-90, 0, 0); Destroy(instance, 3); instance.transform.SetParent(GetParentViewTransform(), true); instance.GetComponent <ParticleSystem>().Play(); Services.SoundService.PlayOneShot(SoundName.buyGenerator); print("coins created..."); if (Data.IsOneTime) { Parent?.Remove(this); } } }
void BuyShip(IShopItem selectedShip) { //Player has enough money? if (!PlayerHasEnoughFundsToBuy(selectedShip.GetPrice())) { PlayErrorSound(); alertMessageManager.SetAlertMessage(notEnoughMoneyMsg); return; } PlayerStatusData playerData = PlayerStatusService.LoadPlayerStatus(); //Player already bought this ship? if (!((IShopCharacterSkin)selectedShip).AlreadyHasShip().Invoke()) { playerScore -= selectedShip.GetPrice(); scoreAmountTxt.text = playerScore.ToString(); selectedShip.BuyItem().Invoke(); PlayerStatusService.SavePlayerStatus(playerData); ((IShopCharacterSkin)selectedShip).DisableCharacterButton(); //Clear data //remove from selectedobjectmanager selectedObjectManager.RemoveSelectedObject(); selectedShip = null; PlayBuySound(); } else { PlayErrorSound(); alertMessageManager.SetAlertMessage(subAlreadyBoughtMsg); } }
public void CreateShopTest() { const ShopTypes ShopType = ShopTypes.ItemShop; IShopItem[] shopItems = new IShopItem[] { new ShopItem( new Armor(ArmorTypes.CopperArmor, 10), 10, 15), new ShopItem( new Weapon(WeaponTypes.Axe, 15), 18, 10), new ShopItem( new Weapon(WeaponTypes.Sword, 12), 6, 3), }; ShopCreator creator = new ShopCreator(); IShop shop = creator.CreateShop(ShopType, shopItems); Assert.AreEqual(ShopType, shop.ShopType); Assert.AreEqual(shopItems.Length, shop.ShopInventory.ShopItems.Length); foreach (IShopItem item in shop.ShopInventory.ShopItems) { IShopItem localShopItem = Array.Find(shopItems, x => x.Item.ItemType == item.Item.ItemType && x.Price == item.Price && x.StockQuantity == item.StockQuantity); Assert.IsNotNull(localShopItem); Assert.IsTrue(item.Item is Armor || item.Item is Weapon); if (item.Item is Armor shopArmor && localShopItem.Item is Armor localArmor) { Assert.AreEqual(localArmor.ArmorType, shopArmor.ArmorType); Assert.AreEqual(localArmor.DefenseValue, shopArmor.DefenseValue); }
private void OnShopItemPurchased(IShopItem shopItem) { if (_item != null && _item.ItemId == shopItem.ItemId) { if (BuyButton != null) { GameObject prefab = GameServices.Instance.ResourceService.Prefabs.GetPrefab("coins"); GameObject instance = Instantiate <GameObject>(prefab); instance.transform.SetParent(BuyButton.transform, false); instance.transform.localPosition = new Vector3(0, 0, -1); instance.transform.localScale = Vector3.one; instance.transform.localRotation = Quaternion.Euler(-90, 0, 0); Destroy(instance, 3); instance.transform.SetParent(FindObjectOfType <IAPScreen>().transform, true); instance.GetComponent <ParticleSystem>().Play(); FindObjectOfType <SoundManager>()?.PlayOneShot("buyGenerator"); print("coins created..."); //if(fxBuyEffect != null ) { // fxBuyEffect.SetActive(true); //} } } }
public static void OnShopItemPurchased(IShopItem shopItem) => ShopItemPurchased?.Invoke(shopItem);
public abstract bool ItemSold(Interfaces.IServerConnection server, Interfaces.IPlayer buyer, IShopItem shopItem, int amount, int price);
private void UpdateShop() { if (listSize <= 0) { upgradeName.text = "No upgrade available"; description.text = "You bought every upgrades we had, there's nothing left here !"; return; } currentItem = robot.ShopList[currentIndex]; upgradeName.text = currentItem.Name; description.text = new StringBuilder(currentItem.Description).Append("\nPrice : ").Append(currentItem.Price).Append(" cogs").ToString(); coinAmount.text = robot.Coins.ToString(); }
public override int EvaluateSell(Interfaces.IServerConnection server, Interfaces.IPlayer seller, IShopItem item, int amount) { throw new NotImplementedException(); }
public abstract int EvaluateBuy(IServerConnection server, IPlayer buyer, IShopItem item, int amount);
public abstract int EvaluateSell(IServerConnection server, IPlayer seller, IShopItem item, int amount);
public bool Remove(IShopItem item) { return((ValidateInternalCollection()) ? _items.Remove(item) : false); }
public void Add(IShopItem shopItem, IShopItemGroup group) { Validate(shopItem, group); group.Add(shopItem); }
public void AddItem(IShopItem model) => _inventory.Add(model);
public override int EvaluateBuy(Interfaces.IServerConnection server, Interfaces.IPlayer buyer, IShopItem item, int amount) { //TODO: SKillcheck return(item.SellPrice * amount); }