From 9809c627dc44e4f2c29bae8c9c354d18cced4bb1 Mon Sep 17 00:00:00 2001 From: nixnoxus Date: Sat, 9 Mar 2024 15:06:38 +0100 Subject: [PATCH] trading gives the player experience --- mods/ENTITIES/mobs_mc/villager.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/mods/ENTITIES/mobs_mc/villager.lua b/mods/ENTITIES/mobs_mc/villager.lua index 3a7dbb93b..2897650c8 100644 --- a/mods/ENTITIES/mobs_mc/villager.lua +++ b/mods/ENTITIES/mobs_mc/villager.lua @@ -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