Module:GFLCalc:修订间差异
来自OGAS数据中枢
更多操作
imported>GFLCalc gflcalc data import dv=sha256:e510650bd49bf03c |
无编辑摘要 |
||
| 第1行: | 第1行: | ||
--[[ | --[[ | ||
Module:GFLCalc —— 少女前线 人形 / 铁血 面板数值取数模块 | Module:GFLCalc —— 少女前线 人形 / 铁血 面板数值取数模块 | ||
用法(模板里): | 用法(模板里): | ||
| 第198行: | 第195行: | ||
return p | return p | ||
2026年10月19日 (一) 20:28的版本
此模块的文档可以在Module:GFLCalc/doc创建
--[[
Module:GFLCalc —— 少女前线 人形 / 铁血 面板数值取数模块
用法(模板里):
{{#invoke:GFLCalc|stat|M4A1|100|damage}}
{{#invoke:GFLCalc|stat|M4A1|100|damage|favor=100|mod=3}}
{{#invoke:GFLCalc|stat|Aegis_SWAP|13|accuracy|res=4|adv=2|shape=2|favor=96}}
{{#invoke:GFLCalc|brief|Aegis_SWAP|4|health}} -- 列表页用精简数据
{{#invoke:GFLCalc|num|Aegis_SWAP|4}} -- 解析度对应的编队数
]]
local p = {}
local ERR = '' -- 取不到时返回的内容(可改成 'N/A')
local FAVOR_STATS = { damage = true, accuracy = true, evasion = true }
-- 改造档位的等级上限(MOD1/2/3 共用同一套「改造」数据,只差上限)
local MOD_MAX = { [0] = 100, [1] = 110, [2] = 115, [3] = 120 }
local function favor_ratio(f)
if f < 10 then return 0.95 end
if f < 90 then return 1.00 end
if f < 140 then return 1.05 end
if f < 190 then return 1.10 end
return 1.15
end
local function ceil9(v)
return math.ceil(v - 1e-9)
end
-- 差值字符解码:编码表是 33..126 但跳过 34(") 与 92(\\),避免 JSON 转义
local function delta_of(byte)
if byte < 34 then return byte - 33 end
if byte < 92 then return byte - 34 end
return byte - 35
end
local function resolve(alias)
local a = mw.text.trim(tostring(alias or ''))
if a == '' then return nil end
local idx = mw.loadData('Module:GFLCalc/index')
return idx[a] or idx[a:lower()]
end
local function load(page, code)
local ok, data = pcall(mw.loadData, 'Module:GFLCalc/' .. page .. '/' .. code)
if not ok then return nil end
return data
end
local function clamp(v, lo, hi, default)
v = tonumber(v) or default
if v < lo then return lo end
if v > hi then return hi end
return v
end
-- ---------------------------------------------------------------- 人形
local function doll_value(d, stat, level, mod)
local series = d.mods[mod] or d.mods['0']
if not series then return nil end
if stat == 'armor' then return series.armor end
local arr = series[stat]
if not arr then return nil end
if level < 1 or level > #arr then return nil end
return arr[level]
end
-- ---------------------------------------------------------------- 铁血
local function sv_value(d, stat, level, res, adv, shape)
local blk = d.s[stat]
if not blk then return nil end
shape = (shape == 0) and 1 or shape -- 形态 0 与 1 同值
local idx = res * 25 + (adv - 1) * 5 + (shape - 1) + 1
local v = blk.b[idx]
if not v then return nil end
local off = (idx - 1) * 99
for i = 1, level - 1 do
v = v + delta_of(string.byte(blk.d, off + i))
end
return v
end
-- ---------------------------------------------------------------- 精简页
local DOLL_BRIEF_IDX = { hp = 1, damage = 2, accuracy = 3, evasion = 4, rof = 5, armor = 6 }
local SV_BRIEF_IDX = { health = 1, damage = 2, rof = 3, accuracy = 4, evasion = 5 }
local function brief_value(d, stat, level, opts)
if d.k == 'doll' then
local mod = clamp(opts.mod, 0, 3, 0)
local key = (mod >= 1 and d.v['3|1'] ~= nil) and '3' or '0'
local lvmax = (key == '0') and 100 or (MOD_MAX[mod] or 100)
level = clamp(level, 1, lvmax, 1)
local arr = d.v[key .. '|' .. tostring(level)]
if not arr then return nil end
local i = DOLL_BRIEF_IDX[stat]
return i and arr[i] or nil
end
local tier = d.tier or 1
local defadv = (tier == 1) and 3 or (tier == 2 and 2 or 1)
local res = clamp(opts.res, 0, 4, 0)
local adv = clamp(opts.adv, 1, 5, defadv)
local shape = clamp(opts.shape, 1, 5, 1)
local arr = d.v[res .. '|' .. adv .. '|' .. shape .. '|' .. tostring(level)]
if not arr then
arr = d.v[res .. '|' .. defadv .. '|1|' .. tostring(level)] -- 回落到默认状态
end
if not arr then return nil end
local i = SV_BRIEF_IDX[stat]
return i and arr[i] or nil
end
-- ---------------------------------------------------------------- 核心
--- 供其他 Lua 模块直接调用
-- @param alias 代码/英文名
-- @param level 等级
-- @param stat 属性(hp/damage/accuracy/evasion/rof/armor)
-- @param opts { favor=, mod=, res=, adv=, shape=, brief= }
function p.value(alias, level, stat, opts)
opts = opts or {}
local code = resolve(alias)
if not code then return nil end
stat = tostring(stat or 'hp'):lower()
local d = load(opts.brief and 'brief' or 'data', code)
if not d then return nil end
local v
if opts.brief then
v = brief_value(d, stat, clamp(level, 1, 120, 1), opts)
elseif d.k == 'doll' then
local mod = clamp(opts.mod, 0, 3, 0)
-- 数据里只有两套:'0' 未改造、'3' 已改造(MOD1/2/3 共用)。
local key = (mod >= 1 and d.mods['3'] ~= nil) and '3' or '0'
local lvmax = MOD_MAX[mod] or 100
if key == '0' then lvmax = 100 end
v = doll_value(d, stat, clamp(level, 1, lvmax, 1), key)
else
local tier = d.tier or 1
local defadv = (tier == 1) and 3 or (tier == 2 and 2 or 1)
v = sv_value(d, stat, clamp(level, 1, 100, 1),
clamp(opts.res, 0, 4, 0),
clamp(opts.adv, 1, 5, defadv),
clamp(opts.shape, 1, 5, 1))
end
if v == nil then return nil end
if FAVOR_STATS[stat] then
v = ceil9(v * favor_ratio(tonumber(opts.favor) or 50))
end
return v
end
--- {{#invoke:GFLCalc|stat|别名|等级|属性|favor=…|mod=…|res=…|adv=…|shape=…}}
function p.stat(frame)
local a = frame.args
local v = p.value(a[1], tonumber(a[2]) or 1, a[3], {
favor = tonumber(a.favor), mod = tonumber(a.mod),
res = tonumber(a.res), adv = tonumber(a.adv), shape = tonumber(a.shape),
})
if v == nil then return ERR end
return tostring(v)
end
--- 精简数据:{{#invoke:GFLCalc|brief|别名|等级|属性|…}}
function p.brief(frame)
local a = frame.args
local v = p.value(a[1], tonumber(a[2]) or 1, a[3], {
favor = tonumber(a.favor), mod = tonumber(a.mod),
res = tonumber(a.res), adv = tonumber(a.adv), shape = tonumber(a.shape),
brief = true,
})
if v == nil then return ERR end
return tostring(v)
end
--- 解析度对应的编队数:{{#invoke:GFLCalc|num|Aegis_SWAP|4}}
function p.num(frame)
local a = frame.args
local code = resolve(a[1])
if not code then return ERR end
local d = load('data', code)
if not d or not d.num then return ERR end
local res = clamp(a[2], 0, 4, 0)
return tostring(d.num[res + 1])
end
--- 数据版本:{{#invoke:GFLCalc|dv}}
function p.dv()
local idx = mw.loadData('Module:GFLCalc/index')
return tostring(idx['__dv__'] or '')
end
return p