細編集の要約なし |
|||
1行目: | 1行目: | ||
local p = {}; |
local p = {}; |
||
+ | |||
⚫ | |||
local function materialPlus( n ) |
local function materialPlus( n ) |
||
return { |
return { |
||
Wooden = n + 0, |
Wooden = n + 0, |
||
+ | Golden = n + 0, |
||
Stone = n + 1, |
Stone = n + 1, |
||
Iron = n + 2, |
Iron = n + 2, |
||
Diamond = n + 3, |
Diamond = n + 3, |
||
− | + | Netherite = n + 4 |
|
}; |
}; |
||
end |
end |
||
20行目: | 23行目: | ||
Axe = { |
Axe = { |
||
Wooden = -3.2, |
Wooden = -3.2, |
||
+ | Golden = -3.0, |
||
Stone = -3.2, |
Stone = -3.2, |
||
Iron = -3.1, |
Iron = -3.1, |
||
Diamond = -3.0, |
Diamond = -3.0, |
||
− | + | Netherite = -3.0 |
|
+ | }, |
||
+ | Hoe = { |
||
+ | Wooden = -3, |
||
+ | Golden = -3, |
||
+ | Stone = -2, |
||
+ | Iron = -1, |
||
+ | Diamond = 0, |
||
+ | Netherite = 0 |
||
}, |
}, |
||
− | Hoe = materialPlus( -3 ), |
||
Other = 0, |
Other = 0, |
||
}; |
}; |
||
38行目: | 49行目: | ||
Axe = { |
Axe = { |
||
Wooden = 6, |
Wooden = 6, |
||
+ | Golden = 6, |
||
Stone = 8, |
Stone = 8, |
||
Iron = 8, |
Iron = 8, |
||
Diamond = 8, |
Diamond = 8, |
||
− | + | Netherite = 9 |
|
}, |
}, |
||
Hoe = 0, |
Hoe = 0, |
||
48行目: | 60行目: | ||
local allTools = 'Sword;Trident;Shovel;Pickaxe;Axe;Hoe;その他'; |
local allTools = 'Sword;Trident;Shovel;Pickaxe;Axe;Hoe;その他'; |
||
− | local allMaterials = { 'Wooden', 'Stone', 'Iron', 'Diamond', ' |
+ | local allMaterials = { 'Wooden', 'Golden', 'Stone', 'Iron', 'Diamond', 'Netherite' }; |
+ | local numberMaterials = #allMaterials |
||
local dpsNote = '<ref group="注釈" name="dpsLimit%g">単一のターゲットに対して、DPSは[[ダメージ#無敵状態|ダメージ無効化時間]]により%gに制限される。</ref>'; |
local dpsNote = '<ref group="注釈" name="dpsLimit%g">単一のターゲットに対して、DPSは[[ダメージ#無敵状態|ダメージ無効化時間]]により%gに制限される。</ref>'; |
||
91行目: | 104行目: | ||
local tool = args.tool or error( '道具を指定してください', 2 ); |
local tool = args.tool or error( '道具を指定してください', 2 ); |
||
local speed = attackSpeed[tool] or attackSpeed.Other; |
local speed = attackSpeed[tool] or attackSpeed.Other; |
||
⚫ | |||
if args.showname then |
if args.showname then |
||
103行目: | 115行目: | ||
local speed = parseInfoArg( 'speed', args.speed or attackSpeed[tool] or attackSpeed.Other ); |
local speed = parseInfoArg( 'speed', args.speed or attackSpeed[tool] or attackSpeed.Other ); |
||
if speed.same then |
if speed.same then |
||
− | table.insert( r, '|colspan= |
+ | table.insert( r, '|colspan=' .. numberMaterials .. '| ' .. speed.same + 4 ); |
else |
else |
||
for _, material in ipairs( allMaterials ) do |
for _, material in ipairs( allMaterials ) do |
||
112行目: | 124行目: | ||
local damage = parseInfoArg( 'damage', args.damage or attackDamage[tool] or attackDamage.Other ); |
local damage = parseInfoArg( 'damage', args.damage or attackDamage[tool] or attackDamage.Other ); |
||
if damage.same then |
if damage.same then |
||
− | table.insert( r, '|colspan= |
+ | table.insert( r, '|colspan=' .. numberMaterials .. '| {{hp|' .. damage.same + 1 .. '}}' ); |
else |
else |
||
for _, material in ipairs( allMaterials ) do |
for _, material in ipairs( allMaterials ) do |
||
120行目: | 132行目: | ||
if speed.same and damage.same then |
if speed.same and damage.same then |
||
− | local c = '|colspan= |
+ | local c = '|colspan=' .. numberMaterials .. '| ' .. ( damage.same + 1 ) * ( speed.same + 4 ); |
if speed.same > -2 then |
if speed.same > -2 then |
||
local d = ( damage.same + 1 ) * 2; |
local d = ( damage.same + 1 ) * 2; |
||
150行目: | 162行目: | ||
table.insert( t, '! 道具 ' ); |
table.insert( t, '! 道具 ' ); |
||
end |
end |
||
− | table.insert( t, '!colspan= |
+ | table.insert( t, '!colspan=' .. numberMaterials .. '| 攻撃速度 !!colspan=' .. numberMaterials |
+ | .. '| 攻撃力 !!colspan=' .. numberMaterials .. '| 攻撃/秒 (DPS)' ); |
||
end |
end |
||
190行目: | 203行目: | ||
end; |
end; |
||
end |
end |
||
− | |||
− | local Autolink = require( [[モジュール:Autolink]] ) |
||
local tools = frame.args.tools or allTools; |
local tools = frame.args.tools or allTools; |
2020年2月11日 (火) 05:52時点における最新版
local p = {};
local Autolink = require( [[モジュール:Autolink]] )
local function materialPlus( n )
return {
Wooden = n + 0,
Golden = n + 0,
Stone = n + 1,
Iron = n + 2,
Diamond = n + 3,
Netherite = n + 4
};
end
-- This is the value of the generic.attackSpeed attribute modifier.
-- Translate from the value shown in the tooltip by subtracting 4.
local attackSpeed = {
Sword = -2.4,
Trident = -2.9,
Shovel = -3.0,
Pickaxe = -2.8,
Axe = {
Wooden = -3.2,
Golden = -3.0,
Stone = -3.2,
Iron = -3.1,
Diamond = -3.0,
Netherite = -3.0
},
Hoe = {
Wooden = -3,
Golden = -3,
Stone = -2,
Iron = -1,
Diamond = 0,
Netherite = 0
},
Other = 0,
};
-- This is the value of the generic.attackDamage attribute modifier.
-- Translate from the value shown in the tooltip by subtracting 1.
local attackDamage = {
Sword = materialPlus( 3 ),
Trident = 8,
Shovel = materialPlus( 1.5 ),
Pickaxe = materialPlus( 1.0 ),
Axe = {
Wooden = 6,
Golden = 6,
Stone = 8,
Iron = 8,
Diamond = 8,
Netherite = 9
},
Hoe = 0,
Other = 0,
};
local allTools = 'Sword;Trident;Shovel;Pickaxe;Axe;Hoe;その他';
local allMaterials = { 'Wooden', 'Golden', 'Stone', 'Iron', 'Diamond', 'Netherite' };
local numberMaterials = #allMaterials
local dpsNote = '<ref group="注釈" name="dpsLimit%g">単一のターゲットに対して、DPSは[[ダメージ#無敵状態|ダメージ無効化時間]]により%gに制限される。</ref>';
local function parseInfoArg( what, arg )
local ret = arg;
if type( ret ) == 'string' then
local vals = mw.text.split( ret, '%s*,%s*' );
if #vals == 1 then
ret = tonumber( vals[1] );
if not ret then
error( 'Value for ' .. what .. ' must be either a single number or five numbers separated by commas', 3 );
end
elseif #vals == 5 then
ret = {}
for i, v in ipairs( vals ) do
v = tonumber( v );
if not v then
error( 'Value for ' .. what .. ' must be either a single number or five numbers separated by commas', 3 );
end
ret[allMaterials[i]] = v;
end
else
error( 'Value for ' .. what .. ' must be either a single number or five numbers separated by commas', 3 );
end
end
if type( ret ) == 'number' then
ret = { same = ret }
for _, material in ipairs( allMaterials ) do
ret[material] = ret.same;
end
end
return ret;
end
function p.infoTableRow( frame )
local r = {};
local args = frame.args or frame;
local tool = args.tool or error( '道具を指定してください', 2 );
local speed = attackSpeed[tool] or attackSpeed.Other;
if args.showname then
if tool == 'その他' then
table.insert( r, '! その他' );
else
table.insert( r, '! [[' .. Autolink.invlink(tool, 'nolink') .. ']]' );
end
end
local speed = parseInfoArg( 'speed', args.speed or attackSpeed[tool] or attackSpeed.Other );
if speed.same then
table.insert( r, '|colspan=' .. numberMaterials .. '| ' .. speed.same + 4 );
else
for _, material in ipairs( allMaterials ) do
table.insert( r, '| {{ItemSprite|' .. material .. ' ' .. tool .. '}} ' .. speed[material] + 4 );
end
end
local damage = parseInfoArg( 'damage', args.damage or attackDamage[tool] or attackDamage.Other );
if damage.same then
table.insert( r, '|colspan=' .. numberMaterials .. '| {{hp|' .. damage.same + 1 .. '}}' );
else
for _, material in ipairs( allMaterials ) do
table.insert( r, '| {{ItemSprite|' .. material .. ' ' .. tool .. '}} {{hp|' .. damage[material] + 1 .. '}}' );
end
end
if speed.same and damage.same then
local c = '|colspan=' .. numberMaterials .. '| ' .. ( damage.same + 1 ) * ( speed.same + 4 );
if speed.same > -2 then
local d = ( damage.same + 1 ) * 2;
c = c .. string.format( dpsNote, d, d );
end
table.insert( r, c );
else
for _, material in ipairs( allMaterials ) do
local c = '| {{ItemSprite|' .. material .. ' ' .. tool .. '}} ' .. ( damage[material] + 1 ) * ( speed[material] + 4 );
if speed[material] > -2 then
local d = ( damage[material] + 1 ) * 2;
c = c .. string.format( dpsNote, d, d );
end
table.insert( r, c );
end
end
r = table.concat( r, '\n' );
if type( frame.preprocess ) == 'function' then
r = frame:preprocess( r );
end
return r;
end
local function makeInfoTableHeader( t, showname )
table.insert( t, '{| class="wikitable" style="text-align:center"' );
table.insert( t, '|-' );
if showname then
table.insert( t, '! 道具 ' );
end
table.insert( t, '!colspan=' .. numberMaterials .. '| 攻撃速度 !!colspan=' .. numberMaterials
.. '| 攻撃力 !!colspan=' .. numberMaterials .. '| 攻撃/秒 (DPS)' );
end
function p.infoTableHeader( frame )
local t = {};
local showname = frame.args.showname or false
makeInfoTableHeader( t, showname );
return frame:preprocess( table.concat( t, '\n' ) );
end
function p.infoTable( frame )
local t = {};
local tools = frame.args.tools or allTools;
local showname = frame.args.showname or string.find( tools, ';', 0, true )
makeInfoTableHeader( t, showname );
for tool in mw.text.gsplit( tools, '%s*;%s*' ) do
table.insert( t, '|-' );
table.insert( t, p.infoTableRow{ tool = tool, showname = showname } );
end
table.insert( t, '|}' );
return frame:preprocess( table.concat( t, '\n' ) );
end
function p.damageReductionTable( frame )
local formula;
if frame.args.enchantment then
formula = function ( t, speed )
return ( ( t + 0.5 ) * ( 4 + speed ) / 20 );
end;
else
formula = function ( t, speed )
return 0.2 + ( ( t + 0.5 ) * ( 4 + speed ) / 20 ) ^ 2 * 0.8;
end;
end
local tools = frame.args.tools or allTools;
local minSpeed = 0;
local rows = {};
for tool in mw.text.gsplit( tools, '%s*;%s*' ) do
local speeds = attackSpeed[tool] or attackSpeed.Other;
if type( speeds ) == 'table' then
local materials = {};
local rowSpeeds = {};
for _, material in ipairs( allMaterials ) do
local speed = speeds[material];
if not materials[speed] then
materials[speed] = '';
table.insert( rowSpeeds, speed );
minSpeed = math.min( minSpeed, speed );
end
materials[speed] = materials[speed] .. '{{ItemSprite|' .. material .. ' ' .. tool .. '}}';
end
table.insert( rows, { Autolink.invlink( tool ), materials, rowSpeeds } );
else
table.insert( rows, { Autolink.invlink( tool ), nil, { speeds } } );
minSpeed = math.min( minSpeed, speeds );
end
end
local maxTicks = 0;
if frame.args.maxTicks then
maxTicks = tonumber( frame.args.maxTicks ) or error( 'Value for maxTicks must be a number', 2 )
maxTicks = math.ceil( maxTicks );
else
maxTicks = 20 / ( 4 + minSpeed );
while formula( maxTicks, minSpeed ) < 0.99995 do
maxTicks = maxTicks + 1;
end
end
local t = {};
table.insert( t, '{| class="wikitable" style="text-align:center"' );
table.insert( t, '|-' );
table.insert( t, '!rowspan=2 colspan=2| アイテム' );
table.insert( t, '!colspan=' .. maxTicks + 1 .. '| 溜め時間(秒)' );
table.insert( t, '|-' );
for i = 0, maxTicks do
table.insert( t, string.format('! %.2f', i / 20 ) );
end
for _, row in ipairs( rows ) do
local tool, materials, speeds = unpack( row );
for _, speed in ipairs( speeds ) do
table.insert( t, '|-' );
if tool then
if tool ~= 'その他' then
tool = '[[' .. tool .. ']]';
end
if materials then
table.insert( t, '|rowspan=' .. #speeds .. '| ' .. tool );
else
table.insert( t, '|colspan=2| ' .. tool );
end
tool = nil;
end
if materials then
table.insert( t, '|style="white-space:nowrap"| ' .. materials[speed] );
end
for i = 0, maxTicks do
local v = formula( i, speed );
if v >= 0.99995 then
table.insert( t, string.format('|colspan=%d style="text-align:left"| 100%%', maxTicks - i + 1 ) );
break;
else
table.insert( t, string.format('| %.2f%%', v * 100 ) );
end
end
end
end
table.insert( t, '|}' );
return frame:preprocess( table.concat( t, '\n' ) );
end
return p;