sorcery  enchants.lua at [93f944b581]

File data/enchants.lua artifact 2bce1083af part of check-in 93f944b581


-- an optional 'enchant' function can be defined, and will
-- be called when the enchantment is placed on the object
local allgroups = {
	'sword'; 'pick'; 'pickaxe';
	'sickle'; 'axe'; 'scythe';
	'shovel'; 'hoe'; 'helmet';
	'leggings'; 'chestplate'; 'boots';
} 
local digtools = {
	'pick'; 'pickaxe'; 'sickle';
	'shovel'; 'axe';
}
return {
	endure = { -- withstand more blows
		name = 'Endure';
		cost = 1;
		tone = {232,102,255};
		desc = 'tools last longer before wearing out';
		affinity = 'counterpraxic';
		groups = allgroups;
		recipe = {
			{lens = 'convex',    gem = 'amethyst', dmg = 2};
			{lens = 'rectifier', gem = 'emerald',  dmg = 4};
			{lens = 'convex',    gem = 'emerald',  dmg = 2};
		};
		apply = function(stack,power,base)
			local caps = table.copy(stack:get_definition().tool_capabilities)
			for g,v in pairs(caps.groupcaps) do
				local unit = base.groupcaps[g].uses * 0.6
				caps.groupcaps[g].uses = v.uses + unit*power
			end
			stack:get_meta():set_tool_capabilities(caps)
			return stack
		end;
	};
	drain = {
		groups = {'sword'};
		cost = 4;
	}; -- health vampirism
	glitter = { -- created prolonged light on digging
		name = 'Glitter';
		groups = digtools;
		affinity = 'cognic';
		cost = 1;
		tone = {255,235,195};
		desc = 'Leave a trail of light hanging in the air as you dig';
	};
	harvest = { -- kills or digging ore replenish durability
		name = 'Harvest';
		cost = 0; -- energy is only depleted when repair takes place
		tone = {255,84,187};
		affinity = 'syncretic';
		groups = {
			'pick'; 'pickaxe'; 'sword';
		};
		recipe = {
			{lens = 'amplifier', gem = 'ruby',     dmg = 5};
			{lens = 'concave',   gem = 'mese',     dmg = 1};
			{lens = 'concave',   gem = 'sapphire', dmg = 1};
		};
		desc = 'some damage is repaired when used to mine ore or kill an attacker';
		on_dig = function(ctx)
			local orepfx = "stone_with_" -- }:<
			-- local oredrop = ' lump'
			local barename = string.sub(ctx.node.name, string.find(ctx.node.name, ':') + 1)
			if minetest.get_item_group(ctx.node.name, 'ore') ~= 0 or
			   string.sub(barename,1,string.len(orepfx)) == orepfx 
			then
				ctx.tool:add_wear(-(sorcery.enchant.strength(ctx.tool,'harvest') * 2000))
				ctx.cost = 3
			end
		end;
	};
	conserve = { -- use less magical energy
		name = 'Conserve';
		tone = {84,255,144};
		cost = 0;
		desc = 'enchantments last longer before running out of power to sustain them';
		groups = allgroups;
		affinity = 'syncretic';
		recipe = {
			{lens = 'rectifier', gem = 'mese',     dmg = 7};
			{lens = 'rectifier', gem = 'sapphire', dmg = 2};
			{lens = 'rectifier', gem = 'amethyst', dmg = 2};
		};
		-- implemented in sorcery/enchanter.lua:register_on_dig
	};
	dowse = { -- send up flare when valuable ores are nearby
		name = 'Dowse';
		tone = {241,251,113};
		cost = 1;
		desc = 'strike colored sparks when used to dig near valuable ore.';
		groups = {'pick','pickaxe'};
		affinity = 'cognic';
		recipe = {
			{lens = 'concave', gem = 'ruby',     dmg = 3};
			{lens = 'concave', gem = 'emerald',  dmg = 3};
			{lens = 'concave', gem = 'sapphire', dmg = 3};
		};
		on_dig = function(ctx)
			local range = 4*sorcery.enchant.strength(ctx.tool,'dowse')
			local colors = {
				['default:stone_with_gold'    ] = {255,234,182};
				['default:stone_with_mese'    ] = {231,255,151};
				['default:stone_with_diamond' ] = {180,253,255};
				['sorcery:stone_with_iridium' ] = {243,180,255};
				['sorcery:stone_with_tungsten'] = {119,234,196};
			}
			local search = {} for k in pairs(colors)
				do search[#search+1] = k end
			local nodes = minetest.find_nodes_in_area(
				vector.subtract(ctx.pos,range),
				vector.add(ctx.pos,range), search)
			for _,n in pairs(nodes) do
				-- we're going to use some ugly math tricks
				-- to avoid having to do a square root, since
				-- that's an expensive operation and we don't
				-- need that level of precision; we can
				-- approximate the distance without it
				local delta = vector.subtract(n,ctx.pos)
				local dstsq = (delta.x^2) + (delta.y^2) + (delta.z^2)
				if dstsq < range^2 then
					local dstfac = 1 - (dstsq / range^2)
					ctx.sparks[#ctx.sparks+1] = {
						color = sorcery.lib.color(colors[minetest.get_node(n).name]);
						count = 100 * dstfac;
					}
				end
			end
		end;
	};
	glitter = { -- increase odds of finding gem
		name = 'Glitter';
		cost = 10;
		tone = {255,50,60};
		desc = 'dramatically improve your chances of finding gems while mining veins';
		groups = {'pick','pickaxe'};
		affinity = 'entropic';
		recipe = {
			{lens = 'amplifier', gem = 'diamond',  dmg = 12};
			{lens = 'rectifier', gem = 'sapphire', dmg = 9};
			{lens = 'convex',    gem = 'ruby',     dmg = 7};
		};
	};
	pierce = { -- faster mining speed
		name = 'Pierce';
		cost = 3;
		tone = {113,240,251};
		groups = digtools;
		{
			'pick';'pickaxe';'axe';'shovel';'sickle';
		};
		desc = 'rip through solid stone or wood like a hot knife through butter';
		recipe = {
			{lens = 'amplifier', gem = 'diamond',  dmg = 4};
			{lens = 'amplifier', gem = 'ruby',     dmg = 4};
			{lens = 'rectifier', gem = 'diamond',  dmg = 2};
		};
		affinity = 'praxic';
		apply = function(stack,power,base)
			local caps = table.copy(stack:get_definition().tool_capabilities)
			for g,v in pairs(caps.groupcaps) do
				for i,t in pairs(v.times) do
					local unit = base.groupcaps[g].times[i] * 0.15
					caps.groupcaps[g].times[i] = math.max(0.01, t - unit*power)
				end
			end
			stack:get_meta():set_tool_capabilities(caps)
			return stack
		end;
	};
	rend = { -- more damage / mine higher level blocks
		name = 'Rend';
		affinity = 'praxic';
		tone = {251,203,113};
		groups = {'sword';'pick';'pickaxe';};
		recipe = {
			{lens = 'convex',    gem = 'mese',    dmg = 3};
			{lens = 'amplifier', gem = 'emerald', dmg = 7};
			{lens = 'amplifier', gem = 'diamond', dmg = 7};
		};
		cost = 5;
		desc = 'cleave through sturdy ores and tear mortal flesh with fearsome ease';
		apply = function(stack,power,base)
			local caps = table.copy(stack:get_definition().tool_capabilities)
			for g,v in pairs(caps.groupcaps) do
				local unit = 2
				caps.groupcaps[g].maxlevel = caps[g].maxlevel + math.floor(unit*power)
			end
			stack:get_meta():set_tool_capabilities(caps)
			return stack
		end;
	};
	-- multiply = {}; --  add a chance of receiving multiple drops of ore/coal
	-- leech = {}; -- draw power from local leylines
}