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

resting

git-svn-id: http://svn.net-core.org/repos/t-engine4@220 51575b47-30f0-44d4-a5cc-537603b46e54
parent 34dc804c
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,7 @@ function _M:simplePopup(title, text, fct)
s:drawColorStringCentered(self.font, text, 2, 2, self.iw - 2, self.ih - 2)
end
game:registerDialog(d)
return d
end
--- Create a Dialog
......
......@@ -40,10 +40,21 @@ function _M:defineResource(name, short_name, talent, regen_prop, desc)
return 0
end
end
-- if there is an associated talent, check for it
self["getMax"..short_name:lower():capitalize()] = function(self)
if self:knowTalent(talent) then
return self[maxname]
else
return 0
end
end
else
self["get"..short_name:lower():capitalize()] = function(self)
return self[short_name]
end
self["getMax"..short_name:lower():capitalize()] = function(self)
return self[maxname]
end
end
end
......
require "engine.class"
local Dialog = require "engine.Dialog"
--- Handles player resting
module(..., package.seeall, class.make)
--- Initializes resting
function _M:restInit()
self.resting = {
cnt = 1,
dialog = Dialog:simplePopup("Resting...", "You are resting, press any key to stop.", function()
self:restStop()
end),
}
self:useEnergy()
game.log("Resting starts...")
end
--- Rest a turn
-- For a turn based game you want in you player's act() something like that:<br/>
-- <pre>
-- if not self:restStep() then game.paused = true end
-- </pre>
-- @return true if we can continue to rest, false otherwise
function _M:restStep()
if not self.resting then return false end
if not self:restCheck() then
self:restStop()
return false
else
self:useEnergy()
self.resting.cnt = self.resting.cnt + 1
return true
end
end
--- Can we continue resting ?
-- Rewrite this method to check for mana, life, whatever. By default we alawys return false so resting will never work
-- @return true if we can continue to rest, false otherwise
function _M:restCheck()
return false
end
--- Stops resting
function _M:restStop()
if not self.resting then return false end
game:unregisterDialog(self.resting.dialog)
game.log("Rested for %d turns.", self.resting.cnt)
self.resting = nil
return true
end
......@@ -194,11 +194,13 @@ function _M:onTurn()
end
function _M:display()
-- We display the player's interface
self.flash:display():toScreen(self.flash.display_x, self.flash.display_y)
self.logdisplay:display():toScreen(self.logdisplay.display_x, self.logdisplay.display_y)
self.player_display:display():toScreen(self.player_display.display_x, self.player_display.display_y)
self.talents_display:display():toScreen(self.talents_display.display_x, self.talents_display.display_y)
-- Now the map, if any
if self.level and self.level.map then
-- Display the map and compute FOV for the player if needed
if self.level.map.changed then
......@@ -336,6 +338,11 @@ function _M:setupCommands()
_RIGHTPAREN = function() self.player:activateHotkey(11) end,
_EQUALS = function() self.player:activateHotkey(12) end,
-- resting
[{"_r","shift"}] = function()
self.player:restInit()
end,
-- talent use
_m = function()
self.player:useTalents()
......@@ -587,6 +594,8 @@ end
--- Ask if we realy want to close, if so, save the game first
function _M:onQuit()
self.player:restStop()
if not self.quit_dialog then
self.quit_dialog = QuitDialog.new()
self:registerDialog(self.quit_dialog)
......
require "engine.class"
require "mod.class.Actor"
require "engine.interface.PlayerRest"
local Savefile = require "engine.Savefile"
local Map = require "engine.Map"
local Dialog = require "engine.Dialog"
local ActorTalents = require "engine.interface.ActorTalents"
module(..., package.seeall, class.inherit(mod.class.Actor))
module(..., package.seeall, class.inherit(mod.class.Actor, engine.interface.PlayerRest))
function _M:init(t, no_default)
t.body = {
......@@ -73,7 +74,10 @@ function _M:act()
-- Clean log flasher
game.flash:empty()
game.paused = true
-- Resting ?
if not self:restStep() then
game.paused = true
end
end
function _M:die()
......@@ -143,3 +147,21 @@ function _M:activateHotkey(id)
Dialog:simplePopup("Hotkey not defined", "You may define a hotkey by pressing 'm' and following the inscructions there.")
end
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()
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)
]]
end
......@@ -2,6 +2,7 @@ newTalent{
name = "Heavy Armour Training",
type = {"physical/combat-training", 1},
mode = "passive",
points = 5,
require = { stat = { str=18 }, },
info = function(self, t)
return [[Teaches the usage of heavy mail armours.]]
......@@ -12,6 +13,7 @@ newTalent{
name = "Massive Armour Training",
type = {"physical/combat-training", 2},
mode = "passive",
points = 5,
require = { stat = { str=22 }, talent = { Talents.T_HEAVY_ARMOUR_TRAINING }, },
info = function(self, t)
return [[Teaches the usage of massive plate armours.]]
......
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