From de799e672ce5c7019a60db98dc7446cc6bc21cf6 Mon Sep 17 00:00:00 2001
From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54>
Date: Fri, 27 Jan 2012 10:52:35 +0000
Subject: [PATCH] Meditation now also have a passive effect: when resting it
 grants an equilibrium regen

git-svn-id: http://svn.net-core.org/repos/t-engine4@4811 51575b47-30f0-44d4-a5cc-537603b46e54
---
 .../default/engine/interface/PlayerRest.lua     | 13 +++++++++++++
 game/modules/tome/class/Player.lua              | 17 +++++++++++++++++
 game/modules/tome/data/talents/gifts/call.lua   | 12 ++++++++++--
 3 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/game/engines/default/engine/interface/PlayerRest.lua b/game/engines/default/engine/interface/PlayerRest.lua
index 92c0e5e582..0a002ae168 100644
--- a/game/engines/default/engine/interface/PlayerRest.lua
+++ b/game/engines/default/engine/interface/PlayerRest.lua
@@ -40,6 +40,8 @@ function _M:restInit(turns, what, past, on_end)
 
 	game.log(what:capitalize().." starts...")
 
+	self:onRestStart()
+
 	local ret, msg = self:restCheck()
 	if ret and self.resting and self.resting.rest_turns and self.resting.cnt > self.resting.rest_turns then ret = false msg = nil end
 	if not ret then
@@ -50,6 +52,16 @@ function _M:restInit(turns, what, past, on_end)
 	end
 end
 
+--- We started resting
+-- Rewrite this method to do whatever you need
+function _M:onRestStart()
+end
+
+--- We stopped resting
+-- Rewrite this method to do whatever you need
+function _M:onRestStop()
+end
+
 --- Rest a turn
 -- For a turn based game you want in you player's act() something like that:<br/>
 -- <pre>
@@ -91,6 +103,7 @@ function _M:restStop(msg)
 	end
 
 	if self.resting.on_end then self.resting.on_end(self.resting.cnt, self.resting.rest_turns) end
+	self:onRestStop()
 	self.resting = nil
 	return true
 end
diff --git a/game/modules/tome/class/Player.lua b/game/modules/tome/class/Player.lua
index 692a2a891c..14027a9bb3 100644
--- a/game/modules/tome/class/Player.lua
+++ b/game/modules/tome/class/Player.lua
@@ -576,6 +576,22 @@ local function spotHostiles(self)
 	return seen
 end
 
+--- We started resting
+function _M:onRestStart()
+	if self:attr("equilibrium_regen_on_rest") and not self.resting.equilibrium_regen then
+		self:attr("equilibrium_regen", self:attr("equilibrium_regen_on_rest"))
+		self.resting.equilibrium_regen = self:attr("equilibrium_regen_on_rest")
+	end
+end
+
+--- We stopped resting
+function _M:onRestStop()
+	if self.resting.equilibrium_regen then
+		self:attr("equilibrium_regen", -self.resting.equilibrium_regen)
+		self.resting.equilibrium_regen = nil
+	end
+end
+
 --- Can we continue resting ?
 -- We can rest if no hostiles are in sight, and if we need life/mana/stamina/psi (and their regen rates allows them to fully regen)
 function _M:restCheck()
@@ -606,6 +622,7 @@ 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:getPsi() < self:getMaxPsi() and self.psi_regen > 0 then return true end
+		if self:getEquilibrium() > 0 and self.equilibrium_regen < 0 then return true end
 		if self.life < self.max_life and self.life_regen> 0 then return true end
 		for act, def in pairs(game.party.members) do if game.level:hasEntity(act) and not act.dead then
 			if act.life < act.max_life and act.life_regen> 0 then return true end
diff --git a/game/modules/tome/data/talents/gifts/call.lua b/game/modules/tome/data/talents/gifts/call.lua
index db962d7e4c..3d6b8be5fd 100644
--- a/game/modules/tome/data/talents/gifts/call.lua
+++ b/game/modules/tome/data/talents/gifts/call.lua
@@ -24,9 +24,15 @@ newTalent{
 	points = 5,
 	message = "@Source@ meditates on nature.",
 	mode = "sustained",
-	cooldown = 10,
+	cooldown = 20,
 	range = 10,
 	no_npc_use = true,
+	on_learn = function(self, t)
+		self.equilibrium_regen_on_rest = (self.equilibrium_regen_on_rest or 0) - 0.5
+	end,
+	on_unlearn = function(self, t)
+		self.equilibrium_regen_on_rest = (self.equilibrium_regen_on_rest or 0) + 0.5
+	end,
 	activate = function(self, t)
 		local pt = 2 + self:combatTalentMindDamage(t, 20, 120) / 10
 		local save = 5 + self:combatTalentMindDamage(t, 10, 40)
@@ -51,11 +57,13 @@ newTalent{
 		local pt = 2 + self:combatTalentMindDamage(t, 20, 120) / 10
 		local save = 5 + self:combatTalentMindDamage(t, 10, 40)
 		local heal = 5 + self:combatTalentMindDamage(t, 12, 30)
+		local rest = 0.5 * self:getTalentLevelRaw(t)
 		return ([[Meditate on your link with Nature.
 		While meditating you regenerate %d equilibrium per turn, your mental save is increased by %d and your healing factor by %d%%.
 		Your deep meditation does not however let you deal damage correctly, reducing your damage done by 50%%.
+		Also, any time you are resting (even with Meditation not sustained) you enter a simple meditation state that lets you regenerate %0.2f equilibrium per turn.
 		The effects will increase with your mindpower.]]):
-		format(pt, save, heal)
+		format(pt, save, heal, rest)
 	end,
 }
 
-- 
GitLab