Модуль:Prototypes/Химия/Растения
Материал из Space Station 14 Вики
Версия от 18:12, 5 августа 2025; Pok (обсуждение | вклад)
Для документации этого модуля может быть создана страница Модуль:Prototypes/Химия/Растения/doc
local p = {}
local plantData = mw.loadData("Модуль:IanComradeBot/prototypes/chem/plant.json/data")
local chemData = mw.loadData("Модуль:IanComradeBot/chem prototypes.json/data")
-- Шаблоны описания эффектов
local EFFECT_TEMPLATES = {
PlantAdjustPotency = "изменяет [[#Потенция|потенцию]] на %s.",
PlantAdjustHealth = "изменяет [[#Здоровье|здоровье]] на %s.",
PlantAdjustNutrition = "изменяет [[#Потребление нутриентов|нутриенты]] на %s.",
PlantAdjustWater = "изменяет [[#Потребление воды|воду]] на %s.",
PlantAdjustToxins = "изменяет [[#Устойчивость к токсинам|токсины]] на %s.",
PlantAdjustPests = "изменяет [[#Защита от вредителей|вредителей]] на %s.",
PlantAdjustWeeds = "изменяет [[#Защита от сорняков|сорняки]] на %s.",
PlantAdjustMutationMod = "изменяет '''модификатор мутации''' на %s.",
PlantAdjustMutationLevel = "изменяет '''уровень мутации''' на %s.",
PlantAffectGrowth = "изменяет [[#Возраст|возраст]] на %s.",
-- более сложные эффекты, которые находятся в коде
PlantRestoreSeeds = "восстанавливает семена (делает растение не [[#Бесплодное|бесплодным]], если оно было таковым).",
PlantDestroySeeds = "уничтожает семена (делает растение [[#Бесплодное|бесплодным]]).",
PlantPhalanximine = "делает растение жизнеспособным (если оно было [[#Нежизнеспособно|нежизнеспособным]]).",
PlantCryoxadone = "уменьшает возраст растения.",
RobustHarvest = "специфический эффект:<ul>" ..
"<li>Если [[#Потенция|потенция]] растения меньше 50, она увеличивается на {{цвет|text|good|c='''3'''}} (до максимума 50).</li>" ..
"<li>Если [[#Потенция|потенция]] превышает 30, растение становится [[#Бесплодное|бесплодным]].</li>" ..
"<li>Если [[#Потенция|потенция]] достигла 50 и [[#Урожайность|урожайность]] больше 1, то с шансом '''10 %''' изменяет [[#Урожайность|урожайность]] на {{цвет|text|bad|c='''-1'''}}.</li>" ..
"</ul>",
PlantDiethylamine = "специфический эффект:<ul>" ..
"<li>С шансом '''10 %''' изменяет [[#Срок жизни|срок жизни]] на {{цвет|text|good|c='''1'''}}.</li>" ..
"<li>С шансом '''10 %''' изменяет [[#Выносливость|выносливость]] на {{цвет|text|good|c='''1'''}}.</li>" ..
"</ul>",
}
-- Вспомогательные функции
local function formatEffect(effect)
local rawType = effect['!type']
if not rawType then return "<li>Ошибка: не найден тип эффекта.</li>" end
local effectType = rawType:gsub("%s*%b{}", "")
local template = EFFECT_TEMPLATES[effectType]
local description
if template then
if effect.amount then
local num = tonumber(effect.amount)
local color = num and (num > 0 and "good" or "bad") or "text"
local amt = num and ((num > 0) and ("+" .. num) or tostring(num)) or tostring(effect.amount)
description = string.format(template, string.format("{{цвет|text|%s|c='''%s'''}}", color, amt))
else
description = template
end
else
description = string.format("<code>Неизвестный эффект: %s</code>", effectType)
end
if effect.probability and effect.probability < 1 then
local pct = tostring(effect.probability * 100)
description = string.format("С шансом '''%s %%''' %s", pct, description:sub(1,1):lower() .. description:sub(2))
end
return "<li>{{ucfirst:" .. description .. "}}</li>"
end
-- Основная функция
function p.reagentRow(frame)
local args = frame.args
local reagentId = args.id or ""
if reagentId == "" then
return [[<tr><td colspan="2">'''Ошибка: не указан ID реагента.'''</td></tr>]]
end
local reagentEntry
for _, r in ipairs(plantData) do
if r.id == reagentId then reagentEntry = r; break end
end
local chemEntry
for _, c in ipairs(chemData) do
if c.id == reagentId then chemEntry = c; break end
end
local entry = chemData[reagentId]
local reagentName = entry and entry.name or reagentId
local reagentCell = string.format("! [[Химия#chem_%s|%s]]", reagentId, reagentName)
local fragments = {}
if reagentEntry and type(reagentEntry.plantMetabolism) == 'table' then
for _, eff in ipairs(reagentEntry.plantMetabolism) do
table.insert(fragments, formatEffect(eff))
end
end
-- Ручное описание при вызове параметром "manualEffects"
if args.manualEffects and args.manualEffects ~= "" then
table.insert(fragments, args.manualEffects)
end
if reagentEntry and reagentEntry.chemicals then
table.insert(fragments, formatChemicals(reagentEntry))
end
local allItems = table.concat(fragments)
local effectsCell = string.format("| <ul>%s</ul>", allItems)
return frame:preprocess(string.format("|-\n%s\n%s", reagentCell, effectsCell))
end
return p