QtCraft API C++ classes QML types Handbook

QcExperience Class

A player's experience (decision E-398): a level and the points gathered towards the next one, with the reference game's cost curve (7 + 2 L points per level below 15, 37 + 5 (L - 15) up to 29, then 112 + 9 (L - 30)). More...

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

Public Functions

QcExperience()
QcExperience(int level, int points)
void addLevels(int levels)
int addPoints(qint64 points)
int deathDrop() const
int level() const
int points() const
double progress() const
void setLevel(int level)
bool setPoints(int points)
bool spendLevels(int levels)
qint64 total() const

Static Public Members

const int deathPointsPerLevel
QcExperience fromTotal(qint64 total)
const int maxDeathPoints
const int maxLevel
int mostPoints(int level)
QList<int> orbValues(int points, int maxOrbs)
int pointsForNext(int level)
qint64 totalForLevel(int level)

Detailed Description

The server owns it; clients only show it. Experience comes from orbs (QcExperienceOrbManager) and /xp; the spending side (trading, enchanting, the anvil) takes levels with spendLevels().

Member Function Documentation

[constexpr noexcept default] QcExperience::QcExperience()

Default-constructs an instance of QcExperience.

QcExperience::QcExperience(int level, int points)

A level and points within it, clamped into range.

void QcExperience::addLevels(int levels)

Adds levels (negative ones take away, down to level 0); the share of the way to the next level stays.

int QcExperience::addPoints(qint64 points)

Adds points (negative ones take away, down to nothing); returns the levels gained (negative when lost).

int QcExperience::deathDrop() const

Returns the points dropped as orbs on death: 7 per level, at most 100.

[static] QcExperience QcExperience::fromTotal(qint64 total)

Returns the level and points of total points.

int QcExperience::level() const

Returns the level.

See also setLevel().

[static] int QcExperience::mostPoints(int level)

Returns the most points a player can hold within level (none at maxLevel).

[static] QList<int> QcExperience::orbValues(int points, int maxOrbs)

Returns the values of orbs that points split into, largest first, as the reference game splits them (2477, 1237, 617, 307, 149, 73, 37, 17, 7, 3, 1); at most maxOrbs orbs, the last one takes the rest.

int QcExperience::points() const

Returns the points within the level.

See also setPoints().

[static] int QcExperience::pointsForNext(int level)

Returns the points needed from level to the next level.

double QcExperience::progress() const

Returns the share of the way to the next level, 0..1 (the bar in the HUD).

void QcExperience::setLevel(int level)

Sets the level to level; the share of the way to the next level stays (as with addLevels).

See also level().

bool QcExperience::setPoints(int points)

Sets the points within the current level. Returns false, with no change, when they are negative or reach the next level.

See also points().

bool QcExperience::spendLevels(int levels)

Takes levels when the player has them (a trade, an enchantment). Returns false, with no change, otherwise.

qint64 QcExperience::total() const

Returns all points from level 0 on.

[static] qint64 QcExperience::totalForLevel(int level)

Returns the points from level 0 up to the start of level.

Member Variable Documentation

const int QcExperience::deathPointsPerLevel

On death a player drops this many points per level (the reference's rule).

const int QcExperience::maxDeathPoints

The most points a player drops on death.

const int QcExperience::maxLevel

Highest level; its total points still fit 32 bits easily (about 4.5e8).