Нет описания правки |
Kokloswine (обс. | вклад) Нет описания правки |
||
(не показаны 62 промежуточные версии 9 участников) | |||
Строка 1: | Строка 1: | ||
local p = {} |
local p = {} |
||
+ | |||
− | p.row = function( f ) |
||
+ | local breakingTimeHeader; |
||
− | local args = require( [[Модуль:ProcessArgs]] ).norm() |
||
+ | local function getBreakingTimeHeader( f ) |
||
− | |||
+ | if breakingTimeHeader == nil then |
||
− | --- args[1] = 'Камень' |
||
+ | breakingTimeHeader = 'Время [[Добывание|разрушения]]' .. f:preprocess( '<ref group="FN" name="breakingtimenote">Время для незачарованных инструментов, используемых игроком без наложенных эффектов, в секундах. Для большей информации см. [[Добывание#Скорость|Добывание § Скорость]].</ref>' ) |
||
− | --- args[1] = mw.title.getCurrentTitle() |
||
+ | end |
||
− | if (args[1] == '') or (args[1] == nil) then |
||
+ | return breakingTimeHeader |
||
− | args[1] = 'Камень' |
||
+ | end |
||
+ | |||
+ | function p.row( f ) |
||
+ | local args = require( [[Модуль:ProcessArgs]] ).norm() |
||
+ | local sprite = require( [[Модуль:Спрайт]] ) |
||
+ | |||
+ | local function getDplVar( var ) |
||
+ | local val = f:callParserFunction( '#dplvar', 'breaking ' .. var ) |
||
+ | if val == '' then |
||
+ | val = false |
||
+ | end |
||
+ | return val |
||
+ | end |
||
+ | local dplVars = {} |
||
+ | local function setDplVar( var, val ) |
||
+ | table.insert( dplVars, 'breaking ' .. var ) |
||
+ | table.insert( dplVars, val or '1' ) |
||
+ | end |
||
+ | |||
+ | local rows = {} |
||
+ | local tableParts = {} |
||
+ | local categories = {} |
||
+ | |||
+ | local horizontal |
||
+ | args[1] = args[1] or '' -- чтобы не переделывать весь модуль, ранее считавший, что тут строка |
||
+ | |||
+ | -- Подставляет название страницы, если параметр args[1] не указан. |
||
+ | if (args[1] == '') or (args[1] == nil) then |
||
+ | args[1] = mw.title.getCurrentTitle().text |
||
+ | args["встолбик"] = 1 |
||
end |
end |
||
+ | if args["встолбик"] or args[1]:match( ';' ) then |
||
− | local getDplVar = function( var ) |
||
+ | horizontal = true |
||
− | local val = f:callParserFunction( '#dplvar', 'breaking ' .. var ) |
||
− | + | end |
|
+ | local showTool = true |
||
− | val = false |
||
+ | local showShears = true |
||
− | end |
||
+ | local showSword = true |
||
− | return val |
||
+ | local header, sortable, simple |
||
− | end |
||
+ | if horizontal or not getDplVar( 'header' ) then |
||
− | local dplVars = {} |
||
+ | if args["скрытьинструмент"] or horizontal and ( not args[2] or args[2]:lower() == 'any' or args[2]:lower() == 'none' ) then |
||
− | local setDplVar = function( var, val ) |
||
+ | showTool = false |
||
− | table.insert( dplVars, 'breaking ' .. var ) |
||
+ | setDplVar( 'hidetool' ) |
||
− | table.insert( dplVars, val or '1' ) |
||
+ | breakingTimeHeader = 'Время [[Добывание|разрушения]]' |
||
− | end |
||
+ | end |
||
− | |||
+ | if args["скрытьножницы"] or horizontal and not args["ножницы"] then |
||
− | local breakingTimeHeader = 'Время [[Добыча|разрушения]]' .. f:preprocess( '<ref group="note">Время для незачарованных инструментов в секундах.</ref>' ) |
||
+ | showShears = false |
||
− | |||
+ | setDplVar( 'hideshears' ) |
||
− | local rows = {} |
||
+ | end |
||
− | local tableParts = {} |
||
+ | if args["скрытьмеч"] or horizontal and not args["меч"] then |
||
− | local categories = {} |
||
+ | showSword = false |
||
− | |||
+ | setDplVar( 'hidesword' ) |
||
− | local horizontal |
||
+ | end |
||
− | if args["встолбик"] or args[1]:match( ';' ) then |
||
+ | |||
− | horizontal = true |
||
+ | sortable = not horizontal and args["сортировка"] |
||
− | end |
||
+ | if sortable then |
||
− | local showTool = true |
||
+ | setDplVar( 'sortable' ) |
||
− | local showShears = true |
||
+ | end |
||
− | local showSword = true |
||
+ | simple = args["простой"] |
||
− | local header, sortable, simple |
||
+ | if simple and not horizontal then |
||
− | if horizontal or not getDplVar( 'header' ) then |
||
+ | setDplVar( 'simple' ) |
||
− | if args["скрытьинструмент"] or horizontal and ( not args[2] or args[2]:lower() == 'any' or args[2]:lower() == 'нет' ) then |
||
+ | end |
||
− | showTool = false |
||
+ | |||
− | setDplVar( 'hidetool' ) |
||
+ | local tableClasses = { 'wikitable' } |
||
− | end |
||
+ | if sortable then |
||
− | if args["скрытьножницы"] or horizontal and not args["ножницы"] then |
||
+ | table.insert( tableClasses, 'sortable' ) |
||
− | showShears = false |
||
+ | end |
||
− | setDplVar( 'hideshears' ) |
||
+ | table.insert( rows, ' {| class="' .. table.concat( tableClasses, ' ' ) .. '" style="text-align:center"' ) |
||
− | end |
||
+ | |||
− | if args["скрытьмеч"] or horizontal and not args["меч"] then |
||
+ | local sortType = '' |
||
− | showSword = false |
||
+ | if sortable then |
||
− | setDplVar( 'hidesword' ) |
||
+ | sortType = 'data-sort-type="number"' |
||
− | end |
||
+ | end |
||
− | |||
+ | local rowspan = '' |
||
− | sortable = not horizontal and args["сортировка"] |
||
− | + | if not horizontal then |
|
+ | rowspan = 'rowspan="2" ' |
||
− | setDplVar( 'sortable' ) |
||
− | + | end |
|
+ | header = { |
||
− | simple = args["простой"] |
||
+ | '! ' .. rowspan .. ' | Блок' |
||
− | if simple and not horizontal then |
||
+ | } |
||
− | setDplVar( 'simple' ) |
||
+ | |||
− | end |
||
+ | if not simple then |
||
− | |||
+ | table.insert( header, '! ' .. rowspan .. sortType .. ' | Прочность' ) |
||
− | local tableClasses = { 'wikitable' } |
||
− | + | if showTool then |
|
− | + | table.insert( header, '! ' .. rowspan .. ' | Инструмент' ) |
|
+ | end |
||
− | end |
||
+ | end |
||
− | table.insert( rows, ' {| class="' .. table.concat( tableClasses, ' ' ) .. '" style="text-align:center"' ) |
||
+ | |||
− | |||
− | + | local toolColumns = {} |
|
− | + | if showTool then |
|
+ | local firstTool = mw.text.trim( simple and 'Инструмент' or args[2] or 'Любой' ):gsub( '^%l', string.upper ) |
||
− | sortType = 'data-sort-type="number"' |
||
+ | firstTool = mw.text.split( firstTool, ';' )[1] |
||
− | end |
||
+ | if firstTool == 'Кирка' or firstTool == 'Лопата' or firstTool == 'Мотыга' then |
||
− | local rowspan = '' |
||
+ | toolColumns = { 'Деревянная', 'Каменная', 'Железная', 'Алмазная', 'Незеритовая', 'Золотая' } |
||
− | if not horizontal then |
||
− | rowspan = 'rowspan="2" ' |
||
− | end |
||
− | header = { |
||
− | '! ' .. rowspan .. ' | Блок' |
||
− | } |
||
− | |||
− | if not simple then |
||
− | table.insert( header, '! ' .. rowspan .. sortType .. ' | Прочность' ) |
||
− | if showTool then |
||
− | table.insert( header, '! ' .. rowspan .. ' | Инструмент' ) |
||
− | end |
||
− | end |
||
− | |||
− | local toolColumns = {} |
||
− | if showTool then |
||
− | local firsttool = mw.text.trim( simple and 'Инструмент' or args[2] or 'Любое' ):gsub( '^%l', string.upper ) |
||
− | firsttool = mw.text.split( firsttool, ';' )[1] |
||
− | if firsttool == 'Кирка' or firsttool == 'Лопата' then |
||
− | toolColumns = { 'Деревянная', 'Каменная', 'Железная', 'Алмазная', 'Золотая' } |
||
else |
else |
||
− | toolColumns = { 'Деревянный', 'Каменный', 'Железный', 'Алмазный', 'Золотой' } |
+ | toolColumns = { 'Деревянный', 'Каменный', 'Железный', 'Алмазный', 'Незеритовый', 'Золотой' } |
end |
end |
||
− | + | end |
|
+ | table.insert( toolColumns, 1, 'По умолчанию' ) |
||
− | table.insert( |
||
+ | |||
− | toolColumns, 1, |
||
+ | if not simple then |
||
− | '<abbr title="Сюда также относятся варианты, когда игрок использует неподходящие инструменты или предметы, не являющиеся инструментами.">Рука</abbr>' |
||
+ | if showShears then |
||
− | ) |
||
+ | table.insert( toolColumns, 'Ножницы' ) |
||
− | if not simple then |
||
+ | end |
||
− | if showShears then |
||
+ | if showSword then |
||
− | table.insert( toolColumns, 'Ножницы' ) |
||
+ | table.insert( toolColumns, 'Меч' ) |
||
− | end |
||
+ | end |
||
− | if showSword then |
||
+ | end |
||
− | table.insert( toolColumns, 'Меч' ) |
||
+ | |||
− | end |
||
+ | if not horizontal then |
||
− | end |
||
+ | table.insert( header, '! colspan="' .. #toolColumns .. '" |' .. getBreakingTimeHeader( f ) ) |
||
− | |||
+ | table.insert( header, '|-' ) |
||
− | if not horizontal then |
||
+ | end |
||
− | table.insert( header, '! colspan="' .. #toolColumns .. '" |' .. breakingTimeHeader ) |
||
+ | |||
− | table.insert( header, '|-' ) |
||
+ | local toolSprites = { |
||
− | end |
||
+ | ["Деревянный"] = {'Спрайт/Блок', 'дубовые-доски' }, |
||
− | |||
+ | ["Деревянная"] = {'Спрайт/Блок', 'дубовые-доски' }, |
||
− | for _, tool in ipairs( toolColumns ) do |
||
+ | ["Каменный"] = { 'Спрайт/Блок', 'булыжник' }, |
||
− | table.insert( header, '! ' .. sortType .. ' | ' .. tool ) |
||
+ | ["Каменная"] = { 'Спрайт/Блок', 'булыжник' }, |
||
− | end |
||
+ | ["Железный"] = { 'Спрайт/Предмет', 'железный-слиток' }, |
||
− | |||
+ | ["Железная"] = { 'Спрайт/Предмет', 'железный-слиток' }, |
||
− | if not horizontal then |
||
+ | ["Алмазный"] = { 'Спрайт/Предмет', 'алмаз' }, |
||
− | header = table.concat( header, '\n' ) |
||
+ | ["Алмазная"] = { 'Спрайт/Предмет', 'алмаз' }, |
||
− | setDplVar( 'header', header ) |
||
+ | ["Незеритовый"] = { 'Спрайт/Предмет', 'незеритовый-слиток' }, |
||
− | end |
||
+ | ["Незеритовая"] = { 'Спрайт/Предмет', 'незеритовый-слиток' }, |
||
− | table.insert( tableParts, header ) |
||
+ | ["Золотой"] = { 'Спрайт/Предмет', 'золотой-слиток' }, |
||
− | else |
||
+ | ["Золотая"] = { 'Спрайт/Предмет', 'золотой-слиток' }, |
||
− | showTool = not getDplVar( 'hidetool' ) |
||
+ | ["Ножницы"] = { 'Спрайт/Предмет', 'ножницы' }, |
||
− | showShears = not getDplVar( 'hideshears' ) |
||
+ | ["Меч"] = { 'Спрайт/Предмет', 'деревянный-меч' } |
||
− | showSword = not getDplVar( 'hidesword' ) |
||
+ | } |
||
− | sortable = getDplVar( 'sortable' ) |
||
+ | for _, tool in ipairs( toolColumns ) do |
||
− | simple = getDplVar( 'simple' ) |
||
+ | if toolSprites[tool] then |
||
− | end |
||
+ | local image, spriteCat = sprite.sprite{ |
||
− | |||
+ | ["данные"] = toolSprites[tool][1], |
||
− | local sprite = require( [[Модуль:Спрайт]] ) |
||
+ | toolSprites[tool][2], |
||
− | local hardness = require( [[Модуль:Значения блоков]] ).value |
||
+ | ["текст"] = tool |
||
− | |||
+ | } |
||
− | local fillCells = function( cellsTable, text, num ) |
||
+ | table.insert( header, '! style="text-align:left" ' .. sortType .. ' | ' .. image ) |
||
− | for i = 1, num do |
||
− | + | table.insert( categories, spriteCat ) |
|
+ | else |
||
− | end |
||
+ | table.insert( header, '! ' .. sortType .. ' | ' .. tool ) |
||
− | end |
||
+ | end |
||
− | local materialGrade = { |
||
+ | end |
||
− | ["Любая"] = 0, ["Любой"] = 0, ["Любое"] = 0, |
||
+ | |||
− | ["Деревянная"] = 1, ["Деревянный"] = 1, |
||
+ | if not horizontal then |
||
− | ["Золотая"] = 1, ["Золотой"] = 1, |
||
+ | header = table.concat( header, '\n' ) |
||
− | ["Каменная"] = 2, ["Каменный"] = 2, |
||
+ | setDplVar( 'header', header ) |
||
− | ["Железная"] = 3, ["Железный"] = 3, |
||
+ | end |
||
− | ["Алмазная"] = 4, ["Алмазный"] = 4, |
||
+ | table.insert( tableParts, header ) |
||
− | ["Нет"] = 5 |
||
+ | else |
||
− | } |
||
+ | showTool = not getDplVar( 'hidetool' ) |
||
− | local materialSpeed = { |
||
+ | showShears = not getDplVar( 'hideshears' ) |
||
− | ["Нет"] = 1, |
||
+ | showSword = not getDplVar( 'hidesword' ) |
||
− | ["Любая"] = 1, ["Любой"] = 1, ["Любое"] = 1, |
||
+ | sortable = getDplVar( 'sortable' ) |
||
− | ["Деревянная"] = 2, ["Деревянный"] = 2, |
||
+ | simple = getDplVar( 'simple' ) |
||
− | ["Каменная"] = 4, ["Каменный"] = 4, |
||
+ | end |
||
− | ["Железная"] = 6, ["Железный"] = 6, |
||
+ | |||
− | ["Алмазная"] = 8, ["Алмазный"] = 8, |
||
+ | local hardness = require( [[Модуль:Значения блоков]] ).value |
||
− | ["Золотая"] = 12, ["Золотой"] = 12 |
||
+ | |||
− | } |
||
− | + | local function fillCells( cellsTable, text, num ) |
|
+ | for i = 1, num do |
||
− | local cells = {} |
||
+ | table.insert( cellsTable, text ) |
||
− | local blocks = mw.text.split( blockArgs[1], '%s*,%s*' ) |
||
+ | end |
||
− | local hardnessVal = tonumber( hardness{ blocks[1], ["тип"] = 'прочности' } ) |
||
+ | end |
||
− | if not hardnessVal then |
||
+ | local materialGrade = { |
||
− | hardnessVal = '?' |
||
+ | ["Любой"] = 0, ["Любая"] = 0, |
||
− | end |
||
+ | ["Деревянный"] = 1, ["Деревянная"] = 1, |
||
− | local unbreakable |
||
+ | ["Золотой"] = 1, ["Золотая"] = 1, |
||
− | if hardnessVal == -1 or blockArgs.liquid then |
||
+ | ["Каменный"] = 2, ["Каменная"] = 2, |
||
− | unbreakable = true |
||
+ | ["Железный"] = 3, ["Железная"] = 3, |
||
− | end |
||
+ | ["Алмазный"] = 4, ["Алмазная"] = 4, |
||
− | |||
+ | ["Незеритовый"] = 5, ["Незеритовая"] = 5, |
||
− | local blockSprites = {} |
||
+ | ["Нет"] = 6 |
||
− | local links = mw.text.split( blockArgs["ссылка"] or '', '%s*,%s*' ) |
||
+ | } |
||
− | local ids = mw.text.split( blockArgs["спрайт"] or '', '%s*,%s*' ) |
||
+ | local materialSpeed = { |
||
− | local items = mw.text.split( blockArgs["предмет"] or '', '%s*,%s*' ) |
||
+ | ["Нет"] = 1, |
||
− | for i, block in ipairs( blocks ) do |
||
+ | ["Любой"] = 1, ["Любая"] = 1, |
||
− | local link |
||
+ | ["Деревянный"] = 2, ["Деревянная"] = 2, |
||
− | if not links[i] and links[1] ~= '' then |
||
+ | ["Каменный"] = 4, ["Каменная"] = 4, |
||
− | link = links[1] |
||
+ | ["Железный"] = 6, ["Железная"] = 6, |
||
− | elseif links[i] ~= '' then |
||
+ | ["Алмазный"] = 8, ["Алмазная"] = 8, |
||
− | link = links[i] |
||
+ | ["Незеритовый"] = 9, ["Незеритовая"] = 9, |
||
− | end |
||
+ | ["Золотой"] = 12, ["Золотая"] = 12 |
||
− | local id |
||
+ | } |
||
− | if not ids[i] and ids[1] ~= '' then |
||
+ | local numberMaterials = 6 |
||
− | id = ids[1] |
||
+ | |||
− | elseif ids[i] ~= '' then |
||
+ | local function insertBlock( blockArgs ) |
||
− | id = ids[i] |
||
+ | local cells = {} |
||
− | end |
||
+ | local blocks = mw.text.split( blockArgs[1], '%s*,%s*' ) |
||
− | local blockText |
||
+ | local hardnessVal = tonumber( hardness{ blocks[1], ["тип"] = 'прочности' } ) |
||
− | if args["сократить"] then |
||
+ | if not hardnessVal then |
||
− | blockText = block:gsub( args["сократить"] .. '$', '' ) |
||
+ | hardnessVal = '?' |
||
− | else |
||
+ | local title = mw.title.getCurrentTitle() |
||
− | blockText = block |
||
+ | if title.namespace == 0 and not title.isSubpage then |
||
− | end |
||
+ | table.insert(categories, '[[Категория:Отсутствующие значения прочности]]') |
||
− | local blockSpriteArgs = { |
||
+ | end |
||
− | ["настройки"] = 'БлокСпрайт', |
||
+ | end |
||
− | block, |
||
+ | local unbreakable |
||
− | ["текст"] = blockText, |
||
+ | if hardnessVal == -1 or blockArgs.liquid then |
||
− | ["ссылка"] = link, |
||
+ | unbreakable = true |
||
− | ["ID"] = id |
||
+ | end |
||
− | } |
||
+ | |||
− | if items[i] == '1' or not items[i] and items[1] == '1' then |
||
+ | local blockSprites = {} |
||
− | blockSpriteArgs.settings = 'ПредметСпрайт' |
||
+ | local links = mw.text.split( blockArgs["ссылка"] or '', '%s*,%s*' ) |
||
− | end |
||
+ | local ids = mw.text.split( blockArgs["спрайт"] or '', '%s*,%s*' ) |
||
− | |||
+ | local items = mw.text.split( blockArgs["предмет"] or '', '%s*,%s*' ) |
||
− | local image, spriteCat = sprite.link( blockSpriteArgs ) |
||
+ | for i, block in ipairs( blocks ) do |
||
− | table.insert( blockSprites, image ) |
||
+ | local link |
||
− | table.insert( categories, spriteCat ) |
||
+ | if not links[i] and links[1] ~= '' then |
||
− | end |
||
+ | link = links[1] |
||
− | table.insert( cells, |
||
+ | elseif links[i] ~= '' then |
||
− | '! style="text-align:left" | ' .. table.concat( blockSprites, '<br>' ) .. ( blockArgs["прим"] or '' ) |
||
+ | link = links[i] |
||
− | ) |
||
+ | end |
||
− | |||
+ | local id |
||
− | local tool = mw.text.trim( simple and 'Инструмент' or blockArgs[2] or 'Любое' ):gsub( '^%l', string.upper ) |
||
+ | if not ids[i] and ids[1] ~= '' then |
||
− | local material = mw.text.trim( simple and blockArgs[2] or blockArgs[3] or 'Любое' ):gsub( '^%l', string.upper ) |
||
+ | id = ids[1] |
||
− | if tool == 'Нет' then |
||
+ | elseif ids[i] ~= '' then |
||
− | material = tool |
||
+ | id = ids[i] |
||
− | end |
||
+ | end |
||
− | if not simple then |
||
+ | local blockText |
||
− | local hardnessText = hardnessVal |
||
+ | if args["сократить"] then |
||
− | if hardnessVal == -1 then |
||
+ | blockText = block:gsub( args["сократить"] .. '$', '' ) |
||
− | hardnessText = ( sortable and 'data-sort-value="999" | ' or '' ) .. '∞' |
||
+ | else |
||
− | end |
||
+ | blockText = block |
||
− | table.insert( cells, '|' .. hardnessText ) |
||
+ | end |
||
− | |||
+ | local blockSpriteArgs = { |
||
− | if showTool then |
||
+ | ["данные"] = 'Спрайт/Блок', |
||
− | local toolCell = '—' |
||
+ | block, |
||
− | if tool ~= 'Любое' and tool ~= 'Нет' then |
||
+ | ["текст"] = blockText, |
||
− | local toolName = ( material ~= 'Любое' and material .. ' ' or '' ) .. tool |
||
− | + | ["ссылка"] = link, |
|
+ | ["ID"] = id |
||
− | if material == 'Любое' then |
||
+ | } |
||
− | if tool == 'Кирка' then |
||
+ | if items[i] == '1' or not items[i] and items[1] == '1' then |
||
− | ftoolName = 'Деревянная кирка' |
||
+ | blockSpriteArgs["данные"] = 'Спрайт/Предмет' |
||
− | end |
||
+ | end |
||
− | if tool == 'Топор' then |
||
+ | |||
− | ftoolName = 'Деревянный топор' |
||
+ | local image, spriteCat = sprite.link( blockSpriteArgs ) |
||
− | end |
||
+ | table.insert( blockSprites, image ) |
||
− | if tool == 'Лопата' then |
||
+ | table.insert( categories, spriteCat ) |
||
− | ftoolName = 'Деревянная лопата' |
||
− | + | end |
|
+ | table.insert( cells, |
||
− | end |
||
+ | '! style="text-align:left" | ' .. table.concat( blockSprites, '<br>' ) .. ( blockArgs["прим"] or '' ) |
||
− | local image, spriteCat = sprite.sprite{ |
||
+ | ) |
||
− | ["настройки"] = 'ПредметСпрайт', |
||
+ | |||
− | ftoolName, |
||
+ | local tool = mw.text.trim( simple and 'Инструмент' or blockArgs[2] or 'Любой' ):gsub( '^%l', string.upper ) |
||
− | ["назв"] = toolName, |
||
+ | local material = mw.text.trim( simple and blockArgs[2] or blockArgs[3] or 'Любой' ):gsub( '^%l', string.upper ) |
||
− | ["ссылка"] = tool |
||
+ | if tool == 'Нет' then |
||
− | } |
||
+ | material = tool |
||
− | toolCell = ( sortable and 'data-sort-value="' .. toolName .. '" |' or '' ) .. image |
||
+ | end |
||
− | table.insert( categories, spriteCat ) |
||
+ | if not simple then |
||
− | end |
||
+ | local hardnessText = hardnessVal |
||
− | table.insert( cells, '|' .. toolCell ) |
||
+ | if hardnessVal == -1 then |
||
− | end |
||
+ | hardnessText = ( sortable and 'data-sort-value="999" | ' or '' ) .. '∞' |
||
− | end |
||
+ | end |
||
− | |||
+ | table.insert( cells, '|' .. hardnessText ) |
||
− | local choices = {} |
||
+ | |||
− | local getChoice = function( choice, text ) |
||
+ | if showTool then |
||
− | if not choices[choice] then |
||
+ | local toolCell = '—' |
||
− | choices[choice] = f:expandTemplate{ title = 'Таблица выбора', args = { choice, '' } } |
||
+ | if tool ~= 'Любой' and tool ~= 'Нет' then |
||
− | end |
||
+ | local isMaterialSpecified = (material ~= 'Любой') and (material ~= 'Нет') |
||
− | return choices[choice] .. text |
||
+ | local toolName = ( isMaterialSpecified and material .. ' ' or '' ) .. tool |
||
− | end |
||
+ | if toolName == 'Топор' then |
||
− | |||
+ | wooden = 'Деревянный ' |
||
− | if hardnessVal == '?' then |
||
+ | else |
||
− | fillCells( cells, '|?', 6 ) |
||
+ | wooden = 'Деревянная ' |
||
− | else |
||
+ | end |
||
− | local processTime = function( num ) |
||
+ | local fullToolName = ( (not isMaterialSpecified) and wooden or '' ) .. toolName |
||
− | if num < 0.05 then -- Blocks have a minimum breaking time of 1 game tick (0.05 seconds) |
||
+ | local image, spriteCat = sprite.sprite{ |
||
− | num = 0.05 |
||
+ | ["данные"] = 'Спрайт/Предмет', |
||
− | else -- And they must be broken in multiples of 1 game tick (0.05 seconds) |
||
+ | fullToolName, |
||
− | num = math.ceil( num * 20 ) / 20 |
||
+ | ["назв"] = toolName, |
||
− | end |
||
+ | ["ссылка"] = tool |
||
− | return num |
||
+ | } |
||
− | end |
||
+ | toolCell = ( sortable and 'data-sort-value="' .. toolName .. '" |' or '' ) .. image |
||
− | |||
+ | table.insert( categories, spriteCat ) |
||
− | if unbreakable then |
||
+ | end |
||
− | table.insert( cells, '| ' .. ( sortable and 'data-sort-value="999" ' or '' ) .. getChoice( 'нет', '∞' ) ) |
||
+ | table.insert( cells, '|' .. toolCell ) |
||
− | if showTool then |
||
+ | end |
||
− | fillCells( cells, '|—', 5 ) |
||
− | + | end |
|
+ | |||
− | else |
||
− | + | local choices = {} |
|
+ | local function getChoice( choice, text ) |
||
− | if blockArgs["дроп"] == '0' then |
||
+ | if not choices[choice] then |
||
− | drop = 'частично' |
||
+ | choices[choice] = f:expandTemplate{ title = 'Таблица выбора', args = { choice, ''} } |
||
− | end |
||
+ | end |
||
− | local requiredLevel = unbreakable and 999 or materialGrade[material] |
||
+ | return choices[choice] .. text |
||
− | local insertMaterialCell = function( material ) |
||
+ | end |
||
− | local willDrop = drop |
||
+ | |||
− | if materialGrade[material] < requiredLevel then |
||
+ | local function processTime( num ) |
||
− | willDrop = 'нет' |
||
+ | -- переданное число было умножено на 100 |
||
− | end |
||
+ | if num <= 5 then -- Минимальные временные затраты на разрушение блока равны 1 игровому такту (0,05 секунды) |
||
− | local breakTime = processTime( hardnessVal / materialSpeed[material] * ( willDrop == 'нет' and 5 or 1.5 ) ) |
||
+ | num = 0.05 |
||
− | table.insert( cells, '|' .. getChoice( willDrop, breakTime ) ) |
||
+ | else -- Блоки должны быть разрушены кратно 1 игровому такту (0,05 секунды) |
||
− | end |
||
+ | num = math.ceil( num / 5 ) / 20 |
||
− | |||
+ | end |
||
− | if not showTool or tool == 'Любое' or tool == 'Нет' then |
||
+ | return num |
||
− | insertMaterialCell( 'Любое' ) |
||
+ | end |
||
− | if showTool then |
||
+ | |||
− | fillCells( cells, '|—', 5 ) |
||
+ | if hardnessVal == '?' then |
||
− | end |
||
+ | fillCells( cells, '|?', numberMaterials + 1 ) |
||
− | else |
||
+ | else |
||
− | for _, material in ipairs{ 'Любое', 'Деревянный', 'Каменный', 'Железный', 'Алмазный', 'Золотой' } do |
||
+ | if unbreakable then |
||
− | insertMaterialCell( material ) |
||
+ | table.insert( cells, '| ' .. ( sortable and 'data-sort-value="999" ' or '' ) .. getChoice( 'no', '∞' ) ) |
||
− | end |
||
+ | if showTool then |
||
− | end |
||
+ | fillCells( cells, '|—', numberMaterials ) |
||
− | end |
||
+ | end |
||
− | |||
+ | else |
||
− | if not simple and ( showShears or showSword ) then |
||
− | + | local drop = 'да' |
|
+ | local forceDrop = false |
||
− | if showShears then |
||
+ | if blockArgs["дроп"] == '0' then |
||
− | table.insert( tools, 'Ножницы' ) |
||
+ | drop = 'частично' |
||
− | end |
||
+ | elseif blockArgs["дроп"] == '1' then |
||
− | if showSword then |
||
+ | forceDrop = 'да' |
||
− | table.insert( tools, 'Меч' ) |
||
+ | end |
||
− | end |
||
+ | local requiredLevel = unbreakable and 999 or materialGrade[material] |
||
− | if hardnessVal == '?' then |
||
+ | local function insertMaterialCell( material ) |
||
− | fillCells( cells, '|?', #tools ) |
||
+ | local shouldDrop = drop |
||
− | else |
||
+ | if materialGrade[material] < requiredLevel then |
||
− | local toolSpeed = { |
||
+ | shouldDrop = 'нет' |
||
− | Shears = 1, |
||
+ | end |
||
− | Sword = 1.5 |
||
+ | -- предотвращение потери точности числа с плавающей запятой: умножить его на 100 и разделить в функции "processTime" |
||
− | } |
||
+ | local breakTime = processTime( hardnessVal * (shouldDrop == 'нет' and 500 or 150) / materialSpeed[material] ) |
||
− | if blocks[1] == 'Шерсть' then |
||
+ | if breakTime == 0.05 then |
||
− | toolSpeed.Shears = 5 |
||
+ | shouldDrop = "запланировано" |
||
− | elseif blocks[1] == 'Листва' then |
||
+ | end |
||
− | toolSpeed.Shears = 15 |
||
+ | table.insert( cells, '|' .. getChoice( forceDrop or shouldDrop, breakTime ) ) |
||
− | elseif blocks[1] == 'Паутина' then |
||
+ | end |
||
− | toolSpeed.Sword = 15 |
||
+ | |||
− | toolSpeed.Shears = 15 |
||
+ | if not showTool or tool == 'Любой' or tool == 'Нет' then |
||
− | end |
||
+ | insertMaterialCell( 'Любой' ) |
||
− | |||
+ | if showTool then |
||
− | for _, tool in ipairs( tools ) do |
||
+ | fillCells( cells, '|—', numberMaterials ) |
||
− | local toolDrop = blockArgs[mw.ustring.lower( tool )] |
||
+ | end |
||
− | if not toolDrop then |
||
+ | else |
||
− | table.insert( cells, '|—' ) |
||
+ | for _, material in ipairs{ 'Любой', 'Деревянный', 'Каменный', 'Железный', 'Алмазный', 'Незеритовый', 'Золотой' } do |
||
− | else |
||
+ | insertMaterialCell( material ) |
||
− | local willDrop = 'да' |
||
+ | end |
||
− | if toolDrop == '0' then |
||
+ | end |
||
− | willDrop = 'частично' |
||
+ | end |
||
− | end |
||
+ | end |
||
− | |||
+ | |||
− | local breakTime = processTime( hardnessVal / toolSpeed[tool] * 1.5 ) |
||
+ | if not simple and ( showShears or showSword ) then |
||
− | table.insert( cells, '|' .. getChoice( willDrop, breakTime ) ) |
||
+ | local tools = {} |
||
− | end |
||
+ | if showShears then |
||
− | end |
||
+ | table.insert( tools, 'Ножницы' ) |
||
− | end |
||
+ | end |
||
− | end |
||
+ | if showSword then |
||
− | end |
||
+ | table.insert( tools, 'Меч' ) |
||
− | |||
+ | end |
||
− | if not horizontal then |
||
+ | if hardnessVal == '?' then |
||
− | cells = table.concat( cells, '\n' ) |
||
+ | fillCells( cells, '|?', #tools ) |
||
− | end |
||
+ | else |
||
− | table.insert( tableParts, cells ) |
||
+ | local toolSpeed = { |
||
− | end |
||
+ | ["Ножницы"] = 1, |
||
− | |||
+ | ["Меч"] = 1.5 |
||
− | if horizontal then |
||
+ | } |
||
− | local blocksArgs = {} |
||
+ | if blocks[1] == 'Шерсть' then |
||
− | for _, arg in ipairs{ 1, 'прим', 'спрайт', 'ссылка', 'предмет', 'дроп', 2, 3, 'ножницы', 'меч' } do |
||
+ | toolSpeed["Ножницы"] = 5 |
||
− | if args[arg] then |
||
+ | elseif blocks[1] == 'Листва' then |
||
− | local col = 0 |
||
+ | toolSpeed["Ножницы"] = 15 |
||
− | for colVal in mw.text.gsplit( args[arg], '%s*;%s*' ) do |
||
+ | elseif blocks[1] == 'Паутина' then |
||
− | col = col + 1 |
||
+ | toolSpeed["Меч"] = 15 |
||
− | if colVal ~= '' then |
||
+ | toolSpeed["Ножницы"] = 15 |
||
− | if not blocksArgs[col] then |
||
+ | elseif blocks[1] == 'Бамбук' then |
||
− | blocksArgs[col] = {} |
||
+ | toolSpeed["Меч"] = 5000 |
||
− | end |
||
+ | end |
||
− | |||
+ | |||
− | blocksArgs[col][arg] = colVal |
||
+ | for _, tool in ipairs( tools ) do |
||
− | end |
||
+ | local toolDrop = blockArgs[mw.ustring.lower( tool )] |
||
− | end |
||
+ | if not toolDrop then |
||
− | end |
||
+ | table.insert( cells, '|—' ) |
||
− | end |
||
+ | else |
||
− | for _, block in ipairs( blocksArgs ) do |
||
+ | local willDrop = 'да' |
||
− | insertBlock( block ) |
||
+ | if toolDrop == '0' then |
||
− | end |
||
+ | willDrop = 'частично' |
||
− | |||
+ | end |
||
− | local columns = #tableParts |
||
+ | -- предотвращение потери точности числа с плавающей запятой: умножить его на 100 и разделить в функции "processTime" |
||
− | for row = 1, #tableParts[1] do |
||
+ | local breakTime = processTime( hardnessVal * 150 / toolSpeed[tool] ) |
||
− | local cells = {} |
||
+ | if breakTime == 0.05 then |
||
− | for col = 1, columns do |
||
+ | willDrop = "запланировано" |
||
− | table.insert( cells, tableParts[col][row] ) |
||
+ | end |
||
− | end |
||
− | + | table.insert( cells, '|' .. getChoice( willDrop, breakTime ) ) |
|
+ | end |
||
− | end |
||
+ | end |
||
− | |||
+ | end |
||
− | -- Insert breaking time header after block row when simple, or after tool or hardness row when not |
||
+ | end |
||
− | table.insert( rows, simple and 3 or showTool and 5 or 4, '! colspan="' .. columns + 1 .. '" |' .. breakingTimeHeader ) |
||
+ | |||
− | else |
||
+ | if not horizontal then |
||
− | insertBlock( args ) |
||
+ | cells = table.concat( cells, '\n' ) |
||
− | for _, row in ipairs( tableParts ) do |
||
+ | end |
||
− | table.insert( rows, row ) |
||
+ | table.insert( tableParts, cells ) |
||
− | end |
||
− | + | end |
|
+ | |||
− | table.insert( rows, '' ) |
||
+ | if horizontal then |
||
− | |||
− | + | local blocksArgs = {} |
|
+ | for _, arg in ipairs{ 1, 'прим', 'спрайт', 'ссылка', 'предмет', 'дроп', 2, 3, 'ножницы', 'меч' } do |
||
− | if args["подвал"] or horizontal then |
||
+ | if args[arg] then |
||
− | note = f:preprocess( '<references group="note"/>' ) |
||
+ | local col = 0 |
||
− | |||
+ | for colVal in mw.text.gsplit( args[arg], '%s*;%s*' ) do |
||
− | if args["подвал"] == '2' then |
||
+ | col = col + 1 |
||
− | table.insert( rows, header or getDplVar( 'header' ) ) |
||
+ | if colVal ~= '' then |
||
− | end |
||
+ | if not blocksArgs[col] then |
||
− | table.insert( rows, '|}' ) |
||
+ | blocksArgs[col] = {} |
||
− | |||
+ | end |
||
− | if not horizontal then |
||
+ | |||
− | f:callParserFunction( '#dplvar:set', |
||
+ | blocksArgs[col][arg] = colVal |
||
− | 'breaking header', '', |
||
+ | end |
||
− | 'breaking hidetool', '', |
||
+ | end |
||
− | 'breaking hideshears', '', |
||
+ | end |
||
− | 'breaking hidesword', '', |
||
+ | end |
||
− | 'breaking simple', '', |
||
+ | for _, block in ipairs( blocksArgs ) do |
||
− | 'breaking sortable', '' |
||
+ | insertBlock( block ) |
||
− | ) |
||
− | + | end |
|
+ | |||
− | elseif #dplVars > 0 then |
||
+ | local columns = #tableParts |
||
− | f:callParserFunction( '#dplvar:set', dplVars ) |
||
+ | for row = 1, #tableParts[1] do |
||
− | end |
||
+ | local cells = {} |
||
− | |||
+ | for col = 1, columns do |
||
− | return table.concat( rows, '\n|-\n' ) .. note .. table.concat( categories ) |
||
+ | table.insert( cells, tableParts[col][row] ) |
||
+ | end |
||
+ | table.insert( rows, table.concat( cells, '\n' ) ) |
||
+ | end |
||
+ | |||
+ | -- Вставка заголовка времени разрушения после строки блока при "simple", или после строки инструмента или твердости, если "simple" не используется |
||
+ | table.insert( rows, simple and 3 or showTool and 5 or 4, '! colspan="' .. columns + 1 .. '" |' .. getBreakingTimeHeader( f ) ) |
||
+ | else |
||
+ | insertBlock( args ) |
||
+ | for _, row in ipairs( tableParts ) do |
||
+ | table.insert( rows, row ) |
||
+ | end |
||
+ | end |
||
+ | table.insert( rows, '' ) |
||
+ | |||
+ | local note = '' |
||
+ | if args["подвал"] or horizontal then |
||
+ | note = f:preprocess( '<references group="FN"/>' ) |
||
+ | |||
+ | if args["подвал"] == '2' then |
||
+ | table.insert( rows, header or getDplVar( 'header' ) ) |
||
+ | end |
||
+ | table.insert( rows, '|}' ) |
||
+ | |||
+ | if not horizontal then |
||
+ | f:callParserFunction( '#dplvar:set', |
||
+ | 'breaking header', '', |
||
+ | 'breaking hidetool', '', |
||
+ | 'breaking hideshears', '', |
||
+ | 'breaking hidesword', '', |
||
+ | 'breaking simple', '', |
||
+ | 'breaking sortable', '' |
||
+ | ) |
||
+ | end |
||
+ | elseif #dplVars > 0 then |
||
+ | f:callParserFunction( '#dplvar:set', dplVars ) |
||
+ | end |
||
+ | |||
+ | return table.concat( rows, '\n|-\n' ) .. note .. table.concat( categories ) |
||
end |
end |
||
return p |
return p |
Текущая версия от 12:29, 9 июля 2021
Модуль реализует шаблон {{Таблица разрушаемости}}
Зависимости
local p = {}
local breakingTimeHeader;
local function getBreakingTimeHeader( f )
if breakingTimeHeader == nil then
breakingTimeHeader = 'Время [[Добывание|разрушения]]' .. f:preprocess( '<ref group="FN" name="breakingtimenote">Время для незачарованных инструментов, используемых игроком без наложенных эффектов, в секундах. Для большей информации см. [[Добывание#Скорость|Добывание § Скорость]].</ref>' )
end
return breakingTimeHeader
end
function p.row( f )
local args = require( [[Модуль:ProcessArgs]] ).norm()
local sprite = require( [[Модуль:Спрайт]] )
local function getDplVar( var )
local val = f:callParserFunction( '#dplvar', 'breaking ' .. var )
if val == '' then
val = false
end
return val
end
local dplVars = {}
local function setDplVar( var, val )
table.insert( dplVars, 'breaking ' .. var )
table.insert( dplVars, val or '1' )
end
local rows = {}
local tableParts = {}
local categories = {}
local horizontal
args[1] = args[1] or '' -- чтобы не переделывать весь модуль, ранее считавший, что тут строка
-- Подставляет название страницы, если параметр args[1] не указан.
if (args[1] == '') or (args[1] == nil) then
args[1] = mw.title.getCurrentTitle().text
args["встолбик"] = 1
end
if args["встолбик"] or args[1]:match( ';' ) then
horizontal = true
end
local showTool = true
local showShears = true
local showSword = true
local header, sortable, simple
if horizontal or not getDplVar( 'header' ) then
if args["скрытьинструмент"] or horizontal and ( not args[2] or args[2]:lower() == 'any' or args[2]:lower() == 'none' ) then
showTool = false
setDplVar( 'hidetool' )
breakingTimeHeader = 'Время [[Добывание|разрушения]]'
end
if args["скрытьножницы"] or horizontal and not args["ножницы"] then
showShears = false
setDplVar( 'hideshears' )
end
if args["скрытьмеч"] or horizontal and not args["меч"] then
showSword = false
setDplVar( 'hidesword' )
end
sortable = not horizontal and args["сортировка"]
if sortable then
setDplVar( 'sortable' )
end
simple = args["простой"]
if simple and not horizontal then
setDplVar( 'simple' )
end
local tableClasses = { 'wikitable' }
if sortable then
table.insert( tableClasses, 'sortable' )
end
table.insert( rows, ' {| class="' .. table.concat( tableClasses, ' ' ) .. '" style="text-align:center"' )
local sortType = ''
if sortable then
sortType = 'data-sort-type="number"'
end
local rowspan = ''
if not horizontal then
rowspan = 'rowspan="2" '
end
header = {
'! ' .. rowspan .. ' | Блок'
}
if not simple then
table.insert( header, '! ' .. rowspan .. sortType .. ' | Прочность' )
if showTool then
table.insert( header, '! ' .. rowspan .. ' | Инструмент' )
end
end
local toolColumns = {}
if showTool then
local firstTool = mw.text.trim( simple and 'Инструмент' or args[2] or 'Любой' ):gsub( '^%l', string.upper )
firstTool = mw.text.split( firstTool, ';' )[1]
if firstTool == 'Кирка' or firstTool == 'Лопата' or firstTool == 'Мотыга' then
toolColumns = { 'Деревянная', 'Каменная', 'Железная', 'Алмазная', 'Незеритовая', 'Золотая' }
else
toolColumns = { 'Деревянный', 'Каменный', 'Железный', 'Алмазный', 'Незеритовый', 'Золотой' }
end
end
table.insert( toolColumns, 1, 'По умолчанию' )
if not simple then
if showShears then
table.insert( toolColumns, 'Ножницы' )
end
if showSword then
table.insert( toolColumns, 'Меч' )
end
end
if not horizontal then
table.insert( header, '! colspan="' .. #toolColumns .. '" |' .. getBreakingTimeHeader( f ) )
table.insert( header, '|-' )
end
local toolSprites = {
["Деревянный"] = {'Спрайт/Блок', 'дубовые-доски' },
["Деревянная"] = {'Спрайт/Блок', 'дубовые-доски' },
["Каменный"] = { 'Спрайт/Блок', 'булыжник' },
["Каменная"] = { 'Спрайт/Блок', 'булыжник' },
["Железный"] = { 'Спрайт/Предмет', 'железный-слиток' },
["Железная"] = { 'Спрайт/Предмет', 'железный-слиток' },
["Алмазный"] = { 'Спрайт/Предмет', 'алмаз' },
["Алмазная"] = { 'Спрайт/Предмет', 'алмаз' },
["Незеритовый"] = { 'Спрайт/Предмет', 'незеритовый-слиток' },
["Незеритовая"] = { 'Спрайт/Предмет', 'незеритовый-слиток' },
["Золотой"] = { 'Спрайт/Предмет', 'золотой-слиток' },
["Золотая"] = { 'Спрайт/Предмет', 'золотой-слиток' },
["Ножницы"] = { 'Спрайт/Предмет', 'ножницы' },
["Меч"] = { 'Спрайт/Предмет', 'деревянный-меч' }
}
for _, tool in ipairs( toolColumns ) do
if toolSprites[tool] then
local image, spriteCat = sprite.sprite{
["данные"] = toolSprites[tool][1],
toolSprites[tool][2],
["текст"] = tool
}
table.insert( header, '! style="text-align:left" ' .. sortType .. ' | ' .. image )
table.insert( categories, spriteCat )
else
table.insert( header, '! ' .. sortType .. ' | ' .. tool )
end
end
if not horizontal then
header = table.concat( header, '\n' )
setDplVar( 'header', header )
end
table.insert( tableParts, header )
else
showTool = not getDplVar( 'hidetool' )
showShears = not getDplVar( 'hideshears' )
showSword = not getDplVar( 'hidesword' )
sortable = getDplVar( 'sortable' )
simple = getDplVar( 'simple' )
end
local hardness = require( [[Модуль:Значения блоков]] ).value
local function fillCells( cellsTable, text, num )
for i = 1, num do
table.insert( cellsTable, text )
end
end
local materialGrade = {
["Любой"] = 0, ["Любая"] = 0,
["Деревянный"] = 1, ["Деревянная"] = 1,
["Золотой"] = 1, ["Золотая"] = 1,
["Каменный"] = 2, ["Каменная"] = 2,
["Железный"] = 3, ["Железная"] = 3,
["Алмазный"] = 4, ["Алмазная"] = 4,
["Незеритовый"] = 5, ["Незеритовая"] = 5,
["Нет"] = 6
}
local materialSpeed = {
["Нет"] = 1,
["Любой"] = 1, ["Любая"] = 1,
["Деревянный"] = 2, ["Деревянная"] = 2,
["Каменный"] = 4, ["Каменная"] = 4,
["Железный"] = 6, ["Железная"] = 6,
["Алмазный"] = 8, ["Алмазная"] = 8,
["Незеритовый"] = 9, ["Незеритовая"] = 9,
["Золотой"] = 12, ["Золотая"] = 12
}
local numberMaterials = 6
local function insertBlock( blockArgs )
local cells = {}
local blocks = mw.text.split( blockArgs[1], '%s*,%s*' )
local hardnessVal = tonumber( hardness{ blocks[1], ["тип"] = 'прочности' } )
if not hardnessVal then
hardnessVal = '?'
local title = mw.title.getCurrentTitle()
if title.namespace == 0 and not title.isSubpage then
table.insert(categories, '[[Категория:Отсутствующие значения прочности]]')
end
end
local unbreakable
if hardnessVal == -1 or blockArgs.liquid then
unbreakable = true
end
local blockSprites = {}
local links = mw.text.split( blockArgs["ссылка"] or '', '%s*,%s*' )
local ids = mw.text.split( blockArgs["спрайт"] or '', '%s*,%s*' )
local items = mw.text.split( blockArgs["предмет"] or '', '%s*,%s*' )
for i, block in ipairs( blocks ) do
local link
if not links[i] and links[1] ~= '' then
link = links[1]
elseif links[i] ~= '' then
link = links[i]
end
local id
if not ids[i] and ids[1] ~= '' then
id = ids[1]
elseif ids[i] ~= '' then
id = ids[i]
end
local blockText
if args["сократить"] then
blockText = block:gsub( args["сократить"] .. '$', '' )
else
blockText = block
end
local blockSpriteArgs = {
["данные"] = 'Спрайт/Блок',
block,
["текст"] = blockText,
["ссылка"] = link,
["ID"] = id
}
if items[i] == '1' or not items[i] and items[1] == '1' then
blockSpriteArgs["данные"] = 'Спрайт/Предмет'
end
local image, spriteCat = sprite.link( blockSpriteArgs )
table.insert( blockSprites, image )
table.insert( categories, spriteCat )
end
table.insert( cells,
'! style="text-align:left" | ' .. table.concat( blockSprites, '<br>' ) .. ( blockArgs["прим"] or '' )
)
local tool = mw.text.trim( simple and 'Инструмент' or blockArgs[2] or 'Любой' ):gsub( '^%l', string.upper )
local material = mw.text.trim( simple and blockArgs[2] or blockArgs[3] or 'Любой' ):gsub( '^%l', string.upper )
if tool == 'Нет' then
material = tool
end
if not simple then
local hardnessText = hardnessVal
if hardnessVal == -1 then
hardnessText = ( sortable and 'data-sort-value="999" | ' or '' ) .. '∞'
end
table.insert( cells, '|' .. hardnessText )
if showTool then
local toolCell = '—'
if tool ~= 'Любой' and tool ~= 'Нет' then
local isMaterialSpecified = (material ~= 'Любой') and (material ~= 'Нет')
local toolName = ( isMaterialSpecified and material .. ' ' or '' ) .. tool
if toolName == 'Топор' then
wooden = 'Деревянный '
else
wooden = 'Деревянная '
end
local fullToolName = ( (not isMaterialSpecified) and wooden or '' ) .. toolName
local image, spriteCat = sprite.sprite{
["данные"] = 'Спрайт/Предмет',
fullToolName,
["назв"] = toolName,
["ссылка"] = tool
}
toolCell = ( sortable and 'data-sort-value="' .. toolName .. '" |' or '' ) .. image
table.insert( categories, spriteCat )
end
table.insert( cells, '|' .. toolCell )
end
end
local choices = {}
local function getChoice( choice, text )
if not choices[choice] then
choices[choice] = f:expandTemplate{ title = 'Таблица выбора', args = { choice, ''} }
end
return choices[choice] .. text
end
local function processTime( num )
-- переданное число было умножено на 100
if num <= 5 then -- Минимальные временные затраты на разрушение блока равны 1 игровому такту (0,05 секунды)
num = 0.05
else -- Блоки должны быть разрушены кратно 1 игровому такту (0,05 секунды)
num = math.ceil( num / 5 ) / 20
end
return num
end
if hardnessVal == '?' then
fillCells( cells, '|?', numberMaterials + 1 )
else
if unbreakable then
table.insert( cells, '| ' .. ( sortable and 'data-sort-value="999" ' or '' ) .. getChoice( 'no', '∞' ) )
if showTool then
fillCells( cells, '|—', numberMaterials )
end
else
local drop = 'да'
local forceDrop = false
if blockArgs["дроп"] == '0' then
drop = 'частично'
elseif blockArgs["дроп"] == '1' then
forceDrop = 'да'
end
local requiredLevel = unbreakable and 999 or materialGrade[material]
local function insertMaterialCell( material )
local shouldDrop = drop
if materialGrade[material] < requiredLevel then
shouldDrop = 'нет'
end
-- предотвращение потери точности числа с плавающей запятой: умножить его на 100 и разделить в функции "processTime"
local breakTime = processTime( hardnessVal * (shouldDrop == 'нет' and 500 or 150) / materialSpeed[material] )
if breakTime == 0.05 then
shouldDrop = "запланировано"
end
table.insert( cells, '|' .. getChoice( forceDrop or shouldDrop, breakTime ) )
end
if not showTool or tool == 'Любой' or tool == 'Нет' then
insertMaterialCell( 'Любой' )
if showTool then
fillCells( cells, '|—', numberMaterials )
end
else
for _, material in ipairs{ 'Любой', 'Деревянный', 'Каменный', 'Железный', 'Алмазный', 'Незеритовый', 'Золотой' } do
insertMaterialCell( material )
end
end
end
end
if not simple and ( showShears or showSword ) then
local tools = {}
if showShears then
table.insert( tools, 'Ножницы' )
end
if showSword then
table.insert( tools, 'Меч' )
end
if hardnessVal == '?' then
fillCells( cells, '|?', #tools )
else
local toolSpeed = {
["Ножницы"] = 1,
["Меч"] = 1.5
}
if blocks[1] == 'Шерсть' then
toolSpeed["Ножницы"] = 5
elseif blocks[1] == 'Листва' then
toolSpeed["Ножницы"] = 15
elseif blocks[1] == 'Паутина' then
toolSpeed["Меч"] = 15
toolSpeed["Ножницы"] = 15
elseif blocks[1] == 'Бамбук' then
toolSpeed["Меч"] = 5000
end
for _, tool in ipairs( tools ) do
local toolDrop = blockArgs[mw.ustring.lower( tool )]
if not toolDrop then
table.insert( cells, '|—' )
else
local willDrop = 'да'
if toolDrop == '0' then
willDrop = 'частично'
end
-- предотвращение потери точности числа с плавающей запятой: умножить его на 100 и разделить в функции "processTime"
local breakTime = processTime( hardnessVal * 150 / toolSpeed[tool] )
if breakTime == 0.05 then
willDrop = "запланировано"
end
table.insert( cells, '|' .. getChoice( willDrop, breakTime ) )
end
end
end
end
if not horizontal then
cells = table.concat( cells, '\n' )
end
table.insert( tableParts, cells )
end
if horizontal then
local blocksArgs = {}
for _, arg in ipairs{ 1, 'прим', 'спрайт', 'ссылка', 'предмет', 'дроп', 2, 3, 'ножницы', 'меч' } do
if args[arg] then
local col = 0
for colVal in mw.text.gsplit( args[arg], '%s*;%s*' ) do
col = col + 1
if colVal ~= '' then
if not blocksArgs[col] then
blocksArgs[col] = {}
end
blocksArgs[col][arg] = colVal
end
end
end
end
for _, block in ipairs( blocksArgs ) do
insertBlock( block )
end
local columns = #tableParts
for row = 1, #tableParts[1] do
local cells = {}
for col = 1, columns do
table.insert( cells, tableParts[col][row] )
end
table.insert( rows, table.concat( cells, '\n' ) )
end
-- Вставка заголовка времени разрушения после строки блока при "simple", или после строки инструмента или твердости, если "simple" не используется
table.insert( rows, simple and 3 or showTool and 5 or 4, '! colspan="' .. columns + 1 .. '" |' .. getBreakingTimeHeader( f ) )
else
insertBlock( args )
for _, row in ipairs( tableParts ) do
table.insert( rows, row )
end
end
table.insert( rows, '' )
local note = ''
if args["подвал"] or horizontal then
note = f:preprocess( '<references group="FN"/>' )
if args["подвал"] == '2' then
table.insert( rows, header or getDplVar( 'header' ) )
end
table.insert( rows, '|}' )
if not horizontal then
f:callParserFunction( '#dplvar:set',
'breaking header', '',
'breaking hidetool', '',
'breaking hideshears', '',
'breaking hidesword', '',
'breaking simple', '',
'breaking sortable', ''
)
end
elseif #dplVars > 0 then
f:callParserFunction( '#dplvar:set', dplVars )
end
return table.concat( rows, '\n|-\n' ) .. note .. table.concat( categories )
end
return p