Skip to content
Snippets Groups Projects
Commit 29f774c7 authored by dg's avatar dg
Browse files

fix cheating in talent learning dialog

git-svn-id: http://svn.net-core.org/repos/t-engine4@409 51575b47-30f0-44d4-a5cc-537603b46e54
parent fafa1860
No related branches found
No related tags found
No related merge requests found
......@@ -140,7 +140,9 @@ function _M:drawSelectionList(s, x, y, hskip, list, sel, prop, scroll, max, colo
elseif prop and type(v[prop]) == "function" then v = tostring(v[prop](v))
else v = tostring(v) end
local lines = v:splitLines(max_size or 100000, self.font)
local lines
if max_size then lines = v:splitLines(max_size, self.font)
else lines = {v} end
for j = 1, #lines do
if sel == i then
s:drawColorString(self.font, lines[j], x, y, selcolor[1], selcolor[2], selcolor[3])
......
......@@ -164,11 +164,13 @@ function _M:isTalentActive(t_id)
end
--- Returns how many talents of this type the actor knows
function _M:numberKnownTalent(type)
-- @param type the talent type to count
-- @param exlude_id if not nil the count will ignore this talent id
function _M:numberKnownTalent(type, exlude_id)
local nb = 0
for id, _ in pairs(self.talents) do
local t = _M.talents_def[id]
if t.type[1] == type then nb = nb + 1 end
if t.type[1] == type and (not exlude_id or exlude_id ~= id) then nb = nb + 1 end
end
return nb
end
......@@ -227,12 +229,15 @@ function _M:unlearnTalent(t_id)
return true
end
function _M:canLearnTalent(t)
--- Checks the talent if learnable
-- @param t the talent to check
-- @param offset the level offset to check, defaults to 1
function _M:canLearnTalent(t, offset)
-- Check prerequisites
if t.require then
local req = t.require
if type(req) == "function" then req = req(self, t) end
local tlev = self:getTalentLevelRaw(t) + 1
local tlev = self:getTalentLevelRaw(t) + (offset or 1)
-- Obviously this requires the ActorStats interface
if req.stat then
......@@ -257,8 +262,10 @@ function _M:canLearnTalent(t)
end
end
if not self:knowTalentType(t.type[1]) and not t.type_no_req then return nil, "unknown talent type" end
-- Check talent type
local known = self:numberKnownTalent(t.type[1])
local known = self:numberKnownTalent(t.type[1], t.id)
if t.type[2] and known < t.type[2] - 1 then
return nil, "not enough talents of this type known"
end
......@@ -280,8 +287,12 @@ function _M:getTalentReqDesc(t_id, levmod)
local str = ""
if not t.type_no_req then
str = str .. (self:knowTalentType(t.type[1]) and "#00ff00#" or "#ff0000#") .. "- Talent category known\n"
end
if t.type[2] and t.type[2] > 1 then
local known = self:numberKnownTalent(t.type[1])
local known = self:numberKnownTalent(t.type[1], t.id)
local c = (known >= t.type[2] - 1) and "#00ff00#" or "#ff0000#"
str = str .. ("- %sTalents of the same category: %d\n"):format(c, t.type[2] - 1)
end
......@@ -327,6 +338,7 @@ end
--- Do we know this talent
function _M:knowTalent(id)
if type(id) == "table" then id = id.id end
return self.talents[id] and true or false
end
......
......@@ -6,15 +6,33 @@ module(..., package.seeall, class.inherit(engine.Dialog))
function _M:init(actor, on_finish)
self.actor = actor
self.actor_dup = actor:clone()
engine.Dialog.init(self, "Talents Levelup: "..actor.name, 800, 600)
engine.Dialog.init(self, "Talents Levelup: "..actor.name, math.max(game.w * 0.85, 800), math.max(game.h * 0.85, 600))
self.actor.__hidden_talent_types = self.actor.__hidden_talent_types or {}
self:generateList()
self.talents_changed = {}
self.sel = 1
self.scroll = 1
self.max = math.floor((self.ih - 45) / self.font_h) - 1
self:keyCommands(nil, {
self:keyCommands({
__TEXTINPUT = function(c)
if not self.list[self.sel] or not self.list[self.sel].type then return end
if c == "+" then
self.actor.__hidden_talent_types[self.list[self.sel].type] = false
self:generateList()
self.changed = true
end
if c == "-" then
self.actor.__hidden_talent_types[self.list[self.sel].type] = true
self:generateList()
self.changed = true
end
end,
}, {
MOVE_UP = function() self.sel = util.boundWrap(self.sel - 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) self.changed = true end,
MOVE_DOWN = function() self.sel = util.boundWrap(self.sel + 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) self.changed = true end,
MOVE_LEFT = function() self:learn(false) self.changed = true end,
......@@ -40,29 +58,32 @@ function _M:generateList()
for i, tt in ipairs(self.actor.talents_types_def) do
if not tt.hide and not (self.actor.talents_types[tt.type] == nil) then
local cat = tt.type:gsub("/.*", "")
list[#list+1] = { name=cat:capitalize().." / "..tt.name:capitalize() ..(" (mastery %.02f)"):format(self.actor:getTalentTypeMastery(tt.type)), type=tt.type }
if self.actor:knowTalentType(tt.type) then
known[#known+1] = "#00FF00#known"
local ttknown = self.actor:knowTalentType(tt.type)
list[#list+1] = { name=cat:capitalize().." / "..tt.name:capitalize() ..(" (mastery %.02f)"):format(self.actor:getTalentTypeMastery(tt.type)), type=tt.type, color=ttknown and {0,200,0} or {128,128,128} }
if ttknown then
known[#known+1] = {name="known", color={0,200,0}}
else
known[#known+1] = {name="0/1", color={128,128,128}}
end
-- Find all talents of this school
-- Find all talents of this school
if (self.actor.__hidden_talent_types[tt.type] == nil and ttknown) or (self.actor.__hidden_talent_types[tt.type] ~= nil and not self.actor.__hidden_talent_types[tt.type]) then
for j, t in ipairs(tt.talents) do
if not t.hide then
local typename = "talent"
if t.type[1]:find("^spell/") then typename = "spell" end
list[#list+1] = { name=" "..t.name.." ("..typename..")", talent=t.id }
list[#list+1] = { name=" "..t.name.." ("..typename..")", talent=t.id, color=not ttknown and {128,128,128} }
if self.actor:getTalentLevelRaw(t.id) == t.points then
known[#known+1] = "#00FF00#known"
known[#known+1] = {name="known", color=ttknown and {0,255,0} or {128,128,128}}
else
if not self.actor:canLearnTalent(t) then
known[#known+1] = "#FF0000#"..self.actor:getTalentLevelRaw(t.id).."/"..t.points
known[#known+1] = {name=self.actor:getTalentLevelRaw(t.id).."/"..t.points, color=ttknown and {255,0,0} or {128,128,128}}
else
known[#known+1] = self.actor:getTalentLevelRaw(t.id).."/"..t.points
known[#known+1] = {name=self.actor:getTalentLevelRaw(t.id).."/"..t.points, color = not ttknown and {128,128,128}}
end
end
end
end
else
known[#known+1] = tt.points.." point(s)"
end
end
end
......@@ -78,6 +99,16 @@ function _M:learn(v)
end
end
function _M:checkDeps()
print("Check deps!")
for t_id, _ in pairs(self.talents_changed) do
local t = self.actor:getTalentFromId(t_id)
print("Check deps!", t.name, self.actor:canLearnTalent(t, 0), self.actor:knowTalent(t))
if not self.actor:canLearnTalent(t, 0) and self.actor:knowTalent(t) then return false, t.name end
end
return true
end
function _M:learnTalent(t_id, v)
local t = self.actor:getTalentFromId(t_id)
if v then
......@@ -95,6 +126,7 @@ function _M:learnTalent(t_id, v)
end
self.actor:learnTalent(t_id)
self.actor.unused_talents = self.actor.unused_talents - 1
self.talents_changed[t_id] = true
else
if not self.actor:knowTalent(t_id) then
self:simplePopup("Impossible", "You do not know this talent!")
......@@ -105,7 +137,14 @@ function _M:learnTalent(t_id, v)
return
end
self.actor:unlearnTalent(t_id)
self.actor.unused_talents = self.actor.unused_talents + 1
local ok, dep_miss = self:checkDeps()
if ok then
self.actor.unused_talents = self.actor.unused_talents + 1
else
self:simplePopup("Impossible", "You can not unlearn this talent because of talent: "..dep_miss)
self.actor:learnTalent(t_id)
return
end
end
self:generateList()
end
......@@ -132,7 +171,14 @@ function _M:learnType(tt, v)
return
end
self.actor:unlearnTalentType(tt)
self.actor.unused_talents_types = self.actor.unused_talents_types + 1
local ok, dep_miss = self:checkDeps()
if ok then
self.actor.unused_talents_types = self.actor.unused_talents_types + 1
else
self:simplePopup("Impossible", "You can not unlearn this category because of talent: "..dep_miss)
self.actor:learnTalentType(tt)
return
end
end
self:generateList()
......@@ -142,7 +188,7 @@ function _M:drawDialog(s)
-- Description part
self:drawHBorder(s, self.iw / 2, 2, self.ih - 4)
local talentshelp = ([[Keyboard: #00FF00#up key/down key#FFFFFF# to select a stat; #00FF00#right key#FFFFFF# to learn; #00FF00#left key#FFFFFF# to unlearn.
local talentshelp = ([[Keyboard: #00FF00#up key/down key#FFFFFF# to select a stat; #00FF00#right key#FFFFFF# to learn; #00FF00#left key#FFFFFF# to unlearn; #00FF00#+#FFFFFF# to expand a category; #00FF00#-#FFFFFF# to reduce a category.
Mouse: #00FF00#Left click#FFFFFF# to learn; #00FF00#right click#FFFFFF# to unlearn.
]]):splitLines(self.iw / 2 - 10, self.font)
......@@ -201,7 +247,7 @@ Mouse: #00FF00#Left click#FFFFFF# to learn; #00FF00#right click#FFFFFF# to unlea
self:drawWBorder(s, 2, 40, 200)
self:drawSelectionList(s, 2, 45, self.font_h, self.list, self.sel, "name" , self.scroll, self.max)
self:drawSelectionList(s, 300, 45, self.font_h, self.list_known, self.sel, nil, self.scroll, self.max)
self:drawSelectionList(s, self.iw / 2 - 70, 45, self.font_h, self.list_known, self.sel, "name", self.scroll, self.max)
self.changed = false
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment