Module:Change

--[==[-- -- LUA script to get Reward Changes -- getRC: get Reward Changes data based on input parameters --]==]

local p = {}

local CHEST = require("Module:EnchantedChest").getChest local EC = require("Module:EC").getEC local LTE = require("Module:LTEvent").getLTE local UpdateNo = require("Module:UpdateNumber").getVersion local util = require("Module:Utility")

local function oneItem(item) if item and item:match(" Chests") then return CHEST({item, "L"}) elseif item and item:match("^EC") then return EC({item, nil, nil, nil, 25}) else return item end end

function p.main(frame) local tArgs = util.getArgs(frame) local tOut = "" if not tArgs[1] or not tArgs[2] then return "" end local k = 1 for i, item in pairs(tArgs) do		if tArgs[k + 1] then local tCh = { "", "the ", tArgs[k + 1], " changed", (tArgs[k + 2] and " from " or ""), oneItem(tArgs[k + 2]), (tArgs[k + 3] and " to " or ""), oneItem(tArgs[k + 3]) }

if tArgs[k + 4] then tCh[1] = ", " else tCh[1] = " and " end

if k == 1 then tCh[1] = " " tCh[2] = (tArgs["P"] or "The") .. " "			end if tArgs[k + 1] == "XP" or tArgs[k + 1] == "Magic" then tCh[3] = EC({tArgs[k + 1], "N", nil, nil, 25}) .. " reward" elseif tArgs[k + 1] == "activity" and ((not tArgs[k + 3] or tArgs[k + 3]=="") or (not tArgs[k + 2] or tArgs[k + 2]=="")) then tCh[5] = "" tCh[6] = "" tCh[7] = "" tCh[8] = ""

local sep = "" local aOut = "" local actType = " removed" local actname = {}

if not tArgs[k + 3] or tArgs[k + 3]=="" then actType = " added" actname = mw.text.split((tArgs[k + 2] or ""), "%s*%$%s*") elseif not tArgs[k + 2] or tArgs[k + 2]=="" then actname = mw.text.split((tArgs[k + 3] or ""), "%s*%$%s*") end

tCh[4] = " was" .. actType

for idx = #actname, 1, -1 do aOut = ' "' .. actname[idx] .. '"' .. sep .. aOut if sep == "" then sep = " and" else sep = "," tCh[3] = "activities" tCh[4] = (" were" .. actType) end end tCh[3] = tCh[3] .. aOut elseif tArgs[k + 1] == "activity" then tCh[3] = '"' .. tCh[6] .. '" activity' tCh[5] = " to " tCh[6] = '"'				tCh[7] = tCh[8]				tCh[8] = '"' end tOut = tOut .. table.concat(tCh) k = k + 3 end end if tArgs[1]:match("^%d%.%d%.%d$") then return tOut .. " with " .. UpdateNo({tArgs[1], "D"}) .. "."	else return tOut .. " for the " .. LTE({tArgs[1], nil, "D"}) .. "."	end end

return p