sorcery  Diff

Differences From Artifact [40c411e2ef]:

To Artifact [81d31df3a3]:


    33     33   		emerald:render();
    34     34   	};
    35     35   
    36     36   	on_timer = function(pos,elapse)
    37     37   		local meta = minetest.get_meta(pos)
    38     38   		local inv = meta:get_inventory()
    39     39   		if inv:is_empty('charge') then return false end
           40  +
           41  +		local put_in_hopper = sorcery.lib.node.discharger(pos)
           42  +		local discharge = function(item,idx)
           43  +			inv:set_stack('charge',put_in_hopper(item))
           44  +		end
    40     45   		
    41     46   		local ley = sorcery.ley.estimate(pos)
    42     47   		local charged = false
    43     48   		for i=1,inv:get_size('charge') do
    44     49   			local curve = function(x) return ((x*10)^2)/10 end
    45     50   			local item = inv:get_stack('charge',i)
    46     51   			if minetest.get_item_group(item:get_name(), 'sorcery_wand') ~= 0 then
................................................................................
    50     55   				local repair_per_tick = (65536 / 80) * curve(ley.force) * mese
    51     56   				local spell = item:get_meta():get_string('sorcery_wand_spell')
    52     57   				if spell == '' then goto skip end
    53     58   				local aff = sorcery.data.spells[spell].leytype
    54     59   				if aff == ley.aff[1] or aff == ley.aff[2] then
    55     60   					repair_per_tick = repair_per_tick * 2 end
    56     61   				item:set_wear(math.max(0,item:get_wear() - repair_per_tick * (elapse / 60)))
           62  +				if item:get_wear() == 0 then item = put_in_hopper(item) end
    57     63   			else 
    58     64   				local e = sorcery.enchant.get(item)
    59     65   				if #e.spells == 0 then goto skip end -- item is not magical
    60     66   				local mat = sorcery.enchant.getsubj(item)
    61     67   				if e.energy < mat.data.maxenergy then
    62     68   					local energy_per_tick = (100 * curve(ley.force)) + ((mat.data.energysource or 0)*2)
    63     69   					e.energy = math.min(e.energy + energy_per_tick, mat.data.maxenergy)
    64     70   					sorcery.enchant.set(item,e,true)
    65         -				else goto skip end -- already fully charged
           71  +				else discharge(item,i) goto skip end -- already fully charged
    66     72   			end
    67     73   			-- print('repair cycle! repairing item'..item:get_name()..' by',repair_per_tick * (elapse / 60))
    68     74   			inv:set_stack('charge',i,item)
    69     75   			charged = true
    70     76   		::skip::end
    71     77   
    72     78   		return charged