getting ready to add mapgen

This commit is contained in:
FaceDeer 2023-02-11 20:06:51 -07:00
parent d5f95d3be9
commit 0ea940f104
2 changed files with 84 additions and 11 deletions

View File

@ -3,6 +3,7 @@ local S = minetest.get_translator(minetest.get_current_modname())
local modmeta = minetest.get_mod_storage()
collectible_lore = {}
collectible_lore.lorebooks = {}
collectible_lore.get_player_unlocks = function(player_name)
local unlocks_string = modmeta:get("player_" .. player_name)
@ -13,17 +14,19 @@ collectible_lore.get_player_unlocks = function(player_name)
end
end
local set_player_unlocks = function(player_name, unlocks_table)
modmeta:set_string("player_" .. player_name, minetest.serialize(unlocks_table))
local set_lock = function(player_name, id, state)
local unlocks = collectible_lore.get_player_unlocks(player_name)
unlocks[id] = state
modmeta:set_string("player_" .. player_name, minetest.serialize(unlocks))
end
collectible_lore.unlock = function(player_name, id)
local unlocks = collectible_lore.get_player_unlocks(player_name)
unlocks[id] = true
set_player_unlocks(player_name, unlocks)
set_lock(player_name, id, true)
end
dofile(modpath.."/items.lua")
collectible_lore.lock = function(player_name, id)
set_lock(player_name, id, nil)
end
local collectible_lore_sort = function(first, second)
if (first.sort or 0) < (second.sort or 0) then
@ -35,14 +38,11 @@ local collectible_lore_sort = function(first, second)
return false
end
collectible_lore.lorebooks = {}
local ids = {}
collectible_lore.register_lorebook = function(def)
if def.id == nil then
minetest.log("error", "[collectible_lore] Nil id for def " .. dump(def))
minetest.log("error", "[collectible_lore] nil id for def " .. dump(def))
return false
end
if ids[def.id] then
@ -54,3 +54,31 @@ collectible_lore.register_lorebook = function(def)
table.sort(collectible_lore.lorebooks, collectible_lore_sort)
end
minetest.register_chatcommand("collectible", {
params = "[lock|unlock|clear|show] <player_name> <id>", -- Short parameter description
description = "Remove privilege from player",
privs = {server=true},
func = function(name, param)
local first, second, third = param:match("^([^%s]+)%s+(%S+)%s*(.*)")
if third == "" then third = nil end
if first == "lock" and second and third then
collectible_lore.lock(second, third)
return
elseif first == "unlock" and second and third then
collectible_lore.unlock(second, third)
return
elseif first == "clear" and second then
modmeta:set_string("player_" .. second, minetest.serialize({}))
return
elseif first == "show" and second then
minetest.chat_send_player(name, dump(collectible_lore.get_player_unlocks(second)))
return
end
minetest.chat_send_player(name, "error parsing command")
end,
})
dofile(modpath.."/items.lua")

View File

@ -1,6 +1,13 @@
local S = minetest.get_translator(minetest.get_current_modname())
local modmeta = minetest.get_mod_storage()
local cairn_area = AreaStore()
local existing_area = modmeta:get("areastore_cairn")
if existing_area then
cairn_area:from_string(existing_area)
end
local get_cairn_looted_by_list = function(pos)
local loot_list_string = modmeta:get("cairn_" .. minetest.pos_to_string(pos))
if not loot_list_string then
@ -28,6 +35,8 @@ local cairn_loot = function(pos, player_name)
end
local range = 10
minetest.register_node("collectible_lore:cairn", {
description = S("Cairn"),
drawtype = "nodebox",
@ -61,8 +70,44 @@ minetest.register_node("collectible_lore:cairn", {
cairn_loot(pos, player_name)
end
end,
is_ground_content = true,
groups = {cracky = 3},
can_dig = function(pos, player)
return minetest.check_player_privs(player, {server = true})
end,
on_destruct = function(pos)
modmeta:set_string("cairn_" .. minetest.pos_to_string(pos), "")
local this_cairn = cairn_area:get_areas_for_pos(pos)
for index, data in pairs(this_cairn) do
minetest.debug("removing " .. dump(index))
cairn_area:remove_area(index)
modmeta:set_string("areastore_cairn", cairn_area:to_string())
end
end,
on_construct = function(pos)
local nearby = cairn_area:get_areas_in_area(vector.subtract(pos, range/2), vector.add(pos, range/2))
if next(nearby) then
minetest.debug("Cairn placed too close to other cairns. Placed at: " .. minetest.pos_to_string(pos) .."\nnearby:\n" .. dump(nearby))
end
cairn_area:insert_area(pos, pos, "")
modmeta:set_string("areastore_cairn", cairn_area:to_string())
end,
})
collectible_lore.get_nearby_cairns = function(pos)
local nearby = cairn_area:get_areas_in_area(vector.subtract(pos, range/2), vector.add(pos, range/2))
if next(nearby) then
return nearby
end
return nil
end
collectible_lore.place_cairn = function(pos)
cairn_area:insert_area(pos, pos, "")
modmeta:set_string("areastore_cairn", cairn_area:to_string())
end
local player_state = {}
@ -106,7 +151,7 @@ end
minetest.register_craftitem("collectible_lore:ledger", {
description = S("Collectible Ledger"),
inventory_image = "df_lorebooks_ledger.png",
inventory_image = "collectible_lore_ledger.png",
stack_max = 99,
on_use = function(itemstack, user, pointed_thing)
local player_name = user:get_player_name()