@@ -47,11 +47,51 @@ local ley = sorcery.ley.estimate(pos) minetest.chat_send_player(caller, 'Leyline force ' .. tostring(ley.force) .. ' with affinities ' .. table.concat(ley.aff, ',')) end; }) + +sorcery.ley.chargetype = function(stack) + if minetest.get_item_group(stack:get_name(),'sorcery_wand') ~= 0 then + return 'wear' + else + local e = sorcery.enchant.get(stack) + if e and #e.spells > 0 then + return 'enchant' + end + end + return false +end + +sorcery.ley.getcharge = function(stack) + local chargetype = sorcery.ley.chargetype(stack) + if not chargetype then return false end + if chargetype == 'wear' then + return (65535 - stack:get_wear()) / 15, 65535 / 15 + elseif chargetype == 'enchant' then + local e = sorcery.enchant.get(stack) + local mat = sorcery.itemclass.get(stack:get_name(), 'material') + return e.energy, mat.data.maxenergy + end +end + +sorcery.ley.setcharge = function(stack, charge, overcharge) + local max = select(2, sorcery.ley.getcharge(stack)) + if not max then return false end + if charge > max and not overcharge then charge = max end + + local chargetype = sorcery.ley.chargetype(stack) + if chargetype == 'wear' then + stack:set_wear(65535 - charge * 15) + elseif chargetype == 'enchant' then + local e = sorcery.enchant.get(stack) + e.energy = charge + sorcery.enchant.set(stack,e) + end + return stack +end -- leyline energy can be transmitted via a conduit from a leysink. however, it cannot be stored like aetheric energy can be; leyline energy must be drawn when needed unless it is bound up in an enchantment (which simply delays its expression). leysinks provide a constant source of ley-force. --- there are two nodes for transmitting leyline energy, wires and conduits. wires transmit a limited amount of energy, but are cheap and small. conduits transmit much more, but are expensive and take up full blocks. both are composed of electrum, the carrier, and copper, which prevents the ley-force from leaking out as dangerous radiance. +-- there are two nodes for transmitting leyline energy, wires and conduits. wires transmit a limited amount of energy, but are cheap and small. conduits transmit much more, but are expensive and take up full blocks. both are composed of a carrier metal and copper, which prevents the ley-force from leaking out as dangerous radiance. minetest.register_node('sorcery:conduit', { description = 'Conduit'; tiles = { @@ -278,9 +318,9 @@ local ley_factor = 0.25 -- a ley harvester will produce this much current with -- access to a full-strength leyline - return strength * ley_factor * time; + return (strength * ley_factor) * time; end do -- register condenser local gem = sorcery.lib.image('default_diamond_block.png') @@ -542,11 +582,11 @@ condset('minpower',min) condset('maxpower',max) end else -- power usage is simply a constant - condset('power',p) - condset('minpower',p) - condset('maxpower',p) + condset('power',p * timespan) + condset('minpower',p * timespan) + condset('maxpower',p * timespan) end else local feval = function(v) if type(v) == 'function' then