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

#include <world.h>

Public Member Functions

 World (uint32_t seed=std::mt19937::default_seed, Terrain terrain=Terrain(), std::shared_ptr< const Content > content=std::make_shared< Content >(), std::shared_ptr< Paths > paths=nullptr)
void Join (uint32_t id, Player player)
void Leave (uint32_t id)
void SetInput (uint32_t id, float x, float z, bool run, bool attack=false)
void Pick (uint32_t id, uint32_t monster, uint32_t player=0)
void SetBehind (uint32_t id, std::chrono::nanoseconds behind)
void Respawn (uint32_t id)
void WalkTo (uint32_t id, Place to)
void UseSkill (uint32_t id, uint32_t skill)
absl::Status Learn (uint32_t id, uint32_t npc, uint32_t skill)
absl::Status TakeQuest (uint32_t id, uint32_t npc, uint32_t quest)
absl::Status TurnIn (uint32_t id, uint32_t npc, uint32_t quest)
absl::Status Enlist (uint32_t id, uint32_t npc)
absl::Status GiveUp (uint32_t id, uint32_t quest)
absl::Status MoveItem (uint32_t id, const protocol::Place &from, const protocol::Place &to, uint32_t count=0)
absl::Status DestroyItem (uint32_t id, const protocol::Place &place)
 Throws away all of what's at the place, unless they offer it in a trade.
absl::Status Craft (uint32_t id, uint32_t recipe)
void StopCrafting (uint32_t id)
 Stops what the player's making, if anything, and they lose nothing.
absl::Status UseItem (uint32_t id, uint32_t slot)
absl::Status AskToTrade (uint32_t id, std::string_view name)
absl::Status OfferToTrade (uint32_t id, const protocol::TradeOffer &offer)
 What the player offers in their trade, as Trades::Offer has it.
absl::StatusOr< uint32_t > ReadyToTrade (uint32_t id, bool ready, uint32_t revision)
void CancelTrade (uint32_t id)
 Calls the player's trade off, for both of them.
protocol::Trade TradeOf (uint32_t id) const
std::set< uint32_t > TakeTradeNews ()
absl::Status AskToDuel (uint32_t id, std::string_view name)
absl::Status AnswerDuel (uint32_t id, bool yes)
absl::Status Yield (uint32_t id)
uint32_t CallOffDuel (uint32_t id)
protocol::Duel DuelOf (uint32_t id) const
std::set< uint32_t > TakeDuelNews ()
void SetGuild (uint32_t id, uint32_t guild)
 The player's guild, by its id, or 0 for none.
void SetWars (const std::vector< War > &wars)
bool Hostile (uint32_t id, uint32_t other) const
std::vector< WarKill > TakeWarKills ()
uint32_t Spawn (Monster monster)
uint32_t Spawn (Npc npc)
 NPCs have ids of their own, apart from the monsters'.
void Step (std::chrono::nanoseconds time)
std::vector< Notice > TakeNotices ()
 The lines for players since the last time, which it hands over.
std::vector< Event > TakeEvents ()
 What's happened since the last time, which it hands over.
const std::map< uint32_t, Player > & players () const
const std::map< uint32_t, Monster > & monsters () const
const std::map< uint32_t, Npc > & npcs () const
const Terrain & terrain () const

Static Public Attributes

static constexpr float kWalkSpeed = nanommo::kWalkSpeed
 As walking.h has them, which the monsters go at too.
static constexpr float kRunSpeed = nanommo::kRunSpeed
static constexpr float kCloseIn = 0.8f
static constexpr std::chrono::seconds kRespawnTime {10}
static constexpr float kAddsAround = 3.0f
 How far from a boss its adds come, in metres.
static constexpr int kEnoughHelp = 5
static constexpr std::chrono::seconds kRisesSoon {30}
 How long before a boss comes back to life its land hears that it will.
static constexpr float kTalkReach = nanommo::kTalkReach
static constexpr float kTradeReach = kTalkReach
 Two players trade within talking reach, as close as they'd stand to talk.

Detailed Description

Definition at line 316 of file world.h.

Constructor & Destructor Documentation

◆ World()

nanommo::World::World ( uint32_t seed = std::mt19937::default_seed,
Terrain terrain = Terrain(),
std::shared_ptr< const Content > content = std::make_shared<Content>(),
std::shared_ptr< Paths > paths = nullptr )
explicit

Players fight with the content's weapons and skills, so in a world without content, nobody can. Content doesn't change as the game runs, so the world's copies of its lands share one. The world's copies of a land share its paths, as they're the same land; without them, the world makes its own.

Definition at line 206 of file world.cc.

Member Function Documentation

◆ AnswerDuel()

absl::Status nanommo::World::AnswerDuel ( uint32_t id,
bool yes )

The player says yes or no to the one who asked them to duel. A yes puts the flag down where the one who asked stands, and starts the countdown.

Definition at line 534 of file world.cc.

◆ AskToDuel()

absl::Status nanommo::World::AskToDuel ( uint32_t id,
std::string_view name )

The player asks the one of that name here, whatever its case, within Duels::kReach, to duel, or says yes to them asking first. Or the error says why not, in words for the player.

Definition at line 493 of file world.cc.

◆ AskToTrade()

absl::Status nanommo::World::AskToTrade ( uint32_t id,
std::string_view name )

The player asks the one of that name here, whatever its case, within kTradeReach, to trade, or says yes to them asking first, which opens the trade. Or the error says why not, in words for the player.

Definition at line 390 of file world.cc.

◆ CallOffDuel()

uint32_t nanommo::World::CallOffDuel ( uint32_t id)

Ends the player's duel, however far it's got, with nobody winning, as when the world hands its players over. Returns who it was with, or 0.

Definition at line 576 of file world.cc.

◆ CancelTrade()

void nanommo::World::CancelTrade ( uint32_t id)

Calls the player's trade off, for both of them.

Definition at line 474 of file world.cc.

◆ Craft()

absl::Status nanommo::World::Craft ( uint32_t id,
uint32_t recipe )

The player starts making the recipe, wherever they are, which takes its seconds, if they're of its level and their bag has all it takes, outside what they offer in a trade, and room for what it makes. Or the error says why not, in words for the player. Moving, a swing or a skill, a blow, a trade or a duel stops it, and they lose nothing.

Definition at line 351 of file world.cc.

◆ DestroyItem()

absl::Status nanommo::World::DestroyItem ( uint32_t id,
const protocol::Place & place )

Throws away all of what's at the place, unless they offer it in a trade.

Definition at line 283 of file world.cc.

◆ DuelOf()

protocol::Duel nanommo::World::DuelOf ( uint32_t id) const

The player's duel, as their client gets it: who with, how far it's got, and its flag, or nobody, once it's over.

Definition at line 578 of file world.cc.

◆ Enlist()

absl::Status nanommo::World::Enlist ( uint32_t id,
uint32_t npc )

The player swears to the faction whose herald the NPC is, in this land, for good, and hears so. Or the error says why not, in words for the player: one who's sworn to a faction stays with it.

Definition at line 835 of file world.cc.

◆ GiveUp()

absl::Status nanommo::World::GiveUp ( uint32_t id,
uint32_t quest )

Gives up a quest the player's on, wherever they are, with what they've killed for it, so that its giver gives it again. A NotFound error says they're not on it.

Definition at line 864 of file world.cc.

◆ Hostile()

bool nanommo::World::Hostile ( uint32_t id,
uint32_t other ) const

Whether the player may hurt the other: their opponent in a duel that's started, or a member of the guild at war with theirs.

Definition at line 624 of file world.cc.

◆ Join()

void nanommo::World::Join ( uint32_t id,
Player player )

Definition at line 215 of file world.cc.

◆ Learn()

absl::Status nanommo::World::Learn ( uint32_t id,
uint32_t npc,
uint32_t skill )

The NPC, a trainer in this land, teaches the player the skill, or the error says why not, in words for the player.

Definition at line 774 of file world.cc.

◆ Leave()

void nanommo::World::Leave ( uint32_t id)

Definition at line 251 of file world.cc.

◆ monsters()

const std::map< uint32_t, Monster > & nanommo::World::monsters ( ) const
inline

Definition at line 514 of file world.h.

◆ MoveItem()

absl::Status nanommo::World::MoveItem ( uint32_t id,
const protocol::Place & from,
const protocol::Place & to,
uint32_t count = 0 )

Moves the player's items around, as Inventory::Move does, wearing them and taking them off, or the error says why not, in words for the player. Nothing goes to or from a place they offer in a trade.

Definition at line 264 of file world.cc.

◆ npcs()

const std::map< uint32_t, Npc > & nanommo::World::npcs ( ) const
inline

Definition at line 515 of file world.h.

◆ OfferToTrade()

absl::Status nanommo::World::OfferToTrade ( uint32_t id,
const protocol::TradeOffer & offer )

What the player offers in their trade, as Trades::Offer has it.

Definition at line 431 of file world.cc.

◆ Pick()

void nanommo::World::Pick ( uint32_t id,
uint32_t monster,
uint32_t player = 0 )

The monster, by its id, that the player's swings and skills go for from now on, or 0 for none. Or a player they may hurt, by their id, in its place: anyone else is no target.

Definition at line 720 of file world.cc.

◆ players()

const std::map< uint32_t, Player > & nanommo::World::players ( ) const
inline

Definition at line 513 of file world.h.

◆ ReadyToTrade()

absl::StatusOr< uint32_t > nanommo::World::ReadyToTrade ( uint32_t id,
bool ready,
uint32_t revision )

Whether the player's ready to trade, at the revision of the trade they saw. Once both are, within kTradeReach, they trade, there and then, and it returns who with, or 0 until then. Or the error says why not.

Definition at line 441 of file world.cc.

◆ Respawn()

void nanommo::World::Respawn ( uint32_t id)

A dead player comes back in the middle of their land, at full health, once their wait is over.

Definition at line 739 of file world.cc.

◆ SetBehind()

void nanommo::World::SetBehind ( uint32_t id,
std::chrono::nanoseconds behind )

The player's client draws everyone else this long ago, so their blows on another player are checked against where that player was then. Inputs believes Inputs::kMostRewind of what a client says, at most.

Definition at line 732 of file world.cc.

◆ SetGuild()

void nanommo::World::SetGuild ( uint32_t id,
uint32_t guild )

The player's guild, by its id, or 0 for none.

Definition at line 609 of file world.cc.

◆ SetInput()

void nanommo::World::SetInput ( uint32_t id,
float x,
float z,
bool run,
bool attack = false )

Definition at line 702 of file world.cc.

◆ SetWars()

void nanommo::World::SetWars ( const std::vector< War > & wars)

The wars between the world's guilds, in place of those before. Members of two guilds at war can hurt each other anywhere.

Definition at line 616 of file world.cc.

◆ Spawn() [1/2]

uint32_t nanommo::World::Spawn ( Monster monster)

Definition at line 685 of file world.cc.

◆ Spawn() [2/2]

uint32_t nanommo::World::Spawn ( Npc npc)

NPCs have ids of their own, apart from the monsters'.

Definition at line 696 of file world.cc.

◆ Step()

void nanommo::World::Step ( std::chrono::nanoseconds time)

Definition at line 940 of file world.cc.

◆ StopCrafting()

void nanommo::World::StopCrafting ( uint32_t id)

Stops what the player's making, if anything, and they lose nothing.

Definition at line 383 of file world.cc.

◆ TakeDuelNews()

std::set< uint32_t > nanommo::World::TakeDuelNews ( )

The players whose duel has been asked for, counted down, started or ended since the last time, which it hands over.

Definition at line 607 of file world.cc.

◆ TakeEvents()

std::vector< Event > nanommo::World::TakeEvents ( )

What's happened since the last time, which it hands over.

Definition at line 1700 of file world.cc.

◆ TakeNotices()

std::vector< Notice > nanommo::World::TakeNotices ( )

The lines for players since the last time, which it hands over.

Definition at line 1691 of file world.cc.

◆ TakeQuest()

absl::Status nanommo::World::TakeQuest ( uint32_t id,
uint32_t npc,
uint32_t quest )

The player takes the quest from the NPC, who gives it, in this land, or the error says why not, in words for the player.

Definition at line 804 of file world.cc.

◆ TakeTradeNews()

std::set< uint32_t > nanommo::World::TakeTradeNews ( )

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

Definition at line 491 of file world.cc.

◆ TakeWarKills()

std::vector< WarKill > nanommo::World::TakeWarKills ( )

The players killed by an enemy at war since the last time, which it hands over.

Definition at line 643 of file world.cc.

◆ terrain()

const Terrain & nanommo::World::terrain ( ) const
inline

Definition at line 516 of file world.h.

◆ TradeOf()

protocol::Trade nanommo::World::TradeOf ( uint32_t id) const

The player's trade, as their client gets it: who with, by name, what each side offers, and its revision, or nobody, once it's over.

Definition at line 480 of file world.cc.

◆ TurnIn()

absl::Status nanommo::World::TurnIn ( uint32_t id,
uint32_t npc,
uint32_t quest )

The player turns the quest in to the NPC, who gave it, once they've killed as many as it asks for, for its experience, and its prizes in their bag, or the error says why not, in words for the player.

Definition at line 875 of file world.cc.

◆ UseItem()

absl::Status nanommo::World::UseItem ( uint32_t id,
uint32_t slot )

The player uses one of what's in the slot of their bag, such as drinks a potion, unless they offer it in a trade, or the error says why not, in words for the player.

Definition at line 300 of file world.cc.

◆ UseSkill()

void nanommo::World::UseSkill ( uint32_t id,
uint32_t skill )

The player uses the skill as soon as they're free, if they know it and it's ready.

Definition at line 767 of file world.cc.

◆ WalkTo()

void nanommo::World::WalkTo ( uint32_t id,
Place to )

The player walks there by themselves, around what's in the way, or as near as the way goes, if they can stand there.

Definition at line 755 of file world.cc.

◆ Yield()

absl::Status nanommo::World::Yield ( uint32_t id)

The player gives their duel up, and the other side wins it, or before it's started, calls it off.

Definition at line 562 of file world.cc.

Member Data Documentation

◆ kAddsAround

float nanommo::World::kAddsAround = 3.0f
staticconstexpr

How far from a boss its adds come, in metres.

Definition at line 332 of file world.h.

◆ kCloseIn

float nanommo::World::kCloseIn = 0.8f
staticconstexpr

A player who swings or uses a skill at the monster they picked, while it's out of reach, runs up to this share of the reach first, so that a monster that steps back is still within it.

Definition at line 325 of file world.h.

◆ kEnoughHelp

int nanommo::World::kEnoughHelp = 5
staticconstexpr

How much of a boss's health a player has to have taken, in percent, for its experience and a roll of its loot when it dies.

Definition at line 336 of file world.h.

◆ kRespawnTime

std::chrono::seconds nanommo::World::kRespawnTime {10}
staticconstexpr

How long the dead wait before they can come back. A monster comes back once it's over, and a player when they ask to.

Definition at line 329 of file world.h.

◆ kRisesSoon

std::chrono::seconds nanommo::World::kRisesSoon {30}
staticconstexpr

How long before a boss comes back to life its land hears that it will.

Definition at line 339 of file world.h.

◆ kRunSpeed

float nanommo::World::kRunSpeed = nanommo::kRunSpeed
staticconstexpr

Definition at line 320 of file world.h.

◆ kTalkReach

float nanommo::World::kTalkReach = nanommo::kTalkReach
staticconstexpr

Definition at line 341 of file world.h.

◆ kTradeReach

float nanommo::World::kTradeReach = kTalkReach
staticconstexpr

Two players trade within talking reach, as close as they'd stand to talk.

Definition at line 344 of file world.h.

◆ kWalkSpeed

float nanommo::World::kWalkSpeed = nanommo::kWalkSpeed
staticconstexpr

As walking.h has them, which the monsters go at too.

Definition at line 319 of file world.h.


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