From 5af2abd222b154a726149d01c6bdeef699210285 Mon Sep 17 00:00:00 2001
From: DarkGod <darkgod@net-core.org>
Date: Sun, 31 May 2020 16:10:05 +0200
Subject: [PATCH] plop

---
 .../default/engine/generator/map/Static.lua   | 10 +++++----
 game/modules/tome/class/Actor.lua             |  8 +++++--
 .../tome/data/general/grids/psicave.lua       | 21 +++++++++++++++++++
 .../data/general/objects/quest-artifacts.lua  |  4 ++--
 .../tome/data/quests/shertul-fortress.lua     |  3 ++-
 .../tome/data/zones/shertul-fortress/zone.lua |  1 +
 6 files changed, 38 insertions(+), 9 deletions(-)

diff --git a/game/engines/default/engine/generator/map/Static.lua b/game/engines/default/engine/generator/map/Static.lua
index be531d072d..466eca5856 100644
--- a/game/engines/default/engine/generator/map/Static.lua
+++ b/game/engines/default/engine/generator/map/Static.lua
@@ -362,7 +362,7 @@ function _M:tmxLoad(file)
 		for _, o in ipairs(map:findAll("object")) do
 			local props = o:findOne("properties"):findAllAttrs("property", "name", "value")
 
-			if og.attr.name:find("^addSpot") then
+			if og.attr.name and og.attr.name:find("^addSpot") then
 				local x, y, w, h = math.floor(tonumber(o.attr.x) / tw), math.floor(tonumber(o.attr.y) / th), math.floor(tonumber(o.attr.width) / tw), math.floor(tonumber(o.attr.height) / th)
 				if props.start then m.startx = x m.starty = y end
 				if props['end'] then m.endx = x m.endy = y end
@@ -374,7 +374,7 @@ function _M:tmxLoad(file)
 						g.addSpot({i, j}, t, st, props)
 					end end
 				end
-			elseif og.attr.name:find("^addZone") then
+			elseif og.attr.name and og.attr.name:find("^addZone") then
 				local x, y, w, h = math.floor(tonumber(o.attr.x) / tw), math.floor(tonumber(o.attr.y) / th), math.floor(tonumber(o.attr.width) / tw), math.floor(tonumber(o.attr.height) / th)
 				if props.type and props.subtype then
 					local t, st = props.type, props.subtype
@@ -383,7 +383,7 @@ function _M:tmxLoad(file)
 					local i2, j2 = rotate_coords(x + w, y + h)
 					g.addZone({i1, j1, i2, j2}, t, st, props)
 				end
-			elseif og.attr.name:find("^attrs") then
+			elseif og.attr.name and og.attr.name:find("^attrs") then
 				local x, y, w, h = math.floor(tonumber(o.attr.x) / tw), math.floor(tonumber(o.attr.y) / th), math.floor(tonumber(o.attr.width) / tw), math.floor(tonumber(o.attr.height) / th)
 				for k, v in pairs(props) do
 					for i = x, x + w do for j = y, y + h do
@@ -394,7 +394,7 @@ function _M:tmxLoad(file)
 						-- print("====", i, j, k)
 					end end
 				end
-			elseif og.attr.name:find("^spawn#") then
+			elseif og.attr.name and og.attr.name:find("^spawn#") then
 				local layername = og.attr.name:sub(7)
 				local x, y, w, h = math.floor(tonumber(o.attr.x) / tw), math.floor(tonumber(o.attr.y) / th), math.floor(tonumber(o.attr.width) / tw), math.floor(tonumber(o.attr.height) / th)
 				if props.id then
@@ -700,6 +700,7 @@ function _M:generate(lev, old_lev)
 		local map = self.zone.map_class.new(g.w, g.h)
 		data.__import_offset_x = self.data.__import_offset_x+g.x
 		data.__import_offset_y = self.data.__import_offset_y+g.y
+		data.parent_data = self.data
 		local generator = require(g.generator).new(
 			self.zone,
 			map,
@@ -707,6 +708,7 @@ function _M:generate(lev, old_lev)
 			data
 		)
 		local ux, uy, dx, dy, subspots = generator:generate(lev, old_lev)
+		data.parent_data = nil
 		if ux and uy then
 			if data.overlay or g.overlay then
 				self.map:overlay(map, g.x, g.y)
diff --git a/game/modules/tome/class/Actor.lua b/game/modules/tome/class/Actor.lua
index cf77e2fc49..edd5db9d9d 100644
--- a/game/modules/tome/class/Actor.lua
+++ b/game/modules/tome/class/Actor.lua
@@ -7841,7 +7841,8 @@ function _M:transmoInven(inven, idx, o, transmo_source)
 	if price ~= price or not tostring(price):find("^[0-9]") then price = 1 end -- NaN is the only value that does not equals itself, this is the way to check it since we do not have a math.isnan method
 	if inven and idx then self:removeObject(inven, idx, true) end
 
-	if self.hasQuest and self:hasQuest("shertul-fortress") and self:isQuestStatus("shertul-fortress", engine.Quest.COMPLETED, "transmo-chest-extract-gems") and self:knowTalent(self.T_EXTRACT_GEMS) and self:callTalent(self.T_EXTRACT_GEMS, "filterGem", o) then
+	local gem_extracted = false
+	if game.state.transmo_chest_extract_gems and self:knowTalent(self.T_EXTRACT_GEMS) and self:callTalent(self.T_EXTRACT_GEMS, "filterGem", o) then
 		local gem = self:callTalent(self.T_EXTRACT_GEMS, "getGem", o)
 
 		if gem then
@@ -7854,12 +7855,15 @@ function _M:transmoInven(inven, idx, o, transmo_source)
 				game.logPlayer(self, "You extract %s from %s", gem:getName{do_color=true, do_count=true}, o:getName{do_color=true, do_count=true})
 				o = gem
 			end
+			gem_extracted = gem
 		end
 	end
 
 	self:sortInven()
 	self:incMoney(price)
-	if self.hasQuest and self:hasQuest("shertul-fortress") and self:isQuestStatus("shertul-fortress", engine.Quest.COMPLETED, "transmo-chest") then self:hasQuest("shertul-fortress"):gain_energy(price/10) end
+	if not self:triggerHook{"TransmogrificationChest:gainedMoney", transmo_source=transmo_source, from=o, price=price, gem_extracted=gem_extracted} then
+		if self.hasQuest and self:hasQuest("shertul-fortress") and self:isQuestStatus("shertul-fortress", engine.Quest.COMPLETED, "transmo-chest") then self:hasQuest("shertul-fortress"):gain_energy(price/10) end
+	end
 	game.log("You gain %0.2f gold from the transmogrification of %s.", price, o:getName{do_count=true, do_color=true})
 end
 
diff --git a/game/modules/tome/data/general/grids/psicave.lua b/game/modules/tome/data/general/grids/psicave.lua
index a14738740e..084536b6b3 100644
--- a/game/modules/tome/data/general/grids/psicave.lua
+++ b/game/modules/tome/data/general/grids/psicave.lua
@@ -81,6 +81,27 @@ newEntity{ base = "PSYCAVE_DOOR_OPEN", define_as = "PSYCAVE_DOOR_HORIZ_OPEN", im
 newEntity{ base = "PSYCAVE_DOOR", define_as = "PSYCAVE_DOOR_VERT", image = "terrain/psicave/psitech_floor_1_01.png", add_displays = {class.new{image="terrain/psicave/psitech_door1_vert.png", z=17}, class.new{image="terrain/psicave/psitech_door1_vert_north.png", z=18, display_y=-1}}, door_opened = "PSYCAVE_DOOR_OPEN_VERT", dig = "PSYCAVE_DOOR_OPEN_VERT"}
 newEntity{ base = "PSYCAVE_DOOR_OPEN", define_as = "PSYCAVE_DOOR_OPEN_VERT", z=3, image = "terrain/psicave/psitech_floor_1_01.png", add_mos={{image="terrain/psicave/psitech_door1_open_vert_backg.png"}}, add_displays = {class.new{image="terrain/psicave/psitech_door1_open_vert.png", z=17, add_mos={{image="terrain/psicave/psitech_door1_open_vert_north_backg.png", display_y=-1}}}, class.new{image="terrain/psicave/psitech_door1_open_vert_north.png", z=18, display_y=-1}}, door_closed = "PSYCAVE_DOOR_VERT"}
 
+newEntity{
+	define_as = "PSYCAVE_DOOR_SEALED",
+	type = "wall", subtype = "psitech",
+	name = "psitech door", image = "terrain/psicave/psitech_door1.png",
+	display = '+', color={r=203,g=189,b=72}, back_color={r=93,g=79,b=22},
+	nice_tiler = { method="door3d", north_south="PSYCAVE_DOOR_SEALED_VERT", west_east="PSYCAVE_DOOR_SEALED_HORIZ" },
+	door_sound = "ambient/door_creaks/icedoor-break",
+	notice = true,
+	always_remember = true,
+	block_sight = true,
+	block_sense = true,
+	block_esp = true,
+	is_door = true,
+	door_player_stop = _t"This door seems to be sealed.",
+	door_opened = "PSYCAVE_DOOR_OPEN",
+	dig = "FLOOR",
+	nice_editer = psitech_floor_editer,
+}
+newEntity{ base = "PSYCAVE_DOOR_SEALED", define_as = "PSYCAVE_DOOR_SEALED_HORIZ", z=3, image = "terrain/psicave/psitech_door1.png", add_displays = {class.new{image="terrain/psicave/psitechwall_8_1.png", z=18, display_y=-1, add_mos={{image="terrain/padlock2.png"}}}}, door_opened = "PSYCAVE_DOOR_HORIZ_OPEN"}
+newEntity{ base = "PSYCAVE_DOOR_SEALED", define_as = "PSYCAVE_DOOR_SEALED_VERT", image = "terrain/psicave/psitech_floor_1_01.png", add_displays = {class.new{image="terrain/psicave/psitech_door1_vert.png", z=17, add_mos={{image="terrain/padlock2.png", display_x=0.15, display_y=-0.3}}}, class.new{image="terrain/psicave/psitech_door1_vert_north.png", z=18, display_y=-1}}, door_opened = "PSYCAVE_DOOR_OPEN_VERT", dig = "PSYCAVE_DOOR_OPEN_VERT"}
+
 -----------------------------------------
 -- Cavy exits
 -----------------------------------------
diff --git a/game/modules/tome/data/general/objects/quest-artifacts.lua b/game/modules/tome/data/general/objects/quest-artifacts.lua
index eace9c003d..fcf6a1003e 100644
--- a/game/modules/tome/data/general/objects/quest-artifacts.lua
+++ b/game/modules/tome/data/general/objects/quest-artifacts.lua
@@ -333,13 +333,13 @@ You have heard of such items before. They are very useful to adventurers, allowi
 			end
 			if not who:attr("never_move") then
 				if who:canBe("worldport") then
-					who:setEffect(who.EFF_RECALL, 40, { where = self.shertul_fortress and "shertul-fortress" or nil })
+					who:setEffect(who.EFF_RECALL, 40, { where = self.recall_target or nil })
 					game.logPlayer(who, "Space around you starts to dissolve...")
 					return {id=true, used=true}
 				elseif game.zone.force_farportal_recall then
 					require("engine.ui.Dialog"):yesnoLongPopup(_t"Force a recall", _t"The Fortress Shadow warned you that trying to force a recall without finding the portal back could break the exploratory farportal forever.", 500, function(ret)
 						if not ret then
-							who:setEffect(who.EFF_RECALL, 40, { where = self.shertul_fortress and "shertul-fortress" or nil, allow_override=true })
+							who:setEffect(who.EFF_RECALL, 40, { where = self.recall_target or nil, allow_override=true })
 							game.logPlayer(who, "Space around you starts to dissolve...")
 							if rng.percent(90) and who:hasQuest("shertul-fortress") then
 								who:hasQuest("shertul-fortress"):break_farportal()
diff --git a/game/modules/tome/data/quests/shertul-fortress.lua b/game/modules/tome/data/quests/shertul-fortress.lua
index 9205e3e778..7578f6ec64 100644
--- a/game/modules/tome/data/quests/shertul-fortress.lua
+++ b/game/modules/tome/data/quests/shertul-fortress.lua
@@ -189,7 +189,7 @@ upgrade_rod = function(self)
 	if not rod then return end
 
 	game.player:setQuestStatus("shertul-fortress", self.COMPLETED, "recall-done")
-	rod.shertul_fortress = true
+	rod.recall_target = "shertul-fortress"
 	game.log("#VIOLET#Your rod of recall glows brightly for a moment.")
 end
 
@@ -201,6 +201,7 @@ upgrade_transmo_gems = function(self)
 	end
 	self.shertul_energy = self.shertul_energy - 25
 
+	game.state.transmo_chest_extract_gems = true
 	game.player:setQuestStatus("shertul-fortress", self.COMPLETED, "transmo-chest-extract-gems")
 	game.log("#VIOLET#Your transmogrification chest glows brightly for a moment.")
 end
diff --git a/game/modules/tome/data/zones/shertul-fortress/zone.lua b/game/modules/tome/data/zones/shertul-fortress/zone.lua
index 6f87c86660..b13be7a946 100644
--- a/game/modules/tome/data/zones/shertul-fortress/zone.lua
+++ b/game/modules/tome/data/zones/shertul-fortress/zone.lua
@@ -40,6 +40,7 @@ return {
 		map = {
 			class = "engine.generator.map.Static",
 			map = "zones/shertul-fortress",
+			fortress_mode = "shertul",
 		},
 		actor = {
 			class = "mod.class.generator.actor.Random",
-- 
GitLab