@@ -1,8 +1,8 @@ local altar_item_offset = { x = 0, y = -0.3, z = 0 } -local log = function(...) sorcery.log('altar',...) end +local log = sorcery.logger('altar') local range = function(min, max) local span = max - min local val = math.random() * span @@ -76,9 +76,9 @@ local stackmeta = stack:get_meta() meta:set_int('favor', stackmeta:get_int('favor')) meta:set_string('last_sacrifice', stackmeta:get_string('last_sacrifice')) - minetest.get_node_timer(pos):start(60) + minetest.get_node_timer(pos):start(1) end; drop = { -- for some idiot reason this is necessary for @@ -170,9 +170,9 @@ local data = god.gifts[gift] local value, rarity = data[1], data[2] if value <= divine_favor and math.random(rarity) == 1 then bestow(gift) - log(god.name .. ' has produced ' .. gift .. ' upon an altar as a gift') + log.act(god.name .. ' has produced ' .. gift .. ' upon an altar as a gift') if math.random(god.generosity) == 1 then -- unappreciated gifts may incur divine -- irritation divine_favor = divine_favor - 1 @@ -218,35 +218,54 @@ -- loop through the list of things this god will consecrate and -- check whether the item on the altar is any of them for s, cons in pairs(god.consecrate) do - local cost, tx = cons[1], cons[2] - if type(tx) == "table" then - tx = tx[math.random(#tx)] - end - -- preserve wear - local gift = ItemStack(tx) - local wear = stack:get_wear() - if wear > 0 then - gift:set_wear(wear) - end - -- preserve meta - gift:get_meta():from_table(stack:get_meta():to_table()) - -- reflash enchantments to ensure label is accurate - local ench = sorcery.enchant.get(gift) - if #ench.spells > 0 then - -- add a bit of energy as a gift? - if math.random(math.ceil(god.stinginess * 0.5)) == 1 then - local max = 0.05 * god.generosity - ench.energy = ench.energy * range(0.7*max,max) + if itemname == s then + local cost, tx + if type(cons) == "table" then + cost, tx = cons[1], cons[2] + tx = tx[math.random(#tx)] + elseif type(cons) == 'function' then + cost, tx = cons { + favor = divine_favor; + pos = pos; + altar = altarmeta; + idol = idolmeta; + god = god; + } + end + -- preserve wear + local gift + if type(tx) == 'string' then + gift = ItemStack(tx) + else gift = tx end + local wear = stack:get_wear() + if wear > 0 then + gift:set_wear(wear) + end + -- preserve meta + local gm = gift:get_meta() + gm:from_table( + sorcery.lib.tbl.merge( + stack:get_meta():to_table(), + gm:to_table() + ) + ) -- oof + -- reflash enchantments to ensure label is accurate + local ench = sorcery.enchant.get(gift) + if #ench.spells > 0 then + -- add a bit of energy as a gift? + if math.random(math.ceil(god.stinginess * 0.5)) == 1 then + local max = 0.05 * god.generosity + ench.energy = ench.energy * range(0.7*max,max) + end + sorcery.enchant.set(gift,ench) end - sorcery.enchant.set(gift,ench) - end - if itemname == s then + if divine_favor >= cost then bestow(gift) divine_favor = divine_favor - cost - print(god.name..'has consecrated ' ..s.. ' into ' ..tx.. ', for the cost of ' ..cost.. ' points of divine favor') + log.act(god.name, 'has consecrated', s, 'into', tx, 'for the cost of', cost, 'points of divine favor') goto refresh end end end