Module:UnitAbility
From Heroes of Might and Magic: Olden Era Official Wiki
Documentation for this module may be created at Module:UnitAbility/doc
-- This module is intended as a supporting muscle for the UnitAbility template.
local p = {}
local NECROMANCY = {
demon = 1,
dragon = 1,
living = 1,
magic_creature = 1,
}
-- Displays a variable
------------------------------------------------------------------------------------------------------------------------
local function dump(target)
return '<pre>' .. mw.dumpObject(target) .. '</pre>'
end
-- Helper to trim standard and full-width Japanese spaces (U+3000)
------------------------------------------------------------------------------------------------------------------------
local function trim(s)
return mw.text.trim(s or "", "%s ")
end
------------------------------------------------------------------------------------------------------------------------
function p.buildStats(frame)
local description = frame.args.description
local type = frame.args.type
local lang = frame.args.lang
local normalized = description:gsub("<[bB][rR]%s*/?>", "\n")
local actualDescription = normalized:match("^([^\n]*)")
local necromancy = NECROMANCY[type] or 0
local necromancy_hint = normalized:match("([^\n]*)$")
local ranges = mw.ustring.gsub(normalized, actualDescription, '')
ranges = mw.ustring.gsub(ranges, necromancy_hint, '')
ranges = mw.ustring.gsub(ranges, ":", ":")
ranges = trim(ranges)
local morale, luck = ranges:match("^([^\n]*)\n?(.*)$")
local morale_hint = trim(morale:match("^([^:]*)") or "")
local morale_range = trim(morale:match("([^:]*)$") or "")
morale_range = mw.ustring.gsub(morale_range, "[.。]$", "")
local luck_hint = trim(luck:match("^([^:]*)") or "")
local luck_range = trim(luck:match("([^:]*)$") or "")
luck_range = mw.ustring.gsub(luck_range, "[.。]$", "")
return frame:preprocess(mw.ustring.format([[
{{UnitAbility/stats
| lang = %s
| morale_hint = %s
| morale_range = %s
| luck_hint = %s
| luck_range = %s
| necromancy_hint = %s
| necromancy = %s
}}
]], lang, morale_hint, morale_range, luck_hint, luck_range, necromancy_hint, necromancy))
end
------------------------------------------------------------------------------------------------------------------------
function p.extractDescription(frame)
local description = frame.args.description
local normalized = description:gsub("<[bB][rR]%s*/?>", "\n")
local actualDescription = normalized:match("^([^\n]*)") or ''
return actualDescription
end
return p


