sorcery  Diff

Differences From Artifact [5366481e82]:

  • File disassembly.lua — part of check-in [72eebac4bc] at 2020-09-26 18:49:51 on branch trunk — add writing stand for editing codexes; add scissors, ink, erasure fluid, pens; touch up codex UI; add many recipe notes; add craft divination type for crafttools; defuckulate fucktarded crafttool impl; enhance table library with missing features like lua's table.unpack; many bug fixes and enhancements; blood for the blood god (user: lexi, size: 4258) [annotate] [blame] [check-ins using]

To Artifact [9a3b11da34]:

  • File disassembly.lua — part of check-in [3f6a913e4e] at 2020-09-29 12:40:28 on branch trunk — * remove former hacky registration system, replace with consistent and flexible API; rewrite metal/gem generation to take advantage of this new API; tweaks to init system to enable world-local tweaks to lore and sorcery behavior * initial documentation commit * initial steps towards calendar - add default date format, astrolabe; prepare infra for division/melding/transmutation spells, various tweaks and fixes (user: lexi, size: 5148) [annotate] [blame] [check-ins using]

            1  +local disassembler_formspec = function(pos)
            2  +	local m = minetest.get_meta(pos)
            3  +	local i = m:get_inventory()
            4  +	local form = [[
            5  +		formspec_version[3]
            6  +		size[10.25,7] real_coordinates[true]
            7  +		list[current_player;main;0.25,2;8,4]
            8  +	]]
            9  +	local slot = function(name,x,y,ghost)
           10  +		local s = string.format('list[context;%s;%f,%f;1,1;]', name, x, y)
           11  +		if ghost and i:is_empty(name) then
           12  +			s = string.format('image[%f,%f;1,1;sorcery_ui_ghost_%s.png]',x,y,ghost) .. s
           13  +		end
           14  +		form = form .. s
           15  +	end
           16  +	slot('item',0.25,0.5)
           17  +	slot('paper',2.25,0.5,'paper')
           18  +	slot('ink',3.50,0.5,'ink_bottle')
           19  +	slot('pen',4.75,0.5,'pen')
           20  +	slot('output',9,0.5)
           21  +	form = form .. [[
           22  +		listring[context;output]
           23  +		listring[current_player;main] listring[context;paper]
           24  +		listring[current_player;main] listring[context;ink]
           25  +		listring[current_player;main] listring[context;item]
           26  +		listring[current_player;main]
           27  +	]]
           28  +	m:set_string('formspec',form)
           29  +end
     1     30   local update_disassembler = function(pos)
     2     31   	local m = minetest.get_meta(pos)
     3     32   	local i = m:get_inventory()
     4     33   	local paper = i:get_stack('paper',1)
     5     34   	local item = i:get_stack('item',1)
           35  +	local ink = i:get_stack('ink',1)
           36  +	local pen = i:get_stack('pen',1)
     6     37   
     7         -	local ink_count
     8         -	for j=1,i:get_size('ink') do
     9         -		local ink = i:get_stack('ink',j)
    10         -		local c = ink:get_count()
    11         -		if ink_count then
    12         -			if c < ink_count then ink_count = c end
    13         -		else ink_count = c end
    14         -	end
           38  +	local ink_count = ink:get_count()
    15     39   	
    16         -	ink_count = ink_count or 0
    17     40   	local maxrecs = math.min(ink_count, paper:get_count(), item:get_count())
           41  +	if pen:is_empty() then maxrecs = 0 end
    18     42   
    19     43   	if maxrecs > 0 and sorcery.cookbook.classes.craft.find(item:get_name()) then
    20     44   		local rec = ItemStack{name = 'sorcery:recipe', count = maxrecs}
    21     45   		sorcery.cookbook.setrecipe(rec, 'craft', item:get_name())
    22     46   		i:set_stack('output',1,rec)
    23     47   	else
    24     48   		i:set_stack('output',1,ItemStack())
    25     49   	end
           50  +	disassembler_formspec(pos)
    26     51   end
    27     52   local dsbox = {
    28     53   	type = 'fixed';
    29     54   	fixed = {
    30     55   		-0.5, -0.5, -0.5;
    31     56   		 0.5,  0.0,  0.5;
    32     57   	};
................................................................................
    55     80   	};
    56     81   	after_dig_node = sorcery.lib.node.purge_container;
    57     82   	on_construct = function(pos)
    58     83   		local m = minetest.get_meta(pos)
    59     84   		local i = m:get_inventory()
    60     85   		i:set_size('item',1)
    61     86   		i:set_size('paper',1)
    62         -		i:set_size('ink',3)
           87  +		i:set_size('ink',1)
           88  +		i:set_size('pen',1)
    63     89   		i:set_size('output',1)
    64     90   		m:set_string('infotext','Disassembly Kit')
    65         -		m:set_string('formspec', [[
    66         -			formspec_version[3]
    67         -			size[10.25,7] real_coordinates[true]
    68         -			list[current_player;main;0.25,2;8,4]
    69         -
    70         -			list[context;item;0.25,0.5;1,1;]
    71         -			list[context;paper;2.25,0.5;1,1;]
    72         -			list[context;ink;4.25,0.5;3,1;]
    73         -			list[context;output;9,0.5;1,1;]
    74         -
    75         -			listring[context;output]
    76         -			listring[current_player;main] listring[context;paper]
    77         -			listring[current_player;main] listring[context;ink]
    78         -			listring[current_player;main] listring[context;item]
    79         -			listring[current_player;main]
    80         -		]])
           91  +		disassembler_formspec(pos)
    81     92   	end;
    82     93   	on_metadata_inventory_put = update_disassembler;
    83     94   	on_metadata_inventory_take = function(pos,list,idx,stack,user)
    84     95   		local m = minetest.get_meta(pos)
    85     96   		local i = m:get_inventory()
    86     97   		local paper = i:get_stack('paper',1)
    87     98   		local item = i:get_stack('item',1)
    88     99   
    89    100   		if list == 'output' then
    90    101   			local count = stack:get_count()
    91         -			local leftover = sorcery.data.infusion_leftovers[item:get_name()]
          102  +			local leftover = sorcery.register.residue.db[item:get_name()]
    92    103   			local lstack if leftover then
    93    104   				lstack = ItemStack(leftover)
    94    105   				lstack:set_count(lstack:get_count() * count)
    95    106   				-- this slightly idiosyncratic code is used to ensure that
    96         -				-- itemstrings can be used in the infusion leftovers table
          107  +				-- itemstrings can be used in the residue table
    97    108   			end
    98    109   			item:take_item(count)
    99    110   			if item:get_count() > 0 then
   100    111   				if leftover then
   101    112   					lstack = user:get_inventory():add_item(lstack)
   102    113   					if lstack:get_count() > 0 then minetest.add_item(pos,lstack) end
   103    114   				end
................................................................................
   105    116   			else
   106    117   				if leftover then
   107    118   					i:set_stack('item',1,lstack)
   108    119   				else
   109    120   					i:set_stack('item',1,ItemStack())
   110    121   				end
   111    122   			end
   112         -			for j=1,i:get_size('ink') do
   113         -				local ink = i:get_stack('ink',j)
   114         -				ink:take_item(count)
   115         -				i:set_stack('ink',j,ink)
   116         -			end
          123  +			local ink = i:get_stack('ink',1)
          124  +			local paper = i:get_stack('paper',1)
          125  +			ink:take_item(count)		paper:take_item(count)
          126  +			i:set_stack('ink',1,ink)	i:set_stack('paper',1,paper)
          127  +			local penstack = i:get_stack('pen',1)
          128  +			local pen = penstack:get_definition()._sorcery
          129  +			local uses = pen.material.data.durability * 0.10
          130  +			local dmg = 65535 / math.random(math.floor(uses*0.5),uses)
          131  +			print('adding damage',dmg,penstack:get_wear())
          132  +			penstack:add_wear(dmg)
          133  +			print('wear now',penstack:get_wear())
          134  +			i:set_stack('pen',1,penstack)
   117    135   		end
   118    136   
   119    137   		update_disassembler(pos)
   120    138   	end;
   121    139   	allow_metadata_inventory_put = function(pos,list,idx,stack,user)
   122    140   		local name = stack:get_name()
   123    141   		if list == 'paper' then
   124    142   			if name == 'default:paper' then return stack:get_count() end
   125    143   		elseif list == 'ink' then
   126         -			if minetest.get_item_group(name,'dye') > 0 then return stack:get_count() end
          144  +			if minetest.get_item_group(name,'ink') > 0 then return stack:get_count() end
          145  +		elseif list == 'pen' then
          146  +			if minetest.get_item_group(name,'sorcery_pen') > 0 then return stack:get_count() end
   127    147   		elseif list == 'item' then
   128    148   			return stack:get_count()
   129    149   		elseif list == 'output' then
   130    150   			return 0
   131    151   		end
   132    152   		return 0
   133    153   	end;