Last active
September 2, 2015 04:09
-
-
Save balaam/333a23236281a94a2918 to your computer and use it in GitHub Desktop.
Stats
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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