mirror of
https://github.com/FaceDeer/dfcaverns.git
synced 2025-07-18 16:30:27 +02:00
add some art
This commit is contained in:
@ -5,27 +5,39 @@ 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)
|
||||
if unlocks_string == nil then
|
||||
collectible_lore.get_player_collected = function(player_name)
|
||||
local collected_string = modmeta:get("player_" .. player_name)
|
||||
if collected_string == nil then
|
||||
return {}
|
||||
else
|
||||
return minetest.deserialize(unlocks_string)
|
||||
return minetest.deserialize(collected_string)
|
||||
end
|
||||
end
|
||||
|
||||
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))
|
||||
collectible_lore.get_player_uncollected_list = function(player_name)
|
||||
local collected = collectible_lore.get_player_collected(player_name)
|
||||
--minetest.debug(dump(collected))
|
||||
local uncollected = {}
|
||||
for index, def in pairs(collectible_lore.lorebooks) do
|
||||
if not collected[def.id] then
|
||||
table.insert(uncollected, index)
|
||||
end
|
||||
end
|
||||
return uncollected
|
||||
end
|
||||
|
||||
collectible_lore.unlock = function(player_name, id)
|
||||
set_lock(player_name, id, true)
|
||||
local set_collected = function(player_name, id, state)
|
||||
local collected = collectible_lore.get_player_collected(player_name)
|
||||
collected[id] = state
|
||||
modmeta:set_string("player_" .. player_name, minetest.serialize(collected))
|
||||
end
|
||||
|
||||
collectible_lore.lock = function(player_name, id)
|
||||
set_lock(player_name, id, nil)
|
||||
collectible_lore.collect = function(player_name, id)
|
||||
set_collected(player_name, id, true)
|
||||
end
|
||||
|
||||
collectible_lore.uncollect = function(player_name, id)
|
||||
set_collected(player_name, id, nil)
|
||||
end
|
||||
|
||||
local collectible_lore_sort = function(first, second)
|
||||
@ -56,27 +68,27 @@ end
|
||||
|
||||
|
||||
minetest.register_chatcommand("collectible", {
|
||||
params = "[lock|unlock|clear|show] <player_name> <id>", -- Short parameter description
|
||||
description = "Remove privilege from player",
|
||||
params = "[collect|uncollect|clear|show] <player_name> <id>", -- Short parameter description
|
||||
description = S("Administrative control of collectibles"),
|
||||
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)
|
||||
if first == "uncollect" and second and third then
|
||||
collectible_lore.uncollect(second, third)
|
||||
return
|
||||
elseif first == "unlock" and second and third then
|
||||
collectible_lore.unlock(second, third)
|
||||
elseif first == "collect" and second and third then
|
||||
collectible_lore.collect(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)))
|
||||
minetest.chat_send_player(name, dump(collectible_lore.get_player_collected(second)))
|
||||
return
|
||||
end
|
||||
|
||||
minetest.chat_send_player(name, "error parsing command")
|
||||
minetest.chat_send_player(name, S("error parsing command"))
|
||||
end,
|
||||
})
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
local S = minetest.get_translator(minetest.get_current_modname())
|
||||
local modmeta = minetest.get_mod_storage()
|
||||
|
||||
cairn_spacing = tonumber(minetest.settings:get("collectible_lore_cairn_spacing")) or 500
|
||||
|
||||
local cairn_area = AreaStore()
|
||||
|
||||
local existing_area = modmeta:get("areastore_cairn")
|
||||
@ -25,15 +27,25 @@ local cairn_loot = function(pos, player)
|
||||
if not player_name then return end
|
||||
|
||||
local list = get_cairn_looted_by_list(pos)
|
||||
if list[player_name] then
|
||||
return false
|
||||
end
|
||||
-- if list[player_name] then
|
||||
-- minetest.chat_send_player(player_name, S("You've already collected the contents of this cairn."))
|
||||
-- return false
|
||||
-- end
|
||||
list[player_name] = true
|
||||
local lore_id = collectible_lore.lorebooks[math.random(#(collectible_lore.lorebooks))].id
|
||||
collectible_lore.unlock(player_name, lore_id)
|
||||
minetest.debug("unlocked " .. lore_id)
|
||||
list[player_name] = true
|
||||
set_cairn_looted_by_list(pos, list)
|
||||
|
||||
local uncollected = collectible_lore.get_player_uncollected_list(player_name)
|
||||
--minetest.debug(dump(uncollected))
|
||||
if next(uncollected) then
|
||||
local random_lorebook = uncollected[math.random(#uncollected)]
|
||||
collectible_lore.collect(player_name, collectible_lore.lorebooks[random_lorebook].id)
|
||||
minetest.show_formspec(player_name, "collectible_lore:collected",
|
||||
"formspec_version[6]size[8,2]label[0.5,0.5;" .. S("You've found a collectible item of lore titled:\n@1", collectible_lore.lorebooks[random_lorebook].title) .. "]")
|
||||
list[player_name] = true
|
||||
set_cairn_looted_by_list(pos, list)
|
||||
else
|
||||
minetest.show_formspec(player_name, "collectible_lore:collected",
|
||||
"formspec_version[6]size[8,2]label[0.5,0.5;" .. S("You've found all of the collectible items contained in cairns like this one").."]")
|
||||
end
|
||||
|
||||
local leftover = player:get_inventory():add_item("main", "collectible_lore:satchel")
|
||||
if not leftover:is_empty() then
|
||||
@ -42,9 +54,6 @@ local cairn_loot = function(pos, player)
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
local range = 10
|
||||
|
||||
minetest.register_node("collectible_lore:cairn", {
|
||||
description = S("Cairn"),
|
||||
drawtype = "nodebox",
|
||||
@ -91,17 +100,17 @@ minetest.register_node("collectible_lore:cairn", {
|
||||
end
|
||||
end,
|
||||
on_construct = function(pos)
|
||||
local nearby = cairn_area:get_areas_in_area(vector.subtract(pos, range/2), vector.add(pos, range/2))
|
||||
local nearby = cairn_area:get_areas_in_area(vector.subtract(pos, cairn_spacing/2), vector.add(pos, cairn_spacing/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))
|
||||
minetest.log("error", "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))
|
||||
collectible_lore.get_nearby_cairns = function(pos, spacing)
|
||||
local nearby = cairn_area:get_areas_in_area(vector.subtract(pos, spacing/2), vector.add(pos, spacing/2))
|
||||
if next(nearby) then
|
||||
return nearby
|
||||
end
|
||||
@ -109,47 +118,52 @@ collectible_lore.get_nearby_cairns = function(pos)
|
||||
end
|
||||
|
||||
collectible_lore.place_cairn = function(pos)
|
||||
cairn_area:insert_area(pos, pos, "")
|
||||
modmeta:set_string("areastore_cairn", cairn_area:to_string())
|
||||
local nearby = collectible_lore.get_nearby_cairns(pos, cairn_spacing)
|
||||
if nearby then return end
|
||||
minetest.place_node(pos, {name="collectible_lore:cairn"})
|
||||
end
|
||||
|
||||
local player_state = {}
|
||||
|
||||
|
||||
local get_formspec_for_player = function(player_name)
|
||||
local selected
|
||||
local state = player_state[player_name] or 1
|
||||
local unlocks = collectible_lore.get_player_unlocks(player_name)
|
||||
local collected = collectible_lore.get_player_collected(player_name)
|
||||
local collected_count = 0
|
||||
for index, val in pairs(collected) do
|
||||
collected_count = collected_count + 1
|
||||
end
|
||||
|
||||
local form = {}
|
||||
table.insert(form, "formspec_version[6]size[10,8]")
|
||||
table.insert(form, "textlist[0,0;4,7;list;")
|
||||
local count = 1
|
||||
for index, value in pairs(collectible_lore.lorebooks) do
|
||||
local unlocked = unlocks[value.id]
|
||||
if unlocked and state == count then
|
||||
selected = value
|
||||
table.insert(form, "formspec_version[6]size[14,8]")
|
||||
table.insert(form, "textlist[0.5,0.5;5,6.5;list;")
|
||||
if collected_count > 0 then
|
||||
local count = 1
|
||||
for index, value in pairs(collectible_lore.lorebooks) do
|
||||
local iscollected = collected[value.id]
|
||||
if iscollected and state == count then
|
||||
selected = value
|
||||
end
|
||||
count = count + 1
|
||||
if iscollected then
|
||||
table.insert(form, minetest.formspec_escape(value.title))
|
||||
else
|
||||
table.insert(form, S("<Not found yet>"))
|
||||
end
|
||||
table.insert(form, ",")
|
||||
end
|
||||
count = count + 1
|
||||
if unlocked then
|
||||
table.insert(form, minetest.formspec_escape(value.title))
|
||||
else
|
||||
table.insert(form, S("<Locked>"))
|
||||
end
|
||||
table.insert(form, ",")
|
||||
table.remove(form) -- removes trailing comma
|
||||
end
|
||||
table.remove(form) -- removes trailing comma
|
||||
table.insert(form, ";" .. state .. "]")
|
||||
|
||||
table.insert(form, "textarea[4.5,0;5.5,7;;text;")
|
||||
|
||||
if selected then
|
||||
local str = selected.text
|
||||
table.insert(form, minetest.formspec_escape(str))
|
||||
else
|
||||
table.insert(form, " ")
|
||||
table.insert(form, "label[6,0.5;" .. minetest.formspec_escape(selected.title) .. "]")
|
||||
if selected.text then
|
||||
table.insert(form, "textarea[6,1;7.5,6.5;;;" .. minetest.formspec_escape(selected.text) .. "]")
|
||||
elseif selected.image then
|
||||
table.insert(form, "image[6.5,1;6.5,6.5;" .. selected.image .. "]")
|
||||
end
|
||||
end
|
||||
table.insert(form, "]")
|
||||
table.insert(form, "label[0.5,7.5;" .. S("Collected: @1/@2", collected_count, #(collectible_lore.lorebooks)) .. "]")
|
||||
|
||||
return table.concat(form)
|
||||
end
|
||||
|
@ -1,8 +1,19 @@
|
||||
# textdomain: collectible_lore
|
||||
|
||||
|
||||
### init.lua ###
|
||||
|
||||
Administrative control of collectibles=
|
||||
error parsing command=
|
||||
|
||||
### items.lua ###
|
||||
|
||||
<Locked>=
|
||||
<Not found yet>=
|
||||
Cairn=
|
||||
Collected: @1/@2=
|
||||
Collectibles Satchel=
|
||||
You've already collected the contents of this cairn.=
|
||||
You've found a collectible item of lore titled:@n@1=
|
||||
|
||||
You've found all of the collectible items contained in cairns like this one=
|
||||
|
||||
|
1
collectible_lore/settingtypes.txt
Normal file
1
collectible_lore/settingtypes.txt
Normal file
@ -0,0 +1 @@
|
||||
collectible_lore_cairn_spacing (Minimum distance between collectible cairns) int 500
|
Reference in New Issue
Block a user