/// <summary> /// Loads inventure for character /// </summary> /// <param name="character">Character</param> public void LoadInventoryForCharacter(Character character) { DBManager.SelectQuery("SELECT * FROM items WHERE owner_id=@id", (MySql.Data.MySqlClient.MySqlDataReader reader) => { character.AddItemToInventory(ItemsFactory.CreateItemForId(reader.GetInt32(1), reader.GetInt32(2)), false, false); }).AddValue("@id", character.ID).Execute(); }
/// <summary> /// Buys an item from the shop for character /// </summary> /// <param name="character">Buyer</param> /// <param name="itemId">Id of the item</param> /// <param name="count">How many to buy</param> public void BuyItem(Character character, int itemId, int count = 1) { if (DoesSellItem(itemId) && storeCheckPoint.IsCharacterInsideCheckpoint(character)) { int sellPrice = GetItemSellPrice(itemId) * count; if (character.money >= sellPrice) { Item item = ItemsFactory.CreateItemForId(itemId, count); bool ret = character.AddItemToInventory(item, true, true); if (ret) { character.SetMoney(character.money - sellPrice); character.SendNotification("Item purchased!"); character.PlayFrontendSound("PURCHASE", "HUD_LIQUOR_STORE_SOUNDSET"); character.TriggerEvent("EVENT_UPDATE_SELL_ITEM_COUNT", itemId, character.GetAmountOfItems(itemId)); } else { character.SendErrorNotification("Your inventory is full!"); } } else { character.SendNotification("You don't have enough money!"); character.PlayFrontendSound("ERROR", "HUD_LIQUOR_STORE_SOUNDSET"); } } }
public Item CreateItemForId(int id) { return(ItemsFactory.CreateItemForId(id)); }