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

#include <inventory.h>

Public Member Functions

 Inventory ()=default
 Inventory (protocol::Inventory items)
const protocol::Inventory & items () const
uint32_t revision () const
uint32_t gold () const
const items::Stack * At (const protocol::Place &place) const
 What's at the place, or nullptr when it's empty, or isn't a place.
uint32_t Add (const ItemTable &table, const items::Stack &stack)
uint32_t AddGold (uint32_t amount)
 Adds the gold, up to kMostGold, and returns how much didn't fit.
bool Wear (const ItemTable &table, const items::Stack &stack)
void Number (const ItemTable &table)
absl::Status Move (const ItemTable &table, const protocol::Place &from, const protocol::Place &to, uint32_t count=0)
absl::Status TakeOne (const protocol::Place &place)
 Takes one off the stack at the place, as using one does.
absl::Status Take (const protocol::Place &place, uint32_t count)
absl::Status TakeGold (uint32_t amount)
 Takes the gold away, or the error says there isn't that much.
absl::Status Destroy (const protocol::Place &place)
 Throws away all of what's at the place.

Static Public Attributes

static constexpr uint32_t kBagSlots = nanommo::kBagSlots
static constexpr uint32_t kMostGold = 1'000'000'000

Detailed Description

What a player carries, in a bag of kBagSlots, and wears, an item in each slot, kept as the message that's saved and sent. Each change takes it to its next revision. Items the table doesn't have, such as one taken out of the content, stay where they are, so that nothing is lost by a mistake in the file, but they can't be worn, used or stacked.

Definition at line 24 of file inventory.h.

Constructor & Destructor Documentation

◆ Inventory() [1/2]

nanommo::Inventory::Inventory ( )
default

◆ Inventory() [2/2]

nanommo::Inventory::Inventory ( protocol::Inventory items)
inlineexplicit

Definition at line 33 of file inventory.h.

Member Function Documentation

◆ Add()

uint32_t nanommo::Inventory::Add ( const ItemTable & table,
const items::Stack & stack )

Into the bag: onto stacks of the item that have room, then into empty slots, from the first. Returns how many didn't fit.

Definition at line 121 of file inventory.cc.

◆ AddGold()

uint32_t nanommo::Inventory::AddGold ( uint32_t amount)

Adds the gold, up to kMostGold, and returns how much didn't fit.

Definition at line 170 of file inventory.cc.

◆ At()

const items::Stack * nanommo::Inventory::At ( const protocol::Place & place) const

What's at the place, or nullptr when it's empty, or isn't a place.

Definition at line 90 of file inventory.cc.

◆ Destroy()

absl::Status nanommo::Inventory::Destroy ( const protocol::Place & place)

Throws away all of what's at the place.

Definition at line 289 of file inventory.cc.

◆ gold()

uint32_t nanommo::Inventory::gold ( ) const
inline

Definition at line 37 of file inventory.h.

◆ items()

const protocol::Inventory & nanommo::Inventory::items ( ) const
inline

Definition at line 35 of file inventory.h.

◆ Move()

absl::Status nanommo::Inventory::Move ( const ItemTable & table,
const protocol::Place & from,
const protocol::Place & to,
uint32_t count = 0 )

Moves count of what's at from to to, or all of it given zero: into an empty place, onto a stack of the same item, as many as it has room for, or swapping with what's there. What's worn has to be worn in its slot. Or the error says why not, in words for the player.

Definition at line 193 of file inventory.cc.

◆ Number()

void nanommo::Inventory::Number ( const ItemTable & table)

Gives each item that doesn't stack and has no serial, such as the kit's or one saved before serials, a NewSerial, and moves to the next revision if it gave any, so that they're saved.

Definition at line 155 of file inventory.cc.

◆ revision()

uint32_t nanommo::Inventory::revision ( ) const
inline

Definition at line 36 of file inventory.h.

◆ Take()

absl::Status nanommo::Inventory::Take ( const protocol::Place & place,
uint32_t count )

Takes count off the stack at the place, as trading some does, or the error says there aren't that many there.

Definition at line 263 of file inventory.cc.

◆ TakeGold()

absl::Status nanommo::Inventory::TakeGold ( uint32_t amount)

Takes the gold away, or the error says there isn't that much.

Definition at line 278 of file inventory.cc.

◆ TakeOne()

absl::Status nanommo::Inventory::TakeOne ( const protocol::Place & place)

Takes one off the stack at the place, as using one does.

Definition at line 249 of file inventory.cc.

◆ Wear()

bool nanommo::Inventory::Wear ( const ItemTable & table,
const items::Stack & stack )

Wears it, if it's worn and its slot is free, and returns whether it did, as for a new player's kit.

Definition at line 180 of file inventory.cc.

Member Data Documentation

◆ kBagSlots

uint32_t nanommo::Inventory::kBagSlots = nanommo::kBagSlots
staticconstexpr

Definition at line 26 of file inventory.h.

◆ kMostGold

uint32_t nanommo::Inventory::kMostGold = 1'000'000'000
staticconstexpr

The most gold a player carries: a billion, so that adding any two amounts of it never goes past what a uint32_t holds.

Definition at line 30 of file inventory.h.


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