From 2cf73222b48e47f145bbcba1581b4024a0015e0d Mon Sep 17 00:00:00 2001
From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54>
Date: Tue, 21 Feb 2012 00:24:04 +0000
Subject: [PATCH] power_source filter

git-svn-id: http://svn.net-core.org/repos/t-engine4@4903 51575b47-30f0-44d4-a5cc-537603b46e54
---
 game/modules/tome/class/GameState.lua | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/game/modules/tome/class/GameState.lua b/game/modules/tome/class/GameState.lua
index 7f4a5e6827..beec639d4d 100644
--- a/game/modules/tome/class/GameState.lua
+++ b/game/modules/tome/class/GameState.lua
@@ -977,31 +977,31 @@ function _M:entityFilterAlter(zone, level, type, filter)
 			print("[TOME ENTITY FILTER] selected Double Greater", r, dg)
 			filter.not_properties = filter.not_properties or {}
 			filter.not_properties[#filter.not_properties+1] = "unique"
-			filter.ego_chance={tries = { {ego_chance=100, properties={"greater_ego"}}, {ego_chance=100, properties={"greater_ego"}} } }
+			filter.ego_chance={tries = { {ego_chance=100, properties={"greater_ego"}, power_source=filter.power_source, forbid_power_source=filter.forbid_power_source}, {ego_chance=100, properties={"greater_ego"}, power_source=filter.power_source, forbid_power_source=filter.forbid_power_source} } }
 
 		elseif r < ge then
 			print("[TOME ENTITY FILTER] selected Greater + Ego", r, ge)
 			filter.not_properties = filter.not_properties or {}
 			filter.not_properties[#filter.not_properties+1] = "unique"
-			filter.ego_chance={tries = { {ego_chance=100, properties={"greater_ego"}}, {ego_chance=100, not_properties={"greater_ego"}} }}
+			filter.ego_chance={tries = { {ego_chance=100, properties={"greater_ego"}, power_source=filter.power_source, forbid_power_source=filter.forbid_power_source}, {ego_chance=100, not_properties={"greater_ego"}, power_source=filter.power_source, forbid_power_source=filter.forbid_power_source} }}
 
 		elseif r < g then
 			print("[TOME ENTITY FILTER] selected Greater", r, g)
 			filter.not_properties = filter.not_properties or {}
 			filter.not_properties[#filter.not_properties+1] = "unique"
-			filter.ego_chance={tries = { {ego_chance=100, properties={"greater_ego"}} } }
+			filter.ego_chance={tries = { {ego_chance=100, properties={"greater_ego"}, power_source=filter.power_source, forbid_power_source=filter.forbid_power_source} } }
 
 		elseif r < de then
 			print("[TOME ENTITY FILTER] selected Double Ego", r, de)
 			filter.not_properties = filter.not_properties or {}
 			filter.not_properties[#filter.not_properties+1] = "unique"
-			filter.ego_chance={tries = { {ego_chance=100, not_properties={"greater_ego"}}, {ego_chance=100, not_properties={"greater_ego"}} }}
+			filter.ego_chance={tries = { {ego_chance=100, not_properties={"greater_ego"}, power_source=filter.power_source, forbid_power_source=filter.forbid_power_source}, {ego_chance=100, not_properties={"greater_ego"}, power_source=filter.power_source, forbid_power_source=filter.forbid_power_source} }}
 
 		elseif r < e then
 			print("[TOME ENTITY FILTER] selected Ego", r, e)
 			filter.not_properties = filter.not_properties or {}
 			filter.not_properties[#filter.not_properties+1] = "unique"
-			filter.ego_chance={tries = { {ego_chance=100, not_properties={"greater_ego"}} } }
+			filter.ego_chance={tries = { {ego_chance=100, not_properties={"greater_ego"}, power_source=filter.power_source, forbid_power_source=filter.forbid_power_source} } }
 
 		elseif r < m then
 			print("[TOME ENTITY FILTER] selected Money", r, m)
@@ -1024,6 +1024,22 @@ function _M:entityFilterAlter(zone, level, type, filter)
 end
 
 function _M:entityFilter(zone, e, filter, type)
+	if filter.forbid_power_source then
+		if e.power_source then
+			for k, _ in pairs(filter.forbid_power_source) do
+				if e.power_source[k] then return false end
+			end
+		end
+	end
+
+	if filter.power_source and e.power_source then
+		local ok = false
+		for k, _ in pairs(filter.power_source) do
+			if e.power_source[k] then ok = true break end
+		end
+		if not ok then return false end
+	end
+
 	if type == "object" then
 		if not filter.ingore_material_restriction then
 			local min_mlvl = util.getval(zone.min_material_level)
-- 
GitLab