模块:Coin expr
跳到导航
跳到搜索
亦可参看英文模块:Module:Coin expr。那边可能有更完整或更正确的信息。
Provides the functionality for {{sell expr}} and {{buy expr}}. Only parameters from the template transclusion are considered (instead of from the
call), with the exception of #invoke
, which, if set, causes the module to divide all coin values gathered via {{iteminfo}} by 5.
sell
local trim = mw.text.trim
local iteminfo = require('Module:Iteminfo')
local itemNames = require('Module:ItemNames').getData
local tr = require('Module:Tr').translate
local currentFrame
local args_table
local lang
local getArg = function(key)
local value = args_table[key]
if not value then
return nil
end
value = trim(value)
return value
end
local getId = function(name)
return itemNames('itemIdFromName', name)
end
-----------------------------------------------------------------
-- main return object
return {
go = function(frame, args)
currentFrame = frame
args_table = frame:getParent().args
lang = getArg('lang') or frame:expandTemplate{ title='lang' }
local sell = frame.args['sell']
local str = ''
local errorStr = ''
local i = 0
while true do
i = i+1
local arg = getArg(i)
if arg == nil then
break
end
if i % 2 == 0 then
str = str .. arg
else
if arg ~= '' then
local itemid
if type(tonumber(arg)) == 'number' and string.byte(arg) ~= 43 and string.byte(arg) ~= 45 and iteminfo.info.IDs.isValidWithUnused(tonumber(arg)) then --tonumber accepts '+' and '-' at the start of the string, so we need to manually exclude that
itemid = tonumber(arg)
else
local _id
_id = getId(arg) -- try English lookup
if _id and _id ~= '' then
itemid = _id
end
end
if itemid and itemid ~= '' then
local coinvalue = iteminfo.getItemStat(tonumber(itemid), 'value')
if sell then
coinvalue = math.floor(coinvalue/5)
end
str = str .. coinvalue
else
errorStr = errorStr .. 'Parameter ' .. i .. ' is not a valid item name or ID (Value: <code>' .. arg .. '</code>)! '
end
end
end
end
if errorStr ~= '' then
local t = (sell and 'sell' or 'buy') .. ' expr'
local tl = frame:expandTemplate{ title='tl', args={t} }
errorStr = 'Error in ' .. tl .. ': ' .. errorStr
return frame:expandTemplate{ title='error', args={errorStr} }
else
str = currentFrame:callParserFunction( '#expr', str )
if getArg('raw') then
return str
else
local round = getArg('round') or 999
return frame:expandTemplate{ title='coin', args={str, round=round} }
end
end
end
}