-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnpc.cpp
More file actions
30 lines (22 loc) · 739 Bytes
/
npc.cpp
File metadata and controls
30 lines (22 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "npc.hpp"
namespace tol {
Npc::Npc(const fs::path& path, const std::shared_ptr<AssetCache> asset_cache, const std::string& name):
Character(path, asset_cache, std::make_shared<Stats>(npc_stats(name)), name, attacks(name)) {}
json Npc::getNpcs() {
std::ifstream ifs("assets/character.json");
json parsed = json::parse(ifs);
return parsed["characters"];
}
json Npc::npc_stats(const std::string& name) const {
json npcs = Npc::getNpcs();
return npcs[name];
}
std::vector<Attack> Npc::attacks(const std::string& name) {
std::vector<Attack> att;
json npcs = Npc::getNpcs();
for (const auto& n: npcs[name]["attacks"]) {
att.push_back(Attack(n["name"], n["damage"]));
}
return att;
}
} // namespace tol