sorcery  Diff

Differences From Artifact [7e265da854]:

To Artifact [235fbb7fc6]:


     1      1   local altar_item_offset = {
     2      2   	x = 0, y = -0.3, z = 0
     3      3   }
     4      4   local log = sorcery.logger('altar')
            5  +local L = sorcery.lib
     5      6   
     6      7   local range = function(min, max)
     7      8   	local span = max - min
     8      9   	local val = math.random() * span
     9     10   	return val + min
    10     11   end
    11     12   
................................................................................
    58     59   		for g in pairs(god.gifts) do
    59     60   			-- can't mutate table while we're iterating it
    60     61   			if not minetest.registered_nodes[g] then bad[#bad+1] = g end
    61     62   		end
    62     63   		for _, g in ipairs(bad) do god.gifts[g] = nil end
    63     64   	end
    64     65   end)
           66  +
           67  +local god_interval = 1
    65     68   
    66     69   for name, god in pairs(sorcery.data.gods) do
    67     70   	local hitbox = {
    68     71   		0-(god.idol.width / 2.0), 0-(god.idol.height / 2.0), -0.15,
    69     72   		   god.idol.width / 2.0,     god.idol.height / 2.0,   0.15
    70     73   	} -- {xmin, ymin, zmin,
    71     74   	  -- xmax, ymax, zmax} in nodes from node center.
    72     75   	paramtype = "light";
           76  +	if god.idol.craft then
           77  +		minetest.register_craft {
           78  +			output = 'sorcery:idol_' .. name;
           79  +			recipe = god.idol.craft;
           80  +		};
           81  +	end
    73     82   	sorcery.lib.node.reg_autopreserve('sorcery:idol_' .. name, {
    74     83   		description = god.idol.desc;
    75     84   		drawtype = "mesh";
    76     85   		mesh = 'sorcery-idol-' .. name .. '.obj';
    77     86   		paramtype = 'light';
    78     87   		paramtype2 = 'facedir';
    79     88   		sunlight_propagates = true;
................................................................................
    80     89   		stack_max = 1;
    81     90   		tiles = god.idol.tex;
    82     91   		selection_box = { type = "fixed"; fixed = {hitbox}; };
    83     92   		collision_box = { type = "fixed"; fixed = {hitbox}; };
    84     93   		groups = { cracky = 2, sorcery_idol = 1, heavy = 1, sorcery_worship = 1};
    85     94   
    86     95   		on_construct = function(pos)
    87         -			minetest.get_node_timer(pos):start(1)
           96  +			minetest.get_node_timer(pos):start(god_interval)
    88     97   		end;
    89     98   
    90     99   		on_timer = function(pos, elapsed)
    91    100   			local altar = minetest.find_node_near(pos, 3, "sorcery:altar")
    92    101   			-- TODO even without an altar, an idol with high favor could still be the source of miracles
    93    102   			-- refills nearby partly empty troughs at cost to favor?
    94    103   			if not altar then return true end
    95    104   
    96    105   			local altarmeta = minetest.get_meta(altar)
    97    106   			local inv = altarmeta:get_inventory()
    98    107   			local idolmeta = minetest.get_meta(pos)
    99    108   			local divine_favor = idolmeta:get_int('favor')
          109  +			if divine_favor > 5 then
          110  +				local ct = divine_favor / 5
          111  +				minetest.add_particlespawner {
          112  +					texture = L.image('sorcery_glitter.png'):glow(L.color(god.color)):render();
          113  +					glow = 14;
          114  +					amount = ct / (1 / god_interval), time = god_interval;
          115  +					minpos = pos:offset(-0.4, -0.5, -0.4);
          116  +					maxpos = pos:offset( 0.4,god.idol.height-0.5,0.4);
          117  +					minvel = vector.new(0, 0.05, 0);
          118  +					minvel = vector.new(0, 0.1, 0);
          119  +					minacc = vector.new(0, 0.1, 0);
          120  +					maxacc = vector.new(0, 0.2, 0);
          121  +					minexptime = 4, maxexptime = 4;
          122  +					minsize = 0.3, maxsize = 1;
          123  +					animation = {
          124  +						type = 'vertical_frames';
          125  +						length = 0.1;
          126  +						aspect_w = 16, aspect_h = 16;
          127  +					}
          128  +				}
          129  +			end
   100    130   			local bestow = function(item,color)
   101    131   				if type(item) == 'string' then
   102    132   					item = ItemStack(item)
   103    133   				end
   104    134   				if color == nil then
   105    135   					color = sorcery.lib.color(god.color)
   106    136   				end
................................................................................
   153    183   					}
   154    184   				end
   155    185   				inv:set_stack('item',1,item)
   156    186   			end
   157    187   			if inv:is_empty('item') then 
   158    188   				-- nothing on the altar. decide if we're going to do a
   159    189   				-- gift cycle by rolling against the god's stinginess
   160         -				if math.random(god.stinginess) == 1 then
          190  +				if god.gifts and next(god.gifts) and math.random(god.stinginess) == 1 then
   161    191   					-- we've beat the odds and started a gift cycle. now
   162    192   					-- we pick a random gift and roll against its rarity
   163    193   					-- to determine if the god is feeling generous
   164    194   					local gift = sorcery.lib.tbl.pick(god.gifts)
   165    195   					local data = god.gifts[gift]
   166    196   					local value, rarity = data[1], data[2]
   167    197   					if value <= divine_favor and math.random(rarity) == 1 then