mirror of
https://github.com/FaceDeer/dfcaverns.git
synced 2025-07-16 07:20:27 +02:00
add an achievement for collecting all lorebooks
This commit is contained in:
34
collectible_lore/README.md
Normal file
34
collectible_lore/README.md
Normal file
@ -0,0 +1,34 @@
|
||||
This mod provides a framework for adding "lore" collectibles, entries that are either a block of text or an image. Players unlock these collectibles by finding stone cairns, and view them by using a "satchel" object. Note that players are not literally carrying these collectibles, whether they've been unlocked is recorded globally and any satchel will allow them to view their collection.
|
||||
|
||||
This is intended as a somewhat similar concept to achievements, but to reward exploration in general and to provide information about the world the player finds themself in.
|
||||
|
||||
An example:
|
||||
|
||||
collectible_lore.register_lorebook({
|
||||
id = "banks tunnels",
|
||||
title = S("Twisting Tunnels"),
|
||||
text = S([[Today's exploration took us deep into the caverns beneath the surface world. As we progressed, I was reminded of the intricate network of passages that make up the bedrock of this world.
|
||||
|
||||
It is fascinating to see how these passages have been carved by a combination of ancient streams and other mysterious processes that have yet to be fully understood. They twist and turn, making navigation a challenging task. Although it is possible to reach almost any location by following these existing passages, they can be so convoluted that it sometimes makes more sense to simply mine a direct route to your destination.
|
||||
|
||||
The significance of these passages cannot be overstated. They provide a glimpse into the geological history of the world and the forces that shaped it. The passages also hold the promise of valuable mineral deposits and other resources, making them a crucial area of exploration for anyone seeking to unlock the secrets of the earth.
|
||||
|
||||
Signed,
|
||||
Dr. Theodore Banks]]),
|
||||
sort = 101,
|
||||
})
|
||||
|
||||
The id should be a unique string, this is the key that will be recorded when a player unlocks a collectible. The title is shown in the list of collectibles when it is unlocked. The sort value is used to sort items in the collectible list in increasing order; it doesn't have to be unique, items with the same sort number will fall back to sorting by id.
|
||||
|
||||
Instead of text, an image can be shown:
|
||||
|
||||
collectible_lore.register_lorebook({
|
||||
id = "rose watercolor chasm wall",
|
||||
title = S("Chasm Wall, By Amelia Rose"),
|
||||
image = "df_lorebooks_chasm_wall.jpg",
|
||||
sort = 201,
|
||||
})
|
||||
|
||||
Note that currently images and text are mutually exclusive, and images should have a square aspect ratio.
|
||||
|
||||
This mod by itself currently only provides a framework and defines the cairn and satchel nodes, you'll need to provide a mapgen to insert them into your world. The ``collectible_lore.place_cairn`` method checks to see if there are nearby cairns before it goes ahead and places a cairn, preventing them from being bunched too closely together, and should prove useful.
|
@ -5,6 +5,14 @@ local modmeta = minetest.get_mod_storage()
|
||||
collectible_lore = {}
|
||||
collectible_lore.lorebooks = {}
|
||||
|
||||
local ids = {}
|
||||
|
||||
on_collected_callbacks = {}
|
||||
|
||||
collectible_lore.register_on_collected = function(callback)
|
||||
table.insert(on_collected_callbacks, callback)
|
||||
end
|
||||
|
||||
collectible_lore.get_player_collected = function(player_name)
|
||||
local collected_string = modmeta:get("player_" .. player_name)
|
||||
if collected_string == nil then
|
||||
@ -27,9 +35,18 @@ collectible_lore.get_player_uncollected_list = function(player_name)
|
||||
end
|
||||
|
||||
local set_collected = function(player_name, id, state)
|
||||
if not ids[id] then
|
||||
minetest.log("error", "[collectible_lore] Setting state for unknown collectible id " .. id .. " for player " .. player_name)
|
||||
state = nil
|
||||
end
|
||||
local collected = collectible_lore.get_player_collected(player_name)
|
||||
collected[id] = state
|
||||
modmeta:set_string("player_" .. player_name, minetest.serialize(collected))
|
||||
if collected[id] ~= state then
|
||||
collected[id] = state
|
||||
modmeta:set_string("player_" .. player_name, minetest.serialize(collected))
|
||||
for _, callback in ipairs(on_collected_callbacks) do
|
||||
callback(player_name, id, state, collected)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
collectible_lore.collect = function(player_name, id)
|
||||
@ -50,8 +67,6 @@ local collectible_lore_sort = function(first, second)
|
||||
return false
|
||||
end
|
||||
|
||||
local ids = {}
|
||||
|
||||
collectible_lore.register_lorebook = function(def)
|
||||
if def.id == nil then
|
||||
minetest.log("error", "[collectible_lore] nil id for def " .. dump(def))
|
||||
|
@ -90,7 +90,7 @@ minetest.register_node("collectible_lore:cairn", {
|
||||
_doc_items_longdesc = S("A cairn of rocks constructed by a previous explorer to protect documents and supplies."),
|
||||
_doc_items_usagehelp = S("The first time you discover a cairn like this, it may reveal to you some new record or piece of lore. Afterward it can be used as a public storage location."),
|
||||
drawtype = "nodebox",
|
||||
tiles = {df_dependencies.texture_cobble, df_dependencies.texture_cobble, df_dependencies.texture_cobble .. "^(collectible_lore_cairn_marker.png^[opacity:100)"},
|
||||
tiles = {df_dependencies.texture_cobble, df_dependencies.texture_cobble, df_dependencies.texture_cobble .. "^(collectible_lore_cairn_marker.png^[multiply:#100000^[opacity:128)"},
|
||||
is_ground_content = true,
|
||||
groups = {cracky = 3, container=2},
|
||||
_mcl_hardness = 1.5,
|
||||
@ -245,6 +245,15 @@ minetest.register_craftitem("collectible_lore:satchel", {
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "collectible_lore:satchel",
|
||||
recipe = {
|
||||
{"", df_dependencies.node_name_string, ""},
|
||||
{df_dependencies.node_name_string, "", df_dependencies.node_name_string},
|
||||
{df_dependencies.node_name_wool_white, df_dependencies.node_name_wool_white, df_dependencies.node_name_wool_white},
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if formname == "collectible_lore:formspec" then
|
||||
if fields.list then
|
||||
|
Reference in New Issue
Block a user