Working on quest system
This commit is contained in:
1 parent
aaae368a07
commit
e7ae148ead
22 files changed
+357
-103
No files matched your search
@@ -20,6 +20,7 @@ namespace ZL {
|
||||
std::unordered_map<int, sol::protected_function> npcBumpsPlayerCallbacks;
|
||||
std::unordered_map<std::string, int>* globalInts = nullptr;
|
||||
std::unordered_map<std::string, float>* globalFloats = nullptr;
|
||||
Quest::QuestJournal* questJournal = nullptr;
|
||||
sol::protected_function locationEnterCallback;
|
||||
sol::protected_function locationExitCallback;
|
||||
sol::protected_function darklandsEnterCallback;
|
||||
@@ -505,6 +506,68 @@ namespace ZL {
|
||||
this_impl->npcBumpsPlayerCallbacks[index] = onNpcBumpsPlayer.as<sol::protected_function>();
|
||||
});
|
||||
|
||||
// quest_unlock(quest_id)
|
||||
api.set_function("quest_unlock",
|
||||
[this_impl = impl.get()](const std::string& questId) -> bool {
|
||||
if (!this_impl->questJournal) {
|
||||
std::cerr << "[script] quest_unlock: QuestJournal not set\n";
|
||||
return false;
|
||||
}
|
||||
return this_impl->questJournal->unlockQuest(questId);
|
||||
});
|
||||
|
||||
// quest_complete(quest_id)
|
||||
api.set_function("quest_complete",
|
||||
[this_impl = impl.get()](const std::string& questId) -> bool {
|
||||
if (!this_impl->questJournal) {
|
||||
std::cerr << "[script] quest_complete: QuestJournal not set\n";
|
||||
return false;
|
||||
}
|
||||
return this_impl->questJournal->completeQuest(questId);
|
||||
});
|
||||
|
||||
// quest_fail(quest_id)
|
||||
api.set_function("quest_fail",
|
||||
[this_impl = impl.get()](const std::string& questId) -> bool {
|
||||
if (!this_impl->questJournal) {
|
||||
std::cerr << "[script] quest_fail: QuestJournal not set\n";
|
||||
return false;
|
||||
}
|
||||
return this_impl->questJournal->failQuest(questId);
|
||||
});
|
||||
|
||||
// quest_set_objective_completed(quest_id, objective_id [, completed])
|
||||
api.set_function("quest_set_objective_completed",
|
||||
[this_impl = impl.get()](const std::string& questId, const std::string& objId, sol::object completed) -> bool {
|
||||
if (!this_impl->questJournal) {
|
||||
std::cerr << "[script] quest_set_objective_completed: QuestJournal not set\n";
|
||||
return false;
|
||||
}
|
||||
const bool val = completed.is<bool>() ? completed.as<bool>() : true;
|
||||
return this_impl->questJournal->setObjectiveCompleted(questId, objId, val);
|
||||
});
|
||||
|
||||
// quest_set_objective_visible(quest_id, objective_id [, visible])
|
||||
api.set_function("quest_set_objective_visible",
|
||||
[this_impl = impl.get()](const std::string& questId, const std::string& objId, sol::object visible) -> bool {
|
||||
if (!this_impl->questJournal) {
|
||||
std::cerr << "[script] quest_set_objective_visible: QuestJournal not set\n";
|
||||
return false;
|
||||
}
|
||||
const bool val = visible.is<bool>() ? visible.as<bool>() : true;
|
||||
return this_impl->questJournal->setObjectiveVisible(questId, objId, val);
|
||||
});
|
||||
|
||||
// quest_set_active_objective(quest_id, objective_index)
|
||||
api.set_function("quest_set_active_objective",
|
||||
[this_impl = impl.get()](const std::string& questId, int index) -> bool {
|
||||
if (!this_impl->questJournal) {
|
||||
std::cerr << "[script] quest_set_active_objective: QuestJournal not set\n";
|
||||
return false;
|
||||
}
|
||||
return this_impl->questJournal->setActiveObjective(questId, index);
|
||||
});
|
||||
|
||||
lua.script_file(scriptPath);
|
||||
}
|
||||
|
||||
@@ -624,6 +687,10 @@ namespace ZL {
|
||||
if (impl) impl->globalFloats = store;
|
||||
}
|
||||
|
||||
void ScriptEngine::setQuestJournal(Quest::QuestJournal* journal) {
|
||||
if (impl) impl->questJournal = journal;
|
||||
}
|
||||
|
||||
void ScriptEngine::callLocationEnterCallback() {
|
||||
if (!impl || !impl->locationEnterCallback.valid()) return;
|
||||
auto result = impl->locationEnterCallback();
|
||||
|
||||
Reference in new issue
Block a user