From e1b068bafef3fb3fe4220a66ffa32c2c2b327241 Mon Sep 17 00:00:00 2001 From: pandaro Date: Sat, 22 Apr 2017 19:24:29 +0200 Subject: [PATCH] rework miner experience in rudimentary direction (#58) * rework miner experience in rudimentary direction * remove useless print --- mods/default/nodes.lua | 6 ++++ mods/skills/init.lua | 62 ++++++++++++++++++++++-------------------- mods/xp/init.lua | 27 ++++++++++++++++++ 3 files changed, 65 insertions(+), 30 deletions(-) diff --git a/mods/default/nodes.lua b/mods/default/nodes.lua index 1c3fc05..1108d08 100644 --- a/mods/default/nodes.lua +++ b/mods/default/nodes.lua @@ -153,6 +153,7 @@ minetest.register_node("default:stones_on_floor", { }, }, drop = "default:stone_item 2", + }) @@ -541,6 +542,7 @@ default.register_wool("black") minetest.register_node("default:stone", { description = "Stone", + tiles = {"default_stone.png"}, groups = {cracky = 3, stone= 1}, drop = { @@ -551,6 +553,7 @@ minetest.register_node("default:stone", { } }, sounds = default.sounds.stone(), + miner_xp ={xp = 10,rnd = 20}, }) minetest.register_node("default:desert_stone", { @@ -662,6 +665,7 @@ minetest.register_node("default:stone_with_coal", { groups = {cracky = 2}, drop = "default:coal_lump", sounds = default.sounds.stone(), + miner_xp ={xp = -1, rm = true} }) minetest.register_node("default:stone_with_iron", { @@ -669,6 +673,7 @@ minetest.register_node("default:stone_with_iron", { tiles = {"default_stone_with_iron.png"}, groups = {cracky = 2}, sounds = default.sounds.stone(), + miner_xp = {xp = 50}, }) minetest.register_node("default:stone_with_copper", { @@ -705,6 +710,7 @@ minetest.register_node("default:stone_with_diamond", { groups = {hard = 2}, drop = "default:diamond", sounds = default.sounds.stone(), + miner_xp = {xp = 14, lvls = 5} }) minetest.register_node("default:stone_with_ruby", { diff --git a/mods/skills/init.lua b/mods/skills/init.lua index e4a24a1..ed7fea5 100644 --- a/mods/skills/init.lua +++ b/mods/skills/init.lua @@ -405,36 +405,38 @@ skills.register_tool("bow", 1, 30, { }) -minetest.override_item("default:stone_with_coal", { - on_dig = function(pos, node, player) - if skills.lvls[player:get_player_name()] then - xp.add_xp(player, (skills.lvls[player:get_player_name()]["miner"]-1)) - end - minetest.node_dig(pos, node, player) - end, -}) - -minetest.override_item("default:stone_with_diamond", { - on_dig = function(pos, node, player) - if skills.lvls[player:get_player_name()] and skills.lvls[player:get_player_name()]["miner"] > 5 then - xp.add_xp(player,xp.get_xp(xp.player_levels[player:get_player_name()], 14)) - end - minetest.node_dig(pos, node, player) - end, -}) - -minetest.override_item("default:stone", { - on_dig = function(pos, node, player) - if skills.lvls[player:get_player_name()] and skills.lvls[player:get_player_name()]["miner"] then - if skills.lvls[player:get_player_name()]["miner"] > 1 then - if math.random(0, 20) == 1 then - xp.add_xp(player,10) - end - end - end - minetest.node_dig(pos, node, player) - end, -}) +-- minetest.override_item("default:stone_with_coal", { +-- on_dig = function(pos, node, player) +-- if skills.lvls[player:get_player_name()] then +-- xp.add_xp(player, (skills.lvls[player:get_player_name()]["miner"]-1)) +-- end +-- minetest.node_dig(pos, node, player) +-- end, +-- }) +-- +-- minetest.override_item("default:stone_with_diamond", { +-- on_dig = function(pos, node, player) +-- if skills.lvls[player:get_player_name()] and skills.lvls[player:get_player_name()]["miner"] > 5 then +-- xp.add_xp(player,xp.get_xp(xp.player_levels[player:get_player_name()], 14)) +-- end +-- minetest.node_dig(pos, node, player) +-- end, +-- }) +-- +-- minetest.override_item("default:stone", { +-- on_dig = function(pos, node, player) +-- if skills.lvls[player:get_player_name()] and skills.lvls[player:get_player_name()]["miner"] then +-- if skills.lvls[player:get_player_name()]["miner"] > 1 then +-- if math.random(0, 20) == 1 then +-- xp.add_xp(player,10) +-- end +-- end +-- end +-- minetest.node_dig(pos, node, player) +-- end, +-- +-- +-- }) local modpath = minetest.get_modpath("skills") diff --git a/mods/xp/init.lua b/mods/xp/init.lua index 34f9436..0bdbed0 100644 --- a/mods/xp/init.lua +++ b/mods/xp/init.lua @@ -182,7 +182,34 @@ function xp.crafter_xp() end) end +function xp.miner_xp() + minetest.register_on_dignode(function(pos, oldnode, digger) + local miner_xp = minetest.registered_nodes[oldnode.name].miner_xp + local player = digger:get_player_name() + local player_lvls = skills.lvls[player] + if not miner_xp then + elseif miner_xp.rm then + if player_lvls then + xp.add_xp(digger, (player_lvls["miner"]-1)) + + end + elseif miner_xp.lvls then + if player_lvls and player_lvls["miner"] > 5 then + xp.add_xp(digger,xp.get_xp(xp.player_levels[player], 14)) + end + elseif miner_xp.rnd then + if math.random(miner_xp.rnd) == miner_xp.rnd then + xp.add_xp(digger, miner_xp.xp) + end + elseif miner_xp.xp then + xp.add_xp(digger, miner_xp.xp) + end + end) +end + +xp.miner_xp() xp.crafter_xp() xp.explorer_xp() + xp.load_xp() xp.load_levels()