// Start is called before the first frame update void OnEnable() { ClearListings(); player = gameObject.transform.root.gameObject; dataHandler = player.GetComponent <DataHandler>(); backpack = player.GetComponentInChildren <Backpack>(true); playerCash.text = "$" + dataHandler.playerData.cash.ToString(); for (int i = 2; i < backpack.slots.Length; i++) { if (backpack.slots[i].GetComponent <Slot>().isFilled) { GameObject listing = (GameObject)GameObject.Instantiate(Resources.Load("StoreListing"), contentPanel.transform); StoreListing storeListing = listing.GetComponent <StoreListing>(); ItemHandler itemHandler = backpack.slots[i].GetComponent <Slot>().item.gameObject.GetComponent <ItemHandler>(); storeListing.name = itemHandler.itemName; if (itemHandler.type == "Weapon") { storeListing.amount = 1; } else { storeListing.amount = itemHandler.amount; } storeListing.image = itemHandler.gameObject.GetComponent <RawImage>().texture; storeListing.price = itemHandler.value; storeListing.inSlot = i; storeListing.PostListing(); } } }
static InMemoryDatabase() { economyData = new ConcurrentDictionary <string, EconomyData>(); dataLock = new object(); // Create some store items IList <StoreItem> storeItems = new List <StoreItem>(); storeItems.Add(new StoreItem(0, new StoreListingItem(ItemType.Vehicle, "adder"))); storeItems.Add(new StoreItem(0, new StoreListingItem(ItemType.Vehicle, "infernus"))); storeItems.Add(new StoreItem(0, new StoreListingItem(ItemType.Vehicle, "coquette"))); storeItems.Add(new StoreItem(0, new StoreListingItem(ItemType.Weapon, "WEAPON_MG"))); storeItems.Add(new StoreItem(0, new StoreListingItem(ItemType.Drug, "Beer"))); store = new StoreListing(storeItems); }
public static StoreProductJsonData Create(StoreListing item, int id) => new StoreProductJsonData { id = id, storeId = item.StoreIdentifier, price = (float)item.Price, coins = item.Coins, hasBonus = item.HasBonus, bonusType = item.BonusType, bonusValue = item.BonusValue, isPromotion = item.IsPromotion, amountSaved = item.AmountSaved, useSecurities = item.useSecurities, usePlayerCash = item.usePlayerCash, isConsumable = item.isConsumable, bosStoreId = item.StoreIdentifier };
public void BuyItemEvent(uint index, [FromSource] Player player) { if (player == null) { throw new ArgumentNullException(nameof(player)); } string id = PlayerHandler.GetPlayerId(player); EconomyData playerData = this.database.GetEconomyDataForPlayer(id); StoreListing storeListing = this.database.GetStoreListingData(); if (index >= storeListing.Items.Count()) { ErrorHandler.PlayerError(player, $"There is no item in the store for slot {index}"); return; } StoreItem storeItem = storeListing.Items.ElementAt((int)index); if (storeItem.Price > playerData.Money) { ErrorHandler.PlayerError(player, $"You cannot afford {storeItem.Item.DisplayName}"); return; } // Deduct money bool success = this.database.DeductMoneyForPlayer(id, storeItem.Price); if (success == false) { ErrorHandler.PlayerError(player, $"Error with database transaction, please retry purchase."); return; } // Give item this.database.AddItemForPlayer(id, ItemCloningFactory.Clone(storeItem.Item, player)); TriggerClientEvent(player, Events.BuyItemEventClient, true, storeItem.Item.DisplayName); }
public void ViewStoreEvent([FromSource] Player player) { if (player == null) { throw new ArgumentNullException(nameof(player)); } StoreListing data = this.database.GetStoreListingData(); StringBuilder items = new StringBuilder(); for (int i = 0; i < data.Items.Count(); ++i) { items.AppendFormat("[{0}:${1}] {2}", i, data.Items.ElementAt(i).Price, data.Items.ElementAt(i).Item.DisplayName); if (i < data.Items.Count() - 1) { items.Append(", "); } } TriggerClientEvent(player, Events.ViewStoreEventClient, items.ToString()); }
public void ConfirmSale() { selectedListing.SellItem(); selectedListing = null; confirmSale.SetActive(false); }