Module:ForgingBondsMultiplier

local Util = require "Module:Util" local lang = mw.language.getContentLanguage local bit32 = require "bit32" local uint32_t = (require "Module:CTypes").uint32_t local p = {}

local FB_DAYS = 14 local FB_PROBS = {30, 40, 30} local FB_MULTS = {100, 150, 200}

local function fn_ee40e0(v0, v1) local state = v1	for i=0,3 do		state = uint32_t.add(uint32_t.mul(1812433253, (bit32.bxor(state, bit32.rshift(state, 30)))), i)		v0[i+1] = state end end

local function fn_ee4230(v0, v1, v2) local t = v0[1]; local s = v0[4]; t = bit32.bxor(t,bit32.lshift(t,11)) t = bit32.bxor(t,bit32.rshift(t,8)) t = bit32.bxor(t,s); t = bit32.bxor(t,bit32.rshift(s,19)) v0[1] = v0[2]; v0[2] = v0[3]; v0[3] = v0[4]; v0[4] = t;	return math.min(v1, v2) + bit32.band(t,0x7FFFFFFF) % (math.abs(v1 - v2) + 1) end

local function get_multiplier(period, t0, probs, mults) local randbuf = {}; fn_ee40e0(randbuf, period + t0); local x = fn_ee4230(randbuf, 1, 100); for i=1,#probs do   	x = x - probs[i] if x <= 0 then return mults[i] end end return 0 end

local function get_multiplier_table(startTime, prngVersion) -- Returns a table of multipliers. hour 1 is UTC 7:00 if not prngVersion then error("prng version not provided") elseif prngVersion ~= 1 then error("prng version not supported") end local t0 = tonumber(lang:formatDate("U",startTime, false)) local t = {} for day=1,FB_DAYS do		t[day] = {} for hour=1,24 do			t[day][hour] = get_multiplier( (day-1) * 24 + (hour-1), t0, FB_PROBS, FB_MULTS) end end return t end

p.makeTable = function(frame) if Util.isNilOrEmpty(frame.args[1]) then error("Start time is empty") end local tbl = mw.html.create("table") :addClass("wikitable") :css("text-align", "center")

local tr = tbl:tag("tr") tr:tag("th"):attr("rowspan",2) tr:tag("th"):attr("colspan",24):wikitext("Hour (UTC)") tr = tbl:tag("tr") tr:tag("th"):wikitext("07:00") tr:tag("th"):wikitext("08:00") tr:tag("th"):wikitext("09:00") tr:tag("th"):wikitext("10:00") tr:tag("th"):wikitext("11:00") tr:tag("th"):wikitext("12:00") tr:tag("th"):wikitext("13:00") tr:tag("th"):wikitext("14:00") tr:tag("th"):wikitext("15:00") tr:tag("th"):wikitext("16:00") tr:tag("th"):wikitext("17:00") tr:tag("th"):wikitext("18:00") tr:tag("th"):wikitext("19:00") tr:tag("th"):wikitext("20:00") tr:tag("th"):wikitext("21:00") tr:tag("th"):wikitext("22:00") tr:tag("th"):wikitext("23:00") tr:tag("th"):wikitext("24:00") tr:tag("th"):wikitext("01:00") tr:tag("th"):wikitext("02:00") tr:tag("th"):wikitext("03:00") tr:tag("th"):wikitext("04:00") tr:tag("th"):wikitext("05:00") tr:tag("th"):wikitext("06:00") for day,daytable in ipairs(get_multiplier_table(frame.args[1])) do		local tr = tbl:tag("tr") tr:tag("th"):wikitext("Day "..day) for _,multiplier in ipairs(daytable) do			local r = tr:tag("td"):wikitext(string.format("%.1f×", multiplier / 100)) end end return tbl end

p.getMultiplierJSON = function(frame) if Util.isNilOrEmpty(frame.args[1]) then error("Start time is empty") end return mw.text.jsonEncode(get_multiplier_table( frame.args[1] )) end

return p