|
|
@ -32,12 +32,19 @@ function toolranks.get_tool_type(description)
|
|
|
|
elseif string.find(d, "sword") then
|
|
|
|
elseif string.find(d, "sword") then
|
|
|
|
return "sword"
|
|
|
|
return "sword"
|
|
|
|
else
|
|
|
|
else
|
|
|
|
return "tool"
|
|
|
|
return "tool"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function toolranks.create_description(name, uses, level)
|
|
|
|
function toolranks.get_level(uses)
|
|
|
|
|
|
|
|
if type(uses) == "number" and uses > 0 then
|
|
|
|
|
|
|
|
return math.min(max_level, math.floor(uses / level_digs))
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function toolranks.create_description(name, uses)
|
|
|
|
local description = name
|
|
|
|
local description = name
|
|
|
|
local tooltype = toolranks.get_tool_type(description)
|
|
|
|
local tooltype = toolranks.get_tool_type(description)
|
|
|
|
local newdesc = S(
|
|
|
|
local newdesc = S(
|
|
|
@ -45,26 +52,24 @@ function toolranks.create_description(name, uses, level)
|
|
|
|
toolranks.colors.green,
|
|
|
|
toolranks.colors.green,
|
|
|
|
description,
|
|
|
|
description,
|
|
|
|
toolranks.colors.gold,
|
|
|
|
toolranks.colors.gold,
|
|
|
|
(level or 1),
|
|
|
|
toolranks.get_level(uses),
|
|
|
|
S(tooltype),
|
|
|
|
S(tooltype),
|
|
|
|
toolranks.colors.grey,
|
|
|
|
toolranks.colors.grey,
|
|
|
|
(uses or 0)
|
|
|
|
(type(uses) == "number" and uses or 0)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
return newdesc
|
|
|
|
return newdesc
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function toolranks.get_level(uses)
|
|
|
|
|
|
|
|
return math.min(max_level, math.floor(uses / level_digs))
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function toolranks.new_afteruse(itemstack, user, node, digparams)
|
|
|
|
function toolranks.new_afteruse(itemstack, user, node, digparams)
|
|
|
|
local itemmeta = itemstack:get_meta()
|
|
|
|
local itemmeta = itemstack:get_meta()
|
|
|
|
local itemdef = itemstack:get_definition()
|
|
|
|
local itemdef = itemstack:get_definition()
|
|
|
|
local itemdesc = itemdef.original_description
|
|
|
|
local itemdesc = itemdef.original_description or ""
|
|
|
|
local dugnodes = tonumber(itemmeta:get_string("dug")) or 0
|
|
|
|
local dugnodes = tonumber(itemmeta:get_string("dug")) or 0
|
|
|
|
local lastlevel = tonumber(itemmeta:get_string("lastlevel")) or 0
|
|
|
|
local lastlevel = tonumber(itemmeta:get_string("lastlevel")) or 0
|
|
|
|
local most_digs = mod_storage:get_int("most_digs") or 0
|
|
|
|
local most_digs = mod_storage:get_int("most_digs") or 0
|
|
|
|
local most_digs_user = mod_storage:get_string("most_digs_user") or 0
|
|
|
|
local most_digs_user = mod_storage:get_string("most_digs_user") or 0
|
|
|
|
|
|
|
|
local pname = user:get_player_name()
|
|
|
|
|
|
|
|
if not pname then return itemstack end -- player nil check
|
|
|
|
|
|
|
|
|
|
|
|
if digparams.wear > 0 then -- Only count nodes that spend the tool
|
|
|
|
if digparams.wear > 0 then -- Only count nodes that spend the tool
|
|
|
|
dugnodes = dugnodes + 1
|
|
|
|
dugnodes = dugnodes + 1
|
|
|
@ -72,24 +77,24 @@ function toolranks.new_afteruse(itemstack, user, node, digparams)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if dugnodes > most_digs then
|
|
|
|
if dugnodes > most_digs then
|
|
|
|
if most_digs_user ~= user:get_player_name() then -- Avoid spam.
|
|
|
|
if most_digs_user ~= pname then -- Avoid spam.
|
|
|
|
minetest.chat_send_all(S(
|
|
|
|
minetest.chat_send_all(S(
|
|
|
|
"Most used tool is now a @1@2@3 owned by @4 with @5 uses.",
|
|
|
|
"Most used tool is now a @1@2@3 owned by @4 with @5 uses.",
|
|
|
|
toolranks.colors.green,
|
|
|
|
toolranks.colors.green,
|
|
|
|
itemdesc,
|
|
|
|
itemdesc,
|
|
|
|
toolranks.colors.white,
|
|
|
|
toolranks.colors.white,
|
|
|
|
user:get_player_name(),
|
|
|
|
pname,
|
|
|
|
dugnodes
|
|
|
|
dugnodes
|
|
|
|
))
|
|
|
|
))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
mod_storage:set_int("most_digs", dugnodes)
|
|
|
|
mod_storage:set_int("most_digs", dugnodes)
|
|
|
|
mod_storage:set_string("most_digs_user", user:get_player_name())
|
|
|
|
mod_storage:set_string("most_digs_user", pname)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if itemstack:get_wear() > 60135 then
|
|
|
|
if itemstack:get_wear() > 60135 then
|
|
|
|
minetest.chat_send_player(user:get_player_name(), S("Your tool is about to break!"))
|
|
|
|
minetest.chat_send_player(user:get_player_name(), S("Your tool is about to break!"))
|
|
|
|
minetest.sound_play("default_tool_breaks", {
|
|
|
|
minetest.sound_play("default_tool_breaks", {
|
|
|
|
to_player = user:get_player_name(),
|
|
|
|
to_player = pname,
|
|
|
|
gain = 2.0,
|
|
|
|
gain = 2.0,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -104,29 +109,40 @@ function toolranks.new_afteruse(itemstack, user, node, digparams)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
minetest.chat_send_player(user:get_player_name(), levelup_text)
|
|
|
|
minetest.chat_send_player(user:get_player_name(), levelup_text)
|
|
|
|
minetest.sound_play("toolranks_levelup", {
|
|
|
|
minetest.sound_play("toolranks_levelup", {
|
|
|
|
to_player = user:get_player_name(),
|
|
|
|
to_player = pname,
|
|
|
|
gain = 2.0,
|
|
|
|
gain = 2.0,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
itemmeta:set_string("lastlevel", level)
|
|
|
|
-- Make tool better by modifying tool_capabilities (if defined)
|
|
|
|
|
|
|
|
if itemdef.tool_capabilities then
|
|
|
|
|
|
|
|
local speed_multiplier = 1 + (level * level_multiplier * (max_speed - 1))
|
|
|
|
|
|
|
|
local use_multiplier = 1 + (level * level_multiplier * (max_use - 1))
|
|
|
|
|
|
|
|
local caps = table.copy(itemdef.tool_capabilities)
|
|
|
|
|
|
|
|
|
|
|
|
local speed_multiplier = 1 + (level * level_multiplier * (max_speed - 1))
|
|
|
|
caps.full_punch_interval = caps.full_punch_interval and (caps.full_punch_interval / speed_multiplier)
|
|
|
|
local use_multiplier = 1 + (level * level_multiplier * (max_use - 1))
|
|
|
|
caps.punch_attack_uses = caps.punch_attack_uses and (caps.punch_attack_uses * use_multiplier)
|
|
|
|
local caps = table.copy(itemdef.tool_capabilities)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
caps.full_punch_interval = caps.full_punch_interval and (caps.full_punch_interval / speed_multiplier)
|
|
|
|
for _,c in pairs(caps.groupcaps) do
|
|
|
|
caps.punch_attack_uses = caps.punch_attack_uses and (caps.punch_attack_uses * use_multiplier)
|
|
|
|
if c.uses then
|
|
|
|
|
|
|
|
c.uses = c.uses * use_multiplier
|
|
|
|
for _,c in pairs(caps.groupcaps) do
|
|
|
|
for i,t in ipairs(c.times) do
|
|
|
|
c.uses = c.uses * use_multiplier
|
|
|
|
c.times[i] = t / speed_multiplier
|
|
|
|
for i,t in ipairs(c.times) do
|
|
|
|
end
|
|
|
|
c.times[i] = t / speed_multiplier
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
itemmeta:set_tool_capabilities(caps)
|
|
|
|
itemmeta:set_tool_capabilities(caps)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
itemmeta:set_string("description", toolranks.create_description(itemdesc, dugnodes, level))
|
|
|
|
-- Old method for compatibility with tools without tool_capabilities defined
|
|
|
|
itemstack:add_wear(digparams.wear)
|
|
|
|
local wear = digparams.wear
|
|
|
|
|
|
|
|
if level > 0 and not itemdef.tool_capabilities then
|
|
|
|
|
|
|
|
local use_multiplier = 1 + (level * level_multiplier * (max_use - 1))
|
|
|
|
|
|
|
|
wear = wear / use_multiplier
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
itemmeta:set_string("lastlevel", level)
|
|
|
|
|
|
|
|
itemmeta:set_string("description", toolranks.create_description(itemdesc, dugnodes))
|
|
|
|
|
|
|
|
itemstack:add_wear(wear)
|
|
|
|
return itemstack
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -135,7 +151,7 @@ function toolranks.add_tool(name)
|
|
|
|
local desc = ItemStack(name):get_definition().description
|
|
|
|
local desc = ItemStack(name):get_definition().description
|
|
|
|
minetest.override_item(name, {
|
|
|
|
minetest.override_item(name, {
|
|
|
|
original_description = desc,
|
|
|
|
original_description = desc,
|
|
|
|
description = toolranks.create_description(desc, 0, 1),
|
|
|
|
description = toolranks.create_description(desc),
|
|
|
|
after_use = toolranks.new_afteruse
|
|
|
|
after_use = toolranks.new_afteruse
|
|
|
|
})
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|