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

resting

git-svn-id: http://svn.net-core.org/repos/t-engine4@221 51575b47-30f0-44d4-a5cc-537603b46e54
parent f98c055d
No related branches found
No related tags found
No related merge requests found
......@@ -25,8 +25,9 @@ end
function _M:restStep()
if not self.resting then return false end
if not self:restCheck() then
self:restStop()
local ret, msg = self:restCheck()
if not ret then
self:restStop(msg)
return false
else
self:useEnergy()
......@@ -43,12 +44,16 @@ function _M:restCheck()
end
--- Stops resting
function _M:restStop()
function _M:restStop(msg)
if not self.resting then return false end
game:unregisterDialog(self.resting.dialog)
game.log("Rested for %d turns.", self.resting.cnt)
if msg then
game.log("Rested for %d turns (stop reason: %s).", self.resting.cnt, msg)
else
game.log("Rested for %d turns.", self.resting.cnt)
end
self.resting = nil
return true
......
......@@ -151,17 +151,18 @@ end
--- Can we continue resting ?
-- We can rest if no hostiles are in sight, and if we need life/mana/stamina (and their regen rates allows them to fully regen)
function _M:restCheck()
local seen = false
-- Check for visible monsters, only see LOS actors, so telepathy wont prevent resting
core.fov.calc_circle(self.x, self.y, 20, game.level.map.opaque, function(map, x, y)
local actor = map(x, y, map.ACTOR)
if actor and self:reactionToward(actor) < 0 and self:canSee(actor) then seen = true end
end, game.level.map)
if seen then return false, "hostile spotted" end
-- Check ressources, make sure they CAN go up, otherwise we will never stop
if self:getMana() < self:getMaxMana() and self.mana_regen > 0 then return true end
if self:getStamina() < self:getMaxStamina() and self.stamina_regen > 0 then return true end
if self.life < self.max_life and self.life_regen> 0 then return true end
--[[
core.fov.calc_circle(x, y, radius, function(self, lx, ly)
if not grids[lx] then grids[lx] = {} end
grids[lx][ly] = true
if block and game.level.map:checkEntity(lx, ly, engine.Map.TERRAIN, "block_move") then return true end
end, function()end, self)
]]
return false, "all resources and life at maximun"
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