Module:Sandbox/Aurelain/HeroClassSkills: Difference between revisions
From Heroes of Might and Magic: Olden Era Official Wiki
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
-- This module is intended as a supporting muscle for the HeroClassSkills template. | -- This module is intended as a supporting muscle for the HeroClassSkills template. | ||
local p = {} | local p = {} | ||
local UtilQuery = require('Module:UtilQuery') | |||
local FACTION = { | |||
human = 'humans', -- changed! | |||
undead = 'necros', -- changed! | |||
nature = 'nature', | |||
demon = 'demons', -- changed! | |||
unfrozen = 'unfrozen', | |||
dungeon = 'dungeon', | |||
} | |||
-- Displays a variable | -- Displays a variable | ||
| Line 9: | Line 18: | ||
------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------ | ||
local function collectChances( | local function collectChances(id) | ||
return {} | local type, faction = id:match("(.*)_(.*)") | ||
local adaptedId = FACTION[faction] .. '_' .. type .. '_skills_table' | |||
local result = UtilQuery.run([[ | |||
tables = | |||
SkillRollWeight = S | |||
|where = | |||
S.table_id = '%s' | |||
|fields = | |||
S.band_kind = band_kind, | |||
S.skill_id = skill_id, | |||
S.weight = weight | |||
]], adaptedId) | |||
return result | |||
end | |||
------------------------------------------------------------------------------------------------------------------------ | |||
local function consolidateChances(queryResult) | |||
local chances = {} | |||
for _, row in ipairs(queryResult) do | |||
local id = row.skill_id | |||
local entry = chances[id] | |||
if not entry then | |||
chances[row.id] = { | |||
id = row.id or '', | |||
} | |||
end | |||
end | |||
return chances | |||
end | end | ||
| Line 28: | Line 64: | ||
local id = frame.args.id; | local id = frame.args.id; | ||
local chances = | local chancesBulk = collectChances(id); | ||
local chances = consolidateChances(chancesBulk); | |||
do return dump(chances) end | |||
local total = computeTotal(chances); | local total = computeTotal(chances); | ||
local formattedChances = formatChances(chances); | local formattedChances = formatChances(chances); | ||
Revision as of 09:46, 8 August 2026
Documentation for this module may be created at Module:Sandbox/Aurelain/HeroClassSkills/doc
-- This module is intended as a supporting muscle for the HeroClassSkills template.
local p = {}
local UtilQuery = require('Module:UtilQuery')
local FACTION = {
human = 'humans', -- changed!
undead = 'necros', -- changed!
nature = 'nature',
demon = 'demons', -- changed!
unfrozen = 'unfrozen',
dungeon = 'dungeon',
}
-- Displays a variable
------------------------------------------------------------------------------------------------------------------------
local function dump(target)
return '<pre>' .. mw.dumpObject(target) .. '</pre>'
end
------------------------------------------------------------------------------------------------------------------------
local function collectChances(id)
local type, faction = id:match("(.*)_(.*)")
local adaptedId = FACTION[faction] .. '_' .. type .. '_skills_table'
local result = UtilQuery.run([[
tables =
SkillRollWeight = S
|where =
S.table_id = '%s'
|fields =
S.band_kind = band_kind,
S.skill_id = skill_id,
S.weight = weight
]], adaptedId)
return result
end
------------------------------------------------------------------------------------------------------------------------
local function consolidateChances(queryResult)
local chances = {}
for _, row in ipairs(queryResult) do
local id = row.skill_id
local entry = chances[id]
if not entry then
chances[row.id] = {
id = row.id or '',
}
end
end
return chances
end
------------------------------------------------------------------------------------------------------------------------
local function computeTotal(chances)
return 1000
end
------------------------------------------------------------------------------------------------------------------------
local function formatChances(chances)
return ''
end
------------------------------------------------------------------------------------------------------------------------
function p.populate(frame)
local lang = frame.args.lang
local id = frame.args.id;
local chancesBulk = collectChances(id);
local chances = consolidateChances(chancesBulk);
do return dump(chances) end
local total = computeTotal(chances);
local formattedChances = formatChances(chances);
local cleanTitle = frame:getTitle():gsub('Module:', '')
return frame:preprocess(mw.ustring.format([[
{{%s/base
| lang = %s
| id = %s
| total = %s
| total = %s
}}
]], cleanTitle, lang, id, total, formattedChances))
end
------------------------------------------------------------------------------------------------------------------------
function p.percent(frame)
local a = frame.args[1]
local b = frame.args[2]
return string.format("%.2f", 100 * a / b)
end
return p


