sorcery  enchants.lua at [77b901d950]

File data/enchants.lua artifact 7139655c44 part of check-in 77b901d950


-- 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';
}
local striketools = {
	'sword'; 'pick'; 'pickaxe'; 'sickle';
	'shovel'; 'axe'; 'sickle'; 'scythe';
	'hammer';
}
local farmtools = {
	'scythe', 'sickle', 'hoe', 'shovel';
}
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};
			{item = 'default:obsidian_shard'};
			{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
	glimmer = { -- created prolonged light on digging
		name = 'Glimmer';
		groups = digtools;
		affinity = 'cognic';
		cost = 1;
		tone = {255,235,195};
		desc = 'Leave a trail of light hanging in the air as you dig';
		recipe = {
			{lens = 'convex',    gem = 'sapphire', dmg = 2};
			{item = 'sorcery:gem_luxite_shard'};
			{lens = 'concave',   gem = 'sapphire', dmg = 1};
		};
		on_dig = function(ctx)
			local chance = 10 -- make dependent on power somehow?
			if math.random(chance) == 1 then
				local lightlevel = math.floor(math.min(minetest.LIGHT_MAX,4*ctx.power))
				-- spawn a light block
				minetest.set_node(ctx.pos, {
					name = 'sorcery:air_glimmer_' .. tostring(lightlevel);
				})
				local lm = minetest.get_meta(ctx.pos)
				lm:set_float('duration',45)
				lm:set_float('timeleft',45)
				lm:set_int('power',lightlevel)
			end
		end;
	};
	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};
			{item = 'sorcery:powder_tungsten'};
			{item = 'sorcery:extract_rye'};
		};
		desc = 'some damage is repaired when used to mine ore or kill an attacker';
		info = {
			note = 'Consumes <b>3</b> thaum-seconds of charge when repair takes place';
		};
		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 sorcery.itemclass.get(ctx.node.name,'ore') 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 = {
			{item = 'default:mese_crystal_fragment'};
			{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 = {
			{item = 'sorcery:gem_luxite'};
			{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 = { 
		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 = {
			{item = 'sorcery:oil_luck'};
			{lens = 'amplifier', gem = 'diamond',  dmg = 12};
			{lens = 'rectifier', gem = 'sapphire', dmg = 9};
		};
	};
	pierce = { -- faster mining speed
		name = 'Pierce';
		cost = 3;
		tone = {113,240,251};
		groups = digtools;
		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};
			{item = 'default:flint'};
		};
		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 = 'amplifier', gem = 'emerald', dmg = 7};
			{item = 'flowers:flower_rose'};
			{item = 'sorcery:powder_silver'};
		};
		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
			if caps.damage_groups and caps.damage_groups.fleshy then
				caps.damage_groups.fleshy = caps.damage_groups.fleshy + power * 5;
			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
	-- shadowcloak = {}; -- make player briefly invisible after blows are struck, reappearing only momentarily after each blow
	sanctify = {
		desc = 'prolong the blessings of the heavens';
		groups = {'sorcery_sanctify'};
		affinity = 'entropic';
		tone = {255,255,255};
		cost = 7;
		recipe = {
			{item = 'sorcery:holy_water'};
			{lens = 'amplifier', gem = 'ruby', dmg = 15};
			{lens = 'amplifier', gem = 'ruby', dmg = 18};
		};
	};
	bounty = { -- produce more crops when used to harvest
		groups = farmtools;
		cost = 8;
		affinity = 'entropic';
		desc = 'ensure a rich and bountiful harvest when next you take to the fields';
	};
	impel = { -- increase knockback
		groups = striketools;
		cost = 13;
		affinity = 'praxic';
		desc = 'cast your enemies aside with fearsome force, and leave their flailing mortal form to the tender mercy of blunt force impact';
	};
	bulwark = { -- increase armor dramatically
		groups = armor;
		affinity = 'counterpraxic';
		cost = 4;
		desc = 'shrug off the most ruthless of blows and endure impacts that should rend flesh and steel alike';
	};
	anchor = { -- resist knockback
		groups = armor;
		affinity = 'counterpraxic';
		cost = 0; -- scales with knockback
		desc = 'stand strong and hold your ground upon the field of battle, no matter how mighty the forces arrayed against you';
	};
}