nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
quests.cc
Go to the documentation of this file.
1#include "content/quests.h"
2
3#include <cstdint>
4#include <map>
5#include <string_view>
6
7#include "absl/strings/str_cat.h"
8#include "content/checks.h"
9#include "content/text.h"
10
11namespace nanommo {
12
13absl::StatusOr<std::map<uint32_t, quests::Quest>> ParseQuests(
14 std::string_view text) {
15 quests::Quests file;
16 const absl::Status parsed = ParseText(text, file);
17 if (!parsed.ok()) {
18 return parsed;
19 }
20 absl::StatusOr<std::map<uint32_t, quests::Quest>> by_id = ById(file.quests());
21 if (!by_id.ok()) {
22 return by_id.status();
23 }
24 // Zero is what protobuf gives a field we leave out, so each of these
25 // would be a quest nobody could take, or finish.
26 for (const auto& [id, quest] : *by_id) {
27 if (quest.giver() == 0) {
28 return absl::InvalidArgumentError(
29 absl::StrCat("the ", quest.name(), " has no giver"));
30 }
31 if (quest.kill().count() == 0) {
32 return absl::InvalidArgumentError(
33 absl::StrCat("the ", quest.name(), " asks for no kills"));
34 }
35 for (const quests::Prize& prize : quest.prizes()) {
36 if (prize.count() == 0) {
37 return absl::InvalidArgumentError(absl::StrCat(
38 "the ", quest.name(), " gives none of item ", prize.item()));
39 }
40 }
41 }
42 return by_id;
43}
44
45} // namespace nanommo
Definition chat.cc:9
absl::StatusOr< std::map< uint32_t, quests::Quest > > ParseQuests(std::string_view text)
Definition quests.cc:13
absl::StatusOr< std::map< uint32_t, Entry > > ById(const google::protobuf::RepeatedPtrField< Entry > &entries)
Definition checks.h:19
absl::Status ParseText(std::string_view text, google::protobuf::Message &message)
Definition text.cc:32