nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
nanommo::Trades Class Reference

#include <trades.h>

Public Member Functions

bool Ask (uint32_t id, uint32_t other)
uint32_t With (uint32_t id) const
 Who the player's trading with, by their id, or 0 for nobody.
const protocol::TradeSide & SideOf (uint32_t id) const
 What the player offers, and whether they're ready, while they trade.
uint32_t RevisionOf (uint32_t id) const
bool Holds (uint32_t id, const protocol::Place &place) const
absl::Status Offer (uint32_t id, const Inventory &bag, const ItemTable &items, const protocol::TradeOffer &offer)
absl::StatusOr< bool > Ready (uint32_t id, bool ready, uint32_t revision)
absl::Status Complete (uint32_t id, Inventory &bag, Inventory &other_bag, const ItemTable &items)
uint32_t End (uint32_t id)
std::set< uint32_t > TakeNews ()

Detailed Description

The trades between the players in one copy of a land, which its World keeps, so that both players are always in it. A player asks another to trade, and the trade opens once the other asks them back. Each side offers stacks from their bag, by their places, and gold, and once both sides are ready, each gets what the other offered.

Nothing a client says is trusted. What's offered is held where it is until the trade's over, each change to an offer takes the trade to its next revision, which a ready has to name, and the trade gives nothing unless each place still has what was offered.

Definition at line 26 of file trades.h.

Member Function Documentation

◆ Ask()

bool nanommo::Trades::Ask ( uint32_t id,
uint32_t other )

The player asks the other to trade, in place of anyone they asked before. If the other asked them first, the trade between them opens, and it returns true. Neither may be trading already.

Definition at line 36 of file trades.cc.

◆ Complete()

absl::Status nanommo::Trades::Complete ( uint32_t id,
Inventory & bag,
Inventory & other_bag,
const ItemTable & items )

Once both sides are ready: each bag gives up what it offered and gets what the other offered, all of it or none, and the trade's over. Each place offered has to have at least as many as it did, of the same item with the same rolls. If one hasn't, a bag hasn't room, or a side hasn't the gold it offered, neither side is ready any more, and the error says why, in words for both players.

Definition at line 122 of file trades.cc.

◆ End()

uint32_t nanommo::Trades::End ( uint32_t id)

Ends the player's trade, if they're in one, their asking, and anyone's asking them. Returns who they were trading with, or 0.

Definition at line 173 of file trades.cc.

◆ Holds()

bool nanommo::Trades::Holds ( uint32_t id,
const protocol::Place & place ) const

Whether the place is one the player offers from, which stays as it is until the trade's over, as the trade takes what was offered from there.

Definition at line 64 of file trades.cc.

◆ Offer()

absl::Status nanommo::Trades::Offer ( uint32_t id,
const Inventory & bag,
const ItemTable & items,
const protocol::TradeOffer & offer )

What the player offers from their bag, in place of what they offered before: copies of the stacks at the offer's places, whole, and gold they have. Neither side is ready any more, as there's something new to look at, and the trade's at its next revision. Or the error says why not, in words for the player.

Definition at line 70 of file trades.cc.

◆ Ready()

absl::StatusOr< bool > nanommo::Trades::Ready ( uint32_t id,
bool ready,
uint32_t revision )

Whether the player's ready to trade what's offered, both ways, at the revision they saw. Returns whether both sides are now, or the error if they aren't trading, or are ready for offers that have changed since.

Definition at line 105 of file trades.cc.

◆ RevisionOf()

uint32_t nanommo::Trades::RevisionOf ( uint32_t id) const

The revision of the player's trade, from 0 as it opens, which each change to either offer takes to the next.

Definition at line 59 of file trades.cc.

◆ SideOf()

const protocol::TradeSide & nanommo::Trades::SideOf ( uint32_t id) const

What the player offers, and whether they're ready, while they trade.

Definition at line 55 of file trades.cc.

◆ TakeNews()

std::set< uint32_t > nanommo::Trades::TakeNews ( )

The players whose trade has opened, changed or ended since the last time, which it hands over.

Definition at line 187 of file trades.cc.

◆ With()

uint32_t nanommo::Trades::With ( uint32_t id) const

Who the player's trading with, by their id, or 0 for nobody.

Definition at line 50 of file trades.cc.


The documentation for this class was generated from the following files: