-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquest.cpp
More file actions
73 lines (58 loc) · 2.2 KB
/
quest.cpp
File metadata and controls
73 lines (58 loc) · 2.2 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "quest.hpp"
namespace tol {
Quest::Quest(std::string title, std::string description, std::function<bool(PlayState& play_state)> condition_):
title_(std::move(title)), description_(std::move(description)), condition(std::move(condition_)) {}
void Quest::check_condition(PlayState& play_state, Info& info) {
if (completed()) {
return;
}
if (condition(play_state)) {
completed_ = true;
info.display_info(fmt::format("Completed Quest: {}", title()), std::chrono::seconds(10));
}
}
QuestStack::QuestStack(Info& info_): selected(std::make_optional(0)), info(info_) {
quests.push_back(Quest("Gather resources!", "You are hungry. Find something to eat.", [](auto play_state) {
return !play_state.player().inventory().empty();
}));
quests.push_back(
Quest("Find the lost item.", "Detlef has lost something in the woods. Find it for him.", [](auto play_state) {
auto& map = play_state.map();
auto& npc = map.getNpc("Detlef de Loost");
auto pair = map.collectible_by_name("tools");
if (pair) {
auto& [id, collectible] = *pair;
return collectible.collides_with(npc.bounds());
}
return false;
}));
quests.push_back(Quest("Get a baguette.", "Find a baguette to stab your last opponent.", [](auto play_state) {
const auto& items = play_state.player().inventory().items();
return std::any_of(items.cbegin(), items.cend(), [](const auto& item) { return item.second.name() == "baguette"; });
}));
}
void QuestStack::select(size_t index) {
if (quests.size() > index) {
selected = index;
const auto& quest = quests[index];
info.display_info(fmt::format("Active Quest: {}", quest.title()), std::chrono::seconds(5));
}
}
[[nodiscard]] int QuestStack::getSelected() const {
return selected.value_or(-1);
}
void QuestStack::check(PlayState& play_state) {
if (selected) {
quests.at(static_cast<size_t>(*selected)).check_condition(play_state, info);
}
}
bool QuestStack::completed(size_t index) const {
return quests[index].completed();
}
void QuestStack::setCompleted(size_t index) const {
quests[index].setCompleted();
}
[[nodiscard]] size_t QuestStack::count() const {
return quests.size();
}
} // namespace tol