From b9083762c44bc3cf9731f09e149ff7d1ffc386a8 Mon Sep 17 00:00:00 2001
From: Alexander Sedov <alex0player@gmail.com>
Date: Mon, 15 Dec 2014 07:56:57 +0300
Subject: [PATCH] Now you can search for effects, not just remove them.

---
 game/modules/tome/class/Actor.lua             | 28 ++++++++++++-------
 .../tome/data/talents/misc/inscriptions.lua   | 18 ++----------
 2 files changed, 20 insertions(+), 26 deletions(-)

diff --git a/game/modules/tome/class/Actor.lua b/game/modules/tome/class/Actor.lua
index a6dbe4ec44..2fe0087038 100644
--- a/game/modules/tome/class/Actor.lua
+++ b/game/modules/tome/class/Actor.lua
@@ -5513,10 +5513,9 @@ function _M:worthExp(target)
 	end
 end
 
---- Remove all effects based on a filter
-function _M:removeEffectsFilter(t, nb, silent, force)
+--- Find effects based on a filter, up to nb.
+function _M:effectsFilter(t, nb)
 	local effs = {}
-	local removed = 0
 
 	for eff_id, p in pairs(self.tmp) do
 		local e = self.tempeffect_def[eff_id]
@@ -5540,19 +5539,28 @@ function _M:removeEffectsFilter(t, nb, silent, force)
 	end
 
 	if nb then
+		local found = {}
 		while #effs > 0 and nb > 0 do
 			local eff = rng.tableRemove(effs)
-			self:removeEffect(eff, silent, force)
+			found[#found + 1] = eff
 			nb = nb - 1
-			removed = removed + 1
 		end
+		return found
 	else
-		removed = #effs
-		for i = 1,#effs do
-			self:removeEffect(effs[i], silent, force)
-		end
+		return effs
+	end
+end
+
+function _M:removeEffects(effs, silent, force)
+	for _, eff_id in ipairs(effs) do
+		self:removeEffect(eff_id, silent, force)
 	end
-	return removed
+end
+
+function _M:removeEffectsFilter(t, nb, silent, force)
+	local eff_ids = self:effectsFilter(t, nb)
+	self:removeEffects(eff_ids, silent, force)
+	return #eff_ids
 end
 
 --- Randomly reduce talent cooldowns based on a filter
diff --git a/game/modules/tome/data/talents/misc/inscriptions.lua b/game/modules/tome/data/talents/misc/inscriptions.lua
index fd9143b3fa..21749275b6 100644
--- a/game/modules/tome/data/talents/misc/inscriptions.lua
+++ b/game/modules/tome/data/talents/misc/inscriptions.lua
@@ -126,15 +126,8 @@ newInscription{
 	tactical = {
 		DEFEND = 3,
 		CURE = function(self, t, target)
-			local nb = 0
 			local data = self:getInscriptionData(t.short_name)
-			for eff_id, p in pairs(self.tmp) do
-				local e = self.tempeffect_def[eff_id]
-				if data.what[e.type] and e.status == "detrimental" then
-					nb = nb + 1
-				end
-			end
-			return nb
+			return #self:effectsFilter({types=data.what, status="detrimental"})
 		end
 	},
 	action = function(self, t)
@@ -178,15 +171,8 @@ newInscription{
 	tactical = {
 		DEFEND = 3,
 		CURE = function(self, t, target)
-			local nb = 0
 			local data = self:getInscriptionData(t.short_name)
-			for eff_id, p in pairs(self.tmp) do
-				local e = self.tempeffect_def[eff_id]
-				if data.what[e.type] and e.status == "detrimental" then
-					nb = nb + 1
-				end
-			end
-			return nb
+			return #self:effectsFilter({types=data.what, status="detrimental"})
 		end
 	},
 	action = function(self, t)
-- 
GitLab