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 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.getSale(frame) local date = require("Dev:Date") local tArgs = util.getArgs(frame)

local tOut = {" ", "The purchase cost was discounted to ", oneItem(tArgs[4] or "???"), " during the ", (tArgs[1] or "?"), "", " from the ", '???', " to the ", '???', "." }	if tArgs[2] and tArgs[2]:match("^%d%d%d%d%/%d%d%/%d%d$") then local endDate = date(tArgs[2]):adddays(tArgs[3] or 0):fmt("%Y/%m/%d") tOut[6] = " Sale " .. tArgs[2]:match("^(%d%d%d%d)%/%d%d%/%d%d$") tOut[8] = util.strDate(tArgs[2]) tOut[10] = util.strDate(endDate) end return table.concat(tOut) 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 " .. require("Module:UpdateNumber").getVersion({tArgs[1], "D"}) .. "."	else return tOut .. " for the " .. require("Module:LTEvent").getLTE({tArgs[1], nil, "D"}) .. "."	end end

return p