Module:Buildup: Difference between revisionsGive feedback
Jump to navigation
Jump to search
Module for item buildup stats |
No edit summary |
||
| Line 55: | Line 55: | ||
-- Core calculation logic | -- Core calculation logic | ||
local function calculate_bps(hero, bb) | local function calculate_bps(hero, bb) | ||
if not hero or not hero.Weapon then return 0 end | |||
local rps = tonumber(hero.Weapon.RoundsPerSecond or 0) | |||
local spin_rps = tonumber(hero.Weapon.RoundsPerSecondAtMaxSpin or 0) | |||
-- 1. Handle Spin-up (McGinnis/Bebop) | |||
if spin_rps > 0 then | |||
rps = spin_rps | |||
end | |||
-- 2. Handle "Fake Burst" Logic (Paige/Doorman) | |||
-- If they have a burst interval, but only 1 bullet per burst, | |||
-- the game ignores that interval for Buildup calculation. | |||
local burst_count = tonumber(hero.Weapon.BulletsPerBurst or 1) | |||
local burst_interval = tonumber(hero.Weapon.BurstInterShotInterval or 0) | |||
if burst_count == 1 and burst_interval > 0 and rps > 0 then | |||
-- Convert RPS back to time | |||
local total_time = 1 / rps | |||
-- Remove the interval | |||
local effective_time = total_time - burst_interval | |||
-- Prevent division by zero if something is weird | |||
if effective_time > 0.001 then | |||
rps = 1 / effective_time | |||
end | |||
end | |||
if rps == 0 then return 0 end | |||
-- Formula: 100 / (BB * (RPS + 1)) | |||
return 100 / (bb * (rps + 1)) | |||
end | end | ||
| Line 89: | Line 108: | ||
--Generates a sortable wikitable for all heroes | --Generates a sortable wikitable for all heroes | ||
p.write_buildup_table = function(frame) | p.write_buildup_table = function(frame) | ||
local item_name = frame.args[1] | |||
local bb = get_item_bb(item_name) | |||
if not bb then return "Error: Item '" .. (item_name or "nil") .. "' not found." end | |||
local hero_list = {} | |||
for key, hero in pairs(heroes_data) do | |||
local is_dev = hero["InDevelopment"] == true | |||
local is_disabled = hero["IsDisabled"] == true | |||
if not is_dev and not is_disabled and hero["Weapon"] then | |||
local val = calculate_bps(hero, bb) | |||
if val > 0 then | |||
local shots = math.ceil(100 / val) | |||
table.insert(hero_list, { | |||
name = hero["Name"], | |||
bps = val, | |||
shots = shots | |||
}) | |||
end | |||
end | |||
end | |||
-- Sorting Logic | |||
table.sort(hero_list, function(a, b) | |||
-- Helper to strip "The " from names just for sorting | |||
local function clean_sort_name(name) | |||
if string.sub(name, 1, 4) == "The " then | |||
return string.sub(name, 5) | |||
end | |||
return name | |||
end | |||
return clean_sort_name(a.name) < clean_sort_name(b.name) | |||
end) | |||
-- Build Table | |||
local html = mw.html.create('table') | |||
html:addClass('wikitable sortable mw-collapsible') | |||
if item_name then | |||
html:tag('caption'):wikitext('Buildup Per Shot: ' .. item_name) | |||
end | |||
-- Headers | |||
local headerRow = html:tag('tr') | |||
headerRow:tag('th'):wikitext('Hero') | |||
headerRow:tag('th'):wikitext('% per shot') | |||
headerRow:tag('th'):wikitext('Shots to Proc') | |||
-- Rows | |||
for _, h in ipairs(hero_list) do | |||
local row = html:tag('tr') | |||
local icon_template = frame:expandTemplate{ title = 'HeroIcon', args = { h.name } } | |||
-- Use data-sort-value so the table sorts correctly even with the icon | |||
row:tag('td') | |||
:attr('data-sort-value', h.name) -- Uses the name including "The" for consistent default sort | |||
:wikitext(icon_template) | |||
row:tag('td'):wikitext(string.format("%.1f", h.bps)) | |||
row:tag('td'):wikitext(tostring(h.shots)) | |||
end | |||
return tostring(html) | |||
end | end | ||