|
|
| (не показано 35 промежуточных версий этого же участника) |
| Строка 1: |
Строка 1: |
| local p = {}
| |
|
| |
|
| -- Конфигурация
| |
| local CHEM_DATA_PATH = "Модуль:IanComradeBot/prototypes/chem/plant.json/data"
| |
|
| |
| local EFFECT_TEMPLATES = {
| |
| PlantAdjustNutrition = "Увеличивает [[#Потребление нутриентов|нутриенты]] на %s.",
| |
| PlantAdjustHealth = "Изменяет [[#Здоровье|здоровье]] на %s.",
| |
| PlantAdjustMutationMod = "Изменяет '''модификатор мутации''' на %s.",
| |
| PlantAdjustToxins = "Увеличивает [[#Устойчивость к токсинам|токсины]] на %s.",
| |
| PlantAdjustPests = "Уменьшает [[#Защита от вредителей|вредителей]] на %s.",
| |
| PlantAdjustWeeds = "Уменьшает [[#Защита от сорняков|сорняки]] на %s.",
| |
| PlantAdjustPotency = "Изменяет [[#Потенция|потенцию]] на %s.",
| |
| PlantAffectGrowth = "Увеличивает [[#Возраст|возраст]] на %s.",
| |
| PlantAdjustWater = "Изменяет [[#Потребление воды|воду]] на %s.",
| |
| PlantAdjustMutationLevel = "Увеличивает '''уровень мутации''' на %s.",
| |
| -- Для более сложных эффектов лучше использовать параметр manual_effects
| |
| PlantRestoreSeeds = "Восстанавливает семена (делает растение не [[#Бесплодное|бесплодным]], если оно было таковым).",
| |
| PlantDestroySeeds = "Уничтожает семена (делает растение [[#Бесплодное|бесплодным]]).",
| |
| PlantPhalanximine = "Делает растение жизнеспособным (если оно было нежизнеспособным).",
| |
| PlantCryoxadone = "Уменьшает возраст растения.",
| |
| RobustHarvest = "Запускает специфический эффект 'Робаст харвест'.",
| |
| PlantDiethylamine = "Запускает специфический эффект 'Диэтиламин'."
| |
| }
| |
|
| |
| -- Вспомогательные функции
| |
| local function formatAmount(amount)
| |
| local color = amount > 0 and "good" or "bad"
| |
| return string.format("{{цвет|text|%s|c='''%s'''}}", color, tostring(amount))
| |
| end
| |
|
| |
| local function formatEffect(effect)
| |
| local effectType = effect.type:gsub("!type:", "")
| |
| local template = EFFECT_TEMPLATES[effectType]
| |
|
| |
| if not template then
| |
| return "<li>Неизвестный эффект: " .. effectType .. "</li>"
| |
| end
| |
|
| |
| local description
| |
| if effect.amount then
| |
| local formatted_amount = formatAmount(effect.amount)
| |
| description = string.format(template, formatted_amount)
| |
| else
| |
| description = string.format(template, "")
| |
| end
| |
|
| |
| if effect.probability and effect.probability < 1 then
| |
| local chance = tostring(effect.probability * 100)
| |
| description = string.format("С шансом '''%s %%''' %s", chance, mw.ustring.lower(mw.ustring.sub(description, 1, 1)) .. mw.ustring.sub(description, 2))
| |
| end
| |
|
| |
| return "<li>" .. description .. "</li>"
| |
| end
| |
|
| |
| function p.reagentRow(frame)
| |
| local args = frame:getParent().args
| |
| local reagentId = args.id
| |
|
| |
| if not reagentId then
| |
| return "<tr><td colspan='2'>'''Ошибка в модуле ReagentEffects: не указан ID реагента.'''</td></tr>"
| |
| end
| |
|
| |
| local success, chemData = pcall(mw.loadData, CHEM_DATA_PATH)
| |
| if not success or not chemData then
| |
| return string.format("<tr><td colspan='2'>'''Ошибка: не удалось загрузить данные из %s.'''</td></tr>", CHEM_DATA_PATH)
| |
| end
| |
|
| |
| local reagent = chemData[reagentId]
| |
| if not reagent then
| |
| return string.format("<tr><td colspan='2'>'''Ошибка: реагент с ID '%s' не найден в базе данных.'''</td></tr>", reagentId)
| |
| end
| |
|
| |
| local reagentName = reagent.name or reagentId
| |
| local reagentCell = string.format("! [[Химия#chem_%s|%s]]", reagentId, reagentName)
| |
|
| |
| local effectsList = {}
| |
| if reagent.plantMetabolism then
| |
| for _, effectData in ipairs(reagent.plantMetabolism) do
| |
| table.insert(effectsList, formatEffect(effectData))
| |
| end
| |
| end
| |
|
| |
| local manualEffects = args.manual_effects
| |
| if manualEffects and manualEffects ~= '' then
| |
| for line in mw.text.gsplit(manualEffects, "\n") do
| |
| if line ~= '' then
| |
| table.insert(effectsList, line)
| |
| end
| |
| end
| |
| end
| |
|
| |
| local effectsCell = "| " .. table.concat(effectsList, "\n")
| |
|
| |
| return "|-\n" .. reagentCell .. "\n" .. effectsCell
| |
| end
| |
|
| |
| return p
| |