Module:Change

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

local p = {}

local EC = require("Module:EC").getEC local UpdateNo = require("Module:UpdateNumber").getVersion local util = require("Module:Utility")

function p.getRC(frame) local tArgs = util.getArgs(frame) local tOut = "" local k = 1 for i, item in pairs(tArgs) do		if tArgs[k + 1] then local tRC = { "", "the ", "", " rewards", " changed from ", "", tArgs[k + 2], " to ", "", tArgs[k + 3] }

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

if k == 1 then tRC[1] = " " tRC[2] = (tArgs["P"] or "The") .. " "			end if tArgs[k + 1] == "Cost" then tRC[4] = "purchase cost" if tArgs[k + 2]:match("^([^,]-)%s*[,%#]%s*([%/%,%d%?%-]*)$") then tRC[7] = EC({tArgs[k + 2]}) else tRC[7] = "" .. tArgs[k + 2] .. "" end if tArgs[k + 3]:match("^([^,]-)%s*[,%#]%s*([%/%,%d%?%-]*)$") then tRC[10] = EC({tArgs[k + 3]}) else tRC[10] = "" .. tArgs[k + 3] .. "" end elseif tArgs[k + 1] == "Build" then tRC[4] = "building time" elseif tArgs[k + 1] == "Time" then tRC[4] = "collect time" elseif tArgs[k + 1] == "XP" or tArgs[k + 1] == "Magic" then tRC[3] = tArgs[k + 1] .. " (" .. EC({tArgs[k + 1]}) .. ")" else tRC[4] = tArgs[k + 1]:lower end tOut = tOut .. table.concat(tRC) k = k + 3 end end return tOut .. " with " .. UpdateNo({tArgs[1], "D"}) .. "." end

function p.main(frame) local tArgs = util.getArgs(frame) local tOut = "" 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 ""), "", tArgs[k + 2], (tArgs[k + 3] and " to " or ""), "", 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] == "purchase cost" then if tArgs[k + 2]:match("^([^,]-)%s*[,%#]%s*([%/%,%d%?%-]*)$") then tCh[7] = EC({tArgs[k + 2]}) else tCh[7] = "" .. tArgs[k + 2] .. "" end if tArgs[k + 3]:match("^([^,]-)%s*[,%#]%s*([%/%,%d%?%-]*)$") then tCh[10] = EC({tArgs[k + 3]}) else tCh[10] = "" .. tArgs[k + 3] .. "" end elseif tArgs[k + 1] == "XP" or tArgs[k + 1] == "Magic" then tCh[3] = tArgs[k + 1] .. " (" .. EC({tArgs[k + 1]}) .. ")" .. " reward" elseif tArgs[k + 1] == "activity" then tCh[4] = " was added" tCh[7] = "" tCh[10] = ""

local sep = "" local aOut = "" local actname = mw.text.split((tArgs[k + 2] or ""), "%s*%$%s*") for idx = #actname, 1, -1 do aOut = ' "' .. actname[idx] .. '"' .. sep .. aOut if sep == "" then sep = " and" tCh[3] = "activities" tCh[4] = " were added" else sep = "," end end tCh[3] = tCh[3] .. aOut end tOut = tOut .. table.concat(tCh) k = k + 3 end end return tOut .. " with " .. UpdateNo({tArgs[1], "D"}) .. "." end

return p