The idea is to have talents automatically reduce their talent level as their requirements change. The initial strategy is to include a call to ActorTalent:canLearnTalent the ActorTalent:knowTalent, ActorTalent:getTalentLevel and ActorTalent:getTalentLevelRaw functions. To do so a new function was introduced:
Code: Select all
function _M:getTalentLevelRawNoCheck(id)
if type(id) == "table" then id = id.id end
return self.talents[id] or 0
end
function _M:getTalentLevelRaw(id)
if type(id) == "table" then id = id.id end
local raw_level = self:getTalentLevelRawNoCheck(id)
if not self.player then return raw_level end
local offset = 0
local t = self.talents_def[id]
-- Keep reducing the raw talent level until the requirements are met
while (raw_level + offset > 0) and not self:canLearnTalent(t, offset) do
offset = offset - 1
end
return raw_level + offset
end
There have been a few other surprises along the way. First, all of the resource pools and racial talents broke. This is because they are of either the "base/race" or "base/class" categories, which are not actually learned by the player. After adding those two categories to the base birth descriptor (they are hidden, so they never appear in any of the displays) the pools appeared again, but I do not know if this break NPC talents yet.
EDIT: Oh, and one of the main concerns here is performance since the requirements are checked every time the talent level is checked.
EDIT2: I modified the code above so that only the player has its talents reduced.