2017-09-27 19:11:19 +02:00
|
|
|
local mod_storage = minetest.get_mod_storage()
|
|
|
|
|
2017-07-13 15:12:49 +02:00
|
|
|
toolranks = {}
|
|
|
|
|
|
|
|
toolranks.colors = {
|
2017-07-09 17:40:31 +02:00
|
|
|
grey = minetest.get_color_escape_sequence("#9d9d9d"),
|
2017-07-10 13:08:07 +02:00
|
|
|
green = minetest.get_color_escape_sequence("#1eff00"),
|
|
|
|
gold = minetest.get_color_escape_sequence("#ffdf00"),
|
|
|
|
white = minetest.get_color_escape_sequence("#ffffff")
|
2017-07-09 17:40:31 +02:00
|
|
|
}
|
|
|
|
|
2017-07-13 15:12:49 +02:00
|
|
|
function toolranks.get_tool_type(description)
|
2017-07-10 13:08:07 +02:00
|
|
|
if string.find(description, "Pickaxe") then
|
|
|
|
return "pickaxe"
|
|
|
|
elseif string.find(description, "Axe") then
|
|
|
|
return "axe"
|
|
|
|
elseif string.find(description, "Shovel") then
|
|
|
|
return "shovel"
|
|
|
|
elseif string.find(description, "Hoe") then
|
|
|
|
return "hoe"
|
|
|
|
else
|
|
|
|
return "tool"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-13 15:12:49 +02:00
|
|
|
function toolranks.create_description(name, uses, level)
|
2017-07-10 13:08:07 +02:00
|
|
|
local description = name
|
2017-07-13 15:12:49 +02:00
|
|
|
local tooltype = toolranks.get_tool_type(description)
|
2017-07-10 13:08:07 +02:00
|
|
|
|
2017-07-13 15:12:49 +02:00
|
|
|
local newdesc = toolranks.colors.green .. description .. "\n" ..
|
2017-09-29 17:08:55 +02:00
|
|
|
toolranks.colors.gold .. "Level " .. (level or 1) .. " " .. tooltype .. "\n" ..
|
|
|
|
toolranks.colors.grey .. "Nodes dug: " .. (uses or 0)
|
2017-07-10 13:08:07 +02:00
|
|
|
|
|
|
|
return newdesc
|
|
|
|
end
|
|
|
|
|
2017-07-13 15:12:49 +02:00
|
|
|
function toolranks.get_level(uses)
|
2017-09-04 10:24:28 +02:00
|
|
|
if uses <= 200 then
|
2017-07-10 13:08:07 +02:00
|
|
|
return 1
|
|
|
|
elseif uses < 400 then
|
2017-09-04 10:24:28 +02:00
|
|
|
return 2
|
|
|
|
elseif uses < 1000 then
|
2017-07-10 13:08:07 +02:00
|
|
|
return 3
|
2017-09-04 10:24:28 +02:00
|
|
|
elseif uses < 2000 then
|
2017-07-12 14:04:34 +02:00
|
|
|
return 4
|
2017-09-04 10:24:28 +02:00
|
|
|
elseif uses < 3200 then
|
2017-07-10 13:08:07 +02:00
|
|
|
return 5
|
2017-07-12 14:04:34 +02:00
|
|
|
else
|
2017-07-10 13:08:07 +02:00
|
|
|
return 6
|
2017-07-09 17:40:31 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-13 15:12:49 +02:00
|
|
|
function toolranks.new_afteruse(itemstack, user, node, digparams)
|
2017-07-09 17:40:31 +02:00
|
|
|
local itemmeta = itemstack:get_meta() -- Metadata
|
|
|
|
local itemdef = itemstack:get_definition() -- Item Definition
|
2017-07-10 13:08:07 +02:00
|
|
|
local itemdesc = itemdef.original_description -- Original Description
|
2017-07-09 17:40:31 +02:00
|
|
|
local dugnodes = tonumber(itemmeta:get_string("dug")) or 0 -- Number of nodes dug
|
2017-07-10 13:08:07 +02:00
|
|
|
local lastlevel = tonumber(itemmeta:get_string("lastlevel")) or 1 -- Level the tool had
|
|
|
|
-- on the last dig
|
2017-09-27 19:11:19 +02:00
|
|
|
local most_digs = mod_storage:get_int("most_digs") or 0
|
|
|
|
local most_digs_user = mod_storage:get_string("most_digs_user") or 0
|
|
|
|
|
2017-07-13 19:46:18 +02:00
|
|
|
-- Only count nodes that spend the tool
|
|
|
|
if(digparams.wear > 0) then
|
|
|
|
dugnodes = dugnodes + 1
|
2017-07-28 14:50:04 +02:00
|
|
|
itemmeta:set_string("dug", dugnodes)
|
2017-07-13 19:46:18 +02:00
|
|
|
end
|
2017-09-27 19:11:19 +02:00
|
|
|
if(dugnodes > most_digs) then
|
|
|
|
most_digs = dugnodes
|
2017-09-27 19:16:47 +02:00
|
|
|
if(most_digs_user ~= user:get_player_name()) then -- Avoid spam.
|
|
|
|
most_digs_user = user:get_player_name()
|
|
|
|
minetest.chat_send_all("Most used tool is now a " .. toolranks.colors.green .. itemdesc
|
|
|
|
.. toolranks.colors.white .. " owned by " .. user:get_player_name()
|
|
|
|
.. " with " .. dugnodes .. " uses.")
|
|
|
|
end
|
|
|
|
mod_storage:set_int("most_digs", dugnodes)
|
|
|
|
mod_storage:set_string("most_digs_user", user:get_player_name())
|
2017-09-27 19:11:19 +02:00
|
|
|
end
|
2017-07-27 13:44:15 +02:00
|
|
|
if(itemstack:get_wear() > 60135) then
|
2017-09-27 19:11:19 +02:00
|
|
|
minetest.chat_send_player(user:get_player_name(), "Your tool is about to break!")
|
2017-07-27 15:21:03 +02:00
|
|
|
minetest.sound_play("default_tool_breaks", {
|
|
|
|
to_player = user:get_player_name(),
|
|
|
|
gain = 2.0,
|
|
|
|
})
|
2017-07-27 13:36:54 +02:00
|
|
|
end
|
2017-07-28 10:24:00 +02:00
|
|
|
local level = toolranks.get_level(dugnodes)
|
2017-07-10 13:08:07 +02:00
|
|
|
|
|
|
|
if lastlevel < level then
|
2017-07-13 15:12:49 +02:00
|
|
|
local levelup_text = "Your " .. toolranks.colors.green ..
|
|
|
|
itemdesc .. toolranks.colors.white ..
|
2017-07-10 13:08:07 +02:00
|
|
|
" just leveled up!"
|
2017-07-27 15:21:03 +02:00
|
|
|
minetest.sound_play("toolranks_levelup", {
|
|
|
|
to_player = user:get_player_name(),
|
|
|
|
gain = 2.0,
|
|
|
|
})
|
2017-07-10 13:08:07 +02:00
|
|
|
minetest.chat_send_player(user:get_player_name(), levelup_text)
|
2017-07-28 14:50:04 +02:00
|
|
|
itemmeta:set_string("lastlevel", level)
|
2017-07-10 13:08:07 +02:00
|
|
|
end
|
2017-07-09 17:40:31 +02:00
|
|
|
|
2017-07-13 15:12:49 +02:00
|
|
|
local newdesc = toolranks.create_description(itemdesc, dugnodes, level)
|
2017-07-09 17:40:31 +02:00
|
|
|
|
|
|
|
itemmeta:set_string("description", newdesc)
|
2017-07-10 13:08:07 +02:00
|
|
|
local wear = digparams.wear
|
|
|
|
if level > 1 then
|
|
|
|
wear = digparams.wear / (1 + level / 4)
|
|
|
|
end
|
|
|
|
|
|
|
|
--minetest.chat_send_all("wear="..wear.."Original wear: "..digparams.wear.." 1+level/4="..1+level/4)
|
|
|
|
-- Uncomment for testing ^
|
|
|
|
|
|
|
|
itemstack:add_wear(wear)
|
2017-07-09 17:40:31 +02:00
|
|
|
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.override_item("default:pick_diamond", {
|
2017-07-10 13:08:07 +02:00
|
|
|
original_description = "Diamond Pickaxe",
|
2017-07-13 15:12:49 +02:00
|
|
|
description = toolranks.create_description("Diamond Pickaxe", 0, 1),
|
2017-07-28 15:11:38 +02:00
|
|
|
after_use = toolranks.new_afteruse})
|
|
|
|
|
2017-07-10 13:08:07 +02:00
|
|
|
minetest.override_item("default:axe_diamond", {
|
|
|
|
original_description = "Diamond Axe",
|
2017-07-13 15:12:49 +02:00
|
|
|
description = toolranks.create_description("Diamond Axe", 0, 1),
|
2017-07-28 15:11:38 +02:00
|
|
|
after_use = toolranks.new_afteruse})
|
|
|
|
|
2017-07-10 13:08:07 +02:00
|
|
|
minetest.override_item("default:shovel_diamond", {
|
|
|
|
original_description = "Diamond Shovel",
|
2017-07-13 15:12:49 +02:00
|
|
|
description = toolranks.create_description("Diamond Shovel", 0, 1),
|
2017-07-28 15:11:38 +02:00
|
|
|
after_use = toolranks.new_afteruse})
|
|
|
|
|
2017-07-10 13:08:07 +02:00
|
|
|
minetest.override_item("default:pick_wood", {
|
|
|
|
original_description = "Wooden Pickaxe",
|
2017-07-13 15:12:49 +02:00
|
|
|
description = toolranks.create_description("Wooden Pickaxe", 0, 1),
|
2017-07-28 15:11:38 +02:00
|
|
|
after_use = toolranks.new_afteruse})
|
|
|
|
|
2017-07-10 13:08:07 +02:00
|
|
|
minetest.override_item("default:axe_wood", {
|
|
|
|
original_description = "Wooden Axe",
|
2017-07-13 15:12:49 +02:00
|
|
|
description = toolranks.create_description("Wooden Axe", 0, 1),
|
2017-07-28 15:11:38 +02:00
|
|
|
after_use = toolranks.new_afteruse})
|
|
|
|
|
2017-07-10 13:08:07 +02:00
|
|
|
minetest.override_item("default:shovel_wood", {
|
|
|
|
original_description = "Wooden Shovel",
|
2017-07-13 15:12:49 +02:00
|
|
|
description = toolranks.create_description("Wooden Shovel", 0, 1),
|
2017-07-28 15:11:38 +02:00
|
|
|
after_use = toolranks.new_afteruse})
|
|
|
|
|
2017-07-10 13:08:07 +02:00
|
|
|
minetest.override_item("default:pick_steel", {
|
|
|
|
original_description = "Steel Pickaxe",
|
2017-07-13 15:12:49 +02:00
|
|
|
description = toolranks.create_description("Steel Pickaxe", 0, 1),
|
2017-07-28 15:11:38 +02:00
|
|
|
after_use = toolranks.new_afteruse})
|
|
|
|
|
2017-07-10 13:08:07 +02:00
|
|
|
minetest.override_item("default:axe_steel", {
|
|
|
|
original_description = "Steel Axe",
|
2017-07-13 15:12:49 +02:00
|
|
|
description = toolranks.create_description("Steel Axe", 0, 1),
|
2017-07-28 15:11:38 +02:00
|
|
|
after_use = toolranks.new_afteruse})
|
|
|
|
|
2017-07-10 13:08:07 +02:00
|
|
|
minetest.override_item("default:shovel_steel", {
|
|
|
|
original_description = "Steel Shovel",
|
2017-07-13 15:12:49 +02:00
|
|
|
description = toolranks.create_description("Steel Shovel", 0, 1),
|
2017-07-28 15:11:38 +02:00
|
|
|
after_use = toolranks.new_afteruse})
|
|
|
|
|
2017-07-10 13:08:07 +02:00
|
|
|
minetest.override_item("default:pick_stone", {
|
|
|
|
original_description = "Stone Pickaxe",
|
2017-07-13 15:12:49 +02:00
|
|
|
description = toolranks.create_description("Stone Pickaxe", 0, 1),
|
2017-07-28 15:11:38 +02:00
|
|
|
after_use = toolranks.new_afteruse})
|
|
|
|
|
2017-07-10 13:08:07 +02:00
|
|
|
minetest.override_item("default:axe_stone", {
|
|
|
|
original_description = "Stone Axe",
|
2017-07-13 15:12:49 +02:00
|
|
|
description = toolranks.create_description("Stone Axe", 0, 1),
|
2017-07-28 15:11:38 +02:00
|
|
|
after_use = toolranks.new_afteruse})
|
|
|
|
|
2017-07-10 13:08:07 +02:00
|
|
|
minetest.override_item("default:shovel_stone", {
|
|
|
|
original_description = "Stone Shovel",
|
2017-07-13 15:12:49 +02:00
|
|
|
description = toolranks.create_description("Stone Shovel", 0, 1),
|
2017-07-28 15:11:38 +02:00
|
|
|
after_use = toolranks.new_afteruse})
|
|
|
|
|
2017-07-10 13:08:07 +02:00
|
|
|
minetest.override_item("default:pick_bronze", {
|
|
|
|
original_description = "Bronze Pickaxe",
|
2017-07-13 15:12:49 +02:00
|
|
|
description = toolranks.create_description("Bronze Pickaxe", 0, 1),
|
2017-07-28 15:11:38 +02:00
|
|
|
after_use = toolranks.new_afteruse})
|
|
|
|
|
2017-07-10 13:08:07 +02:00
|
|
|
minetest.override_item("default:axe_bronze", {
|
|
|
|
original_description = "Bronze Axe",
|
2017-07-13 15:12:49 +02:00
|
|
|
description = toolranks.create_description("Bronze Axe", 0, 1),
|
2017-07-28 15:11:38 +02:00
|
|
|
after_use = toolranks.new_afteruse})
|
|
|
|
|
2017-07-10 13:08:07 +02:00
|
|
|
minetest.override_item("default:shovel_bronze", {
|
|
|
|
original_description = "Bronze Shovel",
|
2017-07-13 15:12:49 +02:00
|
|
|
description = toolranks.create_description("Bronze Shovel", 0, 1),
|
2017-07-28 15:11:38 +02:00
|
|
|
after_use = toolranks.new_afteruse})
|
|
|
|
|
2017-07-10 13:08:07 +02:00
|
|
|
minetest.override_item("default:pick_mese", {
|
|
|
|
original_description = "Mese Pickaxe",
|
2017-07-13 15:12:49 +02:00
|
|
|
description = toolranks.create_description("Mese Pickaxe", 0, 1),
|
2017-07-28 15:11:38 +02:00
|
|
|
after_use = toolranks.new_afteruse})
|
|
|
|
|
2017-07-10 13:08:07 +02:00
|
|
|
minetest.override_item("default:axe_mese", {
|
|
|
|
original_description = "Mese Axe",
|
2017-07-13 15:12:49 +02:00
|
|
|
description = toolranks.create_description("Mese Axe", 0, 1),
|
2017-07-28 15:11:38 +02:00
|
|
|
after_use = toolranks.new_afteruse})
|
|
|
|
|
2017-07-10 13:08:07 +02:00
|
|
|
minetest.override_item("default:shovel_mese", {
|
|
|
|
original_description = "Mese Shovel",
|
2017-07-13 15:12:49 +02:00
|
|
|
description = toolranks.create_description("Mese Shovel", 0, 1),
|
2017-07-28 15:11:38 +02:00
|
|
|
after_use = toolranks.new_afteruse})
|
2017-07-28 10:00:44 +02:00
|
|
|
|
|
|
|
if minetest.get_modpath("moreores") then
|
|
|
|
|
2017-07-28 15:11:38 +02:00
|
|
|
minetest.override_item("moreores:pick_mithril", {
|
|
|
|
original_description = "Mithril Pickaxe",
|
|
|
|
description = toolranks.create_description("Mithril Pickaxe", 0, 1),
|
|
|
|
after_use = toolranks.new_afteruse})
|
|
|
|
|
|
|
|
minetest.override_item("moreores:axe_mithril", {
|
|
|
|
original_description = "Mithril Axe",
|
|
|
|
description = toolranks.create_description("Mithril Axe", 0, 1),
|
|
|
|
after_use = toolranks.new_afteruse})
|
|
|
|
|
|
|
|
minetest.override_item("moreores:shovel_mithril", {
|
|
|
|
original_description = "Mithril Shovel",
|
|
|
|
description = toolranks.create_description("Mithril Shovel", 0, 1),
|
|
|
|
after_use = toolranks.new_afteruse})
|
|
|
|
|
2018-07-01 15:30:49 +02:00
|
|
|
minetest.override_item("moreores:sword_mithril", {
|
|
|
|
original_description = "Mithril Sword",
|
|
|
|
description = toolranks.create_description("Mithril Sword", 0, 1),
|
|
|
|
after_use = toolranks.new_afteruse})
|
|
|
|
|
2017-07-28 15:11:38 +02:00
|
|
|
minetest.override_item("moreores:pick_silver", {
|
|
|
|
original_description = "Silver Pickaxe",
|
|
|
|
description = toolranks.create_description("Silver Pickaxe", 0, 1),
|
|
|
|
after_use = toolranks.new_afteruse})
|
|
|
|
|
|
|
|
minetest.override_item("moreores:axe_silver", {
|
|
|
|
original_description = "Silver Axe",
|
|
|
|
description = toolranks.create_description("Silver Axe", 0, 1),
|
|
|
|
after_use = toolranks.new_afteruse})
|
|
|
|
|
|
|
|
minetest.override_item("moreores:shovel_silver", {
|
|
|
|
original_description = "Silver Shovel",
|
|
|
|
description = toolranks.create_description("Silver Shovel", 0, 1),
|
|
|
|
after_use = toolranks.new_afteruse})
|
2018-07-01 15:30:49 +02:00
|
|
|
|
|
|
|
minetest.override_item("moreores:sword_silver", {
|
|
|
|
original_description = "Silver Sword",
|
|
|
|
description = toolranks.create_description("Silver Sword", 0, 1),
|
|
|
|
after_use = toolranks.new_afteruse})
|
2017-07-28 10:00:44 +02:00
|
|
|
end
|
2018-07-01 15:06:23 +02:00
|
|
|
|
|
|
|
-- add swords for snappy nodes
|
|
|
|
minetest.override_item("default:sword_wood", {
|
|
|
|
original_description = "Wooden Sword",
|
|
|
|
description = toolranks.create_description("Wooden Sword", 0, 1),
|
|
|
|
after_use = toolranks.new_afteruse})
|
|
|
|
|
|
|
|
minetest.override_item("default:sword_stone", {
|
|
|
|
original_description = "Stone Sword",
|
|
|
|
description = toolranks.create_description("Stone Sword", 0, 1),
|
|
|
|
after_use = toolranks.new_afteruse})
|
|
|
|
|
|
|
|
minetest.override_item("default:sword_steel", {
|
|
|
|
original_description = "Steel Sword",
|
|
|
|
description = toolranks.create_description("Steel Sword", 0, 1),
|
|
|
|
after_use = toolranks.new_afteruse})
|
|
|
|
|
|
|
|
minetest.override_item("default:sword_bronze", {
|
|
|
|
original_description = "Bronze Sword",
|
|
|
|
description = toolranks.create_description("Bronze Sword", 0, 1),
|
|
|
|
after_use = toolranks.new_afteruse})
|
|
|
|
|
|
|
|
minetest.override_item("default:sword_mese", {
|
|
|
|
original_description = "Mese Sword",
|
2018-07-01 15:30:49 +02:00
|
|
|
description = toolranks.create_description("Mese Sword", 0, 1),
|
2018-07-01 15:06:23 +02:00
|
|
|
after_use = toolranks.new_afteruse})
|
|
|
|
|
|
|
|
minetest.override_item("default:sword_diamond", {
|
|
|
|
original_description = "Diamond Sword",
|
|
|
|
description = toolranks.create_description("Diamond Sword", 0, 1),
|
|
|
|
after_use = toolranks.new_afteruse})
|