Skip to content

Commit

Permalink
feat: quest sync through stages
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbeBryssinck committed May 3, 2022
1 parent 46cf2fa commit b4609ed
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
13 changes: 5 additions & 8 deletions Code/client/Games/Skyrim/Forms/TESQuest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@ TESQuest::State TESQuest::getState()

void TESQuest::SetCompleted(bool force)
{
using TSetCompleted = void(TESQuest*, bool);
TP_THIS_FUNCTION(TSetCompleted, void, TESQuest, bool);
POINTER_SKYRIMSE(TSetCompleted, SetCompleted, 24991);

SetCompleted(this, force);
}

void TESQuest::CompleteAllObjectives()
{
using TCompleteAllObjectives = void(TESQuest*);
TP_THIS_FUNCTION(TCompleteAllObjectives, void, TESQuest);
POINTER_SKYRIMSE(TCompleteAllObjectives, CompleteAll, 23231);

CompleteAll(this);
}

Expand All @@ -45,7 +43,7 @@ void TESQuest::SetActive(bool toggle)

bool TESQuest::IsStageDone(uint16_t stageIndex)
{
for (auto* it : stages)
for (Stage* it : stages)
{
if (it->stageIndex == stageIndex)
return it->IsDone();
Expand All @@ -72,11 +70,10 @@ bool TESQuest::Kill()
return false;
}

bool TESQuest::UnkSetRunning(bool &success, bool force)
bool TESQuest::EnsureQuestStarted(bool &success, bool force)
{
using TSetRunning = bool(TESQuest*, bool*, bool);
TP_THIS_FUNCTION(TSetRunning, bool, TESQuest, bool*, bool);
POINTER_SKYRIMSE(TSetRunning, SetRunning, 25003);

return SetRunning(this, &success, force);
}

Expand Down
2 changes: 1 addition & 1 deletion Code/client/Games/Skyrim/Forms/TESQuest.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ struct TESQuest : BGSStoryManagerTreeForm
bool Kill();
State getState();

bool UnkSetRunning(bool &succeded, bool force);
bool EnsureQuestStarted(bool &succeded, bool force);

bool SetStage(uint16_t stage);
void ScriptSetStage(uint16_t stage);
Expand Down
7 changes: 3 additions & 4 deletions Code/client/Services/Generic/QuestService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,8 @@ void QuestService::OnQuestUpdate(const NotifyQuestUpdate& aUpdate) noexcept
{
case NotifyQuestUpdate::Started:
{
if (TESQuest* pQuest = SetQuestStage(formId, 0))
if (TESQuest* pQuest = SetQuestStage(formId, aUpdate.Stage))
{
pQuest->ScriptSetStage(aUpdate.Stage);
pQuest->SetActive(true);
bResult = true;
spdlog::info("Remote quest started: {:X}, stage: {}", formId, aUpdate.Stage);
Expand Down Expand Up @@ -171,15 +170,15 @@ TESQuest* QuestService::SetQuestStage(uint32_t aFormId, uint16_t aStage)
pQuest->scopedStatus = -1;

bool bNeedsRegistration = false;
if (pQuest->UnkSetRunning(bNeedsRegistration, false))
if (pQuest->EnsureQuestStarted(bNeedsRegistration, false))
{
auto* pCallbackMgr = QuestCallbackManager::Get();

if (bNeedsRegistration)
pCallbackMgr->RegisterQuest(aFormId);
else
{
pQuest->SetStage(aStage);
pQuest->ScriptSetStage(aStage);
return pQuest;
}
}
Expand Down

0 comments on commit b4609ed

Please sign in to comment.