nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
local_connection.h
Go to the documentation of this file.
1#ifndef NANOMMO_CLIENT_LOCAL_CONNECTION_H_
2#define NANOMMO_CLIENT_LOCAL_CONNECTION_H_
3
4#include <chrono>
5#include <cstdint>
6#include <deque>
7#include <memory>
8#include <optional>
9#include <string>
10#include <vector>
11
12#include "client/link.h"
13#include "content/content.h"
14#include "protocol/nanommo.pb.h"
15#include "protocol/parts.h"
16#include "server/inputs.h"
17#include "server/interest.h"
18#include "server/world.h"
19
20namespace nanommo {
21
22/// A world of the client's own, without a server: the world's library, run
23/// in the client at the server's tick, for one player, in the first land.
24/// Nothing is saved, and there's nobody else.
25class LocalConnection final : public Link {
26 public:
27 LocalConnection(const Content& content, std::string name);
28
29 void Poll() override;
30 void Send(const protocol::Input& input) override;
31 bool connected() const override { return true; }
32 const protocol::World& world() const override { return shown_; }
33 const std::deque<protocol::Chat>& chat() const override { return chat_; }
34 int64_t whole() const override { return parts_.whole(); }
35 const std::optional<protocol::Move>& move() const override { return move_; }
36 const protocol::Inventory& inventory() const override { return inventory_; }
37 const protocol::Quests& quests() const override { return quests_; }
38 const protocol::Guild& guild() const override { return guild_; }
39 const protocol::Trade& trade() const override { return trade_; }
40 const protocol::Duel& duel() const override { return duel_; }
41 std::vector<protocol::Event> TakeEvents() override;
42 std::optional<protocol::GuildInvite> TakeInvite() override;
43
44 private:
45 void Tick();
46 void Show();
47 void Notify(const std::string& text,
48 protocol::Channel channel = protocol::CHANNEL_WORLD);
49 /// A sentence of the world's, as a server sends one.
50 void Notify(const protocol::Message& message,
51 protocol::Channel channel = protocol::CHANNEL_WORLD);
52 void Say(const std::string& name, const std::string& text,
53 protocol::Channel channel = protocol::CHANNEL_WORLD);
54 /// Adds a line to the chat, which keeps the newest.
55 void Add(protocol::Chat line);
56
57 static constexpr uint32_t kYou = 1;
58 static constexpr uint32_t kSeed = 1;
59 static constexpr int kLand = 0;
60
61 std::shared_ptr<const Content> content_;
62 World world_;
63 Inputs inputs_;
64 Cells npc_cells_;
65 std::chrono::steady_clock::time_point next_tick_;
66 int ticks_ = 0;
67 bool in_gate_ = false;
68 Parts parts_;
69 protocol::World shown_;
70 std::deque<protocol::Chat> chat_;
71 std::optional<protocol::Move> move_;
72 protocol::Inventory inventory_;
73 protocol::Quests quests_;
74 protocol::Guild guild_;
75 protocol::Trade trade_;
76 protocol::Duel duel_;
77 std::vector<protocol::Event> events_;
78};
79
80} // namespace nanommo
81
82#endif // NANOMMO_CLIENT_LOCAL_CONNECTION_H_
const std::optional< protocol::Move > & move() const override
Where the world's instance told us to go, once it hands its players over.
int64_t whole() const override
const std::deque< protocol::Chat > & chat() const override
The newest lines said in the world, oldest first.
std::optional< protocol::GuildInvite > TakeInvite() override
The guild that asked us to join since the last time, once.
const protocol::Guild & guild() const override
Our guild, with no name for none.
bool connected() const override
void Send(const protocol::Input &input) override
const protocol::Duel & duel() const override
Our duel, the same.
std::vector< protocol::Event > TakeEvents() override
const protocol::Inventory & inventory() const override
What we carry and wear, as the world last sent it.
const protocol::Quests & quests() const override
const protocol::Trade & trade() const override
Our trade, with nobody in it for none.
const protocol::World & world() const override
void Poll() override
Takes in what's arrived, without waiting.
LocalConnection(const Content &content, std::string name)
Definition chat.cc:9
std::map< Cell, std::vector< uint32_t > > Cells
The ids of what's in each cell.
Definition interest.h:33