Implement leftovers of https://git.minetest.land/Wuzzy/MineClone2/issues/841#issuecomment-11440
parent
290893355b
commit
30d9e54803
|
@ -227,7 +227,7 @@ function minetest.handle_node_drops(pos, drops, digger)
|
||||||
local toolcaps
|
local toolcaps
|
||||||
if digger ~= nil then
|
if digger ~= nil then
|
||||||
if mcl_experience.throw_experience then
|
if mcl_experience.throw_experience then
|
||||||
local experience_amount = minetest.get_item_group(dug_node.name,"experience")
|
local experience_amount = minetest.get_item_group(dug_node.name,"xp")
|
||||||
if experience_amount > 0 then
|
if experience_amount > 0 then
|
||||||
mcl_experience.throw_experience(pos, experience_amount)
|
mcl_experience.throw_experience(pos, experience_amount)
|
||||||
end
|
end
|
||||||
|
|
|
@ -39,7 +39,7 @@ local load_data = function(player)
|
||||||
local meta = player:get_meta()
|
local meta = player:get_meta()
|
||||||
temp_pool.xp = meta:get_int("xp") or 0
|
temp_pool.xp = meta:get_int("xp") or 0
|
||||||
temp_pool.level = mcl_experience.xp_to_level(temp_pool.xp)
|
temp_pool.level = mcl_experience.xp_to_level(temp_pool.xp)
|
||||||
temp_pool.bar, temp_pool.xp_next_level = mcl_experience.xp_to_bar(temp_pool.xp, temp_pool.level)
|
temp_pool.bar, temp_pool.bar_step, temp_pool.xp_next_level = mcl_experience.xp_to_bar(temp_pool.xp, temp_pool.level)
|
||||||
temp_pool.last_time= minetest.get_us_time()/1000000
|
temp_pool.last_time= minetest.get_us_time()/1000000
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -132,31 +132,21 @@ minetest.register_on_shutdown(function()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
local name
|
|
||||||
function mcl_experience.get_player_xp_level(player)
|
function mcl_experience.get_player_xp_level(player)
|
||||||
name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
return(pool[name].level)
|
return(pool[name].level)
|
||||||
end
|
end
|
||||||
|
|
||||||
local name
|
|
||||||
local temp_pool
|
|
||||||
function mcl_experience.set_player_xp_level(player,level)
|
function mcl_experience.set_player_xp_level(player,level)
|
||||||
name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
|
if level == pool[name].level then
|
||||||
|
return
|
||||||
|
end
|
||||||
pool[name].level = level
|
pool[name].level = level
|
||||||
pool[name].xp = mcl_experience.level_to_xp(level)
|
pool[name].xp, pool[name].next_level = mcl_experience.bar_to_xp(pool[name].bar, level)
|
||||||
--todo: update bar
|
hud_manager.change_hud({player = player, hud_name = "xp_level_fg", element = "text", data = tostring(level)})
|
||||||
hud_manager.change_hud({
|
hud_manager.change_hud({player = player, hud_name = "xp_level_bg", element = "text", data = tostring(level)})
|
||||||
player = player,
|
-- we may don't update the bar
|
||||||
hud_name = "xp_level_fg",
|
|
||||||
element = "text",
|
|
||||||
data = tostring(level)
|
|
||||||
})
|
|
||||||
hud_manager.change_hud({
|
|
||||||
player = player,
|
|
||||||
hud_name = "xp_level_bg",
|
|
||||||
element = "text",
|
|
||||||
data = tostring(level)
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local name
|
local name
|
||||||
|
@ -240,8 +230,17 @@ function mcl_experience.xp_to_bar(xp, level)
|
||||||
local level = level or mcl_experience.xp_to_level(xp)
|
local level = level or mcl_experience.xp_to_level(xp)
|
||||||
local xp_this_level = mcl_experience.level_to_xp(level)
|
local xp_this_level = mcl_experience.level_to_xp(level)
|
||||||
local xp_next_level = mcl_experience.level_to_xp(level+1)
|
local xp_next_level = mcl_experience.level_to_xp(level+1)
|
||||||
local bar = math.floor((xp-xp_this_level)/(xp_next_level-xp_this_level)*35)
|
local bar_step = 36 / (xp_next_level-xp_this_level)
|
||||||
return bar, xp_next_level
|
local bar = (xp-xp_this_level) * bar_step
|
||||||
|
return bar, bar_step, xp_next_level
|
||||||
|
end
|
||||||
|
|
||||||
|
function mcl_experience.bar_to_xp(bar, level)
|
||||||
|
local xp_this_level = mcl_experience.level_to_xp(level)
|
||||||
|
local xp_next_level = mcl_experience.level_to_xp(level+1)
|
||||||
|
local bar_step = 36 / (xp_next_level-xp_this_level)
|
||||||
|
local xp = xp_this_level + math.floor(bar/36*(xp_next_level-xp_this_level))
|
||||||
|
return xp, bar_step, xp_next_level
|
||||||
end
|
end
|
||||||
|
|
||||||
function mcl_experience.add_experience(player, experience)
|
function mcl_experience.add_experience(player, experience)
|
||||||
|
@ -250,22 +249,27 @@ function mcl_experience.add_experience(player, experience)
|
||||||
|
|
||||||
local old_bar, old_xp, old_level = temp_pool.bar, temp_pool.xp, temp_pool.level
|
local old_bar, old_xp, old_level = temp_pool.bar, temp_pool.xp, temp_pool.level
|
||||||
temp_pool.xp = math.max(temp_pool.xp + experience, 0)
|
temp_pool.xp = math.max(temp_pool.xp + experience, 0)
|
||||||
temp_pool.level = mcl_experience.xp_to_level(temp_pool.xp)
|
if (temp_pool.xp >= temp_pool.xp_next_level) or (experience < 1) then
|
||||||
temp_pool.bar, temp_pool.xp_next_level = mcl_experience.xp_to_bar(temp_pool.xp, temp_pool.level)
|
temp_pool.level = mcl_experience.xp_to_level(temp_pool.xp)
|
||||||
if old_level ~= temp_pool.level then
|
temp_pool.bar, temp_pool.bar_step, temp_pool.xp_next_level = mcl_experience.xp_to_bar(temp_pool.xp, temp_pool.level)
|
||||||
if minetest.get_us_time()/1000000 - temp_pool.last_time > 0.04 then
|
if old_level ~= temp_pool.level then
|
||||||
minetest.sound_play("level_up",{gain=0.2,to_player = name})
|
if minetest.get_us_time()/1000000 - temp_pool.last_time > 0.04 then
|
||||||
temp_pool.last_time = minetest.get_us_time()/1000000
|
minetest.sound_play("level_up",{gain=0.2,to_player = name})
|
||||||
|
temp_pool.last_time = minetest.get_us_time()/1000000
|
||||||
|
end
|
||||||
|
hud_manager.change_hud({player = player, hud_name = "xp_level_fg", element = "text", data = tostring(temp_pool.level)})
|
||||||
|
hud_manager.change_hud({player = player, hud_name = "xp_level_bg", element = "text", data = tostring(temp_pool.level)})
|
||||||
end
|
end
|
||||||
hud_manager.change_hud({player = player, hud_name = "xp_level_fg", element = "text", data = tostring(temp_pool.level)})
|
else
|
||||||
hud_manager.change_hud({player = player, hud_name = "xp_level_bg", element = "text", data = tostring(temp_pool.level)})
|
if minetest.get_us_time()/1000000 - temp_pool.last_time > 0.01 then
|
||||||
elseif minetest.get_us_time()/1000000 - temp_pool.last_time > 0.01 then
|
temp_pool.last_time = minetest.get_us_time()/1000000
|
||||||
temp_pool.last_time = minetest.get_us_time()/1000000
|
minetest.sound_play("experience",{gain=0.1,to_player = name,pitch=math.random(75,99)/100})
|
||||||
minetest.sound_play("experience",{gain=0.1,to_player = name,pitch=math.random(75,99)/100})
|
end
|
||||||
|
temp_pool.bar = temp_pool.bar + temp_pool.bar_step * experience
|
||||||
end
|
end
|
||||||
|
|
||||||
if old_bar ~= temp_pool.bar then
|
if old_bar ~= temp_pool.bar then
|
||||||
hud_manager.change_hud({player = player, hud_name = "experience_bar", element = "number", data = temp_pool.bar})
|
hud_manager.change_hud({player = player, hud_name = "experience_bar", element = "number", data = math.floor(temp_pool.bar)})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -288,7 +292,7 @@ minetest.register_on_dieplayer(function(player)
|
||||||
|
|
||||||
hud_manager.change_hud({player = player, hud_name = "xp_level_fg", element = "text", data = tostring(temp_pool.level)})
|
hud_manager.change_hud({player = player, hud_name = "xp_level_fg", element = "text", data = tostring(temp_pool.level)})
|
||||||
hud_manager.change_hud({player = player, hud_name = "xp_level_bg", element = "text", data = tostring(temp_pool.level)})
|
hud_manager.change_hud({player = player, hud_name = "xp_level_bg", element = "text", data = tostring(temp_pool.level)})
|
||||||
hud_manager.change_hud({player = player, hud_name = "experience_bar", element = "number", data = temp_pool.bar})
|
hud_manager.change_hud({player = player, hud_name = "experience_bar", element = "number", data = math.floor(temp_pool.bar)})
|
||||||
|
|
||||||
mcl_experience.throw_experience(player:get_pos(), xp_amount)
|
mcl_experience.throw_experience(player:get_pos(), xp_amount)
|
||||||
end)
|
end)
|
||||||
|
@ -516,6 +520,9 @@ minetest.register_chatcommand("xp", {
|
||||||
return false, S("Error: Player not found")
|
return false, S("Error: Player not found")
|
||||||
end
|
end
|
||||||
mcl_experience.add_experience(player, xp)
|
mcl_experience.add_experience(player, xp)
|
||||||
|
local playername = player:get_player_name()
|
||||||
|
-- minetest.chat_send_player(name, "Added " .. tostring(xp) .. " XP to " .. playername .. ", they've got " .. tostring(pool[playername].xp) .. " XP, level " .. tostring(pool[playername].level))
|
||||||
|
minetest.chat_send_player(name, S("Added @1 XP to @2, total: @3, experience level: @4", tostring(xp), playername, tostring(pool[playername].xp), tostring(pool[playername].level)))
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -3,3 +3,4 @@ Gives [[player <player>] <xp>] XP=Даёт [[игроку <игрок> [<xp>]]
|
||||||
Error: Too many parameters!=Ошибка: слишком много параметров!
|
Error: Too many parameters!=Ошибка: слишком много параметров!
|
||||||
Error: Incorrect value of XP=Ошибка: Недопустимое значение XP
|
Error: Incorrect value of XP=Ошибка: Недопустимое значение XP
|
||||||
Error: Player not found=Ошибка: Игрок не найден
|
Error: Player not found=Ошибка: Игрок не найден
|
||||||
|
Added @1 XP to @2, total: @3, experience level: @4=Добавляем @1 XP игроку @2, итого: @3, уровень опыта: @4
|
||||||
|
|
|
@ -3,3 +3,4 @@ Gives [[player <player>] <xp>] XP=
|
||||||
Error: Too many parameters!=
|
Error: Too many parameters!=
|
||||||
Error: Incorrect value of XP=
|
Error: Incorrect value of XP=
|
||||||
Error: Player not found=
|
Error: Player not found=
|
||||||
|
Added @1 XP to @2, total: @3, experience level: @4=
|
||||||
|
|
|
@ -31,7 +31,7 @@ minetest.register_node("mcl_core:stone_with_coal", {
|
||||||
tiles = {"mcl_core_coal_ore.png"},
|
tiles = {"mcl_core_coal_ore.png"},
|
||||||
is_ground_content = true,
|
is_ground_content = true,
|
||||||
stack_max = 64,
|
stack_max = 64,
|
||||||
groups = {pickaxey=1, building_block=1, material_stone=1, experience=1},
|
groups = {pickaxey=1, building_block=1, material_stone=1, xp=1},
|
||||||
drop = 'mcl_core:coal_lump',
|
drop = 'mcl_core:coal_lump',
|
||||||
sounds = mcl_sounds.node_sound_stone_defaults(),
|
sounds = mcl_sounds.node_sound_stone_defaults(),
|
||||||
_mcl_blast_resistance = 3,
|
_mcl_blast_resistance = 3,
|
||||||
|
@ -77,7 +77,7 @@ minetest.register_node("mcl_core:stone_with_redstone", {
|
||||||
tiles = {"mcl_core_redstone_ore.png"},
|
tiles = {"mcl_core_redstone_ore.png"},
|
||||||
is_ground_content = true,
|
is_ground_content = true,
|
||||||
stack_max = 64,
|
stack_max = 64,
|
||||||
groups = {pickaxey=4, building_block=1, material_stone=1, experience=7},
|
groups = {pickaxey=4, building_block=1, material_stone=1, xp=7},
|
||||||
drop = {
|
drop = {
|
||||||
items = {
|
items = {
|
||||||
max_items = 1,
|
max_items = 1,
|
||||||
|
@ -110,7 +110,7 @@ minetest.register_node("mcl_core:stone_with_redstone_lit", {
|
||||||
light_source = 9,
|
light_source = 9,
|
||||||
is_ground_content = true,
|
is_ground_content = true,
|
||||||
stack_max = 64,
|
stack_max = 64,
|
||||||
groups = {pickaxey=4, not_in_creative_inventory=1, material_stone=1, experience=7},
|
groups = {pickaxey=4, not_in_creative_inventory=1, material_stone=1, xp=7},
|
||||||
drop = {
|
drop = {
|
||||||
items = {
|
items = {
|
||||||
max_items = 1,
|
max_items = 1,
|
||||||
|
@ -141,7 +141,7 @@ minetest.register_node("mcl_core:stone_with_lapis", {
|
||||||
tiles = {"mcl_core_lapis_ore.png"},
|
tiles = {"mcl_core_lapis_ore.png"},
|
||||||
is_ground_content = true,
|
is_ground_content = true,
|
||||||
stack_max = 64,
|
stack_max = 64,
|
||||||
groups = {pickaxey=3, building_block=1, material_stone=1, experience=6},
|
groups = {pickaxey=3, building_block=1, material_stone=1, xp=6},
|
||||||
drop = {
|
drop = {
|
||||||
max_items = 1,
|
max_items = 1,
|
||||||
items = {
|
items = {
|
||||||
|
@ -163,7 +163,7 @@ minetest.register_node("mcl_core:stone_with_emerald", {
|
||||||
tiles = {"mcl_core_emerald_ore.png"},
|
tiles = {"mcl_core_emerald_ore.png"},
|
||||||
is_ground_content = true,
|
is_ground_content = true,
|
||||||
stack_max = 64,
|
stack_max = 64,
|
||||||
groups = {pickaxey=4, building_block=1, material_stone=1, experience=6},
|
groups = {pickaxey=4, building_block=1, material_stone=1, xp=6},
|
||||||
drop = "mcl_core:emerald",
|
drop = "mcl_core:emerald",
|
||||||
sounds = mcl_sounds.node_sound_stone_defaults(),
|
sounds = mcl_sounds.node_sound_stone_defaults(),
|
||||||
_mcl_blast_resistance = 3,
|
_mcl_blast_resistance = 3,
|
||||||
|
@ -176,7 +176,7 @@ minetest.register_node("mcl_core:stone_with_diamond", {
|
||||||
tiles = {"mcl_core_diamond_ore.png"},
|
tiles = {"mcl_core_diamond_ore.png"},
|
||||||
is_ground_content = true,
|
is_ground_content = true,
|
||||||
stack_max = 64,
|
stack_max = 64,
|
||||||
groups = {pickaxey=4, building_block=1, material_stone=1, experience=4},
|
groups = {pickaxey=4, building_block=1, material_stone=1, xp=4},
|
||||||
drop = "mcl_core:diamond",
|
drop = "mcl_core:diamond",
|
||||||
sounds = mcl_sounds.node_sound_stone_defaults(),
|
sounds = mcl_sounds.node_sound_stone_defaults(),
|
||||||
_mcl_blast_resistance = 3,
|
_mcl_blast_resistance = 3,
|
||||||
|
|
|
@ -35,7 +35,7 @@ minetest.register_node("mcl_nether:quartz_ore", {
|
||||||
stack_max = 64,
|
stack_max = 64,
|
||||||
tiles = {"mcl_nether_quartz_ore.png"},
|
tiles = {"mcl_nether_quartz_ore.png"},
|
||||||
is_ground_content = true,
|
is_ground_content = true,
|
||||||
groups = {pickaxey=1, building_block=1, material_stone=1, experience=3},
|
groups = {pickaxey=1, building_block=1, material_stone=1, xp=3},
|
||||||
drop = 'mcl_nether:quartz',
|
drop = 'mcl_nether:quartz',
|
||||||
sounds = mcl_sounds.node_sound_stone_defaults(),
|
sounds = mcl_sounds.node_sound_stone_defaults(),
|
||||||
_mcl_blast_resistance = 3,
|
_mcl_blast_resistance = 3,
|
||||||
|
|
Loading…
Reference in New Issue