Skip to content

Commit

Permalink
Mobs: Traders: no race priv usage; detect same race for player & trad…
Browse files Browse the repository at this point in the history
  • Loading branch information
alek13 committed Sep 29, 2023
1 parent 49c8aaa commit 5613053
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
3 changes: 2 additions & 1 deletion mods/lord/Entities/lord_traders/mod.conf
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
name = lord_traders
description = Traders mobs for LORD. (Builtin game mod)
depends = mobs, lottmobs, lottarmor, lottother, lord_money
depends = mobs, lottmobs, lottarmor, lord_classes, lottother, lord_money
optional_d = default, farming, boats, tools, lottblocks, lottplants, lottores, lottthrowing, lottfarming, lottpotion, lord_books

# mobs -- uses common engine 'mobs redo'
# lottmobs -- uses sounds & mod prefix `:lottmobs` for entities. Its for no aliases for old entities on map.
# lottarmor -- uses model (& goods)
# lord_classes -- uses for detect player race
# lottother -- follows lottother:narya (& goods)
# lord_money -- trading coins
#other mods uses for trading (items/goods)
2 changes: 1 addition & 1 deletion mods/lord/Entities/lord_traders/src/traders/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ trader_config.hobbit = {
trader_config.man = {
goods = table.merge(trader_config.common_goods, {
["default:sandstone 40"] = { price = 100, chance = 12, stock = 1 },
["lord_boats:sail_boat 1"] = { price = 40, chance = 14, stock = 1 },
["lord_boats:sail_boat 1"] = { price = 40, chance = 14, stock = 1 },
["lottarmor:shield_bronze 1"] = { price = 200, chance = 20, stock = 1 },
["farming:bread 12"] = { price = 20, chance = 5, stock = 1 },
["lottblocks:marble_brick 35"] = { price = 120, chance = 10, stock = 1 },
Expand Down
20 changes: 9 additions & 11 deletions mods/lord/Entities/lord_traders/src/traders/trader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,10 @@ local common_trader_definition = {

------------------------------------------------------------------------------------------------------------------------

--- @param entity LuaEntity
--- @param clicker Player
--- @param race string
--- @param race_privilege string
local function on_rightclick(entity, clicker, race, race_privilege)
--- @param entity LuaEntity
--- @param clicker Player
--- @param race string
local function on_rightclick(entity, clicker, race)
face_pos(entity, clicker:get_pos())
local player_name = clicker:get_player_name()

Expand All @@ -88,22 +87,21 @@ local function on_rightclick(entity, clicker, race, race_privilege)
tostring(trader_config.messages[math.random(1, #trader_config.messages)]) -- messages already translated
)

local inventory_id = Inventory:new(clicker, entity, trader_config.goods, race_privilege):get_id()
local same_race = races.get_race(clicker:get_player_name()) == race
local inventory_id = Inventory:new(clicker, entity, trader_config.goods, same_race):get_id()
Form:new(clicker, inventory_id, entity.game_name):open()

end

--- @param name string
--- @param definition table
local function register_trader(name, definition)
local def = table.merge(common_trader_definition, definition)
-- TODO: clean up privileges like 'GAME*'. See #1157
local race_privilege = "GAME" .. def.race -- GAMEelf, GAMEman, GAMEhobbit, GAMEdwarf, GAMEorc
local def = table.merge(common_trader_definition, definition)

-- HACK: we can't move this into `common_trader_definition`, because we need `def.race`,
-- but `mobs:register_mob()` does not pass all `def` into `minetest.register_entity()`
def.on_rightclick = function(self, clicker)
on_rightclick(self, clicker, def.race, race_privilege)
def.on_rightclick = function(self, clicker)
on_rightclick(self, clicker, def.race)
end

mobs:register_mob(name, def)
Expand Down
14 changes: 6 additions & 8 deletions mods/lord/Entities/lord_traders/src/traders/trader/Inventory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -207,21 +207,19 @@ end

--- Constructor
--- @public
--- @param player Player
--- @param entity LuaEntity
--- @param goods_config traders.config.good[]
--- @param race_privilege string
--- @param player Player
--- @param entity LuaEntity
--- @param goods_config traders.config.good[]
--- @param same_race boolean
--- @return traders.trader.Inventory
function Inventory:new(player, entity, goods_config, race_privilege)
function Inventory:new(player, entity, goods_config, same_race)
local class = self
self = {}

self.player_name = player:get_player_name()
self.entity_id = entity.id
self.goods_config = goods_config
if minetest.get_player_privs(self.player_name)[race_privilege] ~= nil then
self.same_race = true
end
self.same_race = same_race

return setmetatable(self, { __index = class })
end
Expand Down

0 comments on commit 5613053

Please sign in to comment.