C_Container
namespaceavailable in: camelotStatus 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.
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`)endGetContainerNumSlots returns 0 for a bag slot with no bag in it, so the loop
skips the empty ones.
Functions
| function | what it does | status |
|---|---|---|
CalculateTotalNumberOfFreeBagSlots | Returns the number of free slots across the player's bags. · by wowlua(): number | implemented |
ContainerIDToInventoryID | Returns the inventory slot ID the bag is equipped in. · by wowlua(containerID: BagIndex): number? | implemented |
ContainerRefundItemPurchase | Refunds the vendor purchase of the item in a bag slot. · by wowlua(containerIndex: BagIndex, slotIndex: number, isEquipped: boolean) | guessed |
GetBackpackAutosortDisabled | Whether sorting the bags leaves the backpack alone. · by wowlua(): boolean | recorded |
GetBackpackSellJunkDisabled | Whether selling junk leaves the backpack alone. · by wowlua(): boolean | recorded |
GetBagName | Returns the name of a bag. · by wowlua(bagIndex: BagIndex): string | implemented |
GetBagSlotFlag | Whether a flag is set on a bag. · by wowlua(bagIndex: BagIndex, flag: BagSlotFlags): boolean | implemented |
GetBankAutosortDisabled | Whether sorting leaves the bank alone. · by wowlua(): boolean | guessed |
GetContainerFreeSlots | Returns the indices of the empty slots in a bag. · by wowlua(containerIndex: BagIndex): number[]? | guessed |
GetContainerItemCooldown | Returns 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 |
GetContainerItemDurability | Returns the current and maximum durability of the item in a bag slot. · by wowlua(containerIndex: BagIndex, slotIndex: number): (number?, number?) | guessed |
GetContainerItemEquipmentSetInfo | Returns 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 |
GetContainerItemID | Returns the item ID of the item in a bag slot. · by wowlua(containerIndex: BagIndex, slotIndex: number): number? | implemented |
GetContainerItemInfo | Returns information about the item in a bag slot. · by wowlua(containerIndex: BagIndex, slotIndex: number): ContainerItemInfo? | implemented |
GetContainerItemLink | Returns the item link of the item in a bag slot. · by wowlua(containerIndex: BagIndex, slotIndex: number): string | implemented |
GetContainerItemPurchaseCurrency | Returns 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 |
GetContainerItemPurchaseInfo | Returns what was paid for the item in a bag slot, for its refund. · by wowlua(containerIndex: BagIndex, slotIndex: number, isEquipped: boolean): ItemPurchaseInfo? | guessed |
GetContainerItemPurchaseItem | Returns 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 |
GetContainerItemQuestInfo | Returns the quest information of the item in a bag slot. · by wowlua(containerIndex: BagIndex, slotIndex: number): ItemQuestInfo | implemented |
GetContainerNumFreeSlots | Returns the number of free slots and the bagType that an equipped bag or backpack belongs to.(bagIndex: BagIndex): (number, number?) | implemented |
GetContainerNumSlots | Returns the number of slots in a bag. · by wowlua(containerIndex: BagIndex): number | implemented |
GetInsertItemsLeftToRight | Whether new items go into the bags from left to right. · by wowlua(): boolean | guessed |
GetItemCooldown | Returns an item's cooldown: start time, duration and whether it is enabled. · by wowlua(itemID: number): (number?, number?, number?) | implemented |
GetMaxArenaCurrency | Returns the most arena points the player can hold. · by wowlua(): number | guessed |
GetSortBagsRightToLeft | Whether sorting places items into the bags from right to left. · by wowlua(): boolean | guessed |
HasContainerItem | Whether there is an item in a bag slot. · by wowlua(containerIndex: BagIndex, slotIndex: number): boolean | guessed |
IsBattlePayItem | Whether the item in a bag slot was bought from the in-game shop. · by wowlua(containerIndex: BagIndex, slotIndex: number): boolean | guessed |
IsContainerFiltered | Whether a bag is filtered. · by wowlua(containerIndex: BagIndex): boolean | recorded |
PickupContainerItem | Picks 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 |
PlayerHasHearthstone | Returns the item ID of the player's Hearthstone if it is in the bags. · by wowlua(): number? | guessed |
SetBackpackAutosortDisabled | Sets whether sorting the bags leaves the backpack alone. · by wowlua(disable: boolean) | guessed |
SetBackpackSellJunkDisabled | Sets whether selling junk leaves the backpack alone. · by wowlua(disable: boolean) | guessed |
SetBagPortraitTexture | Sets a texture to a bag's icon. · by wowlua(texture: Texture, bagIndex: BagIndex) | guessed |
SetBagSlotFlag | Sets or clears a flag on a bag. · by wowlua(bagIndex: BagIndex, flag: BagSlotFlags, isSet: boolean) | guessed |
SetBankAutosortDisabled | Sets whether sorting leaves the bank alone. · by wowlua(disable: boolean) | guessed |
SetInsertItemsLeftToRight | Sets whether new items go into the bags from left to right. · by wowlua(enable: boolean) | guessed |
SetItemSearch | Sets the text to search the bags' items for. · by wowlua(searchString: string) | implemented |
SetSortBagsRightToLeft | Sets whether sorting places items into the bags from right to left. · by wowlua(enable: boolean) | guessed |
ShowContainerSellCursor | Shows the sell cursor for the item in a bag slot. · by wowlua(containerIndex: BagIndex, slotIndex: number) | guessed |
SocketContainerItem | Opens the socketing window for the item in a bag slot. Returns whether it did. · by wowlua(containerIndex: BagIndex, slotIndex: number): boolean | guessed |
SortAccountBankBags | Sorts the items in the account bank. · by wowlua() | guessed |
SortBags | Sorts the items in the player's bags. · by wowlua() | implemented |
SortBank | Sorts the items in a bank. · by wowlua(bankType: BankType) | guessed |
SortBankBags | Sorts the items in the bank's bags. · by wowlua() | guessed |
SplitContainerItem | Picks up part of the stack in a bag slot onto the cursor. · by wowlua(containerIndex: BagIndex, slotIndex: number, amount: number) | implemented |
UseContainerItem | Uses an item from a container depending on the situation.(containerIndex: BagIndex, slotIndex: number, unitToken: string?, bankType: BankType?, reagentBankOpen: boolean) | implemented |
UseHearthstone | Uses 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
| event | payload | fired by the emulator |
|---|---|---|
BAG_CLOSED | bagID: BagIndex | implemented |
BAG_CONTAINER_UPDATE | no payload | implemented |
BAG_NEW_ITEMS_UPDATED | no payload | implemented |
BAG_OPEN | bagID: number | not implemented |
BAG_OVERFLOW_WITH_FULL_INVENTORY | no payload | not implemented |
BAG_SLOT_FLAGS_UPDATED | slot: number | not implemented |
BAG_UPDATE | bagID: BagIndex | implemented |
BAG_UPDATE_COOLDOWN | no payload | implemented |
BAG_UPDATE_DELAYED | no payload | implemented |
EQUIP_BIND_REFUNDABLE_CONFIRM | slot: number, itemLocation: ItemLocationMixin | not implemented |
EQUIP_BIND_TRADEABLE_CONFIRM | slot: number, itemLocation: ItemLocationMixin | not implemented |
EXPAND_BAG_BAR_CHANGED | expandBagBar: boolean | not implemented |
INVENTORY_SEARCH_UPDATE | no payload | not implemented |
ITEM_LOCKED | bagOrSlotIndex: BagIndex, slotIndex: number? | implemented |
ITEM_LOCK_CHANGED | bagOrSlotIndex: BagIndex, slotIndex: number? | implemented |
ITEM_UNLOCKED | bagOrSlotIndex: BagIndex, slotIndex: number? | implemented |
USE_COMBINED_BAGS_CHANGED | useCombinedBags: boolean | not 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, itemNameItemPurchaseCurrency· iconFileID?, currencyCount, nameItemPurchaseInfo· money, itemCount, refundSeconds, currencyCount, hasEnchantsItemPurchaseItem· iconFileID?, itemCount, hyperlinkItemQuestInfo· 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.
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")endprint 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.