v0.13.8

C_Container

namespaceavailable in: camelot

Status in wowlua

47 functions: 17 implemented, 3 recorded, 27 guessed. 17 events, 9 of them fired by the emulator on its own.

wowlua test keeps a model of the player's bags: how many slots each bag has and which item is in each slot, with its count and whether it is bound or locked. The functions that read the bags (GetContainerNumSlots, GetContainerNumFreeSlots, GetContainerFreeSlots, GetContainerItemInfo, GetContainerItemID, GetContainerItemLink, HasContainerItem, CalculateTotalNumberOfFreeBagSlots) answer from that model. The ones that change the bags (PickupContainerItem, SplitContainerItem, SortBags, UseContainerItem) update it and fire the events the client fires.

A camelot test that doesn't name a world profile starts with the fresh character recorded from the client. Its backpack has 20 slots and holds Tough Jerky and a Hearthstone. The keyring (bag -1) is always there, with 32 empty slots. There are no equipped bags. mock.setBag(bag, { slots, items }) or a world profile's bags fills a bag, and mock.setBag(bag, nil) takes it away. A missing bag has 0 slots, and GetContainerNumFreeSlots returns 0, nil for it.

The name, link, icon and quality of an item come from its item data: what the test gave mock.defineItem. For an item the test doesn't define, the emulator uses the data of your WoW installation when you run wowlua test --game-data, else what wowlua recorded from the client for that item, if anything.

The setters for the bag settings (sorting direction, insert order, autosort, slot flags) accept their argument but don't keep it, so the getters keep returning the same fixed answer.

NUM_BAG_SLOTS and NUM_TOTAL_EQUIPPED_BAG_SLOTS come from Blizzard's UI code. The emulator defines them even when the manifest doesn't set test.blizzard-ui: on camelot they are 4 and 5, as in the client. On a flavor whose numbers wowlua hasn't recorded, they are nil without Blizzard's UI. The examples on these pages loop from Enum.BagIndex.Backpack to Enum.BagIndex.ReagentBag, which works either way.

Using it

A /bags command that prints the free slots of each bag the player carries, then the total.

src/bags.wowluawowlua
import slash from "wowlua:slash"import print from "wowlua:log" -- /bags: the free slots of each bag the player carries, then the total.@slash("/bags")local function listBags()    for bag = Enum.BagIndex.Backpack, Enum.BagIndex.ReagentBag do        local slots = C_Container.GetContainerNumSlots(bag)        if slots > 0 then            local free = C_Container.GetContainerNumFreeSlots(bag)            print(`bag {bag}: {free} of {slots} free`)        end    end    print(`{C_Container.CalculateTotalNumberOfFreeBagSlots()} slots free`)end

GetContainerNumSlots returns 0 for a bag slot with no bag in it, so the loop skips the empty ones.

Functions

functionwhat it doesstatus
CalculateTotalNumberOfFreeBagSlotsReturns the number of free slots across the player's bags. · by wowlua
(): number
implemented
ContainerIDToInventoryIDReturns the inventory slot ID the bag is equipped in. · by wowlua
(containerID: BagIndex): number?
implemented
ContainerRefundItemPurchaseRefunds the vendor purchase of the item in a bag slot. · by wowlua
(containerIndex: BagIndex, slotIndex: number, isEquipped: boolean)
guessed
GetBackpackAutosortDisabledWhether sorting the bags leaves the backpack alone. · by wowlua
(): boolean
recorded
GetBackpackSellJunkDisabledWhether selling junk leaves the backpack alone. · by wowlua
(): boolean
recorded
GetBagNameReturns the name of a bag. · by wowlua
(bagIndex: BagIndex): string
implemented
GetBagSlotFlagWhether a flag is set on a bag. · by wowlua
(bagIndex: BagIndex, flag: BagSlotFlags): boolean
implemented
GetBankAutosortDisabledWhether sorting leaves the bank alone. · by wowlua
(): boolean
guessed
GetContainerFreeSlotsReturns the indices of the empty slots in a bag. · by wowlua
(containerIndex: BagIndex): number[]?
guessed
GetContainerItemCooldownReturns the cooldown of the item in a bag slot: start time, duration and whether it is enabled. · by wowlua
(containerIndex: BagIndex, slotIndex: number): (number, number, number)
implemented
GetContainerItemDurabilityReturns the current and maximum durability of the item in a bag slot. · by wowlua
(containerIndex: BagIndex, slotIndex: number): (number?, number?)
guessed
GetContainerItemEquipmentSetInfoReturns whether the item in a bag slot is in an equipment set, and the names of its sets. · by wowlua
(containerIndex: BagIndex, slotIndex: number): (boolean, string)
guessed
GetContainerItemIDReturns the item ID of the item in a bag slot. · by wowlua
(containerIndex: BagIndex, slotIndex: number): number?
implemented
GetContainerItemInfoReturns information about the item in a bag slot. · by wowlua
(containerIndex: BagIndex, slotIndex: number): ContainerItemInfo?
implemented
GetContainerItemLinkReturns the item link of the item in a bag slot. · by wowlua
(containerIndex: BagIndex, slotIndex: number): string
implemented
GetContainerItemPurchaseCurrencyReturns a currency paid for the item in a bag slot, for its refund. · by wowlua
(containerIndex: BagIndex, slotIndex: number, itemIndex: number, isEquipped: boolean): ItemPurchaseCurrency?
guessed
GetContainerItemPurchaseInfoReturns what was paid for the item in a bag slot, for its refund. · by wowlua
(containerIndex: BagIndex, slotIndex: number, isEquipped: boolean): ItemPurchaseInfo?
guessed
GetContainerItemPurchaseItemReturns an item paid for the item in a bag slot, for its refund. · by wowlua
(containerIndex: BagIndex, slotIndex: number, itemIndex: number, isEquipped: boolean): ItemPurchaseItem?
guessed
GetContainerItemQuestInfoReturns the quest information of the item in a bag slot. · by wowlua
(containerIndex: BagIndex, slotIndex: number): ItemQuestInfo
implemented
GetContainerNumFreeSlotsReturns the number of free slots and the bagType that an equipped bag or backpack belongs to.
(bagIndex: BagIndex): (number, number?)
implemented
GetContainerNumSlotsReturns the number of slots in a bag. · by wowlua
(containerIndex: BagIndex): number
implemented
GetInsertItemsLeftToRightWhether new items go into the bags from left to right. · by wowlua
(): boolean
guessed
GetItemCooldownReturns an item's cooldown: start time, duration and whether it is enabled. · by wowlua
(itemID: number): (number?, number?, number?)
implemented
GetMaxArenaCurrencyReturns the most arena points the player can hold. · by wowlua
(): number
guessed
GetSortBagsRightToLeftWhether sorting places items into the bags from right to left. · by wowlua
(): boolean
guessed
HasContainerItemWhether there is an item in a bag slot. · by wowlua
(containerIndex: BagIndex, slotIndex: number): boolean
guessed
IsBattlePayItemWhether the item in a bag slot was bought from the in-game shop. · by wowlua
(containerIndex: BagIndex, slotIndex: number): boolean
guessed
IsContainerFilteredWhether a bag is filtered. · by wowlua
(containerIndex: BagIndex): boolean
recorded
PickupContainerItemPicks up the item in a bag slot onto the cursor, or puts the cursor's item into the slot. · by wowlua
(containerIndex: BagIndex, slotIndex: number)
implemented
PlayerHasHearthstoneReturns the item ID of the player's Hearthstone if it is in the bags. · by wowlua
(): number?
guessed
SetBackpackAutosortDisabledSets whether sorting the bags leaves the backpack alone. · by wowlua
(disable: boolean)
guessed
SetBackpackSellJunkDisabledSets whether selling junk leaves the backpack alone. · by wowlua
(disable: boolean)
guessed
SetBagPortraitTextureSets a texture to a bag's icon. · by wowlua
(texture: Texture, bagIndex: BagIndex)
guessed
SetBagSlotFlagSets or clears a flag on a bag. · by wowlua
(bagIndex: BagIndex, flag: BagSlotFlags, isSet: boolean)
guessed
SetBankAutosortDisabledSets whether sorting leaves the bank alone. · by wowlua
(disable: boolean)
guessed
SetInsertItemsLeftToRightSets whether new items go into the bags from left to right. · by wowlua
(enable: boolean)
guessed
SetItemSearchSets the text to search the bags' items for. · by wowlua
(searchString: string)
implemented
SetSortBagsRightToLeftSets whether sorting places items into the bags from right to left. · by wowlua
(enable: boolean)
guessed
ShowContainerSellCursorShows the sell cursor for the item in a bag slot. · by wowlua
(containerIndex: BagIndex, slotIndex: number)
guessed
SocketContainerItemOpens the socketing window for the item in a bag slot. Returns whether it did. · by wowlua
(containerIndex: BagIndex, slotIndex: number): boolean
guessed
SortAccountBankBagsSorts the items in the account bank. · by wowlua
()
guessed
SortBagsSorts the items in the player's bags. · by wowlua
()
implemented
SortBankSorts the items in a bank. · by wowlua
(bankType: BankType)
guessed
SortBankBagsSorts the items in the bank's bags. · by wowlua
()
guessed
SplitContainerItemPicks up part of the stack in a bag slot onto the cursor. · by wowlua
(containerIndex: BagIndex, slotIndex: number, amount: number)
implemented
UseContainerItemUses an item from a container depending on the situation.
(containerIndex: BagIndex, slotIndex: number, unitToken: string?, bankType: BankType?, reagentBankOpen: boolean)
implemented
UseHearthstoneUses the Hearthstone in the player's bags. Returns whether there was one. · by wowlua
(): boolean
guessed

"by wowlua": no one documents this function, so wowlua wrote the description from its name, signature and behaviour.

Events

eventpayloadfired by the emulator
BAG_CLOSEDbagID: BagIndeximplemented
BAG_CONTAINER_UPDATEno payloadimplemented
BAG_NEW_ITEMS_UPDATEDno payloadimplemented
BAG_OPENbagID: numbernot implemented
BAG_OVERFLOW_WITH_FULL_INVENTORYno payloadnot implemented
BAG_SLOT_FLAGS_UPDATEDslot: numbernot implemented
BAG_UPDATEbagID: BagIndeximplemented
BAG_UPDATE_COOLDOWNno payloadimplemented
BAG_UPDATE_DELAYEDno payloadimplemented
EQUIP_BIND_REFUNDABLE_CONFIRMslot: number, itemLocation: ItemLocationMixinnot implemented
EQUIP_BIND_TRADEABLE_CONFIRMslot: number, itemLocation: ItemLocationMixinnot implemented
EXPAND_BAG_BAR_CHANGEDexpandBagBar: booleannot implemented
INVENTORY_SEARCH_UPDATEno payloadnot implemented
ITEM_LOCKEDbagOrSlotIndex: BagIndex, slotIndex: number?implemented
ITEM_LOCK_CHANGEDbagOrSlotIndex: BagIndex, slotIndex: number?implemented
ITEM_UNLOCKEDbagOrSlotIndex: BagIndex, slotIndex: number?implemented
USE_COMBINED_BAGS_CHANGEDuseCombinedBags: booleannot implemented

An event the emulator doesn't fire on its own can still be fired from a test: mock.fireEvent("BAG_OPEN").

Structures

  • ContainerItemInfo · iconFileID, stackCount, isLocked, quality?, isReadable, hasLoot, hyperlink, isFiltered, hasNoValue, itemID, isBound, itemName
  • ItemPurchaseCurrency · iconFileID?, currencyCount, name
  • ItemPurchaseInfo · money, itemCount, refundSeconds, currencyCount, hasEnchants
  • ItemPurchaseItem · iconFileID?, itemCount, hyperlink
  • ItemQuestInfo · isQuestItem, questID?, isActive

Testing

Set up the bags the test needs with mock.setBag. It replaces the whole bag, including the default backpack. An item is an item ID, or a table such as { id = 2589, count = 20 } that can also set link, bound and locked.

tests/bags.test.wowluawowlua
import test, expect from "wowlua:test"import * as mock from "wowlua:mock" @test("/bags counts the free slots of each bag")local function countsFreeSlots()    mock.defineItem(2589, { name = "Linen Cloth", quality = 1 })    mock.setBag(0, { slots = 16, items = { [1] = 2589, [2] = 2589 } })    mock.setBag(1, { slots = 10, items = { [4] = { id = 2589, count = 20 } } })    mock.slash("/bags")    local shown = table.concat(mock.printed(), "\n")    expect(shown).toContain("bag 0: 14 of 16 free")    expect(shown).toContain("bag 1: 9 of 10 free")    expect(shown).toContain("23 slots free")end

print from wowlua:log puts the addon's name in front of each line, so the test checks for the text with toContain.

sources

Signatures, events and structures: Blizzard's API documentation (Blizzard_APIDocumentationGenerated) (Container system, camelot 1.60.1). Descriptions: warcraft.wiki.gg's API pages, by its contributors, CC BY-SA 4.0 ↗; written by wowlua where no documentation describes the entry.