Skip to content
Snippets Groups Projects
Commit a2e5e5fd authored by Alex Ksandra's avatar Alex Ksandra
Browse files

Made Lua errors drain energy on NPCs to prevent infinite chains and allow

potential recoveries.
parent cde22396
No related branches found
No related tags found
1 merge request!74Infinite lua chain
......@@ -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