Skip to content

Instantly share code, notes, and snippets.

@balaam
Last active September 2, 2015 04:09
Show Gist options
  • Select an option

  • Save balaam/333a23236281a94a2918 to your computer and use it in GitHub Desktop.

Select an option

Save balaam/333a23236281a94a2918 to your computer and use it in GitHub Desktop.
Stats
mBase =
{
body = 4,
mind = 5,
vitality = function(stats)
local bodyWeighting = 0.5
local mindWeight = 0.1
return stats:Get("body") * bodyWeighting + stats:Get("mind") * mindWeight
end,
hp_max = function(stats)
return stats:Get("vitality") * stats:Get("level") -- if level is stored in the stats table ... I don't think I do!
end
}
-- Later on in the code
function Stats:Get(id)
local total = 0
if type(self.mBase[id]) == "number" then
total = self.mBase[id]
elseif type(self.mBase[id]) == "function" then
total = self.mBase[id](self)
end
local multiplier = 0
for k, v in pairs(self.mModifiers) do
total = total + (v.add[id] or 0)
multiplier = multiplier + (v.mult[id] or 0)
end
return total + (total * multiplier)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment