From 07d5f16d12b4f799ce3aaf37a11b5aaa3ae6a865 Mon Sep 17 00:00:00 2001
From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54>
Date: Wed, 1 Sep 2010 16:57:22 +0000
Subject: [PATCH] Progressive teleporation resistance affects NPCs being
 teleported against their will

git-svn-id: http://svn.net-core.org/repos/t-engine4@1124 51575b47-30f0-44d4-a5cc-537603b46e54
---
 .../tome/data/talents/spells/conveyance.lua   | 23 ++++++++++-----
 game/modules/tome/data/timed_effects.lua      | 28 +++++++++++++++++++
 2 files changed, 44 insertions(+), 7 deletions(-)

diff --git a/game/modules/tome/data/talents/spells/conveyance.lua b/game/modules/tome/data/talents/spells/conveyance.lua
index 54b8bd092f..f45f1d3383 100644
--- a/game/modules/tome/data/talents/spells/conveyance.lua
+++ b/game/modules/tome/data/talents/spells/conveyance.lua
@@ -40,11 +40,15 @@ newTalent{
 				end
 			end
 		end
-
-		if target ~= self and (not target:canBe("teleport") or not self:checkHit(self:combatSpellpower(), target:combatSpellResist())) then
-			game.logSeen(target, "The spell fizzles!")
-			return true
+		if target ~= self and target:canBe("teleport") then
+			local hit = self:checkHit(self:combatSpellpower(), target:combatSpellResist() + (target:attr("continuum_destabilization") or 0))
+			if not hit then
+				game.logSeen(target, "The spell fizzles!")
+				return true
+			end
+			target:setEffect(target.EFF_CONTINUUM_DESTABILIZATION, 100 , {power=20 - self:getTalentLevel(t)})
 		end
+
 		-- Annoy them!
 		if target ~= self and target:reactionToward(self) < 0 then target:setTarget(self) end
 
@@ -100,10 +104,15 @@ newTalent{
 			end
 		end
 
-		if target ~= self and (not target:canBe("teleport") or not self:checkHit(self:combatSpellpower(), target:combatSpellResist())) then
-			game.logSeen(target, "The spell fizzles!")
-			return true
+		if target ~= self and target:canBe("teleport") then
+			local hit = self:checkHit(self:combatSpellpower(), target:combatSpellResist() + (target:attr("continuum_destabilization") or 0))
+			if not hit then
+				game.logSeen(target, "The spell fizzles!")
+				return true
+			end
+			target:setEffect(target.EFF_CONTINUUM_DESTABILIZATION, 100 , {power=20 - self:getTalentLevel(t)})
 		end
+
 		-- Annoy them!
 		if target ~= self and target:reactionToward(self) < 0 then target:setTarget(self) end
 
diff --git a/game/modules/tome/data/timed_effects.lua b/game/modules/tome/data/timed_effects.lua
index cedbfe29b0..de6224f1f4 100644
--- a/game/modules/tome/data/timed_effects.lua
+++ b/game/modules/tome/data/timed_effects.lua
@@ -1013,3 +1013,31 @@ newEffect{
 		self:removeTemporaryValue("resists", eff.tmpid)
 	end,
 }
+
+newEffect{
+	name = "CONTINUUM_DESTABILIZATION",
+	desc = "Continuum Destabilization",
+	type = "other", -- Type "other" so that nothing can dispel it
+	status = "beneficial",
+	parameters = { power=10 },
+	on_gain = function(self, err) return "#Target# looks a little pale around the edges.", "+Destabilized" end,
+	on_lose = function(self, err) return "#Target# is firmly planted in reality.", "-Destabilized" end,
+	on_merge = function(self, old_eff, new_eff)
+		-- Merge the continuum_destabilization
+		local olddam = old_eff.power * old_eff.dur
+		local newdam = new_eff.power * new_eff.dur
+		local dur = math.ceil((old_eff.dur + new_eff.dur) / 2)
+		old_eff.dur = dur
+		old_eff.power = (olddam + newdam) / dur
+		-- Need to remove and re-add the continuum_destabilization
+		self:removeTemporaryValue("continuum_destabilization", old_eff.effid)
+		old_eff.effid = self:addTemporaryValue("continuum_destabilization", old_eff.power)
+		return old_eff
+	end,
+	activate = function(self, eff)
+		eff.effid = self:addTemporaryValue("continuum_destabilization", eff.power)
+	end,
+	deactivate = function(self, eff)
+		self:removeTemporaryValue("continuum_destabilization", eff.effid)
+	end,
+}
-- 
GitLab