Module:HeroStats2/Utils

From Darkest Dungeon Wiki
Jump to navigation Jump to search
Template-info.svg Documentation

This module defines a set of common utilities for other modules that work with the HeroStats2 table.


local Utils = require("Module:Utils")
local Stat = require("Module:Utils2/Stat")

local HERO_STAT = Stat:bind{
	r0=Stat.HI, g0=Stat.LO, b0=Stat.LO,
	r1=Stat.MID, g1=Stat.MID, b1=Stat.MID,
	r2=Stat.LO, g2=Stat.HI, b2=Stat.LO,
}
local REGULAR_STAT = HERO_STAT:bind{create_cell=Stat.regular_cell}
local RES_STAT = HERO_STAT:bind{create_cell=Stat.res_cell}

local BASE_STATS = {
	REGULAR_STAT:bind{name="hp", label="HP2"},
	REGULAR_STAT:bind{name="speed", label="Speed2"},
	RES_STAT:bind{name="bleed", label="Bleed2"},
	RES_STAT:bind{name="blight", label="Blight2"},
	RES_STAT:bind{name="burn", label="Burn2"},
	RES_STAT:bind{name="disease", label="Disease2"},
	RES_STAT:bind{name="stun", label="Stun2"},
	RES_STAT:bind{name="move", label="Move2"},
	RES_STAT:bind{name="debuff", label="Debuff2"},
	RES_STAT:bind{name="deathblow", label="DB2"},
}

local UPGRADED_STATS = {}
local STATS = {Utils.unpack(BASE_STATS)}
for _, stat in ipairs(BASE_STATS) do
	local upgraded = stat:bind{
		name="upgraded_" .. stat.name,
		base=stat
	}
	stat.upgraded = upgraded
	table.insert(UPGRADED_STATS, upgraded)
	table.insert(STATS, upgraded)
end

local function _parse_hero(args)
	for _, stat in ipairs(STATS) do
		args[stat.name] = tonumber(args[stat.name])
		local cdf = stat.name .. "_cdf"
		if args[cdf] ~= nil then
			args[cdf] = tonumber(args[cdf])
		end
	end
	if args.forward ~= nil then
		args.forward = tonumber(args.forward)
	end
	if args.backward ~= nil then
		args.backward = tonumber(args.backward)
	end
	return args
end

return {
	BASE_STATS=BASE_STATS,
	UPGRADED_STATS=UPGRADED_STATS,
	STATS=STATS,
	_parse_hero=_parse_hero
}