From 3be69150d6b8423179c6dcb300e95e151023a30d Mon Sep 17 00:00:00 2001
From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54>
Date: Sat, 11 Sep 2010 01:41:51 +0000
Subject: [PATCH] Added new world artifacts

git-svn-id: http://svn.net-core.org/repos/t-engine4@1184 51575b47-30f0-44d4-a5cc-537603b46e54
---
 .../engine/interface/ActorInventory.lua       | 20 ++++++++++++++++++-
 .../data/general/objects/world-artifacts.lua  | 16 +++++++++++++++
 game/modules/tome/dialogs/DeathDialog.lua     | 16 +++++++++++++++
 3 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/game/engines/default/engine/interface/ActorInventory.lua b/game/engines/default/engine/interface/ActorInventory.lua
index 28ea4aa6ba..0fbdca3f73 100644
--- a/game/engines/default/engine/interface/ActorInventory.lua
+++ b/game/engines/default/engine/interface/ActorInventory.lua
@@ -59,7 +59,7 @@ end
 function _M:initBody()
 	if self.body then
 		for inven, max in pairs(self.body) do
-			self.inven[self["INVEN_"..inven]] = {max=max, worn=self.inven_def[self["INVEN_"..inven]].is_worn}
+			self.inven[self["INVEN_"..inven]] = {max=max, worn=self.inven_def[self["INVEN_"..inven]].is_worn, id=self["INVEN_"..inven]}
 		end
 		self.body = nil
 	end
@@ -426,3 +426,21 @@ function _M:findInAllInventories(name, getname)
 		if o and item then return o, item, inven_id end
 	end
 end
+
+--- Applies fct over all items
+-- @param inven the inventory to look into
+-- @param fct the function to be called. It will receive three parameters: inven, item, object
+function _M:inventoryApply(inven, fct)
+	for item, o in ipairs(inven) do
+		fct(inven, item, o)
+	end
+end
+
+--- Applies fct over all items in all inventories
+-- @param inven the inventory to look into
+-- @param fct the function to be called. It will receive three parameters: inven, item, object
+function _M:inventoryApplyAll(fct)
+	for inven_id, inven in pairs(self.inven) do
+		self:inventoryApply(inven, fct)
+	end
+end
diff --git a/game/modules/tome/data/general/objects/world-artifacts.lua b/game/modules/tome/data/general/objects/world-artifacts.lua
index bb78cc2af8..c2ebad0696 100644
--- a/game/modules/tome/data/general/objects/world-artifacts.lua
+++ b/game/modules/tome/data/general/objects/world-artifacts.lua
@@ -90,6 +90,22 @@ newEntity{ base = "BASE_RING",
 	},
 }
 
+newEntity{ base = "BASE_RING",
+	unique = true,
+	name = "Ring of Mandos", color = colors.DARK_GREY,
+	unided_name = "dull black ring",
+	desc = [[This dull black ring is completely featureless.]],
+	level_range = {35, 42},
+	rarity = 250,
+	cost = 500,
+	material_level = 4,
+
+	wielder = {
+		inc_stats = { [Stats.STAT_LCK] = 10, },
+	},
+	one_shot_life_saving = true,
+}
+
 newEntity{ base = "BASE_RING",
 	unique = true,
 	name = "Elemental Fury", color = colors.PURPLE,
diff --git a/game/modules/tome/dialogs/DeathDialog.lua b/game/modules/tome/dialogs/DeathDialog.lua
index 987683fa50..ab8008541a 100644
--- a/game/modules/tome/dialogs/DeathDialog.lua
+++ b/game/modules/tome/dialogs/DeathDialog.lua
@@ -138,6 +138,14 @@ function _M:use()
 		self.actor:attr("re-assembled", 1)
 		game.logPlayer(self.actor, "#YELLOW#Your bones magically come back together. You are once more able to dish out pain to your foes!")
 
+		self:cleanActor()
+		self:restoreRessources()
+		self:resurrectBasic()
+	elseif act:find("^consume") then
+		local inven, item, o = self.list[self.sel].inven, self.list[self.sel].item, self.list[self.sel].object
+		self.actor:removeObject(inven, item)
+		game.logPlayer(self.actor, "#YELLOW#Your %s consumes and disappears! You come back to life!", o:getName{do_colour=true})
+
 		self:cleanActor()
 		self:restoreRessources()
 		self:resurrectBasic()
@@ -151,6 +159,14 @@ function _M:generateList()
 	if self.actor:attr("blood_life") and not self.actor:attr("undead") then list[#list+1] = {name="Resurrect with the Blood of Life", action="blood_life"} end
 	if self.actor:getTalentLevelRaw(self.actor.T_SKELETON_REASSEMBLE) >= 5 and not self.actor:attr("re-assembled") then list[#list+1] = {name="Re-assemble your bones and resurrect (Skeleton ability)", action="skeleton"} end
 
+	local consumenb = 1
+	self.actor:inventoryApplyAll(function(inven, item, o)
+		if o.one_shot_life_saving and (not o.slot or inven.worn) then
+			list[#list+1] = {name="Resurrect by consuming "..o:getName{do_colour=true}, action="consume"..consumenb, inven=inven, item=item, object=o}
+			consumenb = consumenb + 1
+		end
+	end)
+
 	list[#list+1] = {name="Character dump", action="dump"}
 	list[#list+1] = {name="Exit to main menu", action="exit"}
 
-- 
GitLab