Модуль:Chemistry Lookup: различия между версиями

Материал из DarkStation Wiki
Нет описания правки
Нет описания правки
 
(не показана 1 промежуточная версия этого же участника)
Строка 1: Строка 1:
local prototypes = mw.loadData("Module:Chemistry Lookup/data")
local p = {}
local p = {}
p.chem = prototypes.chem
p.react = prototypes.react
p.groupDirection = prototypes.groupDirection
function p.readscalar(frame)
return mw.text.nowiki(p.chem[frame.args[1]][frame.args[2]])
end
function p.readscalarreact(frame)
if p.react[frame.args[1]][frame.args[2]] ~= nil then
return mw.text.nowiki(p.react[frame.args[1]][frame.args[2]])
else
return ""
end
end
function p.getcolor(frame)
return mw.text.nowiki(p.chem[frame.args[1]].color:sub(1, 7))
end
function p.gettextcolor(frame)
local basecol = p.chem[frame.args[1]].color
local red = tonumber(basecol:sub(2, 3), 16)
local grn = tonumber(basecol:sub(4, 5), 16)
local blu = tonumber(basecol:sub(6, 7), 16)
local luminance = math.sqrt(0.241*red*red + 0.691*grn*grn + 0.068*blu*blu)
if luminance > 100 then
return mw.text.nowiki("#000")
else
return mw.text.nowiki("#FFF")
end
end


-- Other functions omitted for brevity
function p.hasrecipe(frame)
return p.chem[frame.args[1]]["recipes"][1] ~= nil
end
 
function p.buildboxes(frame)
local out = ""
local group = frame.args[1]
for k in pairs(p.chem) do
if p.chem[k].group == group then
out = out .. frame:expandTemplate{ title = "Chembox", args = { prototype = k }}
elseif group == nil then
out = out .. frame:expandTemplate{ title = "Chembox", args = { prototype = k }}
end
end
return out
end
 
function p.buildreactboxes(frame)
local out = ""
for k in pairs(p.react) do
if p.react[k] and tablelength(p.react[k].effects) ~= 0 then
out = out .. frame:expandTemplate{ title = "Reactionbox", args = { reaction = k }}
end
end
return out
end
 
function p.buildrecipes(frame)
local chem = frame.args[1]
local out = ""
for id, recipe in pairs(p.chem[chem].recipes) do
out = out .. p.buildreaction(frame, recipe)
end
return out
end
 
function p.buildreactionext(frame)
local react = frame.args[1]
return p.buildreaction(frame, react)
end


function p.buildreaction(frame, react)
function p.buildreaction(frame, react)
    local data = p.react[react]
local data = p.react[react]
    local dest = "Chemistry"
if data == nil then
    local args = {}
return "Error: reaction data is nil for " .. tostring(react)
    local i = 0
end
   
    -- Processing reactants
    for k, v in pairs(data.reactants) do
        i = i + 1
        local dest = "Chemistry"
        if p.chem[k] and p.groupDirection[p.chem[k].group] ~= nil then
            dest = p.groupDirection[p.chem[k].group]
        end
        args["component-" .. i] = frame:expandTemplate{ title = "Chem Recipe Component", args = { reagent = k, amount = v.amount, dest = dest }}
    end
   
    -- Processing products
    i = 0
    for k, v in pairs(data.products) do
        i = i + 1
        local dest = "Chemistry"
        if p.chem[k] and p.groupDirection[p.chem[k].group] ~= nil then
            dest = p.groupDirection[p.chem[k].group]
        end
        args["result-" .. i] = frame:expandTemplate{ title = "Chem Recipe Component", args = { reagent = k, amount = v, dest = dest }}
    end
   
    -- Processing effects
    if data.effects ~= nil then
        args.effects = p.geneffectlist(data.effects, frame, 1)
    end


    return frame:expandTemplate{ title = "Chem Box Recipe", args = args }
local dest = "Chemistry"
local args = {}
local i = 0
 
if data.reactants then
for k, v in pairs(data.reactants) do
i = i + 1
local dest = "Chemistry"
if p.groupDirection[p.chem[k].group] ~= nil then
dest = p.groupDirection[p.chem[k].group]
end
args["component-" .. i] = frame:expandTemplate{ title = "Chem Recipe Component", args = { reagent = k, amount = v.amount, dest = dest }}
end
end
 
i = 0
if data.products then
for k, v in pairs(data.products) do
i = i + 1
local dest = "Chemistry"
if p.groupDirection[p.chem[k].group] ~= nil then
dest = p.groupDirection[p.chem[k].group]
end
args["result-" .. i] = frame:expandTemplate{ title = "Chem Recipe Component", args = { reagent = k, amount = v, dest = dest }}
end
end
if data.effects ~= nil then
args.effects = p.geneffectlist(data.effects, frame, 1)
end
 
return frame:expandTemplate{ title = "Chem Box Recipe", args = args }
end
end


-- Function to generate effect list
function p.checksatiatesthirst(frame)
function p.geneffectlist(effects, frame, rate)
local chem = frame.args[1]
    local out = ""
local met = p.chem[chem].metabolisms
    for l, w in pairs(effects) do
if met == nil then
        if w.id == "HealthChange" then
return ""
            out = out .. ":" .. p.genhealthchange(w, rate, frame) .. "\n"
end
        elseif w.id == "AdjustReagent" then
for k, v in pairs(met) do
            out = out .. ":" .. p.genadjustreagent(w, rate, frame) .. "\n"
for l, w in pairs(v.effects) do
        elseif w.id == "FlammableReaction" then
if w.id == "SatiateThirst" then
            out = out .. ":" .. p.genflammablereaction(w, frame) .. "\n"
return "1"
        elseif w.id == "AdjustTemperature" then
end
            out = out .. ":" .. p.genadjusttemperature(w, frame) .. "\n"
end
        elseif w.id == "GenericStatusEffect" then
end
            out = out .. ":" .. p.gengenericstatuseffect(w, frame) .. "\n"
return ""
        elseif w.id == "ExplosionReactionEffect" then
            out = out .. ":" .. p.genexplosionreactioneffect(w, frame) .. "\n"
        elseif w.id == "FoamAreaReactionEffect" then
            out = out .. ":" .. p.genfoamareareactioneffect(w, frame) .. "\n"
        elseif w.id == "SmokeAreaReactionEffect" then
            out = out .. ":" .. p.gensmokeareareactioneffect(w, frame) .. "\n"
        elseif w.id == "ModifyBleedAmount" then
            out = out .. ":" .. p.genmodifybleedamount(w, frame) .. "\n"
        end
    end
    return out
end
end


-- Function to handle SmokeAreaReactionEffect
function p.checksatiateshunger(frame)
function p.gensmokeareareactioneffect(r, frame)
local chem = frame.args[1]
    local conds = ""
local met = p.chem[chem].metabolisms
    if r.conditions ~= nil then  
if met == nil then
        conds = p.genconds(r.conditions, frame)
return ""
    end
end
    return frame:expandTemplate{ title = "SmokeAreaReactionEffect", args = { when = conds, prob = r.probability }}
for k, v in pairs(met) do
for l, w in pairs(v.effects) do
if w.id == "SatiateHunger" then
return "1"
end
end
end
return ""
end
end


-- Function to handle FoamAreaReactionEffect
function p.haseffects(frame)
function p.genfoamareareactioneffect(r, frame)
local chem = frame.args[1]
    local conds = ""
local met = p.chem[chem].metabolisms
    if r.conditions ~= nil then  
if met == nil then
        conds = p.genconds(r.conditions, frame)
return ""
    end
end
    return frame:expandTemplate{ title = "FoamAreaReactionEffect", args = { when = conds, prob = r.probability }}
for k, v in pairs(met) do
for l, w in pairs(v.effects) do
if w.id ~= "SatiateHunger" and w.id ~= "SatiateThirst" then
return "1"
end
end
end
return ""
end
end


-- Function to handle ExplosionReactionEffect
function p.geneffects(frame, chem)
function p.genexplosionreactioneffect(r, frame)
if chem == nil then
    local conds = ""
chem = frame.args[1]
    if r.conditions ~= nil then  
end
        conds = p.genconds(r.conditions, frame)
local met = p.chem[chem].metabolisms
    end
if met == nil then
    return frame:expandTemplate{ title = "ExplosionReactionEffect", args = { when = conds, prob = r.probability }}
return ""
end
local out = ""
for k, v in pairs(met) do
out = out .. "<b>" .. k .. "</b> (" .. v.rate .. " единиц в секунду)\n" .. p.geneffectlist(v.effects, frame, v.rate)
end
return out
end
end


-- Function to handle GenericStatusEffect
function p.geneffectlist(effects, frame, rate)
function p.gengenericstatuseffect(r, frame)
local out = ""
    local conds = ""
for l, w in pairs(effects) do
    if r.conditions ~= nil then  
-- Popup Message is ignored on purpose
        conds = p.genconds(r.conditions, frame)
if w.id == "HealthChange" then
    end
out = out .. ":" .. p.genhealthchange(w, rate, frame) .. "\n"
    return frame:expandTemplate{ title = "GenericStatusEffect", args = { key = r.Key, type = r.Type, time = r.Time, refresh = r.Refresh, when = conds, prob = r.probability }}
elseif w.id == "AdjustReagent" then
out = out .. ":" .. p.genadjustreagent(w, rate, frame) .. "\n"
elseif w.id == "FlammableReaction" then
out = out .. ":" .. p.genflammablereaction(w, frame) .. "\n"
elseif w.id == "AdjustTemperature" then
out = out .. ":" .. p.genadjusttemperature(w, frame) .. "\n"
elseif w.id == "GenericStatusEffect" then
out = out .. ":" .. p.gengenericstatuseffect(w, frame) .. "\n"
elseif w.id == "ExplosionReactionEffect" then
out = out .. ":" .. p.genexplosionreactioneffect(w, frame) .. "\n"
elseif w.id == "FoamAreaReactionEffect" then
out = out .. ":" .. p.genfoamareareactioneffect(w, frame) .. "\n"
elseif w.id == "SmokeAreaReactionEffect" then
out = out .. ":" .. p.gensmokeareareactioneffect(w, frame) .. "\n"
elseif w.id == "ModifyBleedAmount" then
out = out .. ":" .. p.genmodifybleedamount(w, frame) .. "\n"
end
end
return out
end
end


-- Function to handle AdjustTemperature
function p.gensmokeareareactioneffect(r, frame)
function p.genadjusttemperature(r, frame)
if r.conditions ~= nil then  
    local conds = ""
conds = p.genconds(r.conditions, frame)
    if r.conditions ~= nil then  
end
        conds = p.genconds(r.conditions, frame)
return frame:expandTemplate{ title = "SmokeAreaReactionEffect", args = { when = conds, prob = r.probability }}
    end
    return frame:expandTemplate{ title = "AdjustTemperature", args = { amount = r.Amount, when = conds, prob = r.probability }}
end
end


-- Function to handle FlammableReaction
function p.genfoamareareactioneffect(r, frame)
function p.genflammablereaction(r, frame)
if r.conditions ~= nil then  
    local conds = ""
conds = p.genconds(r.conditions, frame)
    if r.conditions ~= nil then  
end
        conds = p.genconds(r.conditions, frame)
return frame:expandTemplate{ title = "FoamAreaReactionEffect", args = { when = conds, prob = r.probability }}
    end
    return frame:expandTemplate{ title = "FlammableReaction", args = { multiplier = r.Multiplier, when = conds, prob = r.probability }}
end
end


-- Function to handle AdjustReagent
function p.genexplosionreactioneffect(r, frame)
function p.genadjustreagent(r, rate, frame)
if r.conditions ~= nil then  
    local conds = ""
conds = p.genconds(r.conditions, frame)
    if r.conditions ~= nil then  
end
        conds = p.genconds(r.conditions, frame)
return frame:expandTemplate{ title = "ExplosionReactionEffect", args = { when = conds, prob = r.probability }}
    end
    return frame:expandTemplate{ title = "AdjustReagent", args = { amount = r.Amount, reagent = r.Reagent, when = conds, prob = r.probability }}
end
end


-- Function to handle ModifyBleedAmount
function p.gengenericstatuseffect(r, frame)
function p.genmodifybleedamount(r, frame)
if r.conditions ~= nil then  
    local conds = ""
conds = p.genconds(r.conditions, frame)
    if r.conditions ~= nil then  
end
        conds = p.genconds(r.conditions, frame)
return frame:expandTemplate{ title = "GenericStatusEffect", args = { key = r.Key, type = r.Type, time = r.Time, refresh = r.Refresh, when = conds, prob = r.probability }}
    end
    return frame:expandTemplate{ title = "ModifyBleedAmount", args = { amount = r.Amount, when = conds, prob = r.probability }}
end
end


-- Function to handle HealthChange
function p.genadjusttemperature(r, frame)
function p.genhealthchange(h, rate, frame)
if r.conditions ~= nil then  
    local healst = {}
conds = p.genconds(r.conditions, frame)
    local dealst = {}
end
    local r = 1.0 / rate
return frame:expandTemplate{ title = "AdjustTemperature", args = { amount = r.Amount, when = conds, prob = r.probability }}
   
    -- Handling damage types
    if h.damage.types ~= nil then
        for k, v in pairs(h.damage.types) do
            if v < 0 then
                healst[k] = v * r
            else
                dealst[k] = v * r
            end
        end
    end
   
    -- Handling damage groups
    if h.damage.groups ~= nil then
        for k, v in pairs(h.damage.groups) do
            if v < 0 then
                healst[k] = v * r
            else
                dealst[k] = v * r
            end
        end
    end
   
    local heals = hchangelist(healst, frame)
    local deals = hchangelist(dealst, frame)
    local conds = nil
    if h.conditions ~= nil then  
        conds = p.genconds(h.conditions, frame)
    end
    return frame:expandTemplate{ title = "HealthChange", args = { heals = heals, deals = deals, when = conds, prob = h.probability }}
end
end


-- Helper function for generating health change list
function p.genflammablereaction(w, frame)
function hchangelist(l, frame)
return frame:expandTemplate{ title = "FlammableReaction", args = { prob = w.probability }}
    local out = ""
    local len = tablelength(l)
    local i = 0
    for k, v in pairs(l) do
        i = i + 1
        if len == i and i ~= 1 then
            out = out .. ", and "
        elseif i ~= 1 then
            out = out .. ", "
        end
        out = out .. hchange(k, v, frame)
    end
    return out
end
end


-- Helper function for health change
function p.genadjustreagent(r, rate, frame)
function hchange(ty, amnt, frame)
local conds = ""
    return frame:expandTemplate{ title = "HealthModifier", args = { adj = amnt, kind = ty } }
if r.conditions ~= nil then
conds = p.genconds(r.conditions, frame)
end
local amount = r.Amount
if r.ScaleWithRate == 1 then
amount = rate * r.Amount
end
return frame:expandTemplate{ title = "AdjustReagent", args = { name = r.Name, amount = amount, when = conds, prob = r.probability }}
end
end


-- Function to generate conditions
function p.genhealthchange(r, rate, frame)
function p.genconds(conds, frame)
local conds = ""
    local out = ""
if r.conditions ~= nil then
    local len = tablelength(conds)
conds = p.genconds(r.conditions, frame)
    local i = 0
end
    for k, v in pairs(conds) do
local amount = r.Amount
        i = i + 1
if r.ScaleWithRate == 1 then
        if len == i and i ~= 1 then
amount = rate * r.Amount
            out = out .. ", and "
end
        elseif i ~= 1 then
return frame:expandTemplate{ title = "HealthChange", args = { amount = amount, when = conds, prob = r.probability }}
            out = out .. ", "
        end
        out = out .. p.gencond(v, frame)
    end
    return out
end
end


-- Function to generate individual condition
function p.genconds(c, frame)
function p.gencond(c, frame)
if c.TimeIngested then
    if c.id == "TotalDamage" then
return frame:expandTemplate{ title = "TimeIngested", args = { min = c.TimeIngested.min, max = c.TimeIngested.max }}
        return frame:expandTemplate{ title = "TotalDamage", args = { min = c.Min, max = c.Max } }
elseif c.BloodAmount then
    elseif c.id == "ReagentThreshold" then
return frame:expandTemplate{ title = "BloodAmount", args = { min = c.BloodAmount.min, max = c.BloodAmount.max }}
        return frame:expandTemplate{ title = "ReagentThreshold", args = { min = c.Min, max = c.Max, reagent = c.Reagent } }
elseif c.TimeInBlood then
    elseif c.id == "OrganType" then
return frame:expandTemplate{ title = "TimeInBlood", args = { min = c.TimeInBlood.min, max = c.TimeInBlood.max }}
        return frame:expandTemplate{ title = "OrganType", args = { shouldhave = c.ShouldHave, type = c.Type } }
elseif c.OverallChemicalAmount then
    elseif c.id == "Temperature" then
return frame:expandTemplate{ title = "OverallChemicalAmount", args = { min = c.OverallChemicalAmount.min, max = c.OverallChemicalAmount.max, chem = c.OverallChemicalAmount.chemical }}
        return frame:expandTemplate{ title = "Temperature", args = { min = c.Min, max = c.Max } }
elseif c.ChemicalAmount then
    end
return frame:expandTemplate{ title = "ChemicalAmount", args = { min = c.ChemicalAmount.min, max = c.ChemicalAmount.max, chem = c.ChemicalAmount.chemical }}
    return ""
else
return ""
end
end
end


-- Function to get the length of a table
function tablelength(T)
function tablelength(T)
    local count = 0
local count = 0
    for _ in pairs(T) do count = count + 1 end
for _ in pairs(T) do
    return count
count = count + 1
end
return count
end
end


return p
return p

Текущая версия от 22:36, 29 июня 2024

Для документации этого модуля может быть создана страница Модуль:Chemistry Lookup/doc

local prototypes = mw.loadData("Module:Chemistry Lookup/data")

local p = {}
p.chem = prototypes.chem
p.react = prototypes.react
p.groupDirection = prototypes.groupDirection

function p.readscalar(frame)
	return mw.text.nowiki(p.chem[frame.args[1]][frame.args[2]])
end

function p.readscalarreact(frame)
	if p.react[frame.args[1]][frame.args[2]] ~= nil then
		return mw.text.nowiki(p.react[frame.args[1]][frame.args[2]])
	else
		return ""
	end
end

function p.getcolor(frame)
	return mw.text.nowiki(p.chem[frame.args[1]].color:sub(1, 7))
end

function p.gettextcolor(frame)
	local basecol = p.chem[frame.args[1]].color
	local red = tonumber(basecol:sub(2, 3), 16)
	local grn = tonumber(basecol:sub(4, 5), 16)
	local blu = tonumber(basecol:sub(6, 7), 16)
	local luminance = math.sqrt(0.241*red*red + 0.691*grn*grn + 0.068*blu*blu)
	if luminance > 100 then
		return mw.text.nowiki("#000")
	else
		return mw.text.nowiki("#FFF")
	end
end

function p.hasrecipe(frame)
	return p.chem[frame.args[1]]["recipes"][1] ~= nil
end

function p.buildboxes(frame)
	local out = ""
	local group = frame.args[1]
	for k in pairs(p.chem) do
		if p.chem[k].group == group then
			out = out .. frame:expandTemplate{ title = "Chembox", args = { prototype = k }}
		elseif group == nil then
			out = out .. frame:expandTemplate{ title = "Chembox", args = { prototype = k }}
		end
	end
	return out
end

function p.buildreactboxes(frame)
	local out = ""
	for k in pairs(p.react) do
		if p.react[k] and tablelength(p.react[k].effects) ~= 0 then
			out = out .. frame:expandTemplate{ title = "Reactionbox", args = { reaction = k }}	
		end
	end
	return out
end

function p.buildrecipes(frame)
	local chem = frame.args[1]
	local out = ""
	for id, recipe in pairs(p.chem[chem].recipes) do
		out = out .. p.buildreaction(frame, recipe)
	end
	return out
end

function p.buildreactionext(frame)
	local react = frame.args[1]
	return p.buildreaction(frame, react)
end

function p.buildreaction(frame, react)
	local data = p.react[react]
	if data == nil then
		return "Error: reaction data is nil for " .. tostring(react)
	end

	local dest = "Chemistry"
	local args = {}
	local i = 0

	if data.reactants then
		for k, v in pairs(data.reactants) do
			i = i + 1
			local dest = "Chemistry"
			if p.groupDirection[p.chem[k].group] ~= nil then
				dest = p.groupDirection[p.chem[k].group]
			end
			args["component-" .. i] = frame:expandTemplate{ title = "Chem Recipe Component", args = { reagent = k, amount = v.amount, dest = dest }}
		end
	end

	i = 0
	if data.products then
		for k, v in pairs(data.products) do
			i = i + 1
			local dest = "Chemistry"
			if p.groupDirection[p.chem[k].group] ~= nil then
				dest = p.groupDirection[p.chem[k].group]
			end
			args["result-" .. i] = frame:expandTemplate{ title = "Chem Recipe Component", args = { reagent = k, amount = v, dest = dest }}
		end
	end
	
	if data.effects ~= nil then
		args.effects = p.geneffectlist(data.effects, frame, 1)
	end

	return frame:expandTemplate{ title = "Chem Box Recipe", args = args }
end

function p.checksatiatesthirst(frame)
	local chem = frame.args[1]
	local met = p.chem[chem].metabolisms
	if met == nil then
		return ""
	end
	for k, v in pairs(met) do
		for l, w in pairs(v.effects) do
			if w.id == "SatiateThirst" then
				return "1"
			end
		end
	end
	return ""
end

function p.checksatiateshunger(frame)
	local chem = frame.args[1]
	local met = p.chem[chem].metabolisms
	if met == nil then
		return ""
	end
	for k, v in pairs(met) do
		for l, w in pairs(v.effects) do
			if w.id == "SatiateHunger" then
				return "1"
			end
		end
	end
	return ""
end

function p.haseffects(frame)
	local chem = frame.args[1]
	local met = p.chem[chem].metabolisms
	if met == nil then
		return ""
	end
	for k, v in pairs(met) do
		for l, w in pairs(v.effects) do
			if w.id ~= "SatiateHunger" and w.id ~= "SatiateThirst" then
				return "1"
			end
		end
	end
	return ""
end

function p.geneffects(frame, chem)
	if chem == nil then
		chem = frame.args[1]
	end
	local met = p.chem[chem].metabolisms
	if met == nil then
		return ""
	end
	local out = ""
	for k, v in pairs(met) do
		out = out .. "<b>" .. k .. "</b> (" .. v.rate .. " единиц в секунду)\n" .. p.geneffectlist(v.effects, frame, v.rate)
	end
	return out
end

function p.geneffectlist(effects, frame, rate)
	local out = ""
	for l, w in pairs(effects) do
		-- Popup Message is ignored on purpose
		if w.id == "HealthChange" then
			out = out .. ":" .. p.genhealthchange(w, rate, frame) .. "\n"
		elseif w.id == "AdjustReagent" then
			out = out .. ":" .. p.genadjustreagent(w, rate, frame) .. "\n"
		elseif w.id == "FlammableReaction" then
			out = out .. ":" .. p.genflammablereaction(w, frame) .. "\n"
		elseif w.id == "AdjustTemperature" then
			out = out .. ":" .. p.genadjusttemperature(w, frame) .. "\n"
		elseif w.id == "GenericStatusEffect" then
			out = out .. ":" .. p.gengenericstatuseffect(w, frame) .. "\n"
		elseif w.id == "ExplosionReactionEffect" then
			out = out .. ":" .. p.genexplosionreactioneffect(w, frame) .. "\n"
		elseif w.id == "FoamAreaReactionEffect" then
			out = out .. ":" .. p.genfoamareareactioneffect(w, frame) .. "\n"
		elseif w.id == "SmokeAreaReactionEffect" then
			out = out .. ":" .. p.gensmokeareareactioneffect(w, frame) .. "\n"
		elseif w.id == "ModifyBleedAmount" then
			out = out .. ":" .. p.genmodifybleedamount(w, frame) .. "\n"
		end
	end
	return out
end

function p.gensmokeareareactioneffect(r, frame)
	if r.conditions ~= nil then 
		conds = p.genconds(r.conditions, frame)
	end
	return frame:expandTemplate{ title = "SmokeAreaReactionEffect", args = { when = conds, prob = r.probability }}
end

function p.genfoamareareactioneffect(r, frame)
	if r.conditions ~= nil then 
		conds = p.genconds(r.conditions, frame)
	end
	return frame:expandTemplate{ title = "FoamAreaReactionEffect", args = { when = conds, prob = r.probability }}
end

function p.genexplosionreactioneffect(r, frame)
	if r.conditions ~= nil then 
		conds = p.genconds(r.conditions, frame)
	end
	return frame:expandTemplate{ title = "ExplosionReactionEffect", args = { when = conds, prob = r.probability }}
end

function p.gengenericstatuseffect(r, frame)
	if r.conditions ~= nil then 
		conds = p.genconds(r.conditions, frame)
	end
	return frame:expandTemplate{ title = "GenericStatusEffect", args = { key = r.Key, type = r.Type, time = r.Time, refresh = r.Refresh, when = conds, prob = r.probability }}
end

function p.genadjusttemperature(r, frame)
	if r.conditions ~= nil then 
		conds = p.genconds(r.conditions, frame)
	end
	return frame:expandTemplate{ title = "AdjustTemperature", args = { amount = r.Amount, when = conds, prob = r.probability }}
end

function p.genflammablereaction(w, frame)
	return frame:expandTemplate{ title = "FlammableReaction", args = { prob = w.probability }}
end

function p.genadjustreagent(r, rate, frame)
	local conds = ""
	if r.conditions ~= nil then 
		conds = p.genconds(r.conditions, frame)
	end
	local amount = r.Amount
	if r.ScaleWithRate == 1 then
		amount = rate * r.Amount
	end
	return frame:expandTemplate{ title = "AdjustReagent", args = { name = r.Name, amount = amount, when = conds, prob = r.probability }}
end

function p.genhealthchange(r, rate, frame)
	local conds = ""
	if r.conditions ~= nil then 
		conds = p.genconds(r.conditions, frame)
	end
	local amount = r.Amount
	if r.ScaleWithRate == 1 then
		amount = rate * r.Amount
	end
	return frame:expandTemplate{ title = "HealthChange", args = { amount = amount, when = conds, prob = r.probability }}
end

function p.genconds(c, frame)
	if c.TimeIngested then
		return frame:expandTemplate{ title = "TimeIngested", args = { min = c.TimeIngested.min, max = c.TimeIngested.max }}
	elseif c.BloodAmount then
		return frame:expandTemplate{ title = "BloodAmount", args = { min = c.BloodAmount.min, max = c.BloodAmount.max }}
	elseif c.TimeInBlood then
		return frame:expandTemplate{ title = "TimeInBlood", args = { min = c.TimeInBlood.min, max = c.TimeInBlood.max }}
	elseif c.OverallChemicalAmount then
		return frame:expandTemplate{ title = "OverallChemicalAmount", args = { min = c.OverallChemicalAmount.min, max = c.OverallChemicalAmount.max, chem = c.OverallChemicalAmount.chemical }}
	elseif c.ChemicalAmount then
		return frame:expandTemplate{ title = "ChemicalAmount", args = { min = c.ChemicalAmount.min, max = c.ChemicalAmount.max, chem = c.ChemicalAmount.chemical }}
	else
		return ""
	end
end

function tablelength(T)
	local count = 0
	for _ in pairs(T) do
		count = count + 1
	end
	return count
end

return p