Skip to content
Snippets Groups Projects
Commit 58046d9d authored by DarkGod's avatar DarkGod
Browse files

Merge branch 'infinite_lua_chain' into 'master'

Infinite lua chain

We all know how an NPC selecting an erroneous talent again and again wrecks the game by infinite Lua chain. This commit fixes it!
parents cde22396 a2e5e5fd
No related branches found
No related tags found
No related merge requests found
......@@ -174,7 +174,11 @@ function _M:useTalent(id, who, force_level, ignore_cd, force_target, silent, no_
-- cancel checked in coroutine
success, err = coroutine.resume(co)
end
if not success and err then print(debug.traceback(co)) error(err) end
if not success and err then
print(debug.traceback(co))
self:onTalentLuaError(err)
error(err)
end
elseif ab.mode == "sustained" and ab.activate and ab.deactivate then
if self:isTalentCoolingDown(ab) and not ignore_cd then
game.logPlayer(who, "%s is still on cooldown for %d turns.", ab.name:capitalize(), self.talents_cd[ab.id])
......@@ -280,6 +284,13 @@ function _M:postUseTalent(talent, ret, silent)
return true
end
--- Called if a talent errors out
-- @param ab the talent
-- @param err the error
function _M:onTalentLuaError(ab, err)
return
end
--- Force a talent to activate without using energy or such
-- "def" can have a field "ignore_energy" to not consume energy; other parameters can be passed and handled by an overload of this method.
-- Object activation interface calls this method with an "ignore_ressources" parameter
......
......@@ -108,6 +108,10 @@ local function spotHostiles(self)
return seen
end
function _M:onTalentLuaError(ab, err)
self:useEnergy() -- prevent infinitely long erroring out turns
end
--- Try to auto use listed talents
-- This should be called in your actors "act()" method
function _M:automaticTalents()
......
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