QtCraft API C++ classes QML types Handbook

QcInventory Class

Player inventory: hotbar slots 0..8 followed by the main storage. More...

Header: #include <common/gameplay/QcInventory.h>

Public Functions

int add(const QcItemStack &adding, const QcContentRegistry &content)
int add(QcItemId item, int count, const QcContentRegistry &content)
const QList<QcItemStack> &allSlots() const
int ammunitionSlot(const QcContentRegistry &content, const QcLauncherDefinition &launcher) const
int countOf(QcItemId item) const
void move(int from, int to, const QcContentRegistry &content)
int removeFromSlot(int index, int count)
bool removeItems(QcItemId item, int count)
int selectedHotbarSlot() const
const QcItemStack &selectedStack() const
void setSelectedHotbarSlot(int slot)
void setSlot(int index, const QcItemStack &stack)
const QcItemStack &slot(int index) const

Static Public Members

const int hotbarSize
bool isAmmunition(const QcItemDefinition &item, const QcLauncherDefinition &launcher)
bool isValidSlot(int index)
const int slotCount

Detailed Description

Pure data; the server owns the authoritative copy and sends it to the client.

Member Function Documentation

int QcInventory::add(const QcItemStack &adding, const QcContentRegistry &content)

Adds the items of adding with their damage and data, filling stacks they stack with first (QcItemStack::stacksWith), then empty slots (hotbar first), with the stack sizes of content. Returns the number of items that did not fit.

int QcInventory::add(QcItemId item, int count, const QcContentRegistry &content)

Returns the same for count plain items (no damage, no data).

const QList<QcItemStack> &QcInventory::allSlots() const

Returns every slot in order.

int QcInventory::ammunitionSlot(const QcContentRegistry &content, const QcLauncherDefinition &launcher) const

Returns the first slot holding ammunition of content that launcher takes (decisions E-425, E-427): an item with a projectile kind (QcContentRegistry::finish clears unknown ones; the client gets the cleared names) by the launcher's ammunition list; -1 without one.

int QcInventory::countOf(QcItemId item) const

Returns the number of item in all slots. Stacks with contents (a filled backpack) never count and are never removed by item: paying or crafting with one would lose what it holds (decision E-832).

[static] bool QcInventory::isAmmunition(const QcItemDefinition &item, const QcLauncherDefinition &launcher)

Returns whether launcher takes item as ammunition: an item with a projectile kind that its ammunition list names (by name or tag); without a list every such item but those thrown by hand.

[static] bool QcInventory::isValidSlot(int index)

Returns whether index is a slot (0 to slotCount - 1).

void QcInventory::move(int from, int to, const QcContentRegistry &content)

Moves the stack in from onto to: merges equal items up to the stack limit of content, else swaps.

int QcInventory::removeFromSlot(int index, int count)

Removes up to count items from slot index; returns how many were removed.

bool QcInventory::removeItems(QcItemId item, int count)

Removes count items of item across all stacks without contents. Returns false, with no change, if there are fewer.

int QcInventory::selectedHotbarSlot() const

Returns the selected hotbar slot.

See also setSelectedHotbarSlot().

const QcItemStack &QcInventory::selectedStack() const

Returns the stack in the selected hotbar slot.

void QcInventory::setSelectedHotbarSlot(int slot)

Selects the hotbar slot slot, clamped to 0..hotbarSize - 1.

See also selectedHotbarSlot().

void QcInventory::setSlot(int index, const QcItemStack &stack)

Puts stack into slot index (0 to slotCount - 1).

See also slot().

const QcItemStack &QcInventory::slot(int index) const

Returns the stack in slot index (0 to slotCount - 1).

See also setSlot().

Member Variable Documentation

const int QcInventory::hotbarSize

Slots of the hotbar.

const int QcInventory::slotCount

Slots in all, the hotbar included.