mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-04 23:31:05 +01:00
trading gives the player experience
This commit is contained in:
parent
21dbc25f13
commit
9809c627dc
1 changed files with 14 additions and 0 deletions
|
@ -1989,6 +1989,17 @@ local trade_inventory = {
|
|||
-- Otherwise, 20% chance to unlock if used freshly reset trade
|
||||
unlock_stuff = true
|
||||
end
|
||||
-- calculate xp based on the price
|
||||
local emeralds = 0
|
||||
if wanted1:get_name() == "mcl_core:emerald" then
|
||||
emeralds = wanted1:get_count()
|
||||
elseif wanted2:get_name() == "mcl_core:emerald" then
|
||||
emeralds = wanted2:get_count()
|
||||
else
|
||||
local offered = inv:get_stack("offered", 1)
|
||||
emeralds = offered:get_name() == "mcl_core:emerald" and offered:get_count() or 0
|
||||
end
|
||||
local xp = 2 + math.ceil(emeralds / (64/4)) -- 1..64 emeralds = 3..6 xp
|
||||
local update_formspec = false
|
||||
if unlock_stuff then
|
||||
-- First-time trade unlock all trades and unlock next trade tier
|
||||
|
@ -2000,6 +2011,7 @@ local trade_inventory = {
|
|||
set_textures(trader)
|
||||
update_max_tradenum(trader)
|
||||
update_formspec = true
|
||||
xp = xp + 5
|
||||
end
|
||||
for t=1, #trades do
|
||||
trades[t].locked = false
|
||||
|
@ -2010,6 +2022,7 @@ local trade_inventory = {
|
|||
-- TODO: Replace by Regeneration I
|
||||
trader.health = math.min(trader.hp_max, trader.health + 4)
|
||||
end
|
||||
mcl_experience.add_xp(player, xp)
|
||||
trade.trade_counter = trade.trade_counter + 1
|
||||
mcl_log("Trade counter is: ".. trade.trade_counter)
|
||||
-- Semi-randomly lock trade for repeated trade (not if there's only 1 trade)
|
||||
|
@ -2047,6 +2060,7 @@ local trade_inventory = {
|
|||
if update_formspec then
|
||||
show_trade_formspec(name, trader, tradenum)
|
||||
end
|
||||
|
||||
else
|
||||
minetest.log("error", "[mobs_mc] Player took item from trader output but player_trading_with or player_tradenum is nil!")
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue