sorcery  Check-in [0dbb4f52c3]

Overview
Comment:add tool wear to lathe, add page turning sounds for cookbooks
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 0dbb4f52c3ee72f790af685a0bc1d4d3f750157204091fdc47d6b9a30ea4ef40
User & Date: lexi on 2021-07-08 01:08:09
Other Links: manifest | tags
Context
2021-07-08
11:25
lathe is a mess but whatever i dont care it works now check-in: 77b901d950 user: lexi tags: trunk
01:08
add tool wear to lathe, add page turning sounds for cookbooks check-in: 0dbb4f52c3 user: lexi tags: trunk
2021-07-07
23:40
add lathe, bug fixes, new sounds check-in: 200ec592d5 user: lexi tags: trunk
Changes

Modified cookbook.lua from [4b9992727f] to [1bf06d7139].

   707    707   	local stack = uinv:get_stack('main', idx)
   708    708   	local book = bookprops(stack)
   709    709   	local meta = stack:get_meta()
   710    710   
   711    711   	local curpage = meta:contains("pagenr") and meta:get_int("pagenr") or 1
   712    712   	local pagect = math.ceil(#book.pages / constants.recipes_per_cookbook_page)
   713    713   
   714         -	if curpage > 1 and fields.pageback then
   715         -		meta:set_int('pagenr', curpage - 1)
   716         -	elseif curpage < pagect and fields.pagenext then
   717         -		meta:set_int('pagenr', curpage + 1)
          714  +	if fields.pageback or fields.pagenext then
          715  +		if curpage > 1 and fields.pageback then
          716  +			meta:set_int('pagenr', curpage - 1)
          717  +		elseif curpage < pagect and fields.pagenext then
          718  +			meta:set_int('pagenr', curpage + 1)
          719  +		end
          720  +		minetest.sound_play('sorcery_pgturn', { pos = pos, gain = 0.6 })
   718    721   	end
   719    722   
   720    723   	uinv:set_stack('main',idx,stack)
   721    724   	bookform(stack,user)
   722    725   end)
   723    726   
   724    727   minetest.register_on_craft(function(stack,player,grid,inv)

Modified itemclass.lua from [5df312f3fb] to [2e8a1de5b1].

    19     19   		-- gem/crystalline and metal/metallic differentiate
    20     20   		-- between crafting materials (i.e. gems or ingots
    21     21   		-- themselves) and items crafted from those materials.
    22     22   		-- the former includes only crafting materials, the
    23     23   		-- latter includes both.
    24     24   		gem = {
    25     25   			compat = 'gems';
           26  +			finagle = function(g) return {data = sorcery.data.gems[g.id]} end;
    26     27   			groups = { 'gem', 'crystal'; };
    27     28   			predicate = function(name)
    28     29   				if minetest.get_item_group(name, 'sorcery_gem') ~= 0 
    29     30   				or minetest.get_item_group(name, 'sorcery_shard') ~= 0 then
    30     31   					return minetest.registered_items[name]._sorcery.material;
    31     32   				end
    32     33   			end;

Modified lathe.lua from [f0ca6bd16e] to [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)

Modified writing.lua from [57199bc1f0] to [cf9865540e].

   477    477   
   478    478   			-- handle page change request
   479    479   			if fields.nextpage or fields.prevpage then
   480    480   				local page = math.max(1,bm:get_int('pagenr'))
   481    481   				if     fields.nextpage then page = page + 1
   482    482   				elseif fields.prevpage then page = page - 1 end
   483    483   				bm:set_int('pagenr',math.max(1,page))
          484  +				minetest.sound_play('sorcery_pgturn', { pos = pos, gain = 0.6 })
   484    485   				changed = true
   485    486   			end
   486    487   
   487    488   			-- handle retitle request
   488    489   			if fields.title then
   489    490   				if fields.title ~= bm:get_string('description') then
   490    491   					if charge_ink(constants.op_cost_retitle) then