Для документации этого модуля может быть создана страница Модуль:Инфобокс/doc
local infobox = {}
--эффективность
function infobox.pick(frame)
if frame.args[1] == "" then
return
else
local pPickaxe = 0
local pAxe = 0
local pHammer = 0
local pick = mw.text.split(frame.args[1], " ")
for i = 1, 3 do
if pick[i] then
local pType = mw.text.split(pick[i], "-")
if pType[1] == "к" then
pPickaxe = pType[2]
elseif pType[1] == "т" then
pAxe = pType[2]
elseif pType[1] == "м" then
pHammer = pType[2]
end
end
end
return "<span style='cursor:help' title='Эффективность кирки'>[[файл:Эффективность кирки.png|link=]]"..pPickaxe.."%</span> <span style='cursor:help' title='Эффективность топора'>[[файл:Эффективность топора.png|link=]]"..pAxe.."%</span> <span style='cursor:help' title='Эффективность молота'>[[файл:Эффективность молота.png|link=]]"..pHammer.."%</span>"
end
end
--тип
function infobox.types(frame)
local content = ""
local args = mw.text.split(frame.args[1], ", ")
local typesLibrary = mw.loadData("Модуль:Инфобокс/Типы_-_"..frame.args[2])
for i = 1, #args do
local lType = mw.ustring.lower(args[i])
if i ~= 1 then
content = content..", "
end
if typesLibrary[lType] then
content = content.."[["..typesLibrary[lType]["статья"].."|"..typesLibrary[lType]["название"].."]]"-- [[Категория:"..typesLibrary[lType]["категория"].."]]"
else
content = content.."<span style='color:red'>Неизвестный</span>"
end
end
return content
end
--дистанция
function infobox.distance(frame)
local content = ""
local types = mw.text.split(frame.args[1], ", ")
local typesLibrary = mw.loadData("Модуль:Инфобокс/Типы_-_"..frame.args[2])
local dist = frame.args[3]
if dist ~= "" then
local fullDist
local tnDist
if mw.ustring.sub(dist, 1, 1) == "!" then
fullDist = tonumber(mw.ustring.sub(dist, 2, -1))
if not fullDist then
fullDist = -1
end
else
tnDist = tonumber(dist)
for i = 1, #types do
local lType = mw.ustring.lower(types[i])
if typesLibrary[lType]["дистанция"] then
if tnDist then
fullDist = tnDist + typesLibrary[lType]["дистанция"]
else
fullDist = -1
end
end
end
end
if fullDist then
if fullDist > 0 then
content = fullDist.." "..infobox.infoboxLibrary.wordsDeclination("блок", fullDist, "", "а", "ов")
else
content = "<span style='color:red'>Проверь правильность заполнения поля</span>"
end
end
end
return content
end
--урон
function infobox.damage(frame)
function determinationAttackType(atType, itTypes)
if atType ~= "" then
return atType
end
local types = mw.text.split(itTypes, ", ")
local typesLibrary = mw.loadData("Модуль:Инфобокс/Типы_-_предмет")
for i = 1, #types do
if typesLibrary[types[i]] and typesLibrary[types[i]]["тип урона"] then
return typesLibrary[types[i]]["тип урона"]
end
end
return ""
end
local content = ""
local attack1 = tonumber(frame.args[1])
local attack2 = tonumber(frame.args[2])
local attackFactor1 = tonumber(frame.args[3])
local attackFactor2 = tonumber(frame.args[4])
local attackSpeed1 = tonumber(frame.args[5])
local attackSpeed2 = tonumber(frame.args[6])
local attacktype = determinationAttackType(frame.args[7], frame.args[8])
local dps = tonumber(frame.args[9])
if attack1 ~= 0 or attack2 ~= 0 then
if attack2 ~= 0 then
content = content.."<span title='Урон от основной атаки'>"..attack1.."</span> + <span title='Урон от дополнительной атаки'>"..attack2.."</span>"
else
content = content..attack1
end
if attacktype == "ближний" then
content = content.."<span title='Этот предмет наносит урон в ближнем бою'> [[файл:Damagetype melee.png|16px|link=]]</span>"
elseif attacktype == "дальний" then
content = content.."<span title='Этот предмет наносит урон в дальнем бою'> [[файл:Damagetype ranged.png|8px|link=]]</span>"
elseif attacktype == "магический" then
content = content.."<span title='Этот предмет наносит магический урон'> [[файл:Damagetype magic new.png|16px|link=]]</span>"
elseif attacktype == "прислужники" then
content = content.."<span title='Этот предмет призывает существ, которые будут сражаться за вас'> [[файл:Damagetype_summon.png|16px|link=]]</span>"
elseif attacktype == "метательный" then
content = content.."<span title='Этот предмет является метательным'> [[файл:Damagetype throwing.png|16px|link=]]</span>"
elseif attacktype == "взрыв" then
content = content.."<span title='Этот предмет наносит урон взрывами'> [[файл:Динамит.png|6px|link=]]</span>"
end
if attackSpeed1 ~= 0 and attack1 ~= 0 or attackSpeed2 ~= 0 and attack2 ~= 0 or dps ~= 0 then
local computedDps = 0
if dps ~= 0 then
computedDps = dps
else
if attackSpeed1 ~= 0 and attack1 ~= 0 then
computedDps = computedDps + math.ceil(60 / attackSpeed1 * attack1 * attackFactor1)
end
if attackSpeed2 ~= 0 and attack2 ~= 0 then
computedDps = computedDps + math.ceil(60 / attackSpeed2 * attack2 * attackFactor2)
end
end
content = content.." <span title='Урон в секунду'>~"..computedDps.." увс</span>"
end
end
return content
end
--размеры крюка
function infobox.hook(frame)
local pHook = mw.text.split(frame.args[1], "*")
if #pHook == 1 then
return "1 ветвь в "..pHook[1].." "..infobox.infoboxLibrary.wordsDeclination("блок", pHook[1], "", "а", "ов")
elseif pHook[1] == "1" then
return "1 ветвь в "..pHook[2].." "..infobox.infoboxLibrary.wordsDeclination("блок", pHook[2], "", "а", "ов")
else
return pHook[1].." "..infobox.infoboxLibrary.wordsDeclination("ветв", pHook[1], "ь", "и", "ей").." по "..pHook[2].." "..infobox.infoboxLibrary.wordsDeclination("блок", pHook[2], "", "а", "ов")
end
end
--цена
function infobox.cost(frame)
function coinCreate(coins, number, imageName)
if tonumber(number) ~= 0 then
if coins ~= '' then
coins = coins.." "
end
coins = coins..number.." [[Файл:"..imageName.."|link=]]"
end
return coins
end
local content = ""
if frame.args[1] == "none,sell" or frame.args[1] == "0,0,0,0,buy" or frame.args[1] == "0,0,0,0,sell" then
content = "Отсутствует"
else
local price = mw.text.split(frame.args[1], ",")
if price[5] == "sell" then
content = coinCreate(content, price[1], "Platinum coin.png")
content = coinCreate(content, price[2], "Gold coin.png")
content = coinCreate(content, price[3], "Silver coin.png")
content = coinCreate(content, price[4], "Copper coin.png")
elseif price[5] == "buy" then
local buy = ""
local sell = ""
buy = coinCreate(buy, price[1], "Platinum coin.png")
buy = coinCreate(buy, price[2], "Gold coin.png")
buy = coinCreate(buy, price[3], "Silver coin.png")
buy = coinCreate(buy, price[4], "Copper coin.png")
local copperPrice = price[1] * 1000000 + price[2] * 10000 + price[3] * 100 + price[4]
local sellCopperPrice
if tonumber(copperPrice) <= 5 then
sellCopperPrice = 1
else
sellCopperPrice = math.floor(copperPrice / 5)
end
sellPrice = {}
local lastCoins = 0
local exponent = 6
for i = 1, 4 do
sellPrice[i] = math.floor(sellCopperPrice / (10^exponent))
sellCopperPrice = sellCopperPrice - sellPrice[i] * (10^exponent)
exponent = exponent - 2
end
sell = coinCreate(sell, sellPrice[1], "Platinum coin.png")
sell = coinCreate(sell, sellPrice[2], "Gold coin.png")
sell = coinCreate(sell, sellPrice[3], "Silver coin.png")
sell = coinCreate(sell, sellPrice[4], "Copper coin.png")
content = "<span style='border-bottom:1px dotted; cursor:help' title='Цена покупки'>"..buy.."</span> / <span style='border-bottom:1px dotted; cursor:help' title='Цена продажи'>"..sell.."</span>"
end
end
return content
end
function infobox.costName(frame)
local content = ""
if frame.args[1] == "none,sell" or frame.args[1] == "0,0,0,0,buy" or frame.args[1] == "0,0,0,0,sell" then
content = "Цена"
else
local price = mw.text.split(frame.args[1], ",")
if price[5] == "sell" then
content = "Цена продажи"
elseif price[5] == "buy" then
content = "Цены"
end
end
return content
end
infobox.infoboxLibrary = {}
function infobox.infoboxLibrary.wordsDeclination(word, number, end1, end2, end3)
local strNum = tostring(number)
local lastSymbol = tonumber(mw.ustring.sub(strNum, -1))
local penultimateSymbol
if mw.ustring.len(strNum) > 1 then
penultimateSymbol = tonumber(mw.ustring.sub(strNum, -2, -2))
else
penultimateSymbol = 0
end
if lastSymbol == 1 and penultimateSymbol ~= 1 then
return word..end1
elseif lastSymbol > 1 and lastSymbol < 5 and penultimateSymbol ~= 1 then
return word..end2
else
return word..end3
end
end
return infobox