mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2024-11-24 20:03:45 +01:00
trading gives the player experience
This commit is contained in:
parent
21dbc25f13
commit
9809c627dc
@ -1989,6 +1989,17 @@ local trade_inventory = {
|
|||||||
-- Otherwise, 20% chance to unlock if used freshly reset trade
|
-- Otherwise, 20% chance to unlock if used freshly reset trade
|
||||||
unlock_stuff = true
|
unlock_stuff = true
|
||||||
end
|
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
|
local update_formspec = false
|
||||||
if unlock_stuff then
|
if unlock_stuff then
|
||||||
-- First-time trade unlock all trades and unlock next trade tier
|
-- First-time trade unlock all trades and unlock next trade tier
|
||||||
@ -2000,6 +2011,7 @@ local trade_inventory = {
|
|||||||
set_textures(trader)
|
set_textures(trader)
|
||||||
update_max_tradenum(trader)
|
update_max_tradenum(trader)
|
||||||
update_formspec = true
|
update_formspec = true
|
||||||
|
xp = xp + 5
|
||||||
end
|
end
|
||||||
for t=1, #trades do
|
for t=1, #trades do
|
||||||
trades[t].locked = false
|
trades[t].locked = false
|
||||||
@ -2010,6 +2022,7 @@ local trade_inventory = {
|
|||||||
-- TODO: Replace by Regeneration I
|
-- TODO: Replace by Regeneration I
|
||||||
trader.health = math.min(trader.hp_max, trader.health + 4)
|
trader.health = math.min(trader.hp_max, trader.health + 4)
|
||||||
end
|
end
|
||||||
|
mcl_experience.add_xp(player, xp)
|
||||||
trade.trade_counter = trade.trade_counter + 1
|
trade.trade_counter = trade.trade_counter + 1
|
||||||
mcl_log("Trade counter is: ".. trade.trade_counter)
|
mcl_log("Trade counter is: ".. trade.trade_counter)
|
||||||
-- Semi-randomly lock trade for repeated trade (not if there's only 1 trade)
|
-- 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
|
if update_formspec then
|
||||||
show_trade_formspec(name, trader, tradenum)
|
show_trade_formspec(name, trader, tradenum)
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
minetest.log("error", "[mobs_mc] Player took item from trader output but player_trading_with or player_tradenum is nil!")
|
minetest.log("error", "[mobs_mc] Player took item from trader output but player_trading_with or player_tradenum is nil!")
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user