QtCraft API C++ classes QML types Handbook

QcPlayerFishing Class

Players fishing with a rod (decision E-503; QcItemDefinition::fishing, QcMsg::ThrowItem): the first use casts the rod's bobber, a projectile that floats on water (QcProjectileDefinition::floats); the second reels it in. More...

Header: #include <server/projectiles/QcPlayerFishing.h>

Public Functions

bool rainsAt(QcBlockPos pos) const
void setRainCheck(std::function<bool (QcBlockPos)> rainsAt)
void tick()
bool use(QcServerClient &client)

Static Public Members

const QcFishingLoot *draw(const QcFishingDefinition &rod, QRandomGenerator &random)
const int useCooldownTicks
int waitTicks(const QcFishingDefinition &rod, bool raining, QRandomGenerator &random)

Detailed Description

While the bobber floats on water, a fish bites after a random wait between the rod's minSeconds and maxSeconds (times rainFactor where it rains on the bobber); the bite lasts biteSeconds, the bobber dips and splashes. Reeling in during the bite throws one entry of the rod's loot table, drawn by weight, from the bobber to the player and wears the rod by one; reeling in at any other time catches nothing. The bobber goes when the player reels in, dies, leaves, selects another hotbar slot or item, or is more than the rod's maxDistance from it; it is never saved (QcProjectile::transient), so a chunk that unloads takes it along.

Member Function Documentation

[static] const QcFishingLoot *QcPlayerFishing::draw(const QcFishingDefinition &rod, QRandomGenerator &random)

Returns the loot entry of rod that random draws by weight; nullptr for an empty table.

bool QcPlayerFishing::rainsAt(QcBlockPos pos) const

Returns whether it rains on a bobber in the block pos.

void QcPlayerFishing::setRainCheck(std::function<bool (QcBlockPos)> rainsAt)

Sets rainsAt, which tells where it rains, for the shorter wait; without it the wait never shortens.

void QcPlayerFishing::tick()

One tick of every player's bobber: the wait, the bite, and the bobbers that go, also those nobody fishes with any more (their player left).

bool QcPlayerFishing::use(QcServerClient &client)

The player of client used the use button with the selected item (QcMsg::ThrowItem): casts when the player has no bobber out, else reels in; the arm swings only then. Returns false when the held item does not fish, within useCooldownTicks of the last cast or reel, or when the cast failed.

[static] int QcPlayerFishing::waitTicks(const QcFishingDefinition &rod, bool raining, QRandomGenerator &random)

Returns the ticks of a wait drawn from random for rod, in rain when raining (at least one tick).

Member Variable Documentation

const int QcPlayerFishing::useCooldownTicks

Ticks after a cast or a reel before the rod does anything again (as the throw cooldown).