0
0
Fork 0
This commit is contained in:
kay27 2020-10-24 02:46:45 +04:00
parent 290893355b
commit 30d9e54803
6 changed files with 53 additions and 44 deletions

View File

@ -227,7 +227,7 @@ function minetest.handle_node_drops(pos, drops, digger)
local toolcaps
if digger ~= nil 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
mcl_experience.throw_experience(pos, experience_amount)
end

View File

@ -39,7 +39,7 @@ local load_data = function(player)
local meta = player:get_meta()
temp_pool.xp = meta:get_int("xp") or 0
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
end
@ -132,31 +132,21 @@ minetest.register_on_shutdown(function()
end)
local name
function mcl_experience.get_player_xp_level(player)
name = player:get_player_name()
local name = player:get_player_name()
return(pool[name].level)
end
local name
local temp_pool
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].xp = mcl_experience.level_to_xp(level)
--todo: update bar
hud_manager.change_hud({
player = player,
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)
})
pool[name].xp, pool[name].next_level = mcl_experience.bar_to_xp(pool[name].bar, level)
hud_manager.change_hud({player = player, 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)})
-- we may don't update the bar
end
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 xp_this_level = mcl_experience.level_to_xp(level)
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)
return bar, xp_next_level
local bar_step = 36 / (xp_next_level-xp_this_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
function mcl_experience.add_experience(player, experience)
@ -250,8 +249,9 @@ function mcl_experience.add_experience(player, experience)
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)
if (temp_pool.xp >= temp_pool.xp_next_level) or (experience < 1) then
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)
if old_level ~= temp_pool.level then
if minetest.get_us_time()/1000000 - temp_pool.last_time > 0.04 then
minetest.sound_play("level_up",{gain=0.2,to_player = name})
@ -259,13 +259,17 @@ function mcl_experience.add_experience(player, experience)
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)})
elseif minetest.get_us_time()/1000000 - temp_pool.last_time > 0.01 then
end
else
if minetest.get_us_time()/1000000 - temp_pool.last_time > 0.01 then
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})
end
temp_pool.bar = temp_pool.bar + temp_pool.bar_step * experience
end
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
@ -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_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)
end)
@ -516,6 +520,9 @@ minetest.register_chatcommand("xp", {
return false, S("Error: Player not found")
end
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,
})

View File

@ -3,3 +3,4 @@ Gives [[player <player>] <xp>] XP=Даёт [[игроку <игрок> [<xp>]]
Error: Too many parameters!=Ошибка: слишком много параметров!
Error: Incorrect value of XP=Ошибка: Недопустимое значение XP
Error: Player not found=Ошибка: Игрок не найден
Added @1 XP to @2, total: @3, experience level: @4=Добавляем @1 XP игроку @2, итого: @3, уровень опыта: @4

View File

@ -3,3 +3,4 @@ Gives [[player <player>] <xp>] XP=
Error: Too many parameters!=
Error: Incorrect value of XP=
Error: Player not found=
Added @1 XP to @2, total: @3, experience level: @4=

View File

@ -31,7 +31,7 @@ minetest.register_node("mcl_core:stone_with_coal", {
tiles = {"mcl_core_coal_ore.png"},
is_ground_content = true,
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',
sounds = mcl_sounds.node_sound_stone_defaults(),
_mcl_blast_resistance = 3,
@ -77,7 +77,7 @@ minetest.register_node("mcl_core:stone_with_redstone", {
tiles = {"mcl_core_redstone_ore.png"},
is_ground_content = true,
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 = {
items = {
max_items = 1,
@ -110,7 +110,7 @@ minetest.register_node("mcl_core:stone_with_redstone_lit", {
light_source = 9,
is_ground_content = true,
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 = {
items = {
max_items = 1,
@ -141,7 +141,7 @@ minetest.register_node("mcl_core:stone_with_lapis", {
tiles = {"mcl_core_lapis_ore.png"},
is_ground_content = true,
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 = {
max_items = 1,
items = {
@ -163,7 +163,7 @@ minetest.register_node("mcl_core:stone_with_emerald", {
tiles = {"mcl_core_emerald_ore.png"},
is_ground_content = true,
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",
sounds = mcl_sounds.node_sound_stone_defaults(),
_mcl_blast_resistance = 3,
@ -176,7 +176,7 @@ minetest.register_node("mcl_core:stone_with_diamond", {
tiles = {"mcl_core_diamond_ore.png"},
is_ground_content = true,
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",
sounds = mcl_sounds.node_sound_stone_defaults(),
_mcl_blast_resistance = 3,

View File

@ -35,7 +35,7 @@ minetest.register_node("mcl_nether:quartz_ore", {
stack_max = 64,
tiles = {"mcl_nether_quartz_ore.png"},
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',
sounds = mcl_sounds.node_sound_stone_defaults(),
_mcl_blast_resistance = 3,