sorcery  Diff

Differences From Artifact [40c411e2ef]:

To Artifact [81d31df3a3]:


33
34
35
36
37
38
39





40
41
42
43
44
45
46
..
50
51
52
53
54
55
56

57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
		emerald:render();
	};

	on_timer = function(pos,elapse)
		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 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







>
>
>
>
>







 







>








|







33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
..
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
		emerald:render();
	};

	on_timer = function(pos,elapse)
		local meta = minetest.get_meta(pos)
		local inv = meta:get_inventory()
		if inv:is_empty('charge') then return false end

		local put_in_hopper = sorcery.lib.node.discharger(pos)
		local discharge = function(item,idx)
			inv:set_stack('charge',put_in_hopper(item))
		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 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)))
				if item:get_wear() == 0 then item = put_in_hopper(item) end
			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 discharge(item,i) 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