sorcery  Diff

Differences From Artifact [e0cdcfa7d5]:

To Artifact [dfbf2cd360]:


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
..
76
77
78
79
80
81
82
























83
84
85
86
87
88
89
90
91
92
93
94




95
96
97

98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
...
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
...
231
232
233
234
235
236
237
238

239
240
241
242
243
244
245
			-- can't mutate table while we're iterating it
			if not minetest.registered_nodes[g] then bad[#bad+1] = g end
		end
		for _, g in ipairs(bad) do god.gifts[g] = nil end
	end
end)

local std_god_interval = 70

for name, god in pairs(sorcery.data.gods) do
	local hitbox = {
		0-(god.idol.width / 2.0), 0-(god.idol.height / 2.0), -0.15,
		   god.idol.width / 2.0,     god.idol.height / 2.0,   0.15
	} -- {xmin, ymin, zmin,
	  -- xmax, ymax, zmax} in nodes from node center.
................................................................................
	if god.idol.craft then
		minetest.register_craft {
			output = 'sorcery:idol_' .. name;
			recipe = god.idol.craft;
		};
	end
	local god_interval = std_god_interval * (god.freq or 1)
























	sorcery.lib.node.reg_autopreserve('sorcery:idol_' .. name, {
		description = god.idol.desc;
		drawtype = "mesh";
		mesh = 'sorcery-idol-' .. name .. '.obj';
		paramtype = 'light';
		paramtype2 = 'facedir';
		sunlight_propagates = true;
		stack_max = 1;
		tiles = god.idol.tex;
		selection_box = { type = "fixed"; fixed = {hitbox}; };
		collision_box = { type = "fixed"; fixed = {hitbox}; };
		groups = { cracky = 2, sorcery_idol = 1, heavy = 1, sorcery_worship = 1};





		on_construct = function(pos)
			minetest.get_node_timer(pos):start(god_interval)

		end;

		on_timer = function(pos, elapsed)
			local altar = minetest.find_node_near(pos, 3, "sorcery:altar")
			-- TODO even without an altar, an idol with high favor could still be the source of miracles
			-- refills nearby partly empty troughs at cost to favor?
			if not altar then return true end

			local altarmeta = minetest.get_meta(altar)
			local inv = altarmeta:get_inventory()
			local idolmeta = minetest.get_meta(pos)
			local divine_favor = idolmeta:get_int('favor')
			if divine_favor > 5 then
				local ct = divine_favor / 5
				minetest.add_particlespawner {
					texture = L.image('sorcery_glitter.png'):glow(L.color(god.color)):render();
					glow = 14;
					amount = ct / (1 / god_interval), time = god_interval;
					minpos = pos:offset(-0.4, -0.5, -0.4);
					maxpos = pos:offset( 0.4,god.idol.height-0.5,0.4);
					minvel = vector.new(0, 0.05, 0);
					minvel = vector.new(0, 0.1, 0);
					minacc = vector.new(0, 0.1, 0);
					maxacc = vector.new(0, 0.2, 0);
					minexptime = 4, maxexptime = 4;
					minsize = 0.3, maxsize = 1;
					animation = {
						type = 'vertical_frames';
						length = 0.1;
						aspect_w = 16, aspect_h = 16;
					}
				}
			end
			local bestow = function(item,color)
				if type(item) == 'string' then
					item = ItemStack(item)
				end
				if color == nil then
					color = sorcery.lib.color(god.color)
				end
................................................................................
					-- 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
................................................................................
								-- the gods are getting bored
								value = math.floor(value / 2)
							end
							bestow(nil)
						end
						divine_favor = divine_favor + value
						
						print(god.name.." has accepted a sacrifice of "..s..", raising divine favor by "..value.." points to "..divine_favor)

						idolmeta:set_string('last_sacrifice', s)

						goto refresh
					end
				end

				-- loop through the list of things this god will consecrate and







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>











|
>
>
>
>



>












|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







|







 







|
>







60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
..
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139




















140
141
142
143
144
145
146
...
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
...
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
			-- can't mutate table while we're iterating it
			if not minetest.registered_nodes[g] then bad[#bad+1] = g end
		end
		for _, g in ipairs(bad) do god.gifts[g] = nil end
	end
end)

local std_god_interval = 40

for name, god in pairs(sorcery.data.gods) do
	local hitbox = {
		0-(god.idol.width / 2.0), 0-(god.idol.height / 2.0), -0.15,
		   god.idol.width / 2.0,     god.idol.height / 2.0,   0.15
	} -- {xmin, ymin, zmin,
	  -- xmax, ymax, zmax} in nodes from node center.
................................................................................
	if god.idol.craft then
		minetest.register_craft {
			output = 'sorcery:idol_' .. name;
			recipe = god.idol.craft;
		};
	end
	local god_interval = std_god_interval * (god.freq or 1)
	local add_sparkles = function(pos,divine_favor)
		divine_favor = divine_favor or minetest.get_meta(pos):get_int('favor')
		if divine_favor > 5 then
			local ct = divine_favor / 5
			minetest.add_particlespawner {
				texture = L.image('sorcery_glitter.png'):glow(L.color(god.color)):render();
				glow = 14;
				amount = ct / (1 / god_interval), time = god_interval;
				minpos = pos:offset(-0.4, -0.5, -0.4);
				maxpos = pos:offset( 0.4,god.idol.height-0.5,0.4);
				minvel = vector.new(0, 0.05, 0);
				minvel = vector.new(0, 0.1, 0);
				minacc = vector.new(0, 0.1, 0);
				maxacc = vector.new(0, 0.2, 0);
				minexptime = 4, maxexptime = 4;
				minsize = 0.3, maxsize = 1;
				animation = {
					type = 'vertical_frames';
					length = 0.1;
					aspect_w = 16, aspect_h = 16;
				}
			}
		end
	end
	sorcery.lib.node.reg_autopreserve('sorcery:idol_' .. name, {
		description = god.idol.desc;
		drawtype = "mesh";
		mesh = 'sorcery-idol-' .. name .. '.obj';
		paramtype = 'light';
		paramtype2 = 'facedir';
		sunlight_propagates = true;
		stack_max = 1;
		tiles = god.idol.tex;
		selection_box = { type = "fixed"; fixed = {hitbox}; };
		collision_box = { type = "fixed"; fixed = {hitbox}; };
		groups = { cracky = 2, sorcery_idol = 1, heavy = 1, sorcery_worship = 1, sorcery_instantiate = 1};
		_sorcery = {
			idol_god = name;
			on_load = function(pos) add_sparkles(pos) end;
		};

		on_construct = function(pos)
			minetest.get_node_timer(pos):start(god_interval)
			add_sparkles(pos)
		end;

		on_timer = function(pos, elapsed)
			local altar = minetest.find_node_near(pos, 3, "sorcery:altar")
			-- TODO even without an altar, an idol with high favor could still be the source of miracles
			-- refills nearby partly empty troughs at cost to favor?
			if not altar then return true end

			local altarmeta = minetest.get_meta(altar)
			local inv = altarmeta:get_inventory()
			local idolmeta = minetest.get_meta(pos)
			local divine_favor = idolmeta:get_int('favor')
			add_sparkles(pos,divine_favor)




















			local bestow = function(item,color)
				if type(item) == 'string' then
					item = ItemStack(item)
				end
				if color == nil then
					color = sorcery.lib.color(god.color)
				end
................................................................................
					-- 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
................................................................................
								-- the gods are getting bored
								value = math.floor(value / 2)
							end
							bestow(nil)
						end
						divine_favor = divine_favor + value
						
						log.actf("%s has accepted a sacrifice of %s, raising divine favor by %u points to %u at altar %s", god.name, s, value, divine_favor, minetest.pos_to_string(pos))

						idolmeta:set_string('last_sacrifice', s)

						goto refresh
					end
				end

				-- loop through the list of things this god will consecrate and