Documentation The documentation below is transcluded from Module:Test/doc. (edit | history)
A test module to avoid disturbing "real" pages.
See Terraria Wiki:Lua for more information about Lua and links to other help resources.
Feel free to test this module at Terraria Wiki:Sandbox.
local trim = mw.text.trim
local cargo = mw.ext.cargo
local possibleModifiers = require('Module:Possible modifiers').getPossibleModifiers
local currentFrame
local getArg = function(key)
local value = currentFrame.args[key]
if not value then
return nil
end
value = trim(value)
if value == '' then
return nil
end
return value
end
local round = function(x)
return x + 0.5 - (x + 0.5) % 1
end
local function arrayToSet(t)
local set = {}
for _, v in ipairs(t) do
set[v] = true
end
return set
end
local function getToolModifier(item, modifierinfoSpeed)
if item.possibleModifiers['Light'] ~= nil then
local low = ''
local alt = ''
local combatmodifier = ''
if item.possibleModifiers['Legendary'] ~= nil then
combatmodifier = 'Legendary'
elseif item.possibleModifiers['Agile'] ~= nil then
combatmodifier = 'Agile'
low = 'low'
end
-- check if Light causes the same toolspeed bonus as the combat modifier option
if combatmodifier ~= '' and item.toolspeed ~= '' then
if round(item.toolspeed*modifierinfoSpeed[combatmodifier]) == round(item.toolspeed*modifierinfoSpeed['Light']) then
alt = 'alt'
end
end
return 'harvest' .. low .. alt
end
return ''
end
local function getWeaponModifier(item)
if item.damagetype == 'melee' then
if item.possibleModifiers['Legendary'] then
return 'melee'
elseif item.possibleModifiers['Godly'] then
return 'meleealt'
elseif item.possibleModifiers['Deadly'] then
return 'nokb'
elseif item.possibleModifiers['Demonic'] then
return 'nokbalt'
end
elseif item.damagetype == 'ranged' then
if item.possibleModifiers['Unreal'] then
return 'ranged'
elseif item.possibleModifiers['Demonic'] then
return 'rangednokb'
end
elseif item.damagetype == 'magic' then
if item.possibleModifiers['Mythical'] then
return 'magic'
elseif item.possibleModifiers['Masterful'] then
return 'magiclow'
elseif item.possibleModifiers['Godly'] then
return 'magicverylow'
elseif item.possibleModifiers['Mystic'] then
return 'magicnokb'
elseif item.possibleModifiers['Demonic'] then
return 'magiclownokb'
end
elseif item.damagetype == 'summon' then
if item.listcat:find('whips', 1, true) then
return 'whip'
elseif item.possibleModifiers['Ruthless'] then
return 'summon'
elseif item.possibleModifiers['Deadly'] then
return 'nokb'
elseif item.possibleModifiers['Demonic'] then
return 'nokbalt'
end
end
return 'none'
end
-----------------------------------------------------------------
-- main return object
return {
go = function(frame, args)
-- init cache
currentFrame = frame
local itemid = getArg('itemid')
local modifierinfoSpeed = {
['Agile'] = getArg('modifierinfo_speed:Agile'),
['Legendary'] = getArg('modifierinfo_speed:Legendary'),
['Light'] = getArg('modifierinfo_speed:Light'),
}
-- fetch info about the item:
local item = cargo.query('Items', 'type, listcat, damagetype, toolspeed', {
where = 'itemid='.. itemid,
limit = 1,
})[1]
item.possibleModifiers = arrayToSet(possibleModifiers(itemid))
-- normalize
for _, stat in ipairs({'type', 'listcat', 'damagetype', 'toolspeed'}) do
item[stat] = item[stat] == nil and '' or item[stat]:lower() -- nil to '', non-nil to lowercase
end
if item.damagetype:find('melee', 1, true) then
item.damagetype = 'melee'
elseif item.damagetype:find('ranged', 1, true) then
item.damagetype = 'ranged'
elseif item.damagetype:find('magic', 1, true) then
item.damagetype = 'magic'
elseif item.damagetype:find('summon', 1, true) then
item.damagetype = 'summon'
end
item.toolspeed = item.toolspeed:gsub('^%D-(%d+).*$', '%1') -- strip non-numerical characters
local isTool = item['type']:find('tool', 1, true) and not item['type']:find('weapon', 1, true) -- has tool type and does not have weapon type
local str = ''
if true then
str = str .. 'type:' .. item['type'] .. ', listcat:' .. item.listcat .. ', damagetype:' .. item.damagetype .. ', toolspeed:' .. item.toolspeed .. ', isTool:' .. tostring(isTool)
end
local result = ''
if isTool then
result = getToolModifier(item, modifierinfoSpeed)
if result == '' then
item.damagetype = 'melee'
end
end
if result == '' then
result = getWeaponModifier(item)
end
if true then
return str
end
return result
end,
}