Fix multithreaded addition of XP
This commit is contained in:
parent
9f98117328
commit
38ad237d92
|
@ -238,31 +238,31 @@ 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.min(math.max(temp_pool.xp + experience, 0), max_xp)
|
temp_pool.xp = math.min(math.max(temp_pool.xp + experience, 0), max_xp)
|
||||||
if (temp_pool.xp >= temp_pool.xp_next_level) or (temp_pool.xp < old_xp) then
|
|
||||||
|
if (temp_pool.xp < temp_pool.xp_next_level) and (temp_pool.xp >= old_xp) then
|
||||||
|
temp_pool.bar = temp_pool.bar + temp_pool.bar_step * experience
|
||||||
|
else
|
||||||
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.bar_step, 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
|
|
||||||
if experience > 0 then
|
|
||||||
minetest.sound_play("level_up",{gain=0.2,to_player = name})
|
|
||||||
end
|
|
||||||
temp_pool.last_time = minetest.get_us_time()/1000000
|
|
||||||
end
|
|
||||||
hud_manager.change_hud({player = player, hud_name = "xp_level", element = "text", data = tostring(temp_pool.level)})
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if minetest.get_us_time()/1000000 - temp_pool.last_time > 0.01 then
|
|
||||||
temp_pool.last_time = minetest.get_us_time()/1000000
|
|
||||||
if experience > 0 then
|
|
||||||
minetest.sound_play("experience",{gain=0.1,to_player = name,pitch=math.random(75,99)/100})
|
|
||||||
end
|
|
||||||
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 = math.floor(temp_pool.bar)})
|
hud_manager.change_hud({player = player, hud_name = "experience_bar", element = "number", data = math.floor(temp_pool.bar)})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if experience > 0 and minetest.get_us_time()/1000000 - temp_pool.last_time > 0.01 then
|
||||||
|
if old_level ~= temp_pool.level then
|
||||||
|
minetest.sound_play("level_up",{gain=0.2,to_player = name})
|
||||||
|
temp_pool.last_time = minetest.get_us_time()/1000000 + 0.2
|
||||||
|
else
|
||||||
|
minetest.sound_play("experience",{gain=0.1,to_player = name,pitch=math.random(75,99)/100})
|
||||||
|
temp_pool.last_time = minetest.get_us_time()/1000000
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if old_level ~= temp_pool.level then
|
||||||
|
hud_manager.change_hud({player = player, hud_name = "xp_level", element = "text", data = tostring(temp_pool.level)})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--reset player level
|
--reset player level
|
||||||
|
|
Loading…
Reference in New Issue
Block a user