sorcery  Diff

Differences From Artifact [26814ac7ca]:

To Artifact [8384a43ac0]:


36
37
38
39
40
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
		local meta = minetest.get_meta(pos)
		local inv = meta:get_inventory()
		if inv:is_empty('charge') then return false end
		
		local ley = sorcery.ley.estimate(pos)
		local charged = false
		for i=1,inv:get_size('charge') do
			local repair_per_tick = (65536 / 64) * (15 * ley.force)
			local item = inv:get_stack('charge',i)
			if minetest.get_item_group(item:get_name(), 'sorcery_wand') ~= 0 then




				local spell = item:get_meta():get_string('sorcery_wand_spell')
				if spell == '' then goto skip end
				local aff = sorcery.data.spells[spell].leytype
				if aff == ley.aff[1] or aff == ley.aff[2] then
					repair_per_tick = repair_per_tick * 2 end



			else goto skip end -- item is not magical







			print('repair cycle! repairing item'..item:get_name()..' by',repair_per_tick * (elapse / 60))
			item:set_wear(math.max(0,item:get_wear() - repair_per_tick * (elapse / 60)))
			inv:set_stack('charge',i,item)
			charged = true
		::skip::end

		return charged
	end;

	on_construct = function(pos)
		local meta = minetest.get_meta(pos)
		local inv = meta:get_inventory()
		inv:set_size('charge', 3)

		meta:set_string('formspec', [[
			size[8,5]
			list[context;charge;2.5,0;3,1;]
			list[current_player;main;0,1.3;8,4;]
			listring[]
		]])
	end;







|


>
>
>
>





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











>







36
37
38
39
40
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
		local meta = minetest.get_meta(pos)
		local inv = meta:get_inventory()
		if inv:is_empty('charge') then return false end
		
		local ley = sorcery.ley.estimate(pos)
		local charged = false
		for i=1,inv:get_size('charge') do
			local curve = function(x) return ((x*10)^2)/10 end
			local item = inv:get_stack('charge',i)
			if minetest.get_item_group(item:get_name(), 'sorcery_wand') ~= 0 then
				local mese = 1
				if sorcery.wands.util.getproto(item).gem == 'mese' then
					mese = 1.5 end
				local repair_per_tick = (65536 / 80) * curve(ley.force) * mese
				local spell = item:get_meta():get_string('sorcery_wand_spell')
				if spell == '' then goto skip end
				local aff = sorcery.data.spells[spell].leytype
				if aff == ley.aff[1] or aff == ley.aff[2] then
					repair_per_tick = repair_per_tick * 2 end
				item:set_wear(math.max(0,item:get_wear() - repair_per_tick * (elapse / 60)))
			else 
				local e = sorcery.enchant.get(item)
				if #e.spells == 0 then goto skip end -- item is not magical
				local mat = sorcery.enchant.getsubj(item)
				if e.energy < mat.data.maxenergy then
					local energy_per_tick = (100 * curve(ley.force)) + ((mat.data.energysource or 0)*2)
					e.energy = math.min(e.energy + energy_per_tick, mat.data.maxenergy)
					sorcery.enchant.set(item,e,true)
				else goto skip end -- already fully charged
			end
			-- print('repair cycle! repairing item'..item:get_name()..' by',repair_per_tick * (elapse / 60))

			inv:set_stack('charge',i,item)
			charged = true
		::skip::end

		return charged
	end;

	on_construct = function(pos)
		local meta = minetest.get_meta(pos)
		local inv = meta:get_inventory()
		inv:set_size('charge', 3)
		meta:set_string('infotext','Harvester')
		meta:set_string('formspec', [[
			size[8,5]
			list[context;charge;2.5,0;3,1;]
			list[current_player;main;0,1.3;8,4;]
			listring[]
		]])
	end;