From 2a9f581983ea44cdec5adea93eb2232437cdea6c Mon Sep 17 00:00:00 2001 From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54> Date: Mon, 4 Jan 2010 13:22:32 +0000 Subject: [PATCH] multipoints talents can now have requirements for each levels git-svn-id: http://svn.net-core.org/repos/t-engine4@195 51575b47-30f0-44d4-a5cc-537603b46e54 --- game/engine/interface/ActorTalents.lua | 20 ++++++++++++++----- game/engine/utils.lua | 7 +++++++ .../data/talents/physical/weapon-training.lua | 4 ++++ .../tome/dialogs/LevelupTalentsDialog.lua | 4 ++-- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/game/engine/interface/ActorTalents.lua b/game/engine/interface/ActorTalents.lua index 1e1284fea8..4b34ecf3ca 100644 --- a/game/engine/interface/ActorTalents.lua +++ b/game/engine/interface/ActorTalents.lua @@ -227,14 +227,19 @@ end function _M:canLearnTalent(t) -- Check prerequisites if t.require then + local tlev = self:getTalentLevelRaw(t) + 1 + -- Obviously this requires the ActorStats interface if t.require.stat then for s, v in pairs(t.require.stat) do + v = util.getval(v, tlev) if self:getStat(s) < v then return nil, "not enough stat" end end end - if t.require.level and self.level < t.require.level then - return nil, "not enough levels" + if t.require.level then + if self.level < util.getval(t.require.level, tlev) then + return nil, "not enough levels" + end end if t.require.talent then for _, tid in ipairs(t.require.talent) do @@ -255,11 +260,14 @@ end --- Formats the requirements as a (multiline) string -- @param t_id the id of the talent to desc -function _M:getTalentReqDesc(t_id) +-- @param levmod a number (1 should be the smartest) to add to current talent level to display requirements, defaults to 0 +function _M:getTalentReqDesc(t_id, levmod) local t = _M.talents_def[t_id] local req = t.require if not req then return "" end + local tlev = self:getTalentLevelRaw(t_id) + (levmod or 0) + local str = "" if t.type[2] and t.type[2] > 1 then @@ -271,13 +279,15 @@ function _M:getTalentReqDesc(t_id) -- Obviously this requires the ActorStats interface if req.stat then for s, v in pairs(req.stat) do + v = util.getval(v, tlev) local c = (self:getStat(s) >= v) and "#00ff00#" or "#ff0000#" str = str .. ("- %s%s %d\n"):format(c, self.stats_def[s].name, v) end end if req.level then - local c = (self.level >= req.level) and "#00ff00#" or "#ff0000#" - str = str .. ("- %sLevel %d\n"):format(c, req.level) + local v = util.getval(req.level, tlev) + local c = (self.level >= v) and "#00ff00#" or "#ff0000#" + str = str .. ("- %sLevel %d\n"):format(c, v) end if req.talent then for _, tid in ipairs(req.talent) do diff --git a/game/engine/utils.lua b/game/engine/utils.lua index 131e21efd2..7ad5d03170 100644 --- a/game/engine/utils.lua +++ b/game/engine/utils.lua @@ -235,6 +235,13 @@ function util.scroll(sel, scroll, max) return scroll end +function util.getval(val, ...) + if type(val) == "function" then return val(...) + elseif type(val) == "table" then return val[rng.range(1, #val)] + else return val + end +end + function core.fov.circle_grids(x, y, radius, block) local grids = {} core.fov.calc_circle(x, y, radius, function(self, lx, ly) diff --git a/game/modules/tome/data/talents/physical/weapon-training.lua b/game/modules/tome/data/talents/physical/weapon-training.lua index 0fedddb7b5..0fe59792cb 100644 --- a/game/modules/tome/data/talents/physical/weapon-training.lua +++ b/game/modules/tome/data/talents/physical/weapon-training.lua @@ -2,6 +2,7 @@ newTalent{ name = "Sword Mastery", type = {"physical/weapon-training", 1}, points = 10, + require = { stat = { str=function(level) return 10 + level * 3 end }, }, mode = "passive", info = function(self) return [[Increases damage and attack with swords.]] @@ -12,6 +13,7 @@ newTalent{ name = "Axe Mastery", type = {"physical/weapon-training", 1}, points = 10, + require = { stat = { str=function(level) return 10 + level * 3 end }, }, mode = "passive", info = function(self) return [[Increases damage and attack with axes.]] @@ -22,6 +24,7 @@ newTalent{ name = "Mace Mastery", type = {"physical/weapon-training", 1}, points = 10, + require = { stat = { str=function(level) return 10 + level * 3 end }, }, mode = "passive", info = function(self) return [[Increases damage and attack with maces.]] @@ -32,6 +35,7 @@ newTalent{ name = "Knife Mastery", type = {"physical/weapon-training", 1}, points = 10, + require = { stat = { str=function(level) return 10 + level * 3 end }, }, mode = "passive", info = function(self) return [[Increases damage and attack with knifes.]] diff --git a/game/modules/tome/dialogs/LevelupTalentsDialog.lua b/game/modules/tome/dialogs/LevelupTalentsDialog.lua index ec6f3eb9bf..c7ac1bdf8a 100644 --- a/game/modules/tome/dialogs/LevelupTalentsDialog.lua +++ b/game/modules/tome/dialogs/LevelupTalentsDialog.lua @@ -159,9 +159,9 @@ Mouse: #00FF00#Left click#FFFFFF# to learn; #00FF00#right click#FFFFFF# to unlea helplines = str:splitLines(self.iw / 2 - 10, self.font) local t = self.actor:getTalentFromId(self.list[self.sel].talent) lines = t.info(self.actor, t):splitLines(self.iw / 2 - 10, self.font) - local req = self.actor:getTalentReqDesc(self.list[self.sel].talent) + local req = self.actor:getTalentReqDesc(self.list[self.sel].talent, 1) if req ~= "" then - req = "Requirements:\n"..req + req = "Requirements for next point:\n"..req reqlines = req:splitLines(self.iw / 2 - 10, self.font) end end -- GitLab