sorcery  Diff

Differences From Artifact [eabb5d4796]:

  • File wands.lua — part of check-in [ea6e475e44] at 2020-10-19 09:52:11 on branch trunk — continue dev on celestial mechanics, add melding+division spells (resonance), refine itemclasses, add keypunch and punchcards, add paper pulp, add a shitload of visuals, add convenience scripts for working with the wiki, make the flamebolt spell actually useful instead of just a pretty lightshow, add essences, inferno crystal, and other goodies; iterate on wands, lots of shit i can't remember, various bugfixes (user: lexi, size: 27150) [annotate] [blame] [check-ins using]

To Artifact [e3e1a760a8]:


100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
...
255
256
257
258
259
260
261

262
263
264
265
266
267
268
...
339
340
341
342
343
344
345

















346
347
348
349
350
351
352
...
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
409
410
411
412
413
...
417
418
419
420
421
422
423



424
425

426

427
428
429



430








431
432
433
434
435
436
437
...
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
...
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
			};
			steel = {
				tone = u.color(255,255,255);
				tex = u.image('default_steel_block');
				wandprops = {};
			};
		};
		gem = sorcery.lib.tbl.deepmerge(sorcery.data.gems, {
			sapphire = {
				wandprops = { sturdiness = 0.5 };
			};
			diamond = {
				wandprops = { sturdiness = (1/3) };
			};
		})
	};
	util = {
		baseid = function(wand)
			local elts = {wand.wood}
			if wand.gem  ~= nil then elts[#elts + 1] = wand.gem end
			if wand.wire ~= nil then elts[#elts + 1] = wand.wire end
			return 'sorcery:wand_' .. table.concat(elts,'_')
................................................................................
			end
		end
	end

	local uprops = user:get_properties();
	local context = {
		base = wand;

		meta = meta;
		item = stack;
		caster = user;
		target = target;
		today = minetest.get_day_count();
		heading = {
			pos   = user:get_pos();
................................................................................
	if kind.gem then
		img.gem = u.image('sorcery_wand_' .. kind.gem .. '_tip.png')
		img.whole = img.gem:blit(img.whole)
	end
	return img
end


















local createstand = function(name, wood, desc, tex, extra)
	local hitbox = {
		type = "fixed";
		fixed = {
			-0.5, -0.5, -0.3;
			0.5, -0.1, 0.3;
		};
................................................................................
		mesh = 'sorcery-wand-stand.obj';
		sunlight_propagates = true;
		paramtype = 'light';
		paramtype2 = 'facedir';
		tiles = images;
		selection_box = hitbox;
		collision_box = hitbox;

		use_texture_alpha = true;






		_proto = {
			wood = wood;
		};
		groups = {
			sorcery_wand_stand = 1;
			choppy = 2;
			oddly_breakable_by_hand = 2;
		};
	}
	minetest.register_node(name, u.tbl.merge(auto,extra))
end
local update_stand_info = function(pos)
	local woodname = minetest.registered_nodes[minetest.get_node(pos).name]._proto.wood
	local meta = minetest.get_meta(pos)
	local inv = meta:get_inventory()





	if inv:is_empty('wand') then
		meta:set_string('infotext',u.str.capitalize(woodname) .. ' wand stand')

	else
		local stack = inv:get_stack('wand',1)


		local spell = stack:get_meta():get_string('sorcery_wand_spell')
		local color = u.color(127,127,127)
		if spell ~= '' then

			color = u.color(sorcery.data.spells[spell].color):readable()




		end
		local wand_proto = sorcery.wands.util.getproto(stack)

















		meta:set_string('infotext',color:fmt(sorcery.wands.util.fullname(stack) .. ' stand'))
	end
end





















































for woodname, wood in pairs(sorcery.wands.materials.wood) do
	local blank = u.image('sorcery_transparent.png'); -- haaaaack
	local name = 'sorcery:wand_stand_' .. woodname

	createstand(name, woodname,
		u.str.capitalize(woodname .. 'wood wand stand'),
		{ wood.tex; blank; blank; blank; }, {
			on_construct = function(pos)
				local meta = minetest.get_meta(pos)
				local inv = meta:get_inventory()
				inv:set_size('wand', 1)
				update_stand_info(pos)
			end;
			on_rightclick = function(pos,node,user,stack)
				local meta = minetest.get_meta(pos)
				local stand = meta:get_inventory()
				local wand_proto = sorcery.wands.util.getproto(stack)
				if minetest.get_item_group(stack:get_name(), 'sorcery_wand') ~= 0 then
					stand:set_stack('wand',1,stack)
					minetest.swap_node(pos, {
................................................................................
					stack = ItemStack(nil)
				end
				update_stand_info(pos)
				return stack
			end
		}
	)



	local plank = wood.plank or 'default:' .. woodname .. '_wood'
	minetest.register_craft {

		recipe = {

			{plank, 'default:stick', plank};
			{plank, plank, plank};
		};



		output = name








	}
end

sorcery.wands.createstands = function(kind)
	-- big oof
	for woodname, wood in pairs(sorcery.wands.materials.wood) do
		local gemimg = u.image('default_diamond_block.png')
................................................................................

	-- iterate through every wand in the tank to see if anything
	-- needs to be done
	local success = false
	for i,wand in pairs(wands) do
		local proto = wand.stack:get_definition()._proto
		local wood = sorcery.wands.materials.wood[proto.wood]
		--print('considering ' .. proto.wood)
		for spell,def in pairs(sorcery.data.spells) do
			if not def.affinity then goto skip_spell end
			local potions, found = {}, false
			for _,a in pairs(def.affinity) do
				if a == proto.wood then found = true else
					potions[#potions + 1] = a
				end
			end
			if not found then goto skip_spell end
		-- for spell,potions in pairs(wood.affinities) do
			--print(' + considering spell ' .. spell)
			-- check whether all the necessary philters
			-- are accounted for
			if #potions ~= #philters then goto skip_spell end
			for _,p in pairs(potions) do
				for _,ph in pairs(philters) do
					local def = ph.stack:get_definition()
					--print(' - + checking for philter ' .. def._protoname)
					if def._protoname == p then goto found end
				end
				goto skip_spell
			::found::end

			success = true
			-- we've confirmed that all the philters for this spell
			-- are present, now we need to apply it to the wand
			--print('setting spell')
			wand.stack:get_meta():set_string('sorcery_wand_spell',spell)
			update_wand_description(wand.stack)
			inv:set_stack('tank',wand.idx,wand.stack)

			do break end -- }:<<<
		::skip_spell::end
	end
................................................................................
	local slot = function(name,x,y,w,h)
		return string.format('list[nodemeta:%d,%d,%d;%s;%f,%f;%f,%f;]',
			pos.x, pos.y, pos.z,
			name, x,y, w,h
		)
	end

	return 'size[8,6.5]' ..
		slot('tank', 0.5,0, 2,2) ..
		slot('wandparts', 5.5,0, 1,2) ..
		slot('preview', 6.5,0.5, 1,1) ..
		slot('input', 4.5,0.5, 1,1) .. [[
		list[current_player;main;0,2.5;8,4;]
		listring[]
	]]







|
<
<
<
<
<
<
<







 







>







 







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







 







>

>
>
>
>
>
>











|
<


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


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



>

|

<
<
<
<
<
<







 







>
>
>


>

>



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







 







<









<
<






<








<







 







|







100
101
102
103
104
105
106
107







108
109
110
111
112
113
114
...
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
...
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
...
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
409


410
411
412
413
414
415
416

417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496






497
498
499
500
501
502
503
...
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
...
683
684
685
686
687
688
689

690
691
692
693
694
695
696
697
698


699
700
701
702
703
704

705
706
707
708
709
710
711
712

713
714
715
716
717
718
719
...
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
			};
			steel = {
				tone = u.color(255,255,255);
				tex = u.image('default_steel_block');
				wandprops = {};
			};
		};
		gem = sorcery.data.gems;







	};
	util = {
		baseid = function(wand)
			local elts = {wand.wood}
			if wand.gem  ~= nil then elts[#elts + 1] = wand.gem end
			if wand.wire ~= nil then elts[#elts + 1] = wand.wire end
			return 'sorcery:wand_' .. table.concat(elts,'_')
................................................................................
			end
		end
	end

	local uprops = user:get_properties();
	local context = {
		base = wand;
		stats = matprops;
		meta = meta;
		item = stack;
		caster = user;
		target = target;
		today = minetest.get_day_count();
		heading = {
			pos   = user:get_pos();
................................................................................
	if kind.gem then
		img.gem = u.image('sorcery_wand_' .. kind.gem .. '_tip.png')
		img.whole = img.gem:blit(img.whole)
	end
	return img
end

local update_stand_info = function(pos)
	local woodname = minetest.registered_nodes[minetest.get_node(pos).name]._proto.wood
	local meta = minetest.get_meta(pos)
	local inv = meta:get_inventory()
	if inv:is_empty('wand') then
		meta:set_string('infotext',u.str.capitalize(woodname) .. ' wand stand')
	else
		local stack = inv:get_stack('wand',1)
		local spell = stack:get_meta():get_string('sorcery_wand_spell')
		local color = u.color(127,127,127)
		if spell ~= '' then
			color = u.color(sorcery.data.spells[spell].color):readable()
		end
		local wand_proto = sorcery.wands.util.getproto(stack)
		meta:set_string('infotext',color:fmt(sorcery.wands.util.fullname(stack) .. ' stand'))
	end
end
local createstand = function(name, wood, desc, tex, extra)
	local hitbox = {
		type = "fixed";
		fixed = {
			-0.5, -0.5, -0.3;
			0.5, -0.1, 0.3;
		};
................................................................................
		mesh = 'sorcery-wand-stand.obj';
		sunlight_propagates = true;
		paramtype = 'light';
		paramtype2 = 'facedir';
		tiles = images;
		selection_box = hitbox;
		collision_box = hitbox;
		after_dig_node = sorcery.lib.node.purge_container;
		use_texture_alpha = true;
		on_construct = function(pos)
			local meta = minetest.get_meta(pos)
			local inv = meta:get_inventory()
			inv:set_size('wand', 1)
			update_stand_info(pos)
		end;
		_proto = {
			wood = wood;
		};
		groups = {
			sorcery_wand_stand = 1;
			choppy = 2;
			oddly_breakable_by_hand = 2;
		};
	}
	minetest.register_node(name, u.tbl.merge(auto,extra))
end
local rack_update = function(pos)

	local meta = minetest.get_meta(pos)
	local inv = meta:get_inventory()
	local wandcount = 0
	local mkslot = function(slot,x,y)
		local stack = inv:get_stack('wands',slot)
		local im = stack:get_meta()
		local r = string.format([[ list[context;wands;%f,%f;1,1;%u] ]], x, y, slot-1)
		if stack:is_empty() then

			r = r .. string.format([[ image[%f,%f;1,1;sorcery_ui_ghost_wand.png] ]], x, y)
		else

			wandcount = wandcount + 1
			if im:contains('sorcery_wand_spell') then
				local spell = im:get_string('sorcery_wand_spell')


				local spname = u.str.capitalize(sorcery.data.spells[spell].name)
				local spclr = u.color(sorcery.data.spells[spell].color or {255,255,255})

				r = r .. string.format([[
					label[%f,%f;%s]
				]], x + 1.25, y + 0.5, minetest.formspec_escape(spclr:fmt(spname)))
			end

		end
		return r
	end
	local spec = [[
		formspec_version[3] size[10.25,11.75] real_coordinates[true]
		list[current_player;main;0.25,6.75;8,4;]
		listring[current_player;main] listring[context;wands]
	]]
	for i=1,inv:get_size('wands') do
		local yo = ((i-1) % 5) * 1.25
		local xo = i > 5 and 5 or 0
		spec = spec .. mkslot(i, 0.25 + xo, 0.25 + yo)
	end
	meta:set_string('formspec',spec)
	if wandcount > 0 then
		meta:set_string('infotext',string.format('Wand rack with %u wands', wandcount))
	else
		meta:set_string('infotext','Wand rack')
	end
end

local createrack = function(name, wood, tex, desc)
	local hitbox = {
		type = "fixed";
		fixed = {
			-0.5, -0.5, 0.5;
			 0.5,  0.5, 0.35;
		};
	}
	local rack = {
		description = desc;
		drawtype = 'mesh';
		mesh = 'sorcery-wand-rack.obj';
		sunlight_propagates = true;
		paramtype = 'light';
		paramtype2 = 'facedir';
		tiles = {
			u.image('default_diamond_block.png'):
				multiply(u.color{50,255,70}):render();
			tex:render();
			'default_diamond_block.png';
			'default_copper_block.png';
			'default_pine_wood.png';
			'default_junglewood.png';
		};
		selection_box = hitbox;
		collision_box = hitbox;
		use_texture_alpha = true;
		after_dig_node = sorcery.lib.node.purge_container;
		on_construct = function(pos)
			local meta = minetest.get_meta(pos)
			local inv = meta:get_inventory()
			inv:set_size('wands',10)
			rack_update(pos)
		end;
		allow_metadata_inventory_put = function(pos, lst, idx, stack, user)
			if minetest.get_item_group(stack:get_name(), 'sorcery_wand') ~= 0
				then return 1
				else return 0
			end
		end;
		on_metadata_inventory_move = rack_update;
		on_metadata_inventory_take = rack_update;
		on_metadata_inventory_put = rack_update;
		_proto = { wood = wood; };
		groups = {
			sorcery_wand_rack = 1;
			choppy = 2;
			oddly_breakable_by_hand = 2;
		};
	}
	minetest.register_node(name, rack)
end
for woodname, wood in pairs(sorcery.wands.materials.wood) do
	local blank = u.image('sorcery_transparent.png'); -- haaaaack
	local name = 'sorcery:wand_stand_' .. woodname
	local rackid = 'sorcery:wand_rack_' .. woodname
	createstand(name, woodname,
		u.str.capitalize(woodname) .. 'wood wand stand',
		{ wood.tex; blank; blank; blank; }, {






			on_rightclick = function(pos,node,user,stack)
				local meta = minetest.get_meta(pos)
				local stand = meta:get_inventory()
				local wand_proto = sorcery.wands.util.getproto(stack)
				if minetest.get_item_group(stack:get_name(), 'sorcery_wand') ~= 0 then
					stand:set_stack('wand',1,stack)
					minetest.swap_node(pos, {
................................................................................
					stack = ItemStack(nil)
				end
				update_stand_info(pos)
				return stack
			end
		}
	)
	createrack(rackid,woodname,wood.tex,
		u.str.capitalize(woodname) .. 'wood wand rack')

	local plank = wood.plank or 'default:' .. woodname .. '_wood'
	minetest.register_craft {
		output = name;
		recipe = {
			-- TODO: whittling/carving knife
			{plank, 'default:stick', plank};
			{plank, plank, plank};
		};
	}

	minetest.register_craft {
		output = rackid;
		recipe = {
			{plank,'default:stick',plank};
			{'sorcery:screw_steel','screwdriver:screwdriver','sorcery:screw_steel'};
			{plank,name,plank};
		};
		replacements = {
			{'screwdriver:screwdriver','screwdriver:screwdriver'};
		};
	}
end

sorcery.wands.createstands = function(kind)
	-- big oof
	for woodname, wood in pairs(sorcery.wands.materials.wood) do
		local gemimg = u.image('default_diamond_block.png')
................................................................................

	-- iterate through every wand in the tank to see if anything
	-- needs to be done
	local success = false
	for i,wand in pairs(wands) do
		local proto = wand.stack:get_definition()._proto
		local wood = sorcery.wands.materials.wood[proto.wood]

		for spell,def in pairs(sorcery.data.spells) do
			if not def.affinity then goto skip_spell end
			local potions, found = {}, false
			for _,a in pairs(def.affinity) do
				if a == proto.wood then found = true else
					potions[#potions + 1] = a
				end
			end
			if not found then goto skip_spell end


			-- check whether all the necessary philters
			-- are accounted for
			if #potions ~= #philters then goto skip_spell end
			for _,p in pairs(potions) do
				for _,ph in pairs(philters) do
					local def = ph.stack:get_definition()

					if def._protoname == p then goto found end
				end
				goto skip_spell
			::found::end

			success = true
			-- we've confirmed that all the philters for this spell
			-- are present, now we need to apply it to the wand

			wand.stack:get_meta():set_string('sorcery_wand_spell',spell)
			update_wand_description(wand.stack)
			inv:set_stack('tank',wand.idx,wand.stack)

			do break end -- }:<<<
		::skip_spell::end
	end
................................................................................
	local slot = function(name,x,y,w,h)
		return string.format('list[nodemeta:%d,%d,%d;%s;%f,%f;%f,%f;]',
			pos.x, pos.y, pos.z,
			name, x,y, w,h
		)
	end

	return 'size[8,6.25]' ..
		slot('tank', 0.5,0, 2,2) ..
		slot('wandparts', 5.5,0, 1,2) ..
		slot('preview', 6.5,0.5, 1,1) ..
		slot('input', 4.5,0.5, 1,1) .. [[
		list[current_player;main;0,2.5;8,4;]
		listring[]
	]]