QcExperienceOrbManager Class
The experience orbs of a world (decision E-398), the table of their kind in the entity register. More...
| Header: | #include <server/items/QcExperienceOrbManager.h> |
Public Types
Public Functions
| bool | add(QcExperienceOrb orb) |
| qsizetype | adopt(const QList<QcExperienceOrb> &orbs, const QcExperienceOrbManager::IdFunction &newId) |
| void | clear() |
| int | drop(int points, const QcVec3 &position, const QcExperienceOrbManager::IdFunction &newId) |
| QList<QcExperienceOrb> & | editableOrbs() |
| qsizetype | limit() const |
| qint64 | mergedCount() const |
| const QList<QcExperienceOrb> & | orbs() const |
| void | setLimit(qsizetype limit) |
| void | tick(const QcBlockAccess &world, const QList<QcPickupPlayer> &players, double dt, const QcExperienceOrbManager::GiveFunction &give) |
| qint64 | totalPoints() const |
Static Public Members
| const double | attractAcceleration |
| const double | attractRange |
| const int | collectIntervalTicks |
| const qsizetype | defaultLimit |
| const double | despawnSeconds |
| const int | maxOrbsPerDrop |
| const int | maxValue |
| const int | mergeIntervalTicks |
| const double | mergeRadius |
| const double | pickupDelay |
| const double | pickupReach |
| const double | size |
Detailed Description
Orbs fall and float like dropped items, fly towards the nearest living player within attractRange, are collected one every collectIntervalTicks per player after a short pickup delay, and go after despawnSeconds in loaded chunks. Only orbs in loaded chunks move and age.
The number of orbs is bounded (QcServerLimits::experienceOrbs): orbs close together merge into one worth their sum every mergeIntervalTicks, and experience dropped while the world is full joins the nearest orb instead of making a new one, so no experience is lost to the bound.
Member Type Documentation
[alias] QcExperienceOrbManager::GiveFunction
Called when the player playerEntityId collects an orb, with its value points.
[alias] QcExperienceOrbManager::IdFunction
Returns a new entity id for an orb.
Member Function Documentation
bool QcExperienceOrbManager::add(QcExperienceOrb orb)
Adds orb as it is (tests, a chunk coming back). Returns false and adds nothing beyond the limit, for an orb without value or in the void.
qsizetype QcExperienceOrbManager::adopt(const QList<QcExperienceOrb> &orbs, const QcExperienceOrbManager::IdFunction &newId)
Adds orbs of a chunk that came back (decision E-374), with new ids from newId. Returns how many were left out beyond the limit (their points join the nearest orb with room).
void QcExperienceOrbManager::clear()
Removes every orb.
int QcExperienceOrbManager::drop(int points, const QcVec3 &position, const QcExperienceOrbManager::IdFunction &newId)
Drops points at position as orbs of the reference's sizes with a small random velocity (a mined ore, a killed creature, a furnace's output, a death). Beyond the limit the points join the nearest orb with room. newId gives the ids of the new orbs. Returns how many orbs appeared.
QList<QcExperienceOrb> &QcExperienceOrbManager::editableOrbs()
Returns the orbs for moving and removing them from outside (pistons push them, chunks unload).
qsizetype QcExperienceOrbManager::limit() const
Returns the bound of the number of orbs.
See also setLimit().
qint64 QcExperienceOrbManager::mergedCount() const
Returns the orbs that merged into others since the start.
const QList<QcExperienceOrb> &QcExperienceOrbManager::orbs() const
Returns the orbs.
void QcExperienceOrbManager::setLimit(qsizetype limit)
Sets the bound of the number of orbs to limit (orbs beyond it stay).
See also limit().
void QcExperienceOrbManager::tick(const QcBlockAccess &world, const QList<QcPickupPlayer> &players, double dt, const QcExperienceOrbManager::GiveFunction &give)
One tick of dt seconds in world: physics and attraction towards players, collecting (give), merging, ageing and despawning.
qint64 QcExperienceOrbManager::totalPoints() const
Returns the points in all orbs (tests and measurements: merging and the bound keep them).
Member Variable Documentation
const double QcExperienceOrbManager::attractAcceleration
Acceleration in m/s² towards a player right next to the orb; it falls off with the square of the distance's share of attractRange (the reference's pull, scaled to this game's gravity).
const double QcExperienceOrbManager::attractRange
Orbs fly towards a living player closer than this, faster the closer he is.
const int QcExperienceOrbManager::collectIntervalTicks
A player collects at most one orb every this many ticks (the reference's two).
const qsizetype QcExperienceOrbManager::defaultLimit
The bound by default (QcServerLimits::experienceOrbs).
const double QcExperienceOrbManager::despawnSeconds
Seconds an orb in a loaded chunk lasts.
const int QcExperienceOrbManager::maxOrbsPerDrop
At most this many orbs from one drop; the last one takes the rest.
const int QcExperienceOrbManager::maxValue
Biggest value of one orb, so a merged orb still fits the protocol and the save comfortably; orbs merge and take overflow only while their sum stays within it.
const double QcExperienceOrbManager::pickupDelay
Seconds before a fresh orb can be collected.
const double QcExperienceOrbManager::pickupReach
Orbs touch a player when they are within the player's box grown by this much.
const double QcExperienceOrbManager::size
Width and height of an orb's box in blocks.