AL-S (обсуждение | вклад) м (1 версия импортирована) |
Нет описания правки Метка: отменено |
||
Строка 2: | Строка 2: | ||
local p = {} | local p = {} | ||
p.chem = prototypes.chem | p.chem = prototypes.chem or {} | ||
p.react = prototypes.react | p.react = prototypes.react or {} | ||
p.groupDirection = prototypes.groupDirection | p.groupDirection = prototypes.groupDirection or {} | ||
-- ===== Хелперы ===== | |||
local function tablelength(T) | |||
local count = 0 | |||
for _ in pairs(T or {}) do count = count + 1 end | |||
return count | |||
end | |||
local function hchangelist(l, frame) | |||
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 .. frame:expandTemplate{ title = "HealthModifier", args = { adj = v, kind = k } } | |||
end | |||
return out | |||
end | |||
function p.readscalar(frame) | function p.readscalar(frame) | ||
local a, b = frame.args[1], frame.args[2] | |||
if not (a and b) or not p.chem[a] then return "" end | |||
local v = p.chem[a][b] | |||
if v == nil then return "" end | |||
return mw.text.nowiki(tostring(v)) | |||
end | end | ||
function p.readscalarreact(frame) | function p.readscalarreact(frame) | ||
local a, b = frame.args[1], frame.args[2] | |||
if not (a and b) or not p.react[a] then return "" end | |||
local v = p.react[a][b] | |||
if v == nil then return "" end | |||
return mw.text.nowiki(tostring(v)) | |||
end | end | ||
function p.getcolor(frame) | function p.getcolor(frame) | ||
return mw.text.nowiki(p.chem[ | local a = frame.args[1] | ||
if not a or not p.chem[a] or not p.chem[a].color then return "" end | |||
return mw.text.nowiki(p.chem[a].color:sub(1, 7)) | |||
end | end | ||
function p.gettextcolor(frame) | function p.gettextcolor(frame) | ||
local | local a = frame.args[1] | ||
local red = tonumber(basecol:sub(2, 3), 16) | if not a or not p.chem[a] or not p.chem[a].color then return mw.text.nowiki("#000") end | ||
local grn = tonumber(basecol:sub(4, 5), 16) | local basecol = p.chem[a].color | ||
local blu = tonumber(basecol:sub(6, 7), 16) | local red = tonumber(basecol:sub(2, 3), 16) or 0 | ||
local grn = tonumber(basecol:sub(4, 5), 16) or 0 | |||
local blu = tonumber(basecol:sub(6, 7), 16) or 0 | |||
local luminance = math.sqrt(0.241*red*red + 0.691*grn*grn + 0.068*blu*blu) | local luminance = math.sqrt(0.241*red*red + 0.691*grn*grn + 0.068*blu*blu) | ||
if luminance > 100 then | if luminance > 100 then | ||
Строка 36: | Строка 67: | ||
function p.hasrecipe(frame) | function p.hasrecipe(frame) | ||
local chem = frame.args[1] | |||
if not chem or not p.chem[chem] then return "" end | |||
return (p.chem[chem].recipes and p.chem[chem].recipes[1]) and "1" or "" | |||
end | end | ||
Строка 42: | Строка 75: | ||
local out = "" | local out = "" | ||
local group = frame.args[1] | local group = frame.args[1] | ||
for k in pairs(p.chem) do | for k, v in pairs(p.chem) do | ||
if | if type(v) == "table" then | ||
if (group == nil) or (v.group == group) then | |||
out = out .. frame:expandTemplate{ title = "Chembox", args = { prototype = k }} | |||
end | |||
end | end | ||
end | end | ||
Строка 54: | Строка 87: | ||
function p.buildreactboxes(frame) | function p.buildreactboxes(frame) | ||
local out = "" | local out = "" | ||
for k in pairs(p.react) do | for k, v in pairs(p.react) do | ||
if tablelength( | if type(v) == "table" and v.effects and tablelength(v.effects) ~= 0 then | ||
out = out .. frame:expandTemplate{ title = "Reactionbox", args = { reaction = k }} | out = out .. frame:expandTemplate{ title = "Reactionbox", args = { reaction = k }} | ||
end | end | ||
end | end | ||
Строка 64: | Строка 97: | ||
function p.buildrecipes(frame) | function p.buildrecipes(frame) | ||
local chem = frame.args[1] | local chem = frame.args[1] | ||
if not chem or not p.chem[chem] then return "" end | |||
local out = "" | local out = "" | ||
for | for _, recipe in pairs(p.chem[chem].recipes or {}) do | ||
out = out .. p.buildreaction(frame, recipe) | out = out .. p.buildreaction(frame, recipe) | ||
end | end | ||
Строка 77: | Строка 111: | ||
function p.buildreaction(frame, react) | function p.buildreaction(frame, react) | ||
if not react or not p.react[react] then return "" end | |||
local data = p.react[react] | local data = p.react[react] | ||
local args = {} | local args = {} | ||
-- Реактанты | |||
local i = 0 | local i = 0 | ||
for k,v in pairs(data.reactants) do | for k, v in pairs(data.reactants or {}) do | ||
i = i + 1 | i = i + 1 | ||
local dest = | local dest = p.groupDirection[(p.chem[k] or {}).group] or "Chemistry" | ||
args["component-" .. i] = frame:expandTemplate{ | |||
title = "Chem Recipe Component", | |||
args = { reagent = k, amount = v.amount, dest = dest } | |||
args["component-" .. i] = frame:expandTemplate{ title = "Chem Recipe Component", args = { reagent = k, amount = v.amount, dest = dest }} | } | ||
end | end | ||
-- Продукты | |||
i = 0 | i = 0 | ||
for k,v in pairs(data.products) do | for k, v in pairs(data.products or {}) do | ||
i = i + 1 | i = i + 1 | ||
local dest = | local dest = p.groupDirection[(p.chem[k] or {}).group] or "Chemistry" | ||
args["result-" .. i] = frame:expandTemplate{ | |||
title = "Chem Recipe Component", | |||
args = { reagent = k, amount = v, dest = dest } | |||
args["result-" .. i] = frame:expandTemplate{ title = "Chem Recipe Component", args = { reagent = k, amount = v, dest = dest }} | } | ||
end | end | ||
-- Эффекты реакции (не метаболизм) | |||
if data.effects ~= nil then | if data.effects ~= nil then | ||
args.effects = p.geneffectlist(data.effects, frame, 1) | args.effects = p.geneffectlist(data.effects, frame, 1) | ||
Строка 104: | Строка 143: | ||
return frame:expandTemplate{ title = "Chem Box Recipe", args = args } | return frame:expandTemplate{ title = "Chem Box Recipe", args = args } | ||
end | |||
local function scan_metab(chem) | |||
local met = (p.chem[chem] or {}).metabolisms | |||
if not met then return nil end | |||
return met | |||
end | end | ||
function p.checksatiatesthirst(frame) | function p.checksatiatesthirst(frame) | ||
local chem = frame.args[1] | local chem = frame.args[1] | ||
local met = | local met = scan_metab(chem) | ||
if met | if not met then return "" end | ||
for _, v in pairs(met) do | |||
for _, w in pairs(v.effects or {}) do | |||
for | if w.id == "SatiateThirst" then return "1" end | ||
for | |||
if w.id == "SatiateThirst" then | |||
end | end | ||
end | end | ||
Строка 124: | Строка 165: | ||
function p.checksatiateshunger(frame) | function p.checksatiateshunger(frame) | ||
local chem = frame.args[1] | local chem = frame.args[1] | ||
local met = | local met = scan_metab(chem) | ||
if met | if not met then return "" end | ||
for _, v in pairs(met) do | |||
for _, w in pairs(v.effects or {}) do | |||
for | if w.id == "SatiateHunger" then return "1" end | ||
for | |||
if w.id == "SatiateHunger" then | |||
end | end | ||
end | end | ||
Строка 140: | Строка 177: | ||
function p.haseffects(frame) | function p.haseffects(frame) | ||
local chem = frame.args[1] | local chem = frame.args[1] | ||
local met = | local met = scan_metab(chem) | ||
if met | if not met then return "" end | ||
for _, v in pairs(met) do | |||
for _, w in pairs(v.effects or {}) do | |||
for | |||
for | |||
if w.id ~= "SatiateHunger" and w.id ~= "SatiateThirst" then | if w.id ~= "SatiateHunger" and w.id ~= "SatiateThirst" then | ||
return "1" | return "1" | ||
Строка 155: | Строка 190: | ||
function p.geneffects(frame, chem) | function p.geneffects(frame, chem) | ||
if chem == nil then | if chem == nil then chem = frame.args[1] end | ||
local met = scan_metab(chem) | |||
if not met then return "" end | |||
local met = | |||
if met | |||
local out = "" | local out = "" | ||
for k, v in pairs(met) do | for k, v in pairs(met) do | ||
out = out .. "<b>" .. k .. "</b> (" .. v.rate .. " единиц в секунду)\n" .. p.geneffectlist(v.effects, frame, v.rate) | out = out .. "<b>" .. k .. "</b> (" .. tostring(v.rate) .. " единиц в секунду)\n" .. | ||
p.geneffectlist(v.effects or {}, frame, v.rate or 1) | |||
end | end | ||
return out | return out | ||
Строка 171: | Строка 203: | ||
function p.geneffectlist(effects, frame, rate) | function p.geneffectlist(effects, frame, rate) | ||
local out = "" | local out = "" | ||
for | for _, w in pairs(effects or {}) do | ||
if w.id == "HealthChange" then | if w.id == "HealthChange" then | ||
out = out .. ":" .. p.genhealthchange(w, rate, frame) .. "\n" | out = out .. ":" .. p.genhealthchange(w, rate, frame) .. "\n" | ||
Строка 197: | Строка 228: | ||
function p.gensmokeareareactioneffect(r, frame) | function p.gensmokeareareactioneffect(r, frame) | ||
local conds = nil | |||
if r.conditions ~= nil then | if r.conditions ~= nil then | ||
conds = p.genconds(r.conditions, frame) | conds = p.genconds(r.conditions, frame) | ||
Строка 204: | Строка 236: | ||
function p.genfoamareareactioneffect(r, frame) | function p.genfoamareareactioneffect(r, frame) | ||
local conds = nil | |||
if r.conditions ~= nil then | if r.conditions ~= nil then | ||
conds = p.genconds(r.conditions, frame) | conds = p.genconds(r.conditions, frame) | ||
Строка 211: | Строка 244: | ||
function p.genexplosionreactioneffect(r, frame) | function p.genexplosionreactioneffect(r, frame) | ||
local conds = nil | |||
if r.conditions ~= nil then | if r.conditions ~= nil then | ||
conds = p.genconds(r.conditions, frame) | conds = p.genconds(r.conditions, frame) | ||
Строка 218: | Строка 252: | ||
function p.gengenericstatuseffect(r, frame) | function p.gengenericstatuseffect(r, frame) | ||
local conds = nil | |||
if r.conditions ~= nil then | if r.conditions ~= nil then | ||
conds = p.genconds(r.conditions, frame) | conds = p.genconds(r.conditions, frame) | ||
end | end | ||
return frame:expandTemplate{ title = "GenericStatusEffect", args = { key = r.Key, type = r.Type, time = r.Time, refresh = r.Refresh, when = conds, prob = r.probability }} | return frame:expandTemplate{ | ||
title = "GenericStatusEffect", | |||
args = { key = r.Key, type = r.Type, time = r.Time, refresh = r.Refresh, when = conds, prob = r.probability } | |||
} | |||
end | end | ||
function p.genadjusttemperature(r, frame) | function p.genadjusttemperature(r, frame) | ||
local conds = nil | |||
if r.conditions ~= nil then | if r.conditions ~= nil then | ||
conds = p.genconds(r.conditions, frame) | conds = p.genconds(r.conditions, frame) | ||
Строка 232: | Строка 271: | ||
function p.genflammablereaction(r, frame) | function p.genflammablereaction(r, frame) | ||
local conds = nil | |||
if r.conditions ~= nil then | if r.conditions ~= nil then | ||
conds = p.genconds(r.conditions, frame) | conds = p.genconds(r.conditions, frame) | ||
Строка 246: | Строка 279: | ||
function p.genadjustreagent(r, rate, frame) | function p.genadjustreagent(r, rate, frame) | ||
local conds = nil | |||
if r.conditions ~= nil then | if r.conditions ~= nil then | ||
conds = p.genconds(r.conditions, frame) | conds = p.genconds(r.conditions, frame) | ||
Строка 253: | Строка 287: | ||
function p.genmodifybleedamount(r, frame) | function p.genmodifybleedamount(r, frame) | ||
local conds = nil | |||
if r.conditions ~= nil then | if r.conditions ~= nil then | ||
conds = p.genconds(r.conditions, frame) | conds = p.genconds(r.conditions, frame) | ||
Строка 262: | Строка 297: | ||
local healst = {} | local healst = {} | ||
local dealst = {} | local dealst = {} | ||
local r = 1.0 / rate | local r = 1.0 / (rate or 1) | ||
if h.damage.types | |||
if h.damage and h.damage.types 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 | ||
end | end | ||
if h.damage and h.damage.groups then | |||
for k, v in pairs(h.damage.groups) do | |||
if h.damage.groups | if v < 0 then healst[k] = v * r else dealst[k] = v * r end | ||
end | end | ||
end | end | ||
local heals = hchangelist(healst, frame) | local heals = hchangelist(healst, frame) | ||
local deals = hchangelist(dealst, frame) | local deals = hchangelist(dealst, frame) | ||
Строка 290: | Строка 317: | ||
end | end | ||
return frame:expandTemplate{ title = "HealthChange", args = { heals = heals, deals = deals, when = conds, prob = h.probability }} | return frame:expandTemplate{ title = "HealthChange", args = { heals = heals, deals = deals, when = conds, prob = h.probability }} | ||
end | end | ||
function p.genconds(conds, frame) | function p.genconds(conds, frame) | ||
out = "" | local out = "" | ||
local len = tablelength(conds) | local len = tablelength(conds or {}) | ||
local i = 0 | local i = 0 | ||
for | for _, c in pairs(conds or {}) do | ||
i = i + 1 | i = i + 1 | ||
if len == i and i ~= 1 then | if len == i and i ~= 1 then | ||
Строка 324: | Строка 330: | ||
out = out .. ", " | out = out .. ", " | ||
end | end | ||
out = out .. p.gencond( | out = out .. p.gencond(c, frame) | ||
end | end | ||
return out | return out | ||
Строка 330: | Строка 336: | ||
function p.gencond(c, frame) | function p.gencond(c, frame) | ||
if not c or not c.id then return "" end | |||
if c.id == "TotalDamage" then | if c.id == "TotalDamage" then | ||
return frame:expandTemplate{ title = "TotalDamage", args = { min = c.Min, max = c.Max } } | return frame:expandTemplate{ title = "TotalDamage", args = { min = c.Min, max = c.Max } } | ||
Строка 337: | Строка 344: | ||
return frame:expandTemplate{ title = "OrganType", args = { shouldhave = c.ShouldHave, type = c.Type } } | return frame:expandTemplate{ title = "OrganType", args = { shouldhave = c.ShouldHave, type = c.Type } } | ||
elseif c.id == "Temperature" then | elseif c.id == "Temperature" then | ||
return frame:expandTemplate{ title = "Temperature", args = { | return frame:expandTemplate{ title = "Temperature", args = { min = c.Min, max = c.Max } } | ||
end | end | ||
return "" | return "" | ||
end | end | ||
return p | return p |
Версия от 22:41, 6 сентября 2025
Для документации этого модуля может быть создана страница Модуль:Chemistry Lookup/doc
local prototypes = mw.loadData("Module:Chemistry Lookup/data")
local p = {}
p.chem = prototypes.chem or {}
p.react = prototypes.react or {}
p.groupDirection = prototypes.groupDirection or {}
-- ===== Хелперы =====
local function tablelength(T)
local count = 0
for _ in pairs(T or {}) do count = count + 1 end
return count
end
local function hchangelist(l, frame)
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 .. frame:expandTemplate{ title = "HealthModifier", args = { adj = v, kind = k } }
end
return out
end
function p.readscalar(frame)
local a, b = frame.args[1], frame.args[2]
if not (a and b) or not p.chem[a] then return "" end
local v = p.chem[a][b]
if v == nil then return "" end
return mw.text.nowiki(tostring(v))
end
function p.readscalarreact(frame)
local a, b = frame.args[1], frame.args[2]
if not (a and b) or not p.react[a] then return "" end
local v = p.react[a][b]
if v == nil then return "" end
return mw.text.nowiki(tostring(v))
end
function p.getcolor(frame)
local a = frame.args[1]
if not a or not p.chem[a] or not p.chem[a].color then return "" end
return mw.text.nowiki(p.chem[a].color:sub(1, 7))
end
function p.gettextcolor(frame)
local a = frame.args[1]
if not a or not p.chem[a] or not p.chem[a].color then return mw.text.nowiki("#000") end
local basecol = p.chem[a].color
local red = tonumber(basecol:sub(2, 3), 16) or 0
local grn = tonumber(basecol:sub(4, 5), 16) or 0
local blu = tonumber(basecol:sub(6, 7), 16) or 0
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)
local chem = frame.args[1]
if not chem or not p.chem[chem] then return "" end
return (p.chem[chem].recipes and p.chem[chem].recipes[1]) and "1" or ""
end
function p.buildboxes(frame)
local out = ""
local group = frame.args[1]
for k, v in pairs(p.chem) do
if type(v) == "table" then
if (group == nil) or (v.group == group) then
out = out .. frame:expandTemplate{ title = "Chembox", args = { prototype = k }}
end
end
end
return out
end
function p.buildreactboxes(frame)
local out = ""
for k, v in pairs(p.react) do
if type(v) == "table" and v.effects and tablelength(v.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]
if not chem or not p.chem[chem] then return "" end
local out = ""
for _, recipe in pairs(p.chem[chem].recipes or {}) 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)
if not react or not p.react[react] then return "" end
local data = p.react[react]
local args = {}
-- Реактанты
local i = 0
for k, v in pairs(data.reactants or {}) do
i = i + 1
local dest = p.groupDirection[(p.chem[k] or {}).group] or "Chemistry"
args["component-" .. i] = frame:expandTemplate{
title = "Chem Recipe Component",
args = { reagent = k, amount = v.amount, dest = dest }
}
end
-- Продукты
i = 0
for k, v in pairs(data.products or {}) do
i = i + 1
local dest = p.groupDirection[(p.chem[k] or {}).group] or "Chemistry"
args["result-" .. i] = frame:expandTemplate{
title = "Chem Recipe Component",
args = { reagent = k, amount = v, dest = dest }
}
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
local function scan_metab(chem)
local met = (p.chem[chem] or {}).metabolisms
if not met then return nil end
return met
end
function p.checksatiatesthirst(frame)
local chem = frame.args[1]
local met = scan_metab(chem)
if not met then return "" end
for _, v in pairs(met) do
for _, w in pairs(v.effects or {}) do
if w.id == "SatiateThirst" then return "1" end
end
end
return ""
end
function p.checksatiateshunger(frame)
local chem = frame.args[1]
local met = scan_metab(chem)
if not met then return "" end
for _, v in pairs(met) do
for _, w in pairs(v.effects or {}) do
if w.id == "SatiateHunger" then return "1" end
end
end
return ""
end
function p.haseffects(frame)
local chem = frame.args[1]
local met = scan_metab(chem)
if not met then return "" end
for _, v in pairs(met) do
for _, w in pairs(v.effects or {}) 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 = scan_metab(chem)
if not met then return "" end
local out = ""
for k, v in pairs(met) do
out = out .. "<b>" .. k .. "</b> (" .. tostring(v.rate) .. " единиц в секунду)\n" ..
p.geneffectlist(v.effects or {}, frame, v.rate or 1)
end
return out
end
function p.geneffectlist(effects, frame, rate)
local out = ""
for _, w in pairs(effects or {}) do
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)
local conds = nil
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)
local conds = nil
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)
local conds = nil
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)
local conds = nil
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)
local conds = nil
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(r, frame)
local conds = nil
if r.conditions ~= nil then
conds = p.genconds(r.conditions, frame)
end
return frame:expandTemplate{ title = "FlammableReaction", args = { multiplier = r.Multiplier, when = conds, prob = r.probability }}
end
function p.genadjustreagent(r, rate, frame)
local conds = nil
if r.conditions ~= nil then
conds = p.genconds(r.conditions, frame)
end
return frame:expandTemplate{ title = "AdjustReagent", args = { amount = r.Amount, reagent = r.Reagent, when = conds, prob = r.probability }}
end
function p.genmodifybleedamount(r, frame)
local conds = nil
if r.conditions ~= nil then
conds = p.genconds(r.conditions, frame)
end
return frame:expandTemplate{ title = "ModifyBleedAmount", args = { amount = r.Amount, when = conds, prob = r.probability }}
end
function p.genhealthchange(h, rate, frame)
local healst = {}
local dealst = {}
local r = 1.0 / (rate or 1)
if h.damage and h.damage.types 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
if h.damage and h.damage.groups 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
function p.genconds(conds, frame)
local out = ""
local len = tablelength(conds or {})
local i = 0
for _, c in pairs(conds or {}) do
i = i + 1
if len == i and i ~= 1 then
out = out .. ", and "
elseif i ~= 1 then
out = out .. ", "
end
out = out .. p.gencond(c, frame)
end
return out
end
function p.gencond(c, frame)
if not c or not c.id then return "" end
if c.id == "TotalDamage" then
return frame:expandTemplate{ title = "TotalDamage", args = { min = c.Min, max = c.Max } }
elseif c.id == "ReagentThreshold" then
return frame:expandTemplate{ title = "ReagentThreshold", args = { min = c.Min, max = c.Max, reagent = c.Reagent } }
elseif c.id == "OrganType" then
return frame:expandTemplate{ title = "OrganType", args = { shouldhave = c.ShouldHave, type = c.Type } }
elseif c.id == "Temperature" then
return frame:expandTemplate{ title = "Temperature", args = { min = c.Min, max = c.Max } }
end
return ""
end
return p