Module:Quest reward and Module:Quest reward/sandbox: Difference between pages
(Difference between pages)
(Declare variables locally.) |
mNo edit summary |
||
Line 49: | Line 49: | ||
-- ---------------------------------------------------------------------------- | -- ---------------------------------------------------------------------------- | ||
function p._shared.reward_tbl_head() | function p._shared.reward_tbl_head(class, reward_map) | ||
local tbl = mw.html.create('table') | local tbl = mw.html.create('table') | ||
tbl:attr('class', 'wikitable sortable') | tbl:attr('class', 'wikitable sortable') | ||
local | local tr1 = tbl:tag('tr') | ||
tr1:tag('th') | |||
:attr('class', 'unsortable') | |||
:wikitext(i18n.quest_reward.character_class) | :wikitext(i18n.quest_reward.character_class) | ||
tr1:tag('th') | |||
:attr('rowspan', 1) | |||
:attr('colspan', 8) | |||
:wikitext(string.format('[[%s]]', class)) | |||
local tr2 = tbl:tag('tr') | |||
tr2:tag('th') | |||
:wikitext(i18n.quest_reward.quest) | |||
: | tr2:tag('th') | ||
:attr('rowspan', 1) | |||
:attr('colspan', 4) | |||
:wikitext(string.format('[[%s]]', reward_map[1])) | |||
tr2:tag('th') | |||
:attr('rowspan', 1) | |||
:attr('colspan', 4) | |||
:wikitext(string.format('[[%s]]', reward_map[2])) | |||
return tbl | return tbl | ||
end | end | ||
Line 112: | Line 116: | ||
}) | }) | ||
frame = m_util.misc.get_frame(frame) | frame = m_util.misc.get_frame(frame) | ||
if tpl_args.item_link then | if tpl_args.item_link then | ||
tpl_args.item_link = m_util.cast.boolean(tpl_args.item_link) | tpl_args.item_link = m_util.cast.boolean(tpl_args.item_link) | ||
Line 119: | Line 122: | ||
end | end | ||
local | local valid_type = false | ||
if tpl_args.type == 'quest_rewards' then | local vendor_rewards = {} | ||
if tpl_args.type == 'vendor_rewards' or tpl_args.type == 'all_rewards' then | |||
local q_where = tpl_args.q_where | |||
if q_where and tpl_args.type == 'all_rewards' then | |||
q_where = string.gsub(q_where, "all", "vendor") | |||
end | |||
vendor_rewards = m_cargo.query( | |||
{'vendor_rewards'}, | |||
{ | |||
'vendor_rewards.quest', | |||
'vendor_rewards.act', | |||
'vendor_rewards.classes', | |||
'vendor_rewards.npc', | |||
'vendor_rewards._pageName', | |||
}, | |||
{ | |||
where=q_where, | |||
orderBy='vendor_rewards.act ASC, vendor_rewards.quest_id ASC, vendor_rewards._pageName ASC', | |||
limit=5000, | |||
} | |||
) | |||
valid_type = true; | |||
end | |||
local quest_rewards = {} | |||
if tpl_args.type == 'quest_rewards' or tpl_args.type == 'all_rewards' then | |||
local q_where = tpl_args.q_where | |||
if q_where and tpl_args.type == 'all_rewards' then | |||
q_where = string.gsub(q_where, "all", "quest") | |||
end | |||
quest_rewards = m_cargo.query( | |||
{'quest_rewards'}, | {'quest_rewards'}, | ||
{ | { | ||
Line 138: | Line 169: | ||
} | } | ||
) | ) | ||
valid_type = true; | |||
end | |||
if not valid_type then | |||
error(i18n.errors.invalid_type, tpl_args.type) | error(i18n.errors.invalid_type, tpl_args.type) | ||
end | end | ||
Line 161: | Line 178: | ||
-- Build output table | -- Build output table | ||
-- ------------------------------------------------------------------------ | -- ------------------------------------------------------------------------ | ||
local tbl = p._shared.reward_tbl_head() | local reward_map = {"vendor","quest"} | ||
local tbl = p._shared.reward_tbl_head(tpl_args.class, reward_map) | |||
local data_pure = {} | |||
if tpl_args.type == 'vendor_rewards' or tpl_args.type == 'all_rewards' then | |||
if #vendor_rewards == 0 then | |||
return tostring(tbl) | |||
else | |||
table.insert(data_pure, vendor_rewards) | |||
end | |||
end | |||
if # | if tpl_args.type == 'quest_rewards' or tpl_args.type == 'all_rewards' then | ||
if #quest_rewards == 0 then | |||
return tostring(tbl) | |||
else | |||
table.insert(data_pure, quest_rewards) | |||
end | |||
end | end | ||
local | local quest_in_order = {} | ||
local quests = {} | local quests = {} | ||
local pages = {} | local pages = {} | ||
Line 174: | Line 206: | ||
-- remap data to quests[questid].classes[class] | -- remap data to quests[questid].classes[class] | ||
-- | -- | ||
for _, | local class_to_attribute_map = { | ||
Duelist = "StrDex", | |||
Marauder = "Str", | |||
Ranger = "Dex", | |||
Scion = "StrDexInt", | |||
Shadow = "DexInt", | |||
Templar = "StrInt", | |||
Witch = "Int" | |||
} | |||
local data_types = {} | |||
if tpl_args.type == 'vendor_rewards' or tpl_args.type == "all_rewards" then | |||
table.insert(data_types, "vendor_rewards") | |||
end | |||
if tpl_args.type == 'quest_rewards' or tpl_args.type == "all_rewards" then | |||
table.insert(data_types, "quest_rewards") | |||
end | |||
for reward_type_index, reward_type in ipairs(data_types) do | |||
for _, data in ipairs(data_pure[reward_type_index]) do | |||
local classes = quests[data[reward_type .. '.quest']] | |||
if quest_in_order[reward_type_index] == nil then | |||
table.insert(quest_in_order[reward_type_index], data[reward_type .. '.quest']) | |||
classes = {} | |||
quests[reward_type_index][data[reward_type .. '.quest']] = classes | |||
end | |||
if data[reward_type .. '.classes'] then | |||
for _, class in ipairs(m_util.string.split(data[reward_type .. '.classes'], ',')) do | |||
if classes[reward_type_index][class] == nil then | |||
classes[reward_type_index][class] = {} | |||
end | |||
if class == tpl_args.class then | |||
table.insert(classes[reward_type_index][class], data) | |||
end | |||
end | |||
else | |||
if classes[reward_type_index][0] == nil then | |||
classes[reward_type_index][0] = {} | |||
end | |||
table.insert(reward_map[reward_type_index][reward_type_index], data) | |||
end | |||
pages[data[reward_type .. '._pageName']] = true | |||
end | |||
end | end | ||
-- | -- | ||
-- Cache item data | -- Cache item data | ||
Line 258: | Line 309: | ||
end | end | ||
for _, quest_key in ipairs( | for _, quest_key in ipairs(quest_in_order) do | ||
local classes = quests[quest_key] | local classes = quests[quest_key] | ||
Line 270: | Line 321: | ||
end | end | ||
tr:tag('td') | tr:tag('td') | ||
:attr('colspan', | :attr('colspan', 4) | ||
:attr('style', 'text-align: center;') | :attr('style', 'text-align: center;') | ||
:wikitext(element(classes[0])) | :wikitext(element(classes[0])) | ||
Line 283: | Line 334: | ||
end | end | ||
for _, class in ipairs(m_game.constants.characters_order) do | for _, class in ipairs(m_game.constants.characters_order) do | ||
if class == tpl_args.class then | |||
tr:tag('td') | |||
:wikitext(element(classes[m_game.constants.characters[class].name])) | |||
end | |||
end | end | ||
end | end |