sorcery  Diff

Differences From Artifact [a7a1197203]:

To Artifact [080406f8d2]:


1
2
3
4
5
6
7
8
9
10
11
..
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
...
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
...
215
216
217
218
219
220
221

222
223

224








225
226


227

228
229
230
231
232



233



234
235
236
237
238
239
240
241
242
243
244

245
246
247
248
249
250
251
252
253
254
255
local altar_item_offset = {
	x = 0, y = -0.3, z = 0
}
local log = function(...) sorcery.log('altar',...) end

local range = function(min, max)
	local span = max - min
	local val = math.random() * span
	return val + min
end

................................................................................

		after_place_node = function(pos, placer, stack, pointat)
			local meta = minetest.get_meta(pos)
			local stackmeta = stack:get_meta()
			meta:set_int('favor', stackmeta:get_int('favor'))
			meta:set_string('last_sacrifice', stackmeta:get_string('last_sacrifice'))

			minetest.get_node_timer(pos):start(60)
		end;

		drop = {
			-- for some idiot reason this is necessary for
			-- preserve_metadata to work right
			max_items = 1;
			items = {
................................................................................
					-- we pick a random gift and roll against its rarity
					-- to determine if the god is feeling generous
					local gift = sorcery.lib.tbl.pick(god.gifts)
					local data = god.gifts[gift]
					local value, rarity = data[1], data[2]
					if value <= divine_favor and math.random(rarity) == 1 then
						bestow(gift)
						log(god.name .. ' has produced ' .. gift .. ' upon an altar as a gift')
						if math.random(god.generosity) == 1 then
							-- unappreciated gifts may incur divine
							-- irritation
							divine_favor = divine_favor - 1
						end
					end
				end
................................................................................
						goto refresh
					end
				end

				-- loop through the list of things this god will consecrate and
				-- check whether the item on the altar is any of them
				for s, cons in pairs(god.consecrate) do

					local cost, tx = cons[1], cons[2]
					if type(tx) == "table" then

						tx = tx[math.random(#tx)]








					end
					-- preserve wear


					local gift = ItemStack(tx)

					local wear = stack:get_wear()
					if wear > 0 then
						gift:set_wear(wear)
					end
					-- preserve meta



					gift:get_meta():from_table(stack:get_meta():to_table())



					-- reflash enchantments to ensure label is accurate
					local ench = sorcery.enchant.get(gift)
					if #ench.spells > 0 then
						-- add a bit of energy as a gift?
						if math.random(math.ceil(god.stinginess * 0.5)) == 1 then
							local max = 0.05 * god.generosity
							ench.energy = ench.energy * range(0.7*max,max)
						end
						sorcery.enchant.set(gift,ench)
					end
					if itemname == s then

						if divine_favor >= cost then
							bestow(gift)
							divine_favor = divine_favor - cost
							print(god.name..'has consecrated ' ..s.. ' into ' ..tx.. ', for the cost of ' ..cost.. ' points of divine favor')
							goto refresh
						end
					end
				end
			end

			::refresh::



|







 







|







 







|







 







>
|
|
>
|
>
>
>
>
>
>
>
>
|
|
>
>
|
>
|
|
|
|
|
>
>
>
|
>
>
>
|
|
|
|
|
|
|
|
|
|
<
>



|







1
2
3
4
5
6
7
8
9
10
11
..
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
...
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
...
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262

263
264
265
266
267
268
269
270
271
272
273
274
local altar_item_offset = {
	x = 0, y = -0.3, z = 0
}
local log = sorcery.logger('altar')

local range = function(min, max)
	local span = max - min
	local val = math.random() * span
	return val + min
end

................................................................................

		after_place_node = function(pos, placer, stack, pointat)
			local meta = minetest.get_meta(pos)
			local stackmeta = stack:get_meta()
			meta:set_int('favor', stackmeta:get_int('favor'))
			meta:set_string('last_sacrifice', stackmeta:get_string('last_sacrifice'))

			minetest.get_node_timer(pos):start(1)
		end;

		drop = {
			-- for some idiot reason this is necessary for
			-- preserve_metadata to work right
			max_items = 1;
			items = {
................................................................................
					-- we pick a random gift and roll against its rarity
					-- to determine if the god is feeling generous
					local gift = sorcery.lib.tbl.pick(god.gifts)
					local data = god.gifts[gift]
					local value, rarity = data[1], data[2]
					if value <= divine_favor and math.random(rarity) == 1 then
						bestow(gift)
						log.act(god.name .. ' has produced ' .. gift .. ' upon an altar as a gift')
						if math.random(god.generosity) == 1 then
							-- unappreciated gifts may incur divine
							-- irritation
							divine_favor = divine_favor - 1
						end
					end
				end
................................................................................
						goto refresh
					end
				end

				-- loop through the list of things this god will consecrate and
				-- check whether the item on the altar is any of them
				for s, cons in pairs(god.consecrate) do
					if itemname == s then
						local cost, tx
						if type(cons) == "table" then
							cost, tx = cons[1], cons[2]
							tx = tx[math.random(#tx)]
						elseif type(cons) == 'function' then
							cost, tx = cons {
								favor = divine_favor;
								pos = pos;
								altar = altarmeta;
								idol = idolmeta;
								god = god;
							}
						end
						-- preserve wear
						local gift
						if type(tx) == 'string' then
							gift = ItemStack(tx)
						else gift = tx end
						local wear = stack:get_wear()
						if wear > 0 then
							gift:set_wear(wear)
						end
						-- preserve meta
						local gm = gift:get_meta()
						gm:from_table(
							sorcery.lib.tbl.merge(
								stack:get_meta():to_table(),
								gm:to_table()
							)
						) -- oof
						-- reflash enchantments to ensure label is accurate
						local ench = sorcery.enchant.get(gift)
						if #ench.spells > 0 then
							-- add a bit of energy as a gift?
							if math.random(math.ceil(god.stinginess * 0.5)) == 1 then
								local max = 0.05 * god.generosity
								ench.energy = ench.energy * range(0.7*max,max)
							end
							sorcery.enchant.set(gift,ench)
						end


						if divine_favor >= cost then
							bestow(gift)
							divine_favor = divine_favor - cost
							log.act(god.name, 'has consecrated', s, 'into', tx, 'for the cost of', cost, 'points of divine favor')
							goto refresh
						end
					end
				end
			end

			::refresh::