sorcery  Diff

Differences From Artifact [f0ca6bd16e]:

To Artifact [5af73c1767]:


    54     54   		if not inv:is_empty('preview') then
    55     55   			for i=1, inv:get_size('preview') do
    56     56   				inv:set_stack('preview',i,ItemStack())
    57     57   			end
    58     58   		end
    59     59   		return
    60     60   	end
           61  +
           62  +	local tmat = sorcery.itemclass.get(tool:get_name(),'material')
           63  +	local wmat = sorcery.itemclass.get(wkpc:get_name(),'material')
           64  +	-- obey level restrictions. TODO honor Rend
           65  +	if (wmat and wmat.data.level or 0) > (tmat and (tmat.data.maxlevel or tmat.data.level) or 0) then
           66  +		return
           67  +	end
    61     68   
    62     69   	local tech = sorcery.lathe.tooltech(tool)
    63     70   	local rec = R[wkpc:get_name()][tech]
    64     71   	tech = sorcery.lathe.techs[tech]
    65     72   
    66     73   	-- fill in the preview slots
    67     74   	local j = 1
................................................................................
   162    169   			else return 0 end
   163    170   		else return stack:get_count() end
   164    171   	end;
   165    172   	on_metadata_inventory_put = sorcery.lathe.update;
   166    173   	on_metadata_inventory_take = function(pos, list, idx, stack, user)
   167    174   		if list == 'preview' then
   168    175   			local l = sorcery.lathe.get(pos,idx,stack:get_count())
   169         -
   170    176   			if sorcery.lathe.techs[l.tech].consume then
   171    177   				l.tool:take_item(l.cost)
   172    178   			elseif sorcery.lathe.techs[l.tech].dmg then
   173         -			--TODO wear down tool
          179  +				local mat = sorcery.itemclass.get(l.tool,'material')
          180  +				local mmat = sorcery.itemclass.get(l.wkpc,'metal')
          181  +				local dur = 100
          182  +				local lfac = 1
          183  +				if mat then
          184  +					local dur = mat.data.durability or dur
          185  +					lfac = (mmat and mmat.data.level or 1) /
          186  +						(mat.data.maxlevel or mat.data.level or 1)
          187  +				end
          188  +				local ch = 65535 / dur
          189  +				l.tool:add_wear(4 * ch * l.cost * lfac)
   174    190   			end
   175    191   			l.wkpc:take_item(l.qty)
   176    192   			l.inv:set_stack('tool', 1, l.tool)
   177    193   			l.inv:set_stack('workpiece', 1, l.wkpc)
   178    194   			minetest.sound_play('sorcery_clank', { pos = pos, gain = 0.9 })
   179    195   		end
   180    196   		sorcery.lathe.update(pos)