Module:Quest
Documentation for this module may be created at Module:Quest/doc
local p = {}
local utils = require("Module:Utils")
local data = mw.loadJsonData("Module:Data/quest.json")
function p.createInfobox(frame)
local tempName = frame.args.name
local name = ""
if tempName == nil or tempName == "" then tempName = mw.title.getCurrentTitle().subpageText end
-- check if title contains additional "tags" such as "The Bloodworks (quest)" and removes it
if string.match(tempName,"%(quest%)") then
local i, _ = string.find(tempName," %(quest%)")
name = string.sub(tempName,1,i-1)
-- move title from soft reference to main reference, immutable.
else
name = tempName
end
-- end additions, Squatch
local obj = data[name]
local rewards = ""
if obj.rewards ~= nil then
if obj.rewards.guaranteedRewards ~= nil then
for k, v in ipairs(obj.rewards.guaranteedRewards) do
rewards = rewards .. frame:expandTemplate{title = 'Icon', args = {v.name, v.amount > 1 and v.amount or ""}} .. "<br>"
end
end
if obj.rewards.lootRewards ~= nil then
for k, v in ipairs(obj.rewards.lootRewards) do
if v.type == "Inventory" then
for k2, v2 in ipairs(v.items) do
local amount = ""
if type(v2.amount) == "table" then
amount = v2.amount[1]
else
amount = v2.amount
end
rewards = rewards .. frame:expandTemplate{title = 'Icon', args = {v2.name, amount > 1 and amount or ""}} .. "<br>"
end
end
end
end
if obj.rewards.fauxRewards ~= nil then
for k, v in ipairs(obj.rewards.fauxRewards) do
rewards = rewards .. v.name .. "<br>"
end
end
end
local str = {
name = name,
type = obj.type,
subtype = obj.subtype,
jobType = obj.jobType,
questGiver = obj.questGiver,
repeatable = (obj.type == "Side Story" and tostring(obj.repeatable) or ''),
rewards = rewards,
previous = frame.args.previous ~= nil and frame.args.previous or obj.previous,
next = frame.args.next ~= nil and frame.args.next or obj.next
}
return frame:expandTemplate{title = 'Infobox quest', args = str}
end
function p.getDescription(frame)
local tempName = frame.args.name
local name = ""
if tempName == nil or tempName == "" then tempName = mw.title.getCurrentTitle().subpageText end
-- check if title contains additional "tags" such as "The Bloodworks (quest)" and removes it
if string.match(tempName,"%(quest%)") then
local i, _ = string.find(tempName," %(quest%)")
name = string.sub(tempName,1,i-1)
-- move title from soft reference to main reference, immutable.
else
name = tempName
end
-- end additions, Squatch
local obj = data[name]
local str = ""
if obj.startDescription ~= "" then
str = str .. "=== Start ===\n"
str = str .. obj.startDescription .. "\n"
end
if obj.activeDescription ~= "" then
str = str .. "=== Active ===\n"
str = str .. obj.activeDescription .. "\n"
end
if obj.successDescription ~= "" then
str = str .. "=== Clear ===\n"
str = str .. obj.successDescription .. "\n"
end
str = str:sub(1, -2)
return str
end
function p.getPrerequisite(frame)
local tempName = frame.args.name
local name = ""
if tempName == nil or tempName == "" then tempName = mw.title.getCurrentTitle().subpageText end
-- check if title contains additional "tags" such as "The Bloodworks (quest)" and removes it
if string.match(tempName,"%(quest%)") then
local i, _ = string.find(tempName," %(quest%)")
name = string.sub(tempName,1,i-1)
-- move title from soft reference to main reference, immutable.
else
name = tempName
end
-- end additions, Squatch
local obj = data[name]
local str = ""
if utils.length(obj.prerequisite) == 1 then
str = "Clear [[" .. obj.prerequisite[1] .. "]]."
else
for k, v in ipairs(obj.prerequisite) do
str = str .. "* Clear [[" .. v .. "]]\n"
end
str = str:sub(1, -2)
end
if str == "" then
str = "None."
end
return str
end
function p.getObjectives(frame)
local tempName = frame.args.name
local name = ""
if tempName == nil or tempName == "" then tempName = mw.title.getCurrentTitle().subpageText end
-- check if title contains additional "tags" such as "The Bloodworks (quest)" and removes it
if string.match(tempName,"%(quest%)") then
local i, _ = string.find(tempName," %(quest%)")
name = string.sub(tempName,1,i-1)
-- move title from soft reference to main reference, immutable.
else
name = tempName
end
-- end additions, Squatch
local obj = data[name]
local str = ""
local phaseCount = 1
for k, v in ipairs(obj.phases) do
str = str .. "* Phase " .. phaseCount .. "\n"
phaseCount = phaseCount + 1
for k2, v2 in ipairs(v.objectives) do
str = str .. "** " .. v2.text
if v2.location ~= nil then
str = str .. "<br>" .. "''[[" .. v2.location .. "]]''" .. "</i>"
end
str = str .. "\n"
end
end
str = str:sub(1, -2)
return str
end
function p.createDialogue(frame)
local tempName = frame.args.name
local name = ""
if tempName == nil or tempName == "" then tempName = mw.title.getCurrentTitle().subpageText end
-- check if title contains additional "tags" such as "The Bloodworks (quest)" and removes it
if string.match(tempName,"%(quest%)") then
local i, _ = string.find(tempName," %(quest%)")
name = string.sub(tempName,1,i-1)
-- move title from soft reference to main reference, immutable.
else
name = tempName
end
-- end additions, Squatch
local obj = data[name]
local str = ""
local start = true
if utils.length(obj.onStartDialogue) ~= 0 then
start = false
str = str .. "<div class='text-center'>Start Quest</div>"
str = str .. p.createDialogueBox(obj.onStartDialogue)
end
local currentPhase = 0
for k, v in ipairs(obj.phases) do
if v.phaseDialogue ~= nil or v.phaseQuip ~= nil then
start = false
if start == false then str = str .. "<hr>" end
local phase = currentPhase == 0 and "Start Quest" or "Clear Phase " .. currentPhase
str = str .. "<div class='text-center'>".. phase .."</div>"
str = str .. p.createDialogueBox(v.phaseQuip)
str = str .. p.createDialogueBox(v.phaseDialogue)
end
currentPhase = currentPhase + 1
end
if utils.length(obj.onSuccessDialogue) ~= 0 then
if start == false then str = str .. "<hr>" end
str = str .. "<div class='text-center'>Clear Quest</div>"
str = str .. p.createDialogueBox(obj.onSuccessDialogue)
end
if #str == 0 then
str = "This quest has no dialogue."
end
return str
end
function p.createDialogueBox(t)
local str = ""
if t ~= nil then
local args = {align = "", name = "", text = ""}
local currentName = ""
local frame = mw.getCurrentFrame()
for k, v in ipairs(t) do
if currentName ~= v.name then
if currentName ~= "" then str = str .. frame:expandTemplate{title = 'Dialogue', args = args} end
currentName = v.name
args = {
name = v.name,
text = v.text
}
if v.name == "Player" then args.align = "right" end
else
args = {
name = v.name,
text = args.text .. "\n\n" .. v.text
}
if v.name == "Player" then args.align = "right" end
end
end
str = str .. frame:expandTemplate{title = 'Dialogue', args = args}
end
return str
end
return p