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 LTE = require("Module:LTEvent").getLTE local UpdateNo = require("Module:UpdateNumber").getVersion local util = require("Module:Utility")

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 ""), "", 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" or tArgs[k + 1] == "building rewards" 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" and (not tArgs[k + 3] or tArgs[k + 3]=="") then tCh[4] = " was added" tCh[5] = "" tCh[7] = ""

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" else sep = "," tCh[3] = "activities" tCh[4] = " were added" end end tCh[3] = tCh[3] .. aOut elseif tArgs[k + 1] == "activity" and (not tArgs[k + 2] or tArgs[k + 2]=="") then tCh[4] = " was removed" tCh[5] = "" tCh[7] = ""

local sep = "" local aOut = "" local actname = mw.text.split((tArgs[k + 3] or ""), "%s*%$%s*") for idx = #actname, 1, -1 do aOut = ' "' .. actname[idx] .. '"' .. sep .. aOut if sep == "" then sep = " and" else sep = "," tCh[3] = "activities" tCh[4] = " were removed" end end tCh[3] = tCh[3] .. aOut 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