QtCraft API C++ classes QML types Handbook

QcClientTrading Class

The trading screen of a villager the server opened for the local player (decision E-414): the villager, its profession, level and experience and its offers (QcMsg::TradeState), and the trades the player asks for. More...

Header: #include <clientcore/session/QcClientTrading.h>
Inherits: QObject

Public Types

Sender

Public Functions

bool affordable(int index, const QList<QcItemStack> &inventory) const
void close()
bool handle(const QcMessage &message)
bool isOpen() const
void setSender(QcClientTrading::Sender sender)
const QcMsg::TradeState &state() const
bool trade(int index, bool repeat)
void usedEntity()

Signals

void changed()
void closed()
void opened()

Detailed Description

Part of QcClientSession; GUI-free.

Member Type Documentation

[alias] QcClientTrading::Sender

Sends a message to the server.

Member Function Documentation

bool QcClientTrading::affordable(int index, const QList<QcItemStack> &inventory) const

Returns whether the inventory slots hold the costs of the offer at index (two costs of one item add up).

[signal] void QcClientTrading::changed()

A new TradeState of the open villager arrived (offers, level or experience).

void QcClientTrading::close()

The player closed the screen. A TradeState still on its way is an answer to a use the player already closed again (the server closed it too): such states are ignored until the player uses a creature again (usedEntity()).

[signal] void QcClientTrading::closed()

The screen closed (by the server or by close()).

bool QcClientTrading::handle(const QcMessage &message)

Takes over message when it is TradeState or CloseTrade. Returns false for other messages. The offers keep the server's order (a trade names its index); the content of the session knows their items.

bool QcClientTrading::isOpen() const

Returns whether a trading screen is open.

[signal] void QcClientTrading::opened()

The server opened the trading screen of a villager.

void QcClientTrading::setSender(QcClientTrading::Sender sender)

Sets the way out to the server to sender (the session's connection).

const QcMsg::TradeState &QcClientTrading::state() const

Returns the villager and its offers as the server last sent them.

bool QcClientTrading::trade(int index, bool repeat)

Asks the server to trade the offer at index once, or as often as possible (repeat). Returns false when no screen is open or there is no such offer.

void QcClientTrading::usedEntity()

The player used a creature: TradeState messages count again (see close()).