sorcery  Diff

Differences From Artifact [ac299c4e97]:

To Artifact [b3a388d8b4]:


            1  +-- an optional 'enchant' function can be defined, and will
            2  +-- be called when the enchantment is placed on the object
            3  +local allgroups = {
            4  +	'sword'; 'pick'; 'pickaxe';
            5  +	'sickle'; 'scythe'; 'shovel';
            6  +	'hoe'; 'helmet'; 'leggings';
            7  +	'chestplate'; 'boots';
            8  +} 
     1      9   return {
     2     10   	endure = { -- withstand more blows
     3     11   		name = 'Endure';
           12  +		cost = 1;
     4     13   		tone = {232,102,255};
     5     14   		desc = 'durability magnified';
     6     15   		affinity = 'counterpraxic';
     7         -		apply = function(stack,power)
           16  +		groups = allgroups;
           17  +		recipe = {
           18  +			{lens = 'convex',    gem = 'amethyst', dmg = 2};
           19  +			{lens = 'rectifier', gem = 'emerald',  dmg = 4};
           20  +			{lens = 'convex',    gem = 'emerald',  dmg = 2};
           21  +		};
           22  +		apply = function(stack,power,base)
           23  +			local caps = table.copy(stack:get_definition().tool_capabilities)
           24  +			for g,v in pairs(caps.groupcaps) do
           25  +				local unit = base.groupcaps[g].uses * 0.6
           26  +				caps.groupcaps[g].uses = v.uses + unit*power
           27  +			end
           28  +			stack:get_meta():set_tool_capabilities(caps)
           29  +			return stack
     8     30   		end;
     9     31   	};
    10         -	drain = {}; -- health vampirism
           32  +	drain = {
           33  +		groups = {'sword'};
           34  +		cost = 4;
           35  +	}; -- health vampirism
    11     36   	harvest = { -- kills or digging ore replenish durability
    12     37   		name = 'Harvest';
           38  +		cost = 0; -- energy is only depleted when repair takes place
    13     39   		tone = {255,84,187};
    14     40   		affinity = 'syncretic';
           41  +		groups = {
           42  +			'pick'; 'pickaxe'; 'sword';
           43  +		};
           44  +		recipe = {
           45  +			{lens = 'amplifier', gem = 'ruby',     dmg = 5};
           46  +			{lens = 'concave',   gem = 'mese',     dmg = 1};
           47  +			{lens = 'concave',   gem = 'sapphire', dmg = 1};
           48  +		};
    15     49   		desc = 'some damage is repaired when used to mine ore or kill an attacker';
    16         -		apply = function(stack,power)
           50  +		on_dig = function(ctx)
           51  +			local orepfx = "stone_with_" -- }:<
           52  +			-- local oredrop = ' lump'
           53  +			local dug = minetest.get_node(ctx.target.under)
           54  +			local barename = string.sub(dug.name, string.find(dug.name, ':') + 1)
           55  +			print('is ore? ',dug.name,barename)
           56  +			if minetest.get_item_group(dug.name, ore) ~= 0 or
           57  +			   string.sub(barename,1,string.len(orepfx)) == orepfx 
           58  +			then
           59  +				print('is ore!')
           60  +				ctx.tool:add_wear(-(sorcery.enchant.strength(ctx.tool,'harvest') * 2000))
           61  +				ctx.cost = 3
           62  +			end
    17     63   		end;
    18     64   	};
    19     65   	conserve = { -- use less magical energy
    20     66   		name = 'Conserve';
    21     67   		tone = {84,255,144};
           68  +		cost = 0;
    22     69   		desc = 'enchantments last longer before running out of power to sustain them.';
           70  +		groups = allgroups;
    23     71   		affinity = 'syncretic';
    24         -		apply = function(stack,power)
    25         -		end;
           72  +		recipe = {
           73  +			{lens = 'rectifier', gem = 'mese',     dmg = 7};
           74  +			{lens = 'rectifier', gem = 'sapphire', dmg = 2};
           75  +			{lens = 'rectifier', gem = 'amethyst', dmg = 2};
           76  +		};
           77  +		-- implemented in sorcery/enchanter.lua:register_on_dig
    26     78   	};
    27     79   	dowse = { -- send up flare when valuable ores are nearby
    28     80   		name = 'Dowse';
    29     81   		tone = {241,251,113};
           82  +		cost = 1;
    30     83   		desc = 'strike colored sparks when used to dig near valuable ore.';
           84  +		groups = {'pick','pickaxe'};
    31     85   		affinity = 'cognic';
    32         -		apply = function(stack,power)
           86  +		recipe = {
           87  +			{lens = 'concave', gem = 'ruby',     dmg = 3};
           88  +			{lens = 'concave', gem = 'emerald',  dmg = 3};
           89  +			{lens = 'concave', gem = 'sapphire', dmg = 3};
           90  +		};
           91  +		on_dig = function(ctx)
           92  +			local range = 4*sorcery.enchant.strength(ctx.tool,'dowse')
           93  +			local colors = {
           94  +				['default:stone_with_gold'    ] = {255,234,182};
           95  +				['default:stone_with_mese'    ] = {231,255,151};
           96  +				['default:stone_with_diamond' ] = {180,253,255};
           97  +				['sorcery:stone_with_iridium' ] = {243,180,255};
           98  +				['sorcery:stone_with_tungsten'] = {119,234,196};
           99  +			}
          100  +			local search = {} for k in pairs(colors)
          101  +				do search[#search+1] = k end
          102  +			local nodes = minetest.find_nodes_in_area(
          103  +				vector.subtract(ctx.pos,range),
          104  +				vector.add(ctx.pos,range), search)
          105  +			for _,n in pairs(nodes) do
          106  +				-- we're going to use some ugly math tricks
          107  +				-- to avoid having to do a square root, since
          108  +				-- that's an expensive operation and we don't
          109  +				-- need that level of precision; we can
          110  +				-- approximate the distance without it
          111  +				local delta = vector.subtract(n,ctx.pos)
          112  +				local dstsq = (delta.x^2) + (delta.y^2) + (delta.z^2)
          113  +				if dstsq < range^2 then
          114  +					local dstfac = 1 - (dstsq / range^2)
          115  +					ctx.sparks[#ctx.sparks+1] = {
          116  +						color = sorcery.lib.color(colors[minetest.get_node(n).name]);
          117  +						count = 100 * dstfac;
          118  +					}
          119  +				end
          120  +			end
    33    121   		end;
    34    122   	};
    35    123   	pierce = { -- faster mining speed
    36    124   		name = 'Pierce';
          125  +		cost = 3;
    37    126   		tone = {113,240,251};
    38         -		desc = 'rip through solid stone like a hot knife through butter';
          127  +		groups = {
          128  +			'pick';'pickaxe';'axe';'shovel';'sickle';
          129  +		};
          130  +		desc = 'rip through solid stone or wood like a hot knife through butter';
          131  +		recipe = {
          132  +			{lens = 'amplifier', gem = 'diamond',  dmg = 4};
          133  +			{lens = 'amplifier', gem = 'ruby',     dmg = 4};
          134  +			{lens = 'rectifier', gem = 'diamond',  dmg = 2};
          135  +		};
    39    136   		affinity = 'praxic';
    40         -		apply = function(stack,power)
          137  +		apply = function(stack,power,base)
          138  +			local caps = table.copy(stack:get_definition().tool_capabilities)
          139  +			for g,v in pairs(caps.groupcaps) do
          140  +				for i,t in pairs(v.times) do
          141  +					local unit = base.groupcaps[g].times[i] * 0.15
          142  +					caps.groupcaps[g].times[i] = math.max(0.01, t - unit*power)
          143  +				end
          144  +			end
          145  +			stack:get_meta():set_tool_capabilities(caps)
          146  +			return stack
    41    147   		end;
    42    148   	};
    43    149   	rend = { -- more damage / mine higher level blocks
    44    150   		name = 'Rend';
    45    151   		affinity = 'praxic';
    46    152   		tone = {251,203,113};
          153  +		groups = {'sword';'pick';'pickaxe';};
          154  +		recipe = {
          155  +			{lens = 'convex',    gem = 'mese',    dmg = 3};
          156  +			{lens = 'amplifier', gem = 'emerald', dmg = 7};
          157  +			{lens = 'amplifier', gem = 'diamond', dmg = 7};
          158  +		};
          159  +		cost = 5;
    47    160   		desc = 'cleave through sturdy ores and tear mortal flesh with fearsome ease';
    48         -		apply = function(stack,power)
          161  +		apply = function(stack,power,base)
          162  +			local caps = table.copy(stack:get_definition().tool_capabilities)
          163  +			for g,v in pairs(caps.groupcaps) do
          164  +				local unit = 2
          165  +				caps.groupcaps[g].maxlevel = caps[g].maxlevel + math.floor(unit*power)
          166  +			end
          167  +			stack:get_meta():set_tool_capabilities(caps)
          168  +			return stack
    49    169   		end;
    50    170   	};
    51    171   }