113 lines
4.4 KiB
Lua
113 lines
4.4 KiB
Lua
|
|
reward_inv = {}
|
|
|
|
-- save reward_inv.player_data in this file:
|
|
reward_inv.file_name_player_data = "reward_inv_player_data.data"
|
|
-- save reward_inv.inv_data in this file:
|
|
reward_inv.file_name_inv_data = "reward_inv_inv_data.data"
|
|
|
|
-- key: player name; value: reward_id the player is currently accessing
|
|
reward_inv.player_using = {}
|
|
|
|
-- key: player name; value: true if the player is in edit mode
|
|
reward_inv.player_is_editing = {}
|
|
|
|
-- per-player status of the reward inventories; key: reward_id
|
|
-- reward_inv.player_data[reward_id][pname] = {
|
|
-- Time when access was first granted for this player,
|
|
-- Have all rewards been claimed?,
|
|
-- How much has been taken out of which slot?
|
|
-- When has the player last taken from this inventory?}
|
|
reward_inv.player_data = {}
|
|
|
|
|
|
-- what does the respective reward inventory actually contain? key: reward_id
|
|
-- reward_inv.inv_data[reward_id] = {
|
|
-- content = The actual content of the inventory (get_list),
|
|
-- hint = Hint shown to the player in "/rewards" command so that the
|
|
-- player has a chance to find this reward.,
|
|
-- text_when_found = Text shown to the player in "/rewards" command *when*
|
|
-- the player has *found*/*been awarded* this reward.,
|
|
-- pos = if it is a treasure chest: its position,
|
|
-- npc = n_id of the NPC that hands out the reward,
|
|
-- first_found = When was this reward first found/awarded?,
|
|
-- last_found = When was this award most recently found/awarded?,
|
|
-- anz_found = How many times was this reward found/awarded?
|
|
-- last_taken = When was something from this award last taken by a player?
|
|
-- refill_after_t_seconds = The inventory will auto-refill t seconds after
|
|
-- the player last took something from the reward inventory.
|
|
-- A value of 0 or less disables that.
|
|
--
|
|
-- }
|
|
reward_inv.inv_data = {}
|
|
|
|
-- here we can store which chest was right-clicked by the player
|
|
reward_inv.clicked_at_chest = {}
|
|
|
|
|
|
-- in case someone wants to change the naming scheme:
|
|
reward_inv.reward_inv_get_name = function(pname)
|
|
return "reward_inv_"..tostring(pname)
|
|
end
|
|
|
|
|
|
-- react to player input in formspecs;
|
|
-- handled in show_fs.lua
|
|
minetest.register_on_player_receive_fields( function(player, formname, fields)
|
|
return reward_inv.input_handler(player, formname, fields)
|
|
end)
|
|
|
|
|
|
-- suppord hot reload
|
|
reward_inv.reload_mod = function(modpath)
|
|
-- create and handle the physical access to the detached inventory
|
|
dofile(modpath .. "reward_inv.lua")
|
|
-- handle access to the reward inventories regarding the internal data structure;
|
|
-- API function: reward_inv.grant_access(pname, reward_id)
|
|
dofile(modpath .. "handle_access.lua")
|
|
-- fill the detached inventory with whatever rewards the player hasn't taken yet;
|
|
-- items with a quest id and metadata "yl_speak_up:quest_item_for" set will be updated
|
|
-- to the name of the player so that they become *that player's* quest items
|
|
dofile(modpath .. "update_inv.lua")
|
|
-- show the formspec to the player and handle player input
|
|
dofile(modpath .. "show_reward_fs.lua")
|
|
-- provide a list of hints and treasures found
|
|
dofile(modpath .. "show_reward_list_fs.lua")
|
|
-- the actual chest functions
|
|
dofile(modpath .. "chest_functions.lua")
|
|
end
|
|
|
|
local modpath = minetest.get_modpath("reward_inv")..DIR_DELIM
|
|
|
|
|
|
reward_inv.reload_mod(modpath)
|
|
-- an actual treasure chest
|
|
dofile(modpath .. "treasure_chest.lua")
|
|
|
|
-- restore saved data
|
|
reward_inv.player_data = reward_inv.load_data(reward_inv.file_name_player_data)
|
|
reward_inv.inv_data = reward_inv.load_data(reward_inv.file_name_inv_data)
|
|
|
|
-- most of the files of this mod can be reloaded without the server having to
|
|
-- be restarted;
|
|
-- handled in init.lua
|
|
minetest.register_chatcommand( 'reward_inv_reload', {
|
|
description = "Reloads most of the files of this mod so that you can update their code "..
|
|
"without having to restart the server. Requires the privs priv.",
|
|
privs = {privs = true},
|
|
func = function(pname, param)
|
|
minetest.chat_send_player(pname, "Reloading most files from mod reward_inv...")
|
|
reward_inv.reload_mod(modpath)
|
|
minetest.chat_send_player(pname, "Reloaded successfully.")
|
|
end
|
|
})
|
|
|
|
minetest.register_chatcommand( 'rewards', {
|
|
description = "Shows a list of rewards and treasures you have/have not yet found.",
|
|
privs = {},
|
|
func = function(pname, param)
|
|
reward_inv.show_reward_list_fs(minetest.get_player_by_name(pname), nil)
|
|
return
|
|
end
|
|
})
|