sorcery  Diff

Differences From Artifact [a7a1197203]:

To Artifact [080406f8d2]:


     1      1   local altar_item_offset = {
     2      2   	x = 0, y = -0.3, z = 0
     3      3   }
     4         -local log = function(...) sorcery.log('altar',...) end
            4  +local log = sorcery.logger('altar')
     5      5   
     6      6   local range = function(min, max)
     7      7   	local span = max - min
     8      8   	local val = math.random() * span
     9      9   	return val + min
    10     10   end
    11     11   
................................................................................
    73     73   
    74     74   		after_place_node = function(pos, placer, stack, pointat)
    75     75   			local meta = minetest.get_meta(pos)
    76     76   			local stackmeta = stack:get_meta()
    77     77   			meta:set_int('favor', stackmeta:get_int('favor'))
    78     78   			meta:set_string('last_sacrifice', stackmeta:get_string('last_sacrifice'))
    79     79   
    80         -			minetest.get_node_timer(pos):start(60)
           80  +			minetest.get_node_timer(pos):start(1)
    81     81   		end;
    82     82   
    83     83   		drop = {
    84     84   			-- for some idiot reason this is necessary for
    85     85   			-- preserve_metadata to work right
    86     86   			max_items = 1;
    87     87   			items = {
................................................................................
   167    167   					-- we pick a random gift and roll against its rarity
   168    168   					-- to determine if the god is feeling generous
   169    169   					local gift = sorcery.lib.tbl.pick(god.gifts)
   170    170   					local data = god.gifts[gift]
   171    171   					local value, rarity = data[1], data[2]
   172    172   					if value <= divine_favor and math.random(rarity) == 1 then
   173    173   						bestow(gift)
   174         -						log(god.name .. ' has produced ' .. gift .. ' upon an altar as a gift')
          174  +						log.act(god.name .. ' has produced ' .. gift .. ' upon an altar as a gift')
   175    175   						if math.random(god.generosity) == 1 then
   176    176   							-- unappreciated gifts may incur divine
   177    177   							-- irritation
   178    178   							divine_favor = divine_favor - 1
   179    179   						end
   180    180   					end
   181    181   				end
................................................................................
   215    215   						goto refresh
   216    216   					end
   217    217   				end
   218    218   
   219    219   				-- loop through the list of things this god will consecrate and
   220    220   				-- check whether the item on the altar is any of them
   221    221   				for s, cons in pairs(god.consecrate) do
   222         -					local cost, tx = cons[1], cons[2]
   223         -					if type(tx) == "table" then
   224         -						tx = tx[math.random(#tx)]
   225         -					end
   226         -					-- preserve wear
   227         -					local gift = ItemStack(tx)
   228         -					local wear = stack:get_wear()
   229         -					if wear > 0 then
   230         -						gift:set_wear(wear)
   231         -					end
   232         -					-- preserve meta
   233         -					gift:get_meta():from_table(stack:get_meta():to_table())
   234         -					-- reflash enchantments to ensure label is accurate
   235         -					local ench = sorcery.enchant.get(gift)
   236         -					if #ench.spells > 0 then
   237         -						-- add a bit of energy as a gift?
   238         -						if math.random(math.ceil(god.stinginess * 0.5)) == 1 then
   239         -							local max = 0.05 * god.generosity
   240         -							ench.energy = ench.energy * range(0.7*max,max)
          222  +					if itemname == s then
          223  +						local cost, tx
          224  +						if type(cons) == "table" then
          225  +							cost, tx = cons[1], cons[2]
          226  +							tx = tx[math.random(#tx)]
          227  +						elseif type(cons) == 'function' then
          228  +							cost, tx = cons {
          229  +								favor = divine_favor;
          230  +								pos = pos;
          231  +								altar = altarmeta;
          232  +								idol = idolmeta;
          233  +								god = god;
          234  +							}
          235  +						end
          236  +						-- preserve wear
          237  +						local gift
          238  +						if type(tx) == 'string' then
          239  +							gift = ItemStack(tx)
          240  +						else gift = tx end
          241  +						local wear = stack:get_wear()
          242  +						if wear > 0 then
          243  +							gift:set_wear(wear)
          244  +						end
          245  +						-- preserve meta
          246  +						local gm = gift:get_meta()
          247  +						gm:from_table(
          248  +							sorcery.lib.tbl.merge(
          249  +								stack:get_meta():to_table(),
          250  +								gm:to_table()
          251  +							)
          252  +						) -- oof
          253  +						-- reflash enchantments to ensure label is accurate
          254  +						local ench = sorcery.enchant.get(gift)
          255  +						if #ench.spells > 0 then
          256  +							-- add a bit of energy as a gift?
          257  +							if math.random(math.ceil(god.stinginess * 0.5)) == 1 then
          258  +								local max = 0.05 * god.generosity
          259  +								ench.energy = ench.energy * range(0.7*max,max)
          260  +							end
          261  +							sorcery.enchant.set(gift,ench)
   241    262   						end
   242         -						sorcery.enchant.set(gift,ench)
   243         -					end
   244         -					if itemname == s then
          263  +
   245    264   						if divine_favor >= cost then
   246    265   							bestow(gift)
   247    266   							divine_favor = divine_favor - cost
   248         -							print(god.name..'has consecrated ' ..s.. ' into ' ..tx.. ', for the cost of ' ..cost.. ' points of divine favor')
          267  +							log.act(god.name, 'has consecrated', s, 'into', tx, 'for the cost of', cost, 'points of divine favor')
   249    268   							goto refresh
   250    269   						end
   251    270   					end
   252    271   				end
   253    272   			end
   254    273   
   255    274   			::refresh::