1
0
Fork 0

Pick random villager profession on spawn

This commit is contained in:
Wuzzy 2018-06-04 14:59:10 +02:00
parent f1dc75f097
commit 10e2c174d4
1 changed files with 42 additions and 13 deletions

View File

@ -11,9 +11,11 @@ local S, NS = dofile(MP.."/intllib.lua")
--################### VILLAGER --################### VILLAGER
--################### --###################
-- LIST OF VILLAGES PROFESSIONS AND TRADES
local E1 = { "mcl_core:emerald", 1, 1 } -- one emerald local E1 = { "mcl_core:emerald", 1, 1 } -- one emerald
local professions = { local professions = {
{ farmer = {
id = "farmer",
name = "Farmer", name = "Farmer",
trades = { trades = {
{ {
@ -39,7 +41,8 @@ local professions = {
}, },
} }
}, },
{ fisherman = {
id = "fisherman",
name = "Fisherman", name = "Fisherman",
trades = { trades = {
{ {
@ -50,7 +53,8 @@ local professions = {
-- TODO: enchanted fishing rod -- TODO: enchanted fishing rod
}, },
}, },
{ fletcher = {
id = "fletcher",
name = "Fletcher", name = "Fletcher",
trades = { trades = {
{ {
@ -64,7 +68,8 @@ local professions = {
}, },
} }
}, },
{ shepherd ={
id = "shepherd",
name = "Shepherd", name = "Shepherd",
trades = { trades = {
{ {
@ -91,7 +96,8 @@ local professions = {
}, },
}, },
}, },
{ librarian = {
id = "librarian",
name = "Librarian", name = "Librarian",
trades = { trades = {
{ {
@ -119,7 +125,8 @@ local professions = {
} }
}, },
}, },
{ cartographer = {
id = "cartographer",
name = "Cartographer", name = "Cartographer",
trades = { trades = {
{ {
@ -138,7 +145,8 @@ local professions = {
-- TODO: special maps -- TODO: special maps
}, },
}, },
{ armorer = {
id = "armorer",
name = "Armorer", name = "Armorer",
trades = { trades = {
{ {
@ -165,7 +173,7 @@ local professions = {
}, },
}, },
}, },
{ leatherworker = {
name = "Leatherworker", name = "Leatherworker",
trades = { trades = {
{ {
@ -183,7 +191,7 @@ local professions = {
}, },
}, },
}, },
{ butcher = {
name = "Butcher", name = "Butcher",
trades = { trades = {
{ {
@ -198,7 +206,7 @@ local professions = {
}, },
}, },
}, },
{ weapon_smith = {
name = "Weapon Smith", name = "Weapon Smith",
trades = { trades = {
{ {
@ -221,7 +229,7 @@ local professions = {
}, },
}, },
}, },
{ tool_smith = {
name = "Tool Smith", name = "Tool Smith",
trades = { trades = {
{ {
@ -243,7 +251,7 @@ local professions = {
}, },
}, },
}, },
{ cleric = {
name = "Cleric", name = "Cleric",
trades = { trades = {
{ {
@ -267,6 +275,21 @@ local professions = {
-- TODO: Nitwit -- TODO: Nitwit
} }
local profession_names = {}
for id, _ in pairs(professions) do
table.insert(profession_names, id)
end
local init_profession = function(self)
if not self._profession then
local p = math.random(1, #profession_names)
self._profession = profession_names[p]
end
if not self._max_trade_tier then
-- TODO: Randomize
self._max_trade_tier = 10
end
end
mobs:register_mob("mobs_mc:villager", { mobs:register_mob("mobs_mc:villager", {
type = "npc", type = "npc",
@ -414,7 +437,9 @@ mobs:register_mob("mobs_mc:villager", {
inv:set_stack("offered", i, "") inv:set_stack("offered", i, "")
end end
local profession = professions[math.random(1, #professions)] init_profession(self)
local profession = professions[self._profession]
local trade_tiers = profession.trades local trade_tiers = profession.trades
if trade_tiers == nil then if trade_tiers == nil then
return return
@ -452,6 +477,10 @@ mobs:register_mob("mobs_mc:villager", {
minetest.sound_play("mobs_mc_villager_trade", {to_player = clicker:get_player_name()}) minetest.sound_play("mobs_mc_villager_trade", {to_player = clicker:get_player_name()})
minetest.show_formspec(clicker:get_player_name(), "mobs_mc:trade", formspec) minetest.show_formspec(clicker:get_player_name(), "mobs_mc:trade", formspec)
end, end,
on_spawn = function(self)
init_profession(self)
end,
}) })
-- Returns a single itemstack in the given inventory to the player's main inventory, or drop it when there's no space left -- Returns a single itemstack in the given inventory to the player's main inventory, or drop it when there's no space left