Модуль:Песочница/Pok: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 3: | Строка 3: | ||
local eventData = mw.loadData("Модуль:IanComradeBot/prototypes/StationEvent.json/data") | local eventData = mw.loadData("Модуль:IanComradeBot/prototypes/StationEvent.json/data") | ||
local cargoData = mw.loadData("Модуль:IanComradeBot/prototypes/cargo.json/data") | local cargoData = mw.loadData("Модуль:IanComradeBot/prototypes/cargo.json/data") | ||
local function splitIds(idsStr) | |||
local ids = {} | |||
for id in string.gmatch(idsStr, '([^,]+)') do | |||
table.insert(ids, mw.text.trim(id)) | |||
end | |||
return ids | |||
end | |||
local function buildCellEvent(name, eventID, image) | |||
local cell = '<div style="text-align:center;">' | |||
cell = cell .. "" .. name .. "<br>" | |||
cell = cell .. '[[File:' .. image .. '|64px]]' | |||
cell = cell .. '</div>' | |||
return cell | |||
end | |||
local function buildCharacteristicsList(frame, stationEvent) | |||
local list = "" | |||
local characteristics = { | |||
{"Вес", "Вес события в системе случайных событий (чем выше, тем чаще случается)", stationEvent.weight}, | |||
{"Мин. игроков", "Минимальное количество игроков для начала события", stationEvent.minimumPlayers}, | |||
{"Время старта", "Время с которого событие может начаться", (stationEvent.earliestStart and stationEvent.earliestStart .. " сек.")}, | |||
{"Длительность", "Длительность события в секундах", (stationEvent.duration and stationEvent.duration .. " сек.")} | |||
} | |||
for _, char in ipairs(characteristics) do | |||
local value = char[3] or "Нет" | |||
list = list .. "- " .. frame:expandTemplate{ | |||
title = "AltTooltip", | |||
args = { char[1], char[2] } | |||
} .. ": " .. value .. "<br>" | |||
end | |||
return list | |||
end | |||
function p.eventStation(frame) | function p.eventStation(frame) | ||
| Строка 11: | Строка 45: | ||
local description = args.description or "Нет описания" | local description = args.description or "Нет описания" | ||
local out = "" | local out = "" | ||
local ids = | local ids = splitIds(idsStr) | ||
for _, searchId in ipairs(ids) do | for _, searchId in ipairs(ids) do | ||
for _, event in ipairs(eventData) do | for _, event in ipairs(eventData) do | ||
if event.id == searchId then | if event.id == searchId then | ||
local cellEvent = | local cellEvent = buildCellEvent(name, image) | ||
local advert = (event.StationEvent and event.StationEvent.startAnnouncement) or "Нет оповещения" | local advert = (event.StationEvent and event.StationEvent.startAnnouncement) or "Нет оповещения" | ||
local characteristicsList = | local characteristicsList = buildCharacteristicsList(frame, event.StationEvent or {}) | ||
out = out .. "|-\n" | out = out .. "|-\n" | ||
out = out .. " | out = out .. "! " .. cellEvent .. "\n" | ||
out = out .. "| {{#invoke:Ftl|main|translation|" .. advert .. "}}\n" | out = out .. "| {{#invoke:Ftl|main|translation|" .. advert .. "}}\n" | ||
out = out .. "| " .. description .. "\n" | out = out .. "| " .. description .. "\n" | ||
| Строка 60: | Строка 74: | ||
local description = args.description or "Нет описания" | local description = args.description or "Нет описания" | ||
local out = "" | local out = "" | ||
local ids = | local ids = splitIds(idsStr) | ||
for _, searchId in ipairs(ids) do | for _, searchId in ipairs(ids) do | ||
for _, event in ipairs(eventData) do | for _, event in ipairs(eventData) do | ||
if event.id == searchId then | if event.id == searchId then | ||
local cellEvent = | local cellEvent = buildCellEvent(name, image) | ||
local cargo = event.CargoGiftsRule or {} | local cargo = event.CargoGiftsRule or {} | ||
local sender = cargo.sender or "Нет отправителя" | local sender = cargo.sender or "Нет отправителя" | ||
local cargoDescription = cargo.description or "Нет описания" | local cargoDescription = cargo.description or "Нет описания" | ||
local dest = cargo.dest or "Нет получателя" | local dest = cargo.dest or "Нет получателя" | ||
local advert = "Поздравляем! {{#invoke:Ftl|main|translation|" .. sender .. "}} решили отправить {{#invoke:Ftl|main|translation|" .. cargoDescription .. "}} {{#invoke:Ftl|main|translation|" .. dest .. "}} станции. Всё прибудет со следующей партией груза." | local advert = "Поздравляем! {{#invoke:Ftl|main|translation|" .. sender .. "}} решили отправить {{#invoke:Ftl|main|translation|" .. cargoDescription .. "}} {{#invoke:Ftl|main|translation|" .. dest .. "}} станции. Всё прибудет со следующей партией груза." | ||
local giftsCell = "" | local giftsCell = "" | ||
if cargo.gifts then | if cargo.gifts then | ||
| Строка 93: | Строка 97: | ||
end | end | ||
if productFound then | if productFound then | ||
giftsCell = giftsCell .. "- {{#invoke:Entity Lookup|getname|" .. productFound .. "}} | giftsCell = giftsCell .. "- {{#invoke:Entity Lookup|getname|" .. productFound .. "}} x" .. giftValue .. "<br>" | ||
else | else | ||
giftsCell = giftsCell .. "Ошибка: id продукта не найден." | giftsCell = giftsCell .. "Ошибка: id продукта не найден." | ||
| Строка 102: | Строка 106: | ||
end | end | ||
local characteristicsList = | local characteristicsList = buildCharacteristicsList(frame, event.StationEvent or {}) | ||
out = out .. "|-\n" | out = out .. "|-\n" | ||
out = out .. " | out = out .. "! " .. cellEvent .. "\n" | ||
out = out .. "| " .. advert .. "\n" | out = out .. "| " .. advert .. "\n" | ||
out = out .. "| " .. description .. "\n" | out = out .. "| " .. description .. "\n" | ||