User:LunarEcklipse/Templates/Sandbox
Template:InfoboxVoyage
The Dark Relic Voyage to The Ancient Isles was one of the Mercenary Voyages in Sea of Thieves. Players could buy the voyage from Duke at the Tavern for 5 Doubloons from August 14th to September 11th, 2019.
The Voyage
This Mercenary Voyage was centred around two Bounty maps and two Treasure Maps to find mysterious Dark Relics in The Ancient Isles.
Chapters
- Chapter 1: One Bounty Map with two regular Skeleton Captains. Both of them dropped a guaranteed Villainous Bounty Skull.
- Chapter 2: One Treasure Map with 3 X's. One of these was a guaranteed Dark Relic, whereas the two others could unearth either a Crate of Ancient Bone Dust, one of the four Devil's Roar Trinkets or a Ritual Skull.
- Chapter 3: One Bounty Map with four guaranteed Gold Skeleton Captains. All of them would drop a guaranteed Villainous Bounty Skull.
- Chapter 4: The Final Chapter is a Treasure Map on a Fortress with 3 X's. One of these was a guaranteed Dark Relic, whereas the two others could unearth either a Crate of Ancient Bone Dust, one of the four Devil's Roar Trinkets or a Ritual Skull.
Description
"The Order of Souls suspects that Dark Relics have been taken to The Ancient Isles."
|
Old
Patch Module Fix Steps
- Ensure incoming argument is a string with
type()
.- If not, convert it to one if possible or throw appropriate error/skip.
- All Lua variable types:
nil, boolean, number, string, userdata, function, thread, table
- Do convert:
number, boolean
- Don't convert all others, potential for undefined behaviour otherwise (they shouldn't even be able to get there in the first place).
- All Lua variable types:
- Ensure string is longer than zero.
- If not, convert it to one if possible or throw appropriate error/skip.
- Perform pattern match for linebreaks with
string.gsub()
to create string array separated by newlines.- Pattern match characters should be
/r/n
.
- Pattern match characters should be
- For each substring, pattern match to determine number of asterisks (*) between string start and first alphanumeric character/non-asterisk special character.
- Compare number of asterisks to number of asterisks in last iteration, use
for
loop to nest or break additional<ul></ul>
tags as needed.- Start at 0 for first iteration.
- Declare
li
, use pattern match to put de-asterisked and de-leading whitespaced string into it, and closeli
.- It's important that any UL tags in the substring are escaped, because it'll prevent breakages in case someone is being naughty and trying to break the template.
- If this is the last iteration (no more elements in array after this), escape all remaining uls according to current depth
- Repeat as necessary.
Patch Module Altered Code
local p = {}
function p.main(frame)
local args = require('Dev:Arguments').getArgs(frame)
local raisebadargissue = false -- For error handling later.
-- Cargo Query
local a = mw.ext.cargo.query( "Versions", "_pageName,version,name,release_date", { where = 'version="' .. args[1] .. '"', ["no html"] = true } )
a = a[1] or { }
local html = mw.html.create( "ul" )
:tag("li")
-- Version + Date
if a.version then
html = html
:tag("b")
:wikitext( '[[' .. a.version .. ']] (' .. a.release_date .. ')' )
:done()
:tag("ul")
-- Detail notes sub-bullets
for i=2,25 do -- #args should get the array length of args to prevent unncessecary loops.
if args[i] ~= nil then
local inc_arg = args[i]
local arg_isvalid = false
if type(inc_arg) == 'string' then -- If the argument is a string, it's valid.
arg_isvalid = true
elseif type(inc_arg) == 'number' then -- If the argument is a number, cast to string to make valid.
inc_arg = tostring(inc_arg)
arg_isvalid = true
elseif type(inc_arg) == 'boolean' then -- If the argument is a boolean, then a little logic can convert it to a string easily.
if inc_arg == true then
inc_arg = 'true'
else
inc_arg = 'false'
end
arg_isvalid = true
end -- If one of the remaining types gets in, then something is very wrong and that line should be skipped and probably flagged.
if arg_isvalid then -- If the arg is valid then do the following.
-- First, we separate the string by newline characters into an array via a gmatch.
local arg_nsplit = {}
for j in inc_arg:gmatch("([^\n]*)\n?") do
if type(j) == 'string' then
if #j ~= 0 then -- Don't do anything if the string is completely empty.
-- Now, we use pattern matches to find the first alphanumeric character.
local strstart, _ = string.find(j, '[^%*^%s]') -- Locates the first character that's not a whitespace or a * in the string.
local asteriskdepth = 0 -- Predefine asterisk depth as 0.
if strstart ~= nil then
if strstart > 1 then -- If strstart = 1 then there is no asterisks to worry about in the string at all.
local strslicefront = string.sub(j, 1, strstart - 1) -- We need to subtract 1 here otherwise it includes the first part of the string. This fetches a substring that is everything up to the first character.
_, asteriskdepth = string.gsub(strslicefront, "%*", "") -- Returns the number of asterisks in the substring.
end
local strsliceback = string.sub(j, strstart, #j) -- This will return all of the test we want to actually display in the li
if asteriskdepth > 0 then
for k=1, asteriskdepth do
html = html
:tag('ul')
end
end
if #strsliceback > 0 then -- One last check to make sure this part of the string isn't empty.
html = html
:tag('li')
:wikitext( strsliceback )
:done()
end
if asteriskdepth > 0 then
for k=1, asteriskdepth do
html = html
:done()
end
end
end
end
end
end
else
raisebadargissue = true
end
end
end
else
html = html
:tag('span')
:css('color', 'red')
:wikitext('Error: Patch version not found! An issue exists with the inputted patch name, please check that an existing version has been used.')
end
html = html:allDone()
strout = tostring(html)
if raisebadargissue then
strout = strout .. '[[Category:Patches with arguments causing undefined behavior]]' -- Any page in this category needs to be looked at *thoroughly* because this shouldn't happen. Yes, this includes nil because it means that the argument somehow became nil after it was checked for nil the first time.
end
return strout
end
return p
Patch Module Original Code (In Case I Mess Up)
local p = {}
function p.main(frame)
local args = require('Dev:Arguments').getArgs(frame)
-- Cargo Query
local a = mw.ext.cargo.query( "Versions", "_pageName,version,name,release_date", { where = 'version="' .. args[1] .. '"', ["no html"] = true } )
a = a[1] or { }
local html = mw.html.create( "ul" )
:tag("li")
:tag("b")
-- Version + Date
if a.version then
html = html
:wikitext( '[[' .. a.version .. ']] (' .. a.release_date .. ')' )
:done()
:tag('ul')
-- Detail notes sub-bullets
for i=2,25 do
if args[i] ~= NIL then
html = html
:tag('li')
:wikitext( args[i] )
end
end
else
html = html
:tag('span')
:css('color', 'red')
:wikitext('Error: Patch version not found! An issue exists with the inputted patch name, please check that an existing version has been used.')
:done()
end
html = html:allDone()
return tostring(html)
end
return p