Skip to content

Commit 0f066bc

Browse files
author
LocalIdentity
committed
Import Quests from character ingame
Added the logic to import quest rewards from your character in game The quest rewards in the API are just a list of strings for the given rewards so we have to guess and match them to a quest We loop through all the quests and see if the stat or options match 1 or more lines in the API list. If a match is made we remove those quest rewards from the API so that we don't enable multiple quests from 1 quest reward (e.g. +30 spirit is the reward from 2 different quests) We also only rebuild the mod list if the config option is not already set from a previous import or manual change.
1 parent ee41284 commit 0f066bc

1 file changed

Lines changed: 78 additions & 1 deletion

File tree

src/Classes/ImportTab.lua

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,82 @@ function ImportTabClass:DownloadItems()
583583
end)
584584
end
585585

586+
function ImportTabClass:ImportQuestRewardConfig(questStats)
587+
local configTab = self.build.configTab
588+
local statLines = {}
589+
for _, stat in ipairs(questStats) do
590+
t_insert(statLines, escapeGGGString(stat):lower())
591+
end
592+
593+
local function splitLine(text)
594+
local out = {}
595+
for line in text:gmatch("[^\r\n]+") do
596+
line = line:gsub("^%s+", ""):lower()
597+
t_insert(out, line)
598+
end
599+
return out
600+
end
601+
602+
-- Ensure all required lines exist, then remove them so they can't match again
603+
local function matchQuest(requiredLines)
604+
local indices = {}
605+
for _, needed in ipairs(requiredLines) do
606+
local found
607+
for idx, line in ipairs(statLines) do
608+
if line == needed then
609+
found = idx
610+
break
611+
end
612+
end
613+
if not found then
614+
return false
615+
end
616+
t_insert(indices, found)
617+
end
618+
table.sort(indices, function(a, b) return a > b end)
619+
for _, idx in ipairs(indices) do
620+
t_remove(statLines, idx)
621+
end
622+
return true
623+
end
624+
625+
local updated = false
626+
for _, quest in ipairs(data.questRewards) do
627+
if #statLines == 0 then
628+
break
629+
end
630+
if quest.useConfig == true then
631+
local var = "quest" .. quest.Description .. quest.Area .. quest.Info
632+
if quest.Stat then
633+
local matches = matchQuest(splitLine(quest.Stat))
634+
if configTab.input[var] ~= matches then
635+
configTab.input[var] = matches
636+
updated = true
637+
end
638+
elseif quest.Options then
639+
local selected = configTab.defaultState[var] or "None"
640+
for _, option in ipairs(quest.Options) do
641+
if matchQuest(splitLine(option)) then
642+
selected = option
643+
break
644+
end
645+
end
646+
if configTab.input[var] ~= selected then
647+
configTab.input[var] = selected
648+
updated = true
649+
end
650+
end
651+
end
652+
end
653+
654+
if updated then
655+
configTab:BuildModList()
656+
configTab:UpdateControls()
657+
configTab.modFlag = true
658+
self.build.buildFlag = true
659+
end
660+
end
661+
586662
function ImportTabClass:ImportPassiveTreeAndJewels(charData)
587663
local charPassiveData = charData.passives
588664
self.charImportStatus = colorCodes.POSITIVE.."Passive tree and jewels successfully imported."
@@ -639,6 +715,7 @@ function ImportTabClass:ImportPassiveTreeAndJewels(charData)
639715
end
640716

641717
self.build.spec:AddUndoState()
718+
self:ImportQuestRewardConfig(charPassiveData.quest_stats)
642719
self.build.characterLevel = charData.level
643720
self.build.characterLevelAutoMode = false
644721
self.build.configTab:UpdateLevel()
@@ -1138,4 +1215,4 @@ function UrlDecode(url)
11381215
url = url:gsub("+", " ")
11391216
url = url:gsub("%%(%x%x)", HexToChar)
11401217
return url
1141-
end
1218+
end

0 commit comments

Comments
 (0)