#include <entityx/entityx.h>
+#include <forward_list>
#include <string>
#include <vector>
std::string name; /**< the quest's title */
std::string desc; /**< the quest's description */
+
+ using Req = std::pair<std::string, int>;
+ std::forward_list<Req> reqs; /**< the quest's item requirements */
+ std::forward_list<Req> rewards; /**< the quest's rewards */
};
/**
else {
qname = qxml->Attribute("check");
if (qname != nullptr) {
- if (qname != nullptr && qsys->hasQuest(qname) && qsys->finish(qname) == 0) {
+ if (qname != nullptr && qsys->finish(qname) == 0) {
d.index = 9999;
} else {
ui::dialogBox(name.name, "", false, "Finish my quest u nug");
#include <algorithm>
+#include <engine.hpp>
+#include <inventory.hpp>
#include <tokens.hpp>
+std::string& trim(std::string& s)
+{
+ auto start = std::find_if(s.begin(), s.end(),
+ [](char c) { return !isspace(c); }) - s.begin();
+ auto end = std::find_if(s.rbegin(), s.rend(),
+ [](char c) { return !isspace(c); }).base() - s.begin();
+ s = s.substr(start, end - start);
+ return s;
+}
+
void QuestSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
{
(void)en;
int QuestSystem::assign(std::string title, std::string desc, std::string req)
{
+ current.emplace_back(title, desc);
+
+ auto* list = ¤t.back().reqs;
+ std::string reqTitle;
for (auto s : tokens(req, ',')) {
- s.erase(std::remove_if(s.begin(), s.end(),
- [](char c) { return isspace(c); }), s.end());
+ trim(s);
- std::cout << s << '\n';
+ if (s == "Reward") {
+ list = ¤t.back().rewards;
+ } else {
+ if (!reqTitle.empty()) {
+ list->emplace_front(reqTitle, std::stoi(s));
+ reqTitle.clear();
+ } else {
+ reqTitle = s;
+ }
+ }
}
- current.emplace_back(title, desc);
return 0;
}
if (quest == std::end(current))
return -1;
- // TODO requirements
+ for (const auto& r : quest->reqs) {
+ if (!game::engine.getSystem<InventorySystem>()->take(r.first, r.second))
+ return -1;
+ }
+
+ for (const auto& r : quest->rewards)
+ game::engine.getSystem<InventorySystem>()->add(r.first, r.second);
drop(title);
<weather>Sunny</weather>
<link right="!town2.xml"/>
<spawnx>-300</spawnx>
+ <time>8000</time>
<npc name="Sanc" hasDialog="true"/>
<npc name="Bob" hasDialog="true" position="50.0,100.0"/>
<structure type="1" position="300.0,100.0"/>
</World>
<Dialog name="Bob">
- <text id="0" nextid="1" pause="true">
+ <text id="0" nextid="1">
<give name="Dank MayMay" count="10"/>
<content>
Hey there! The name's Bob. Good to see you've finally woken up from your nap by the cliff there... lol
</content>
</text>
- <text id="1" pause="true">
+ <text id="1" pause="true" nextid="2">
<quest assign="Check out m'swag, man!" desc="Go inside Bob's house and check out the stuff he has.">
- Debug, 5
+ Debug, 5,
+ Reward,
+ Dank MayMay, 50
</quest>
<content>
Looks like you've got yourself pretty empty handed... you know, I have a simple solution for that. Come on inside, I have somethin' to show you.
</content>
</text>
+ <text id="2">
+ <quest check="Check out m'swag, man!" />
+ <content>Hooray!</content>
+ </text>
</Dialog>
<Dialog name="Sanc">