Jump to content
Menü aufrufen
Toggle preferences menu
Persönliches Menü aufrufen
Nicht angemeldet
Ihre IP-Adresse wird öffentlich sichtbar sein, wenn Sie Änderungen vornehmen.

Die Dokumentation für dieses Modul kann unter Modul:Entity/Facet/Medical/doc erstellt werden

require('strict')

--- @module Entity/Facet/Medical
--- Medical facet. A medical consumable (injector pen — type FPS_Consumable,
--- sub_type Medical/MedPack) carries a `medical` block describing the dose it
--- delivers: the blood drug level it raises, plus the combat buffs and impact
--- resistances the drug confers while active. Data-driven: fires on any entity
--- with a `medical` block, regardless of kind. (OxygenCap consumables like OxyPen
--- carry a `food` block instead, so the Consumable facet handles those.)

local format = require('Module:Entity/Format')
local sectionBuilder = require('Module:Entity/SectionBuilder')
local Util = require('Module:Entity/Facet/Util')
local msg = require('Module:Entity/Message').msg

local p = {}

-- Friendlier labels for the effect keys; falls back to title-case.
local EFFECT_LABELS = {
	a_d_s_enter = 'Aim-down-sights',
	stun_recovery = 'Stun recovery',
	move_speed = 'Movement speed',
	weapon_sway = 'Weapon sway',
	atrophic = 'Atrophy',
}

--- Collects the active effect keys as a sorted, comma-joined label list.
--- Handles both API shapes: a boolean flag map (combat_buffs /
--- impact_resistances — {stun_recovery=true,…}) and the magnitude map the
--- debuffs field uses ({atrophic=900}). A key counts as active unless its
--- value is explicitly false, so flag and magnitude maps both work; an empty
--- array ([]) yields nothing. Returns nil when no key is active.
---
--- @param effects table|nil
--- @return string|nil
local function effectList(effects)
	if type(effects) ~= 'table' then
		return nil
	end
	local labels = {}
	for k, v in pairs(effects) do
		if v ~= false and type(k) == 'string' then
			table.insert(labels, msg(EFFECT_LABELS[k] or Util.titleCase(k)))
		end
	end
	if #labels == 0 then
		return nil
	end
	table.sort(labels)
	return table.concat(labels, ', ')
end

--- @param apiData table|nil
--- @return boolean
function p.matches(apiData)
	return apiData ~= nil and type(apiData.medical) == 'table'
end

--- @param ctx EntityHookContext
--- @return table[] Ordered list of section entries with key field
function p.getSections(ctx)
	local apiData = ctx.apiData
	local m = apiData.medical
	if type(m) ~= 'table' then
		return {}
	end
	local nutrition = type(m.nutrition) == 'table' and m.nutrition or {}

	local items = {}

	local bdl = tonumber(nutrition.blood_drug_level)
	if bdl ~= nil then
		sectionBuilder.push(items, msg('Blood drug level'), format.formatNum(bdl))
	end
	sectionBuilder.push(items, msg('Combat buffs'), effectList(m.combat_buffs))
	sectionBuilder.push(items, msg('Impact resistances'), effectList(m.impact_resistances))
	sectionBuilder.push(items, msg('Debuffs'), effectList(m.debuffs))

	return sectionBuilder.build(sectionBuilder.section({
		key = 'medical',
		label = msg('Medical'),
		collapsible = true,
		items = items,
	}))
end

--- @param ctx EntityHookContext
--- @return table<string, any>
function p.getStructuredData(ctx)
	local apiData = ctx.apiData
	local m = apiData.medical
	if type(m) ~= 'table' then
		return {}
	end
	local nutrition = type(m.nutrition) == 'table' and m.nutrition or {}
	return { blood_drug_level = tonumber(nutrition.blood_drug_level) }
end

-- Test-only exports. Not part of the public API.
p._internal = {
	effectList = effectList,
	titleCase = Util.titleCase,
}

return p
Zuletzt geändert
Urheberrecht
Cookies helfen uns bei der Bereitstellung dieses Wikis. Durch die Nutzung des Star Citizen Wiki erklärst du dich damit einverstanden, dass wir Cookies speichern.