sorcery  Diff

Differences From Artifact [196ad8b009]:

To Artifact [3dd4d17be3]:


41
42
43
44
45
46
47
48







































49
50
51
52
53
54
55
56
57
58



























































59



60
61
62
63
64
65
66
..
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
147
148
149
150
151
152
153
154
...
168
169
170
171
172
173
174

175
176
177
178
179
180
181
182
183
...
188
189
190
191
192
193
194


195
196
197
198
199
200

201
202
203
204
205
206
207
208

209
210
211
212
213
214
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














			-- the item material and look up the slots offered by this
			-- material. we iterate through the slot definitions to pick 
			-- out a candidate slot, criteria being that the slot
			-- possesses the proper affinity, and that the corresponding
			-- slot on the item enchantment record is empty, then pick
			-- the final slot at random from this table if #candidates>0
			-- (otherwise, we fail unceremoniously).
			--







































			-- once we have selected an appropriate slot, we iterate
			-- through the list of known enchantments to check the
			-- affinity of each against `aff`. if the affinity matches
			-- the wand, we then check whether the 'recipe' matches.
			-- if so, we've found the enchantment -- apply it to the
			-- object and update its enchantment data. otherwise, we
			-- move on to the next. if no matching recipe is found,
			-- we give up and bail, returning 'nil' to signify that
			-- a spell was not cast.




























































			enchantment_sparkle(ctx,affcolor)



		end
	};
end
-- note: this was written before terminology was standardized,
-- and "leytype" corresponds to what is otherwise known as an
-- "affinity"; "affinity" after this comment is widely misused
return {
................................................................................
		leytype = 'imperic';
		affinity = {'pine','dark'};
		cast = function(ctx)
			if ctx.target == nil or ctx.target.type ~= 'node' then return false end
			local meta = minetest.get_meta(ctx.target.under)
			-- first we need to check if the wand has an identifying 'key' yet,
			-- and set one if not.
			local wandmode = ctx.base.gem == 'amethyst'
			local keycode
			if ctx.meta:contains('sorcery_wand_key') then
				keycode = ctx.meta:get_string('sorcery_wand_key')
			else
				keycode = sorcery.lib.str.rand(32)
				ctx.meta:set_string('sorcery_wand_key', keycode)

			end
			if meta:contains('owner') then
				-- owner is already set -- can we break the enchantment?
				if meta:get_string('sorcery_wand_key') == keycode then
					meta:set_string('owner','')
					meta:set_string('sorcery_wand_key','')
					meta:set_string('sorcery_seal_mode','')
					enchantment_sparkle(ctx,sorcery.lib.color(101,255,142))
				else return false end
			else
				meta:set_string('sorcery_wand_key',keycode)

				meta:set_string('owner',ctx.caster:get_player_name())
				if wandmode then
					meta:set_string('sorcery_seal_mode','wand')
				end
				enchantment_sparkle(ctx,sorcery.lib.color(255,201,27))
			end
		end;
	};
	leyspark = {
		name = 'Leyspark';
		leytype = 'cognic';

		affinity = {'apple','silent'};
		uses = 64;
		desc = 'Reveal the strength and affinities of the local leyline';
		cast = function(ctx)
			local color = ctx.base.gem == 'sapphire';

			local ley = sorcery.ley.estimate(ctx.caster:get_pos())
			local emit = function(color,strength)
				minetest.add_particlespawner {
					amount = 70 * strength;
					time = 2 * strength;
					attached = ctx.caster;
					texture = sorcery.lib.image('sorcery_spark.png'):
						multiply(color):render();
					minpos = { x =  0.5, z =  0.0, y =  1.5}; 
					maxpos = { x =  0.5, z =  0.0, y =  1.5}; 
					minvel = { x = -0.5, z = -0.5, y = -0.5};
					maxvel = { x =  0.5, z =  0.5, y =  0.5};
					minacc = { x =  0.0, z =  0.0, y =  0.5};
					minacc = { x =  0.0, z =  0.0, y =  0.5};
					minsize = 0.4, maxsize = 0.8;
					minexptime = 1, maxexptime = 1;
					glow = 14;
					animation = {
						type = 'vertical_frames';
						aspect_w = 16;
						aspect_h = 16;
................................................................................
			end

		end;
	};
	dowse = {
		name = 'dowsing';
		leytype = 'cognic';

		affinity = {'acacia','dark','silent'};
		uses = 128;
		desc = 'Send up sparks of radia to indicate nearness or absence of attuned blocks';
	};
	verdant = {
		name = 'verdant';
		color = {16,29,255};
		uses = 48;
		leytype = 'imperic';
................................................................................
	counterpraxic = anchorwand('counterpraxic',23, {'pine','shimmering','silent'});
	entropic      = anchorwand('entropic',      8, {'jungle','dark'});
	syncretic     = anchorwand('syncretic',    12, {'aspen','verdant','shimmering','blazing'});
	cognic        = anchorwand('cognic',       36, {'acacia','verdant','dark'});
	shape = {
		name = 'shaping';
		uses = 24;


		affinity = {'apple','blazing'};
		desc = 'With an enchanter, physically alter the mundane qualities of an object';
	};
	attune = {
		name = 'attunement';
		uses = 38;

		leytype = 'syncretic';
		affinity = {'pine','verdant','dark'};
		desc = 'Establish a connection between mystic mechanisms, like connecting two sides of a portal or impressing targets onto a dowsing wand in an enchanter';
	};
	meld = {
		name = 'melding';
		uses = 48;
		leytype = 'syncretic';

		affinity = {'apple','verdant'};
		desc = 'Meld the properties of three balanced items on an enchanter to create a new one with special properties, but destroying the old ones and losing two thirds of the mass in the process. The precise outcome is not always predictable.';
	};
	divide = {
		name = 'division';
		uses = 19;
		leytype = 'syncretic';

		affinity = {'apple','shimmering'};
		desc = 'Shatter an item on an enchanter, dividing its essence equally into three parts and precipitating it into new items embodying various properties of the destroyed item. The outcome is not always predictable.';
	};
	obliterate = {
		name = 'obliteration';
		uses = 129;

		affinity = {'aspen','dark'};
		leytype = 'occlutic';
		desc = 'Totally and irreversibly obliterate all items on an enchanter.';
	};
	sacrifice = {
		name = 'sacrifice';
		uses = 58;

		affinity = {'aspen','blazing'};
		leytype = 'syncretic';
		desc = 'Transform the matter of one to three items on an enchanter into energy and empower the item on the center of the enchanter with it. Useful to recharge wands in areas with weak leylines.';
	};
	transfer = {
		name = 'transfer';
		uses = 65;

		leytype = 'syncretic';
		affinity = {'aspen','shimmering','silent'};
		desc = 'Transfer ley-current from items on an enchanter into the item in the center, but at a 50% loss if they are of mismatched affinities. One third of maximum current is transferred, and when used on items with little power may destroy them or their enchantments';
	};








	disjoin = {
		name = 'disjunction';
		uses = 32;

		leytype = 'occlutic';
		affinity = {'jungle','silent'};
		desc = 'With an enchanter, disjoin the anchor holding a spell into an object so a new spell can instead be bound in';
	};

























}





















<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







|


>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>







 







|






>











>











>

|



>




|


|
|
|



|







 







>

|







 







>
>






>








>







>






>







>







>




>
>
>
>
>
>
>
>



>




>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
41
42
43
44
45
46
47

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
...
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
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
...
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
...
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
			-- the item material and look up the slots offered by this
			-- material. we iterate through the slot definitions to pick 
			-- out a candidate slot, criteria being that the slot
			-- possesses the proper affinity, and that the corresponding
			-- slot on the item enchantment record is empty, then pick
			-- the final slot at random from this table if #candidates>0
			-- (otherwise, we fail unceremoniously).


			local current_enchant = sorcery.enchant.get(subj)
			local material, eligible_spells = sorcery.enchant.getsubj(subj)
			if     eligible_spells == nil
			   or #eligible_spells == 0
			   or  material == nil
			   or  material.data.slots == nil
			   or #material.data.slots == 0
				   then return false end

			-- determine the properties the enchantment will have
			local power = 10
			local energy = material.data.maxenergy
			local reliability = 100
			if ctx.base.gem == 'sapphire' then power = power + 5
			elseif ctx.base.gem == 'amethyst' then
				energy = energy * (math.random() * 0.7)
			elseif ctx.base.gem == 'diamond' then
				if math.random(5) == 1 then
					power = power * 2
					reliability = reliability - (reliability / 4)
				else
					power = power + 5
					reliability = reliability - 10
				end
			end

			local viable_slots = {}
			for i,slot in pairs(material.data.slots) do
				if sorcery.lib.tbl.has(slot.affinity,aff) then
					for _,spell in pairs(current_enchant.spells) do
						if spell.slot == i then goto nonviable end
					end
					viable_slots[#viable_slots + 1] = i
				end
			::nonviable::end
			if #viable_slots == 0 then return false end

			local target_slot = viable_slots[math.random(#viable_slots)]
			-- once we have selected an appropriate slot, we iterate
			-- through the list of known enchantments to check the
			-- affinity of each against `aff`. if the affinity matches
			-- the wand, we then check whether the 'recipe' matches.
			-- if so, we've found the enchantment -- apply it to the
			-- object and update its enchantment data. otherwise, we
			-- move on to the next. if no matching recipe is found,
			-- we give up and bail, returning 'false' to signify that
			-- a spell was not cast.

			local focus_match = function(spec,stack)
				local default_mode
				if spec.lens then
					default_mode = 'dmg'
					if minetest.get_item_group(stack:get_name(), 'sorcery_enchanting_lens') == 0
						then return false end
					local proto = stack:get_definition()._proto
					if proto.kind ~= spec.lens or proto.gem ~= spec.gem
						then return false end
				elseif spec.item then
					default_mode = 'consume'
					if stack:get_name() ~= spec.item then
						return false end
				else
					return false
				end

				local mode
				if spec.dmg then mode = 'dmg'
				elseif spec.consume then mode = 'consume'
				else mode = default_mode end

				if mode == 'dmg' then
					stack:add_wear((spec.dmg or 1) * 1000)
					return stack
				elseif mode == 'consume' then
					stack:take_item(spec.consume or 1)
					return stack
				end
			end
			for ench,data in pairs(sorcery.data.enchants) do
				if data.affinity ~= aff or data.recipe == nil then goto skip end
				local newinv = {}
				for s,v in pairs(data.recipe) do
					newinv[s] = focus_match(v,inv:get_stack('foci',s))
					if newinv[s] == false then goto skip end
				end
				-- is the tool compatible with the chosen spell? we check its groups to
				-- see if any of them grant it eligibility; if not, we skip to the next
				-- spell. NOTE: this means the same recipe could mean different things
				-- for different kinds of tools, if one were so inclined.
				for g,v in pairs(subj:get_definition().groups) do
					if v ~= 0 and sorcery.lib.tbl.has(data.groups, g)
						then goto enchant end
				end
				goto skip
				-- spell matches!
				::enchant:: current_enchant.spells[#current_enchant.spells + 1] = {
					id = ench;
					slot = target_slot;
					boost = power;
					reliability = reliability;
				}
				current_enchant.energy = math.max(current_enchant.energy, energy)

				sorcery.enchant.set(subj, current_enchant)
				inv:set_stack('item',1,subj)
				for i,v in pairs(newinv) do inv:set_stack('foci',i,v) end
				sorcery.enchant.update_enchanter(ctx.target.under)
				enchantment_sparkle(ctx,affcolor)
				do return nil end
			::skip::end
			return false
		end
	};
end
-- note: this was written before terminology was standardized,
-- and "leytype" corresponds to what is otherwise known as an
-- "affinity"; "affinity" after this comment is widely misused
return {
................................................................................
		leytype = 'imperic';
		affinity = {'pine','dark'};
		cast = function(ctx)
			if ctx.target == nil or ctx.target.type ~= 'node' then return false end
			local meta = minetest.get_meta(ctx.target.under)
			-- first we need to check if the wand has an identifying 'key' yet,
			-- and set one if not.
			local wandmode = ctx.base.gem == 'sapphire'
			local keycode
			if ctx.meta:contains('sorcery_wand_key') then
				keycode = ctx.meta:get_string('sorcery_wand_key')
			else
				keycode = sorcery.lib.str.rand(32)
				ctx.meta:set_string('sorcery_wand_key', keycode)
				-- ctx.meta:mark_as_private('sorcery_wand_key')
			end
			if meta:contains('owner') then
				-- owner is already set -- can we break the enchantment?
				if meta:get_string('sorcery_wand_key') == keycode then
					meta:set_string('owner','')
					meta:set_string('sorcery_wand_key','')
					meta:set_string('sorcery_seal_mode','')
					enchantment_sparkle(ctx,sorcery.lib.color(101,255,142))
				else return false end
			else
				meta:set_string('sorcery_wand_key',keycode)
				meta:mark_as_private('sorcery_wand_key')
				meta:set_string('owner',ctx.caster:get_player_name())
				if wandmode then
					meta:set_string('sorcery_seal_mode','wand')
				end
				enchantment_sparkle(ctx,sorcery.lib.color(255,201,27))
			end
		end;
	};
	leyspark = {
		name = 'Leyspark';
		leytype = 'cognic';
		color = {255,246,142}; -- bright yellow
		affinity = {'apple','silent'};
		uses = 128;
		desc = 'Reveal the strength and affinities of the local leyline';
		cast = function(ctx)
			local color = ctx.base.gem == 'sapphire';
			local duration = (ctx.base.gem == 'amethyst' and 4) or 2;
			local ley = sorcery.ley.estimate(ctx.caster:get_pos())
			local emit = function(color,strength)
				minetest.add_particlespawner {
					amount = 70 * strength;
					time = duration * strength;
					attached = ctx.caster;
					texture = sorcery.lib.image('sorcery_spark.png'):
						multiply(color:brighten(1.3)):render();
					minpos = { x = -0.1, z =  0.5, y =  1.2}; 
					maxpos = { x =  0.1, z =  0.3, y =  1.6}; 
					minvel = { x = -0.5, z = -0.5, y = -0.5};
					maxvel = { x =  0.5, z =  0.5, y =  0.5};
					minacc = { x =  0.0, z =  0.0, y =  0.5};
					maxacc = { x =  0.0, z =  0.0, y =  0.5};
					minsize = 0.4, maxsize = 0.8;
					minexptime = 1, maxexptime = 1;
					glow = 14;
					animation = {
						type = 'vertical_frames';
						aspect_w = 16;
						aspect_h = 16;
................................................................................
			end

		end;
	};
	dowse = {
		name = 'dowsing';
		leytype = 'cognic';
		color = {65,116,255};
		affinity = {'acacia','dark','silent'};
		uses = 176;
		desc = 'Send up sparks of radia to indicate nearness or absence of attuned blocks';
	};
	verdant = {
		name = 'verdant';
		color = {16,29,255};
		uses = 48;
		leytype = 'imperic';
................................................................................
	counterpraxic = anchorwand('counterpraxic',23, {'pine','shimmering','silent'});
	entropic      = anchorwand('entropic',      8, {'jungle','dark'});
	syncretic     = anchorwand('syncretic',    12, {'aspen','verdant','shimmering','blazing'});
	cognic        = anchorwand('cognic',       36, {'acacia','verdant','dark'});
	shape = {
		name = 'shaping';
		uses = 24;
		color = {255,114,65};
		leytype = 'praxic';
		affinity = {'apple','blazing'};
		desc = 'With an enchanter, physically alter the mundane qualities of an object';
	};
	attune = {
		name = 'attunement';
		uses = 38;
		color = {255,65,207};
		leytype = 'syncretic';
		affinity = {'pine','verdant','dark'};
		desc = 'Establish a connection between mystic mechanisms, like connecting two sides of a portal or impressing targets onto a dowsing wand in an enchanter';
	};
	meld = {
		name = 'melding';
		uses = 48;
		leytype = 'syncretic';
		color = {172,65,255};
		affinity = {'apple','verdant'};
		desc = 'Meld the properties of three balanced items on an enchanter to create a new one with special properties, but destroying the old ones and losing two thirds of the mass in the process. The precise outcome is not always predictable.';
	};
	divide = {
		name = 'division';
		uses = 19;
		leytype = 'syncretic';
		color = {255,65,121};
		affinity = {'apple','shimmering'};
		desc = 'Shatter an item on an enchanter, dividing its essence equally into three parts and precipitating it into new items embodying various properties of the destroyed item. The outcome is not always predictable.';
	};
	obliterate = {
		name = 'obliteration';
		uses = 129;
		color = {175,6,212};
		affinity = {'aspen','dark'};
		leytype = 'occlutic';
		desc = 'Totally and irreversibly obliterate all items on an enchanter.';
	};
	sacrifice = {
		name = 'sacrifice';
		uses = 58;
		color = {212,6,63};
		affinity = {'aspen','blazing'};
		leytype = 'syncretic';
		desc = 'Transform the matter of one to three items on an enchanter into energy and empower the item on the center of the enchanter with it. Useful to recharge wands in areas with weak leylines.';
	};
	transfer = {
		name = 'transfer';
		uses = 65;
		color = {6,212,121};
		leytype = 'syncretic';
		affinity = {'aspen','shimmering','silent'};
		desc = 'Transfer ley-current from items on an enchanter into the item in the center, but at a 50% loss if they are of mismatched affinities. One third of maximum current is transferred, and when used on items with little power may destroy them or their enchantments';
	};
	transmute = {
		name = 'transmutation';
		uses = 7;
		color = {255,90,18};
		leytype = 'imperic';
		affinity = {'aspen','shimmering','dark','blazing'};
		desc = 'Transmute three ingots into one of a different metal, determined by chance and influenced by configuration of the wand';
	};
	disjoin = {
		name = 'disjunction';
		uses = 32;
		color = {17,6,212};
		leytype = 'occlutic';
		affinity = {'jungle','silent'};
		desc = 'With an enchanter, disjoin the anchor holding a spell into an object so a new spell can instead be bound in';
	};
	luminate = {
		name = 'lumination';
		desc = 'Banish darkness all about you for a few moments';
		uses = 40;
		color = {244,255,157};
		affinity = {'acacia','shimmering','blazing'};
		leytype = 'cognic';
		cast = function(ctx)
			local center = ctx.heading.pos
			local maxpower = 20
			local power = (ctx.base.gem == 'sapphire' and maxpower) or maxpower/2
			local range = (ctx.base.gem == 'emerald' and 10) or 5
			local duration = (ctx.base.gem == 'amethyst' and 60) or 30
			if ctx.base.gem == 'diamond' then
				power = power * (math.random()*2)
				range = range * (math.random()*2)
				duration = duration * (math.random()*2)
			end
			local lum = math.ceil((power/maxpower) * minetest.LIGHT_MAX)
			print('setting lum',lum)
			for i=1,power do
				local pos = vector.add(center, {
					x = math.random(-range,range);
					z = math.random(-range,range);
					y = math.random(0,range/2);
				})
				local delta = vector.subtract(pos,center)
				local near = 1 - (delta.x^2 + delta.y^2 + delta.z^2)/(range^2)
				if minetest.get_node(pos).name == 'air' then
					minetest.set_node(pos,{name='sorcery:air_glimmer_' .. tostring(lum)})
					do local lm = minetest.get_meta(pos)
						lm:set_float('duration',duration)
						lm:set_float('timeleft',duration)
						lm:set_float('power',lum * near)
					end
				end
			end
		end;
	};
}