Modul:Entity/Facet/Hacking
Aus Star Citizen Wiki
Weitere Optionen
Die Dokumentation für dieses Modul kann unter Modul:Entity/Facet/Hacking/doc erstellt werden
require('strict')
--- @module Entity/Facet/Hacking
--- Hacking facet. A cryptokey / hacking chip (type FPS_Consumable, sub_type
--- Hacking — IcePick, Ripper, …) carries a `hacking_chip` block: how many breach
--- charges it holds, the multiplier it applies to the hack duration (below 1 is
--- faster), and the per-attempt error chance. Data-driven: fires on any entity
--- with a `hacking_chip` block.
local format = require('Module:Entity/Format')
local sectionBuilder = require('Module:Entity/SectionBuilder')
local msg = require('Module:Entity/Message').msg
local p = {}
--- 0-1 chance as a percentage ("0.9" -> "90%"); nil when absent.
---
--- @param value number|string|nil
--- @return string|nil
local function percent(value)
local n = tonumber(value)
if n == nil then
return nil
end
return format.formatNum(math.floor(n * 1000 + 0.5) / 10) .. '%'
end
--- @param apiData table|nil
--- @return boolean
function p.matches(apiData)
return apiData ~= nil and type(apiData.hacking_chip) == 'table'
end
--- @param ctx EntityHookContext
--- @return table[] Ordered list of section entries with key field
function p.getSections(ctx)
local apiData = ctx.apiData
local h = apiData.hacking_chip
if type(h) ~= 'table' then
return {}
end
local items = {}
local charges = tonumber(h.max_charges)
if charges and charges > 0 then
sectionBuilder.push(items, msg('Charges'), format.formatNum(charges))
end
-- duration_multiplier: below 1 hacks faster, so lower is better — green below ×1.
local dur = tonumber(h.duration_multiplier)
if dur ~= nil and dur ~= 1 then
sectionBuilder.push(
items,
msg('Hack time'),
format.colorByDirection('×' .. format.formatNum(dur), dur, 1, 'lower')
)
end
sectionBuilder.push(items, msg('Error chance'), percent(h.error_chance))
return sectionBuilder.build(sectionBuilder.section({
key = 'hacking',
label = 'Hacking',
collapsible = true,
items = items,
}))
end
--- @param ctx EntityHookContext
--- @return table<string, any>
function p.getStructuredData(ctx)
local apiData = ctx.apiData
local h = apiData.hacking_chip
if type(h) ~= 'table' then
return {}
end
local charges = tonumber(h.max_charges)
local err = tonumber(h.error_chance)
return {
charges = (charges and charges > 0) and charges or nil,
error_chance = err and (math.floor(err * 1000 + 0.5) / 10) or nil,
}
end
return p