sorcery  Diff

Differences From Artifact [6c72918b5d]:

To Artifact [ed6c69759e]:

  • File potions.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: 7460) [annotate] [blame] [check-ins using]

     1      1   local u = sorcery.lib
     2         -sorcery.data.infusions = {} -- not sure where to put this tbh
     3         -sorcery.data.infusion_leftovers = {}
            2  +sorcery.registry.mk('infusions',false)
            3  +sorcery.registry.mk('residue',false)
     4      4   
     5      5   sorcery.register_potion = function(name,label,desc,color,imgvariant,glow,extra)
     6      6   	local image = 'sorcery_liquid_'..(imgvariant or 'dull')..'.png' .. 
     7      7   		'^[multiply:'..tostring(color)..
     8      8   		'^vessels_glass_bottle.png'
     9      9   
    10         -	sorcery.data.register.infusion_leftover('sorcery:' .. name, 'vessels:glass_bottle')
           10  +	sorcery.register.residue.link('sorcery:' .. name, 'vessels:glass_bottle')
    11     11   	local node = {
    12     12   		description = color:darken(0.8):bg(
    13     13   			sorcery.lib.ui.tooltip {
    14     14   				title = label;
    15     15   				desc = desc;
    16     16   				color = color:readable();
    17     17   			}
................................................................................
    44     44   	node.groups.vessel = 1;
    45     45   	node.groups.not_in_creative_inventory = 1;
    46     46   	minetest.register_node("sorcery:"..name, node)
    47     47   end
    48     48   
    49     49   sorcery.register_oil = function(name,label,desc,color,imgvariant,extra)
    50     50   	local image = 'xdecor_bowl.png^(sorcery_oil_' .. (imgvariant or 'dull') .. '.png^[colorize:'..tostring(color)..':140)'
    51         -	sorcery.data.register.infusion_leftover('sorcery:' .. name, 'xdecor:bowl')
           51  +	sorcery.register.residue.link('sorcery:' .. name, 'xdecor:bowl')
    52     52   	extra.description = label;
    53     53   	extra.inventory_image = image;
    54     54   	if not extra.groups then extra.groups = {} end
    55     55   	minetest.register_craftitem('sorcery:' .. name, extra)
    56     56   end
    57     57   
    58     58   sorcery.register_potion('blood', 'Blood', 'A bottle of sacrificial blood, imbued\nwith stolen life force', u.color(219,19,14))
    59     59   sorcery.register_potion('potion_water', 'Water Bottle', 'A bottle of plain water', u.color(43,90,162))
    60     60   sorcery.register_potion('holy_water', 'Holy Water','A bottle of consecrated water',u.color(94,138,206),'sparkle',6)
    61     61   
    62     62   local create_infusion_recipe = function(id,potion,default_basis,proto)
    63     63   	if potion.infusion then
    64         -		sorcery.data.register.infusion {
           64  +		sorcery.register.infusions.link {
    65     65   			infuse = potion.infusion;
    66     66   			into = potion.basis or default_basis;
    67     67   			output = 'sorcery:' .. id;
    68     68   			_proto = proto;
    69     69   		}
    70     70   	end
    71     71   end
    72     72   
    73         -for n,v in pairs(sorcery.data.potions) do
           73  +-- for n,v in pairs(sorcery.data.potions) do
           74  +sorcery.register.potions.foreach('sorcery:mknodes',{},function(n,v)
    74     75   	local color = u.color(v.color)
    75     76   	local kind = v.style
    76     77   	local glow = v.glow
    77     78   	local id = 'potion_' .. string.lower(n)
    78     79   	local desc = 'A ' .. ((glow and 'glowing ') or '') ..
    79     80   		'bottle of ' .. string.lower(n) .. 
    80     81   		((kind == 'sparkle' and ', fiercely bubbling') or '') ..
................................................................................
    84     85   		_proto = v;
    85     86   		groups = {
    86     87   			sorcery_potion = 1;
    87     88   			sorcery_magical = 1;
    88     89   		};
    89     90   	})
    90     91   	create_infusion_recipe(id,v,'sorcery:potion_serene',{data=v,name=fullname})
    91         -end
           92  +end)
    92     93   
    93         -for n,potion in pairs(sorcery.data.draughts) do
           94  +-- for n,potion in pairs(sorcery.data.draughts) do
           95  +sorcery.register.draughts.foreach('sorcery:mknodes',{},function(n,potion)
    94     96   	local name = 'draught_' .. n
    95     97   	local behavior = {
    96     98   		_proto = potion;
    97     99   		groups = {
    98    100   			sorcery_potion = 2;
    99    101   			sorcery_draught = 1;
   100    102   			sorcery_magical = 1;
................................................................................
   101    103   			sorcery_usable_magic = 1;
   102    104   		};
   103    105   		on_use = function(stack, user, pointat)
   104    106   			local pproto = stack:get_definition()._proto
   105    107   			if potion.effect(stack, user, pproto) == false then return nil end
   106    108   			local meta = stack:get_meta()
   107    109   			local force = meta:get_int('force');
          110  +			local duration = pproto:duration(meta);
   108    111   			minetest.add_particlespawner {
   109         -				amount = 200 + (30 * force);
   110         -				time = pproto:duration(meta);
          112  +				amount = (7 + (10 * force)) * duration;
          113  +				time = duration;
   111    114   				minpos = { x = -0.1; y = 0; z = -0.1; };
   112    115   				maxpos = { x = 0.1; y = 2; z = 0.1; };
   113    116   				minvel = { x = -0.1; y = 0; z = -0.1; };
   114    117   				maxvel = { x = 0.1; y = 0; z = 0.1; };
   115    118   				minacc = { x = 0; y = 0.1; z = 0; };
   116    119   				maxacc = { x = 0; y = 1; z = 0; };
   117    120   				minexptime = 1;
................................................................................
   141    144   	sorcery.register_potion(name, fullname,
   142    145   		potion.desc,
   143    146   		u.color(potion.color),
   144    147   		potion.style or 'dull',
   145    148   		potion.glow or 0,
   146    149   		behavior)
   147    150   	create_infusion_recipe(name,potion,'sorcery:potion_luminous',{data=potion,name=fullname})
   148         -end
          151  +end)
   149    152   
   150         -for n,elixir in pairs(sorcery.data.elixirs) do
          153  +-- for n,elixir in pairs(sorcery.data.elixirs) do
          154  +sorcery.register.elixirs.foreach('sorcery:mknodes',{},function(n,elixir)
   151    155   	local color = u.color(elixir.color)
   152    156   	local id = 'elixir_' .. string.lower(n)
   153    157   	local fullname = 'Elixir of ' .. n
   154    158   	sorcery.register_potion(id, fullname, nil, color, 'dull', false, {
   155    159   		_proto = elixir;
   156    160   		groups = {
   157    161   			sorcery_elixir = 1;
   158    162   			sorcery_magical = 1;
   159    163   		};
   160    164   	})
   161    165   	create_infusion_recipe(id,elixir,'sorcery:potion_misty',{data=elixir,name=fullname})
   162         -end
          166  +end)
   163    167   
   164         -for n,v in pairs(sorcery.data.oils) do
          168  +-- for n,v in pairs(sorcery.data.oils) do
          169  +sorcery.register.oils.foreach('sorcery:mknodes',{},function(n,v)
   165    170   	local color = u.color(v.color)
   166    171   	local kind = v.style
   167    172   	local id = 'oil_' .. n
   168    173   	n = v.name or u.str.capitalize(n)
   169    174   	sorcery.register_oil(id, n .. ' Oil', nil, color, kind, {
   170    175   		groups = { sorcery_oil = 1 };
   171    176   	})
   172         -end
          177  +end)
   173    178   
   174         -for n,v in pairs(sorcery.data.greases) do
          179  +-- for n,v in pairs(sorcery.data.greases) do
          180  +sorcery.register.greases.foreach('sorcery:mknodes',{},function(n,v)
   175    181   	local color = u.color(v.color)
   176    182   	local kind = v.style
   177    183   	sorcery.register_oil('grease_' .. n, u.str.capitalize(n) .. ' Grease', nil, color, kind, {
   178    184   		groups = { sorcery_grease = 1 }
   179    185   	})
   180         -end
          186  +end)
   181    187   
   182         -for n,v in pairs(sorcery.data.philters) do
          188  +-- for n,v in pairs(sorcery.data.philters) do
          189  +sorcery.register.philters.foreach('sorcery:mknodes',{},function(n,v)
   183    190   	local color = u.color(v.color)
   184    191   	local id = 'philter_' .. n
   185    192   	local name = v.name or u.str.capitalize(n)
   186    193   	local fullname = name .. ' Philter'
   187    194   	sorcery.register_potion(id, fullname, v.desc, color, 'sparkle',v.glow or 4, {
   188    195   		_proto = v;
   189    196   		_protoname = n;
   190    197   		groups = {
   191    198   			sorcery_magical = 1;
   192    199   			sorcery_philter = 1;
   193    200   		};
   194    201   	})
   195    202   	create_infusion_recipe(id,v,'sorcery:potion_viscous',{data=v,name=fullname})
   196         -end
          203  +end)
   197    204   
   198         -for n,v in pairs(sorcery.data.extracts) do
          205  +-- for n,v in pairs(sorcery.data.extracts) do
          206  +sorcery.register.extracts.foreach('sorcery:mknodes',{},function(n,v)
   199    207   	local item = v[1]
   200    208   	local color = u.color(v[2])
   201    209   	local name = 'extract_' .. n
   202    210   	sorcery.register_potion(name, u.str.capitalize(n) .. ' Extract', nil, color, 'sparkle', false, {
   203    211   		groups = {
   204         -			sorcery_extracts = 1;
          212  +			sorcery_extract = 1;
   205    213   		};
   206    214   	})
   207    215   
   208    216   	local add_alcohol = function(booze)
   209    217   		minetest.register_craft {
   210    218   			type = "shapeless";
   211    219   			recipe = {
................................................................................
   220    228   			};
   221    229   		}
   222    230   	end
   223    231   	-- need a relatively pure alcohol for this, tho other alcohols can be used
   224    232   	-- for potionmaking in other ways
   225    233   	add_alcohol('farming:bottle_ethanol')
   226    234   	add_alcohol('wine:glass_vodka')
   227         -end
          235  +end)