nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
test_content.h
Go to the documentation of this file.
1#ifndef NANOMMO_SERVER_TEST_CONTENT_H_
2#define NANOMMO_SERVER_TEST_CONTENT_H_
3
4#include <cstdint>
5#include <map>
6#include <memory>
7#include <utility>
8
9#include "content/content.h"
10#include "content/items.h"
11#include "content/monsters.h"
12#include "content/quests.h"
13#include "content/skills.h"
14
16
17// The tests' own content, so that the game's can change.
18
19inline ItemTable Sword() {
20 return *ParseItems(R"pb(
21 starting { item: 1 }
22 items {
23 id: 1
24 weapon { reach: 1.6 swing_ms: 2000 hit_ms: 900 damage: 15 }
25 equip { slot: SLOT_MAIN_HAND }
26 }
27 )pb");
29
30inline SkillTable Kick() {
31 return *ParseSkills(R"pb(
32 skills {
33 id: 1
34 name: "Kick"
35 level: 2
36 cooldown_ms: 6000
37 effect { cast_ms: 1000 hit_ms: 500 reach: 1.4 damage: 10 push: 3 }
38 }
39 )pb");
40}
41
42// What a player might carry: what stacks, what's worn, and what rolls.
43inline ItemTable Gear() {
44 return *ParseItems(R"pb(
45 starting { item: 1 }
46 starting { item: 2 count: 3 }
47 items {
48 id: 1
49 name: "Sword"
50 weapon { reach: 1.6 swing_ms: 2000 hit_ms: 900 damage: 15 }
51 equip { slot: SLOT_MAIN_HAND }
52 }
53 items {
54 id: 2
55 name: "Potion"
56 stack: 10
57 use { heal: 40 cooldown_ms: 10000 }
58 }
59 items { id: 3 name: "Bone" stack: 50 }
60 items {
61 id: 4
62 name: "Cap"
63 equip {
64 slot: SLOT_HEAD
65 modifiers { stat: STAT_ARMOUR amount: 2 }
66 modifiers { stat: STAT_HEALTH amount: 10 }
67 }
68 }
69 items {
70 id: 5
71 name: "Blade"
72 weapon { reach: 1.6 swing_ms: 2000 hit_ms: 900 damage: 20 }
73 equip {
74 slot: SLOT_MAIN_HAND
75 modifiers { stat: STAT_DAMAGE amount: 1 }
76 }
77 rolls { stat: STAT_DAMAGE min: 2 max: 4 }
78 }
79 )pb");
80}
81
82/// Content with these items, skills, monsters and quests, and nothing else,
83/// for a World.
84// The swing on Space, by its id in every test's skills.
85inline constexpr uint32_t kStrike = 100;
86
87// Every world has a swing on Space, a skill with the weapon's reach, damage
88// and timing, as the game's does.
89inline SkillTable WithStrike(SkillTable skills) {
90 skills::Skill strike;
91 strike.set_id(kStrike);
92 strike.set_name("Strike");
93 strike.set_level(1);
94 strike.mutable_effect()->set_weapon(true);
95 skills.by_id[kStrike] = strike;
96 skills.starting.insert(kStrike);
97 skills.attack = kStrike;
98 return skills;
99}
100
101inline std::shared_ptr<const Content> With(
102 ItemTable items, SkillTable skills = {}, MonsterTable monsters = {},
103 std::map<uint32_t, quests::Quest> quests = {}) {
104 return std::make_shared<const Content>(
105 Content{.items = std::move(items),
106 .monsters = std::move(monsters),
107 .quests = std::move(quests),
108 .skills = WithStrike(std::move(skills))});
109}
110
111/// The first kind of NPC asks for three of the first kind of monster, for
112/// experience and two of the second item.
113inline std::map<uint32_t, quests::Quest> Bones() {
114 return *ParseQuests(R"pb(
115 quests {
116 id: 1
117 name: "Bones"
118 giver: 1
119 kill { monster: 1 count: 3 }
120 experience: 100
121 prizes { item: 2 count: 2 }
122 }
123 )pb");
124}
125
126inline monsters::Kind Skeleton() {
127 return ParseMonsters(R"pb(
128 kinds {
129 id: 1
130 name: "Skeleton"
131 level: 1
132 max_health: 50
133 experience: 50
134 fight {
135 damage: 5
136 swing_ms: 900
137 hit_ms: 650
138 reach: 1.2
139 sight: 3
140 leash: 4
141 wander: 3
142 }
143 }
144 )pb")
145 ->kinds.at(1);
146}
147
148} // namespace nanommo::testing
149
150#endif // NANOMMO_SERVER_TEST_CONTENT_H_
monsters::Kind Skeleton()
constexpr uint32_t kStrike
ItemTable Gear()
std::shared_ptr< const Content > With(ItemTable items, SkillTable skills={}, MonsterTable monsters={}, std::map< uint32_t, quests::Quest > quests={})
SkillTable WithStrike(SkillTable skills)
std::map< uint32_t, quests::Quest > Bones()
SkillTable Kick()
ItemTable Sword()
absl::StatusOr< std::map< uint32_t, quests::Quest > > ParseQuests(std::string_view text)
Definition quests.cc:13
absl::StatusOr< ItemTable > ParseItems(std::string_view text)
Definition items.cc:61
absl::StatusOr< MonsterTable > ParseMonsters(std::string_view text)
Definition monsters.cc:103
absl::StatusOr< SkillTable > ParseSkills(std::string_view text)
Definition skills.cc:15
The items in the items file, by id.
Definition items.h:18
std::set< uint32_t > starting
Definition skills.h:18
uint32_t attack
Definition skills.h:19
std::map< uint32_t, skills::Skill > by_id
Definition skills.h:17