Модуль:Песочница/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 buildCellEvent(name, image, id)
    local cell = '<div style="text-align:center;">'
    cell = cell .. name .. "<br>"
    cell = cell .. "<span style='color:#adadad'>" .. id .. "</span><br>"
    cell = cell .. '[[File:' .. image .. '|64px]]'
    cell = cell .. '</div>'
    return cell
end
local function buildCharacteristicsList(frame, stationEvent)
    return frame:expandTemplate{
        title = "Prototypes/Механика/Случайный события",
        args = {
            weight = stationEvent.weight or "",
            minimumPlayers = stationEvent.minimumPlayers or "",
            earliestStart = stationEvent.earliestStart and (stationEvent.earliestStart) or "",
            duration = stationEvent.duration and (stationEvent.duration) or ""
        }
    }
end


function p.eventStation(frame)
function p.eventStation(frame)
     local args = frame.args
     local args = frame.args
     local idsStr = args.id or ""
     local searchId = args.id or ""
     local name = args.name or ""
     local name = args.name or ""
     local image = args.image or "test.png"
     local image = args.image or ""
     local description = args.description or "Нет описания"
     local description = args.description or "Нет описания"
     local out = ""
     local out = ""
     local ids = {}
      
     for id in string.gmatch(idsStr, '([^,]+)') do
     for _, event in ipairs(eventData) do
         table.insert(ids, mw.text.trim(id))
         if event.id == searchId then
    end
            local cellEvent = buildCellEvent(name, image, searchId)
            local advert = (event.StationEvent and event.StationEvent.startAnnouncement) or ""
            local characteristicsList = buildCharacteristicsList(frame, event.StationEvent or {})


    for _, searchId in ipairs(ids) do
             out = out .. "|-\n"
        for _, event in ipairs(eventData) do
            out = out .. "! " .. cellEvent .. "\n"
             if event.id == searchId then
            if advert ~= "" then
                local cellEvent = '<div style="text-align:center;">'
                cellEvent = cellEvent .. "'''" .. name .. "'''<br>"
                cellEvent = cellEvent .. "<span style='color:#adadad'>'''" .. event.id .. "'''</span><br>"
                cellEvent = cellEvent .. '[[File:' .. image .. '|64px]]'
                cellEvent = cellEvent .. '</div>'
                local advert = (event.StationEvent and event.StationEvent.startAnnouncement) or "Нет оповещения"
                local characteristicsList = ""
                local stationEvent = event.StationEvent or {}
                local characteristics = {
                    {"Вес", "Вес события в системе случайных событий (чем выше, тем чаще случается)", stationEvent.weight},
                    {"Мин. игроков", "Минимальное количество игроков для начала события", stationEvent.minimumPlayers},
                    {"Время старта", "Время с которого событие может начаться", (stationEvent.earliestStart and stationEvent.earliestStart .. " сек.")},
                    {"Длительность", "Длительность события в секундах", (stationEvent.duration and stationEvent.duration .. " сек.")}
                }
                for _, char in ipairs(characteristics) do
                    local charValue = char[3] or "Нет"
                    characteristicsList = characteristicsList .. "- " .. frame:expandTemplate{
                        title = "AltTooltip",
                        args = { char[1], char[2] }
                    } .. ": " .. charValue .. "<br>"
                end
                out = out .. "|-\n"
                out = out .. "| " .. cellEvent .. "\n"
                 out = out .. "| {{#invoke:Ftl|main|translation|" .. advert .. "}}\n"
                 out = out .. "| {{#invoke:Ftl|main|translation|" .. advert .. "}}\n"
                out = out .. "| " .. description .. "\n"
            else
                 out = out .. "| " .. characteristicsList .. "\n"
                 out = out .. "| Происходит без объявления\n"
                break
             end
             end
            out = out .. "| " .. description .. "\n"
            out = out .. "| " .. characteristicsList
            break
         end
         end
     end
     end
Строка 55: Строка 57:
function p.eventCargo(frame)
function p.eventCargo(frame)
     local args = frame.args
     local args = frame.args
     local idsStr = args.id or ""
     local searchId = args.id or ""
     local name = args.name or ""
     local name = args.name or ""
     local image = args.image or "test.png"
     local image = args.image or ""
    local description = args.description or "Нет описания"
     local out = ""
     local out = ""
     local ids = {}
      
 
     for _, event in ipairs(eventData) do
     for id in string.gmatch(idsStr, '([^,]+)') do
        if event.id == searchId then
        table.insert(ids, mw.text.trim(id))
            local cellEvent = buildCellEvent(name, image, searchId)
    end
            local cargo = event.CargoGiftsRule or {}
 
            local sender = cargo.sender or "Нет отправителя"
    for _, searchId in ipairs(ids) do
            local cargoDescription = cargo.description or "Нет описания"
        for _, event in ipairs(eventData) do
            local dest = cargo.dest or "Нет получателя"
            if event.id == searchId then
            local advert = "Поздравляем! {{#invoke:Ftl|main|translation|" .. sender .. "}} решили отправить {{#invoke:Ftl|main|translation|" .. cargoDescription .. "}} {{#invoke:Ftl|main|translation|" .. dest .. "}} станции. Всё прибудет со следующей партией груза."
                local cellEvent = '<div style="text-align:center;">'
                cellEvent = cellEvent .. "'''" .. name .. "'''<br>"
                cellEvent = cellEvent .. "<span style='color:#adadad'>'''" .. event.id .. "'''</span><br>"
                cellEvent = cellEvent .. '[[File:' .. image .. '|64px]]'
                cellEvent = cellEvent .. '</div>'


                local cargo = event.CargoGiftsRule or {}
            local giftsCell = ""
                local sender = cargo.sender or "Нет отправителя"
            if cargo.gifts then
                local cargoDescription = cargo.description or "Нет описания"
                for giftId, giftValue in pairs(cargo.gifts) do
                local dest = cargo.dest or "Нет получателя"
                    local productFound = nil
 
                    for _, cargoItem in ipairs(cargoData) do
                local advert = "Поздравляем! {{#invoke:Ftl|main|translation|" .. sender .. "}} решили отправить {{#invoke:Ftl|main|translation|" .. cargoDescription .. "}} {{#invoke:Ftl|main|translation|" .. dest .. "}} станции. Всё прибудет со следующей партией груза."
                        if cargoItem.id == giftId then
 
                            productFound = cargoItem.product
                local giftsCell = ""
                            break
                if cargo.gifts then
                    for giftId, giftValue in pairs(cargo.gifts) do
                        local productFound = nil
                        for _, cargoItem in ipairs(cargoData) do
                            if cargoItem.id == giftId then
                                productFound = cargoItem.product
                                break
                            end
                        end
                        if productFound then
                            giftsCell = giftsCell .. "- {{#invoke:Entity Lookup|getname|" .. productFound .. "}}: x" .. giftValue .. "<br>"
                        else
                            giftsCell = giftsCell .. "Ошибка: id продукта не найден."
                         end
                         end
                     end
                     end
                else
                    if productFound then
                    giftsCell = "Нет подарков"
                        giftsCell = giftsCell .. "- [[Таблица грузов#{{#invoke:Entity Lookup|getname|" .. productFound .. "}}|{{#invoke:Entity Lookup|getname|" .. productFound .. "}}]] x" .. giftValue .. "<br>"
                end
                    else
 
                         giftsCell = giftsCell .. "Ошибка: id продукта не найден."
                local characteristicsList = ""
                    end
                local stationEvent = event.StationEvent or {}
                local characteristics = {
                    {"Вес", "Вес события в системе случайных событий (чем выше, тем чаще случается)", stationEvent.weight},
                    {"Мин. игроков", "Минимальное количество игроков для начала события", stationEvent.minimumPlayers},
                    {"Время старта", "Время с которого событие может начаться", (stationEvent.earliestStart and stationEvent.earliestStart .. " сек.")},
                    {"Длительность", "Длительность события в секундах", (stationEvent.duration and stationEvent.duration .. " сек.")}
                }
                for _, char in ipairs(characteristics) do
                    local charValue = char[3] or "Нет"
                    characteristicsList = characteristicsList .. "- " .. frame:expandTemplate{
                        title = "AltTooltip",
                         args = { char[1], char[2] }
                    } .. ": " .. charValue .. "<br>"
                 end
                 end
            else
                giftsCell = "Нет подарков"
            end


                out = out .. "|-\n"
            local characteristicsList = buildCharacteristicsList(frame, event.StationEvent or {})
                out = out .. "| " .. cellEvent .. "\n"
            out = out .. "|-\n"
                out = out .. "| " .. advert .. "\n"
            out = out .. "! " .. cellEvent .. "\n"
                out = out .. "| " .. description .. "\n"
            out = out .. "| " .. advert .. "\n"
                out = out .. "| " .. characteristicsList .. "\n"
            out = out .. "| " .. giftsCell .. "\n"
                out = out .. "| " .. giftsCell .. "\n"
            out = out .. "| " .. characteristicsList
                break
            break
            end
         end
         end
     end
     end