1#ifndef NANOMMO_SERVER_WORLD_H_
2#define NANOMMO_SERVER_WORLD_H_
19#include "absl/status/status.h"
20#include "absl/status/statusor.h"
23#include "protocol/nanommo.pb.h"
45 const items::Weapon*
weapon =
nullptr;
52 std::optional<protocol::Looks>
looks;
94 std::chrono::nanoseconds
cast{0};
136inline constexpr std::chrono::milliseconds
kPushTime{200};
144inline constexpr float kPop = 2.5f;
150inline constexpr std::chrono::milliseconds
kSteady{2000};
187 std::chrono::nanoseconds
rest{0};
201 std::chrono::nanoseconds
cast{0};
256 protocol::Channel
channel = protocol::CHANNEL_WORLD;
353 std::shared_ptr<const Content> content = std::make_shared<Content>(),
354 std::shared_ptr<Paths> paths =
nullptr);
358 void Leave(uint32_t
id);
360 void SetInput(uint32_t
id,
float x,
float z,
bool run,
bool attack =
false);
365 void Pick(uint32_t
id, uint32_t monster, uint32_t player = 0);
370 void SetBehind(uint32_t
id, std::chrono::nanoseconds behind);
382 void UseSkill(uint32_t
id, uint32_t skill);
386 absl::Status
Learn(uint32_t
id, uint32_t npc, uint32_t skill);
390 absl::Status
TakeQuest(uint32_t
id, uint32_t npc, uint32_t quest);
395 absl::Status
TurnIn(uint32_t
id, uint32_t npc, uint32_t quest);
400 absl::Status
Enlist(uint32_t
id, uint32_t npc);
405 absl::Status
GiveUp(uint32_t
id, uint32_t quest);
410 absl::Status
MoveItem(uint32_t
id,
const protocol::Place& from,
411 const protocol::Place& to, uint32_t count = 0);
414 absl::Status
DestroyItem(uint32_t
id,
const protocol::Place& place);
421 absl::Status
Craft(uint32_t
id, uint32_t recipe);
429 absl::Status
UseItem(uint32_t
id, uint32_t slot);
434 absl::Status
AskToTrade(uint32_t
id, std::string_view name);
437 absl::Status
OfferToTrade(uint32_t
id,
const protocol::TradeOffer& offer);
442 absl::StatusOr<uint32_t>
ReadyToTrade(uint32_t
id,
bool ready,
450 protocol::Trade
TradeOf(uint32_t
id)
const;
459 absl::Status
AskToDuel(uint32_t
id, std::string_view name);
463 absl::Status
AnswerDuel(uint32_t
id,
bool yes);
471 absl::Status
Yield(uint32_t
id);
479 protocol::Duel
DuelOf(uint32_t
id)
const;
486 void SetGuild(uint32_t
id, uint32_t guild);
490 void SetWars(
const std::vector<War>& wars);
494 bool Hostile(uint32_t
id, uint32_t other)
const;
505 void Step(std::chrono::nanoseconds time);
513 const std::map<uint32_t, Player>&
players()
const {
return players_; }
514 const std::map<uint32_t, Monster>&
monsters()
const {
return monsters_; }
515 const std::map<uint32_t, Npc>&
npcs()
const {
return npcs_; }
521 void Act(uint32_t
id,
Player& player, std::chrono::nanoseconds time);
522 void Move(
Player& player, std::chrono::nanoseconds time);
525 void Go(
Player& player,
float x,
float z,
bool run,
526 std::chrono::nanoseconds time);
528 void Approach(
Player& player,
float reach, std::chrono::nanoseconds time);
530 void Follow(
Player& player, std::chrono::nanoseconds time);
533 std::optional<Place> Target(
const Player& player,
float reach)
const;
537 Place Seen(
const Player& player, uint32_t other)
const;
538 void Aim(
Player& player,
float reach);
541 skills::Effect EffectOf(
const Player& player,
542 const skills::Skill& skill)
const;
547 const skills::Skill* Usable(
const Player& player, uint32_t
id)
const;
548 void Start(
Player& player,
const skills::Skill& skill);
552 void Land(uint32_t
id,
Player& player,
const skills::Effect& effect,
553 const skills::Blow& blow,
int index,
int blows);
556 void Stride(
Player& player,
const skills::Effect& effect);
558 void Push(
const Player& player,
Monster& monster,
float metres);
560 bool Slide(
Monster& monster, std::chrono::nanoseconds time);
563 static void Throw(
Monster& monster,
float lift);
566 static bool Fly(
Monster& monster, std::chrono::nanoseconds time);
567 void Hurt(uint32_t
id,
Player& player, uint32_t monster_id,
Monster& monster,
573 void Hurt(uint32_t from, uint32_t
id,
Player& player,
int damage);
575 const War* WarBetween(
const Player& player,
const Player& other)
const;
577 void Heal(uint32_t
id,
Player& player,
int health);
580 void Reward(uint32_t
id,
Player& player,
const Monster& monster);
583 void Loot(uint32_t
id,
Player& player,
const Monster& monster);
586 uint32_t Give(
Inventory& bag, uint32_t item, uint32_t count);
590 absl::StatusOr<Inventory> Made(uint32_t
id,
const Player& player,
591 const recipes::Recipe& recipe);
594 void Make(uint32_t
id,
Player& player, std::chrono::nanoseconds time);
596 void Interrupt(uint32_t
id,
Player& player);
599 void Count(uint32_t
id,
Player& player,
const Monster& monster);
600 void Act(
Monster& monster, std::chrono::nanoseconds time);
603 void CallAdds(uint32_t
id, std::size_t phase);
607 void Announce(
const Monster& boss,
610 void Tell(uint32_t player,
Sentence said,
611 protocol::Channel channel = protocol::CHANNEL_WORLD);
615 void Hit(uint32_t
id,
Player& player,
const Monster& monster,
int blow);
618 void LandSkill(
const Monster& monster);
623 void Referee(std::chrono::nanoseconds time);
625 void Lose(uint32_t
id);
628 std::shared_ptr<const Content> content_;
629 std::shared_ptr<Paths> paths_;
630 std::map<uint32_t, Player> players_;
631 std::map<uint32_t, Monster> monsters_;
632 uint32_t next_monster_ = 1;
633 std::map<uint32_t, Npc> npcs_;
634 uint32_t next_npc_ = 1;
635 std::mt19937 random_;
636 std::vector<Notice> notices_;
637 std::vector<Event> events_;
640 std::vector<std::pair<uint32_t, std::size_t>> calls_;
646 std::map<uint32_t, War> wars_;
647 std::vector<WarKill> war_kills_;
649 std::chrono::nanoseconds clock_{0};
const std::map< uint32_t, Player > & players() const
void Step(std::chrono::nanoseconds time)
const std::map< uint32_t, Monster > & monsters() const
const Terrain & terrain() const
protocol::Duel DuelOf(uint32_t id) const
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)
std::vector< Notice > TakeNotices()
The lines for players since the last time, which it hands over.
void SetGuild(uint32_t id, uint32_t guild)
The player's guild, by its id, or 0 for none.
void Join(uint32_t id, Player player)
std::vector< Event > TakeEvents()
What's happened since the last time, which it hands over.
protocol::Trade TradeOf(uint32_t id) const
absl::Status Craft(uint32_t id, uint32_t recipe)
absl::StatusOr< uint32_t > ReadyToTrade(uint32_t id, bool ready, uint32_t revision)
absl::Status AnswerDuel(uint32_t id, bool yes)
static constexpr float kAddsAround
How far from a boss its adds come, in metres.
std::set< uint32_t > TakeTradeNews()
void UseSkill(uint32_t id, uint32_t skill)
void Pick(uint32_t id, uint32_t monster, uint32_t player=0)
static constexpr std::chrono::seconds kRespawnTime
void StopCrafting(uint32_t id)
Stops what the player's making, if anything, and they lose nothing.
std::vector< WarKill > TakeWarKills()
absl::Status Learn(uint32_t id, uint32_t npc, uint32_t skill)
static constexpr int kEnoughHelp
absl::Status TakeQuest(uint32_t id, uint32_t npc, uint32_t quest)
static constexpr std::chrono::seconds kRisesSoon
How long before a boss comes back to life its land hears that it will.
void WalkTo(uint32_t id, Place to)
absl::Status AskToTrade(uint32_t id, std::string_view name)
void Respawn(uint32_t id)
uint32_t Spawn(Monster monster)
absl::Status OfferToTrade(uint32_t id, const protocol::TradeOffer &offer)
What the player offers in their trade, as Trades::Offer has it.
absl::Status MoveItem(uint32_t id, const protocol::Place &from, const protocol::Place &to, uint32_t count=0)
static constexpr float kCloseIn
void SetInput(uint32_t id, float x, float z, bool run, bool attack=false)
absl::Status TurnIn(uint32_t id, uint32_t npc, uint32_t quest)
static constexpr float kTalkReach
absl::Status Enlist(uint32_t id, uint32_t npc)
uint32_t CallOffDuel(uint32_t id)
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.
void SetBehind(uint32_t id, std::chrono::nanoseconds behind)
absl::Status AskToDuel(uint32_t id, std::string_view name)
void SetWars(const std::vector< War > &wars)
absl::Status Yield(uint32_t id)
static constexpr float kTradeReach
Two players trade within talking reach, as close as they'd stand to talk.
std::set< uint32_t > TakeDuelNews()
void CancelTrade(uint32_t id)
Calls the player's trade off, for both of them.
static constexpr float kWalkSpeed
As walking.h has them, which the monsters go at too.
absl::Status UseItem(uint32_t id, uint32_t slot)
bool Hostile(uint32_t id, uint32_t other) const
const std::map< uint32_t, Npc > & npcs() const
static constexpr float kRunSpeed
absl::Status GiveUp(uint32_t id, uint32_t quest)
constexpr float kWalkSpeed
In tiles a second. A tile is a metre, and walking is the walk clip's speed.
void Dress(Model &model, const std::vector< figures::Part > &parts, float metre)
constexpr std::chrono::milliseconds kPushTime
How long a blow's push takes, fast at first and slowing, as a shove does.
constexpr float kRunSpeed
constexpr float kTalkReach
std::vector< uint32_t > WornOf(const Player &player)
int MaxHealthOf(const Player &player)
Part Of(const items::Item &item, uint32_t count)
uint32_t MainHandOf(const Player &player)
constexpr std::chrono::milliseconds kMostInAir
constexpr std::chrono::milliseconds kSteady
int land
By its place in kLands.
uint32_t monster
The monster killed, or that killed or hit the player.
uint32_t monster_id
The monster the player hit, by its id in the world.
uint32_t copy
The copy of the land it happened in, which Copies fills in.
uint32_t level
The level a player's reached.
uint32_t amount
The health a hit took, or that a potion or a skill gave back.
uint32_t item
An item dropped, given for a quest, used or made, and how many.
uint32_t player_id
The player's id in the world, which the clients know them by.
std::chrono::nanoseconds steady
std::chrono::nanoseconds rest
std::chrono::nanoseconds pushed
std::map< uint32_t, std::chrono::nanoseconds > cooldowns
How long until each skill it's used is ready again, by its id.
std::vector< monsters::Skill > skills
std::chrono::nanoseconds swing
std::chrono::nanoseconds cast
float reach
In metres, from its kind's fight.
std::chrono::nanoseconds respawn
std::chrono::nanoseconds hit_time
std::chrono::nanoseconds swing_time
bool boss() const
A monster with phases is a boss.
std::chrono::nanoseconds in_air
uint32_t kind
By its id in the monsters file.
std::map< uint32_t, int > threat
std::vector< monsters::Phase > phases
std::chrono::nanoseconds respawn_time
protocol::Message message
protocol::Channel channel
bool talks
Whether players can talk to it.
uint32_t kind
By its id in the NPCs file.
std::set< uint32_t > teaches
The skills it teaches, by their ids in the skills file.
In metres from the middle of a land.
std::chrono::nanoseconds respawn
While they're dead, how long until they can come back.
const items::Weapon * cast_weapon
std::set< uint32_t > skills
The skills the player knows, by their ids in the skills file.
std::chrono::nanoseconds crafted
int land
Which of the world's lands, by its place in kLands.
uint32_t input_skill
A skill the player asked for, which waits until they're free.
float cast_x
Where they stood as the skill started, which its strides go on from.
std::set< uint32_t > quests_done
The quests they've turned in, which they can't take again.
std::optional< protocol::Looks > looks
std::chrono::nanoseconds cast
float yaw
In radians, around the vertical. Zero faces along z, towards the camera.
std::chrono::nanoseconds chain_left
std::map< uint32_t, std::chrono::nanoseconds > item_cooldowns
std::map< uint32_t, uint32_t > quests
std::map< uint32_t, std::chrono::nanoseconds > cooldowns
How long until each skill they've used is ready again, by its id.
Inventory inventory
What the player carries and wears.
std::chrono::nanoseconds behind
const items::Weapon * weapon
The weapon in the player's main hand, from the content, or nullptr.