From e12640e54887a41a22586474e0389b597e588f0b Mon Sep 17 00:00:00 2001
From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54>
Date: Mon, 4 Jan 2010 13:44:45 +0000
Subject: [PATCH] disruption shield

git-svn-id: http://svn.net-core.org/repos/t-engine4@196 51575b47-30f0-44d4-a5cc-537603b46e54
---
 game/engine/interface/ActorLife.lua           |  2 +-
 game/modules/tome/class/Actor.lua             | 15 +++++++++++++
 game/modules/tome/class/NPC.lua               |  3 ++-
 .../data/talents/physical/combat-training.lua |  2 +-
 .../tome/data/talents/spells/arcane.lua       | 21 ++++++++++++-------
 5 files changed, 32 insertions(+), 11 deletions(-)

diff --git a/game/engine/interface/ActorLife.lua b/game/engine/interface/ActorLife.lua
index 8ed6b654a5..3b18d2ecca 100644
--- a/game/engine/interface/ActorLife.lua
+++ b/game/engine/interface/ActorLife.lua
@@ -39,8 +39,8 @@ end
 -- If HP is reduced to 0 then remove from the level and call the die method.<br/>
 -- When an actor dies its dead property is set to true, to wait until garbage collection deletes it
 function _M:takeHit(value, src)
+	if self.onTakeHit then value = self:onTakeHit(value, src) end
 	self.life = self.life - value
-	if self.onTakeHit then self:onTakeHit(value, src) end
 	if self.life <= 0 then
 		game.logSeen(self, "%s killed %s!", src.name:capitalize(), self.name)
 		game.level:removeEntity(self)
diff --git a/game/modules/tome/class/Actor.lua b/game/modules/tome/class/Actor.lua
index bb75b60f4e..fbe6eed890 100644
--- a/game/modules/tome/class/Actor.lua
+++ b/game/modules/tome/class/Actor.lua
@@ -122,6 +122,21 @@ function _M:tooltip()
 	return ("%s\n#00ffff#Level: %d\nExp: %d/%d\n#ff0000#HP: %d"):format(self.name, self.level, self.exp, self:getExpChart(self.level+1) or "---", self.life)
 end
 
+--- Called before taking a hit, it's the chance to check for shields
+function _M:onTakeHit(value, src)
+	if self:attr("mana_shield") then
+		local mana = self:getMana()
+		local mana_val = value * self:attr("mana_shield")
+		-- We have enough to absord the full hit
+		if mana_val <= mana then
+			self:incMana(-mana_val)
+			return 0
+		-- Or we dont! and we do nothing
+		end
+	end
+	return value
+end
+
 function _M:die(src)
 	-- Gives the killer some exp for the kill
 	if src then
diff --git a/game/modules/tome/class/NPC.lua b/game/modules/tome/class/NPC.lua
index cf750d2e53..09c58e3afb 100644
--- a/game/modules/tome/class/NPC.lua
+++ b/game/modules/tome/class/NPC.lua
@@ -22,10 +22,11 @@ end
 --- Called by ActorLife interface
 -- We use it to pass aggression values to the AIs
 function _M:onTakeHit(value, src)
-	print("took hit from", src.name, "::", self.ai_target.actor)
 	if not self.ai_target.actor then
 		self.ai_target.actor = src
 	end
+
+	return mod.class.Actor.onTakeHit(self, value, src)
 end
 
 function _M:tooltip()
diff --git a/game/modules/tome/data/talents/physical/combat-training.lua b/game/modules/tome/data/talents/physical/combat-training.lua
index 74a56cad66..bd0d7227fc 100644
--- a/game/modules/tome/data/talents/physical/combat-training.lua
+++ b/game/modules/tome/data/talents/physical/combat-training.lua
@@ -23,7 +23,7 @@ newTalent{
 	type = {"physical/combat-training", 1},
 	mode = "passive",
 	points = 5,
-	require = { stat = { con=14 }, },
+	require = { stat = { con=function(level) return 14 + level * 5 end }, },
 	on_learn = function(self, t)
 		self.max_life = self.max_life + 40
 	end,
diff --git a/game/modules/tome/data/talents/spells/arcane.lua b/game/modules/tome/data/talents/spells/arcane.lua
index a84b7bda56..b533fdaf23 100644
--- a/game/modules/tome/data/talents/spells/arcane.lua
+++ b/game/modules/tome/data/talents/spells/arcane.lua
@@ -13,7 +13,6 @@ newTalent{
 		if self:getTalentLevel(t) >= 3 then tg.type = "beam" end
 		local x, y = self:getTarget(tg)
 		if not x or not y then return nil end
-		print("lvel", self:getTalentLevel(t))
 		self:project(tg, x, y, DamageType.ARCANE, self:spellCrit(10 + self:combatSpellpower(0.5) * self:getTalentLevel(t)))
 		return true
 	end,
@@ -54,13 +53,13 @@ newTalent{
 	points = 5,
 	require = { stat = { mag=28 }, },
 	on_learn = function(self, t)
-		self.combat_spellpower = self.combat_spellpower + 3
+		self.combat_spellpower = self.combat_spellpower + 5
 	end,
 	on_unlearn = function(self, t)
-		self.combat_spellpower = self.combat_spellpower - 3
+		self.combat_spellpower = self.combat_spellpower - 5
 	end,
 	info = function(self, t)
-		return [[Your mastery of magic allows your to permanently increase your spellpower by 3.]]
+		return [[Your mastery of magic allows your to permanently increase your spellpower by 5.]]
 	end,
 }
 
@@ -74,12 +73,18 @@ newTalent{
 		DEFEND = 10,
 	},
 	activate = function(self, t)
-		game.log("IMPLEMENT ME!")
+		local power = 3 - (self:combatSpellpower(1) * self:getTalentLevel(t)) / 280
+		return {
+			shield = self:addTemporaryValue("mana_shield", power),
+		}
+	end,
+	deactivate = function(self, t, p)
+		self:removeTemporaryValue("mana_shield", p.shield)
 		return true
 	end,
-	require = { stat = { mag=60 }, level=40 },
+	require = { stat = { mag=40 }, level=20 },
 	info = function(self, t)
-		return ([[Uses mana instead of life to take damage
-		The damage to mana ratio increases with the Magic stat]]):format(10 + self:combatSpellpower())
+		return ([[Uses mana instead of life to take damage. Uses %0.2f mana per damage taken.
+		The damage to mana ratio increases with the Magic stat]]):format(3 - (self:combatSpellpower(1) * self:getTalentLevel(t)) / 280)
 	end,
 }
-- 
GitLab