Expanding preUseTalent
Posted: Wed Sep 22, 2010 4:24 pm
I believe there has been some confusion about when talents are actually used by players since the talent message (eg. "Player rushes out") is displayed even though the talent may fail or be canceled due to targeting. I have played a bit with this in my module, and propose the following for discussion.
We can add a check in preUseTalent just after checking the resources and before printing the message:
The on_preuse function can take handle simple things like ammo for bows/slings (so that the bad ammo messages still appear but the "Player shoots" does not). The on_preuse function could also handle the talent targetting, although then there is the issue of where to store the targeting information (probably in the actor). For example, here is my on_preuse function for the Stealth talent:
A corresponding on_postuse function could also be implemented. Thoughts?
We can add a check in preUseTalent just after checking the resources and before printing the message:
Code: Select all
-- Check for special preuse
if ab.on_preuse and not ab.on_preuse(self, ab) then
return false
end
Code: Select all
on_preuse = function(self, t)
-- Check nearby actors
local grids = core.fov.circle_grids(self.x, self.y, math.floor(10 - self:getTalentLevel(t) * 1.1), true)
for x, yy in pairs(grids) do for y in pairs(yy) do
local actor = game.level.map(x, y, game.level.map.ACTOR)
if actor and actor ~= self and actor:reactionToward(self) < 0 and not rng.percent(self.hide_chance or 0) then
game.logPlayer(self, "You cannot Stealth with nearby foes watching!")
return nil
end
end end
return true
end,