mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2025-06-28 14:16:06 +02:00
Add quest framework and basic periodic quest support
This commit is contained in:
5
mods/mff/README.md
Normal file
5
mods/mff/README.md
Normal file
@ -0,0 +1,5 @@
|
||||
* MFF-specific mods folder
|
||||
|
||||
** Code convention
|
||||
All MFF mods must be in the `mff` global table, and thus shall depend on the mff_core mod first defining it.
|
||||
The reason for this is to allow introspection using mff_introspect to track bugs at runtime, and more generally to define a code namespace.
|
2
mods/mff/mff_core/init.lua
Normal file
2
mods/mff/mff_core/init.lua
Normal file
@ -0,0 +1,2 @@
|
||||
mff = {}
|
||||
mff.core = {}
|
0
mods/mff/mff_introspect/UPCOMING
Normal file
0
mods/mff/mff_introspect/UPCOMING
Normal file
3
mods/mff/mff_quests/depends.txt
Normal file
3
mods/mff/mff_quests/depends.txt
Normal file
@ -0,0 +1,3 @@
|
||||
mff_core
|
||||
default
|
||||
quests
|
119
mods/mff/mff_quests/init.lua
Normal file
119
mods/mff/mff_quests/init.lua
Normal file
@ -0,0 +1,119 @@
|
||||
--- HIGLY UNFINISHED!!!!
|
||||
--- HIGLY UNFINISHED!!!!
|
||||
--- HIGLY UNFINISHED!!!!
|
||||
--- HIGLY UNFINISHED!!!!
|
||||
--- HIGLY UNFINISHED!!!!
|
||||
--- HIGLY UNFINISHED!!!!
|
||||
--- HIGLY UNFINISHED!!!!
|
||||
--- HIGLY UNFINISHED!!!!
|
||||
--- HIGLY UNFINISHED!!!!
|
||||
--- HIGLY UNFINISHED!!!!
|
||||
--- HIGLY UNFINISHED!!!!
|
||||
--- HIGLY UNFINISHED!!!!
|
||||
-- GOT THAT ENOUGH?
|
||||
-- - gravgun
|
||||
mff.quests = {}
|
||||
mff.QPREFIX = "mff_quests:"
|
||||
|
||||
mff.quests.quests = {
|
||||
testdiggydiggyhole = {
|
||||
title = "Dig 10 nodes",
|
||||
max = 10,
|
||||
desc = "As long as you can not dig, you are not a real miner.",
|
||||
periodicity = 10,
|
||||
objective = {
|
||||
dig = {"default:stone"}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mff.quests.quest_status = {}
|
||||
|
||||
function table.contains(table, element)
|
||||
for _, value in pairs(table) do
|
||||
if value == element then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function mff.quests.start_quest(playername, qname, meta)
|
||||
mff.quests.quest_status[playername][qname] = 0
|
||||
quests.start_quest(playername, mff.QPREFIX .. qname, meta)
|
||||
end
|
||||
|
||||
function mff.quests.restart_periodic_quest(playername, qname)
|
||||
mff.quests.start_quest(playername, qname)
|
||||
end
|
||||
|
||||
function mff.quests.start_periodicity_timer(playername, qname)
|
||||
local tstamp = -mff.quests.quest_status[playername][qname]
|
||||
minetest.after(tstamp-os.time(), mff.quests.restart_periodic_quest, playername, qname)
|
||||
end
|
||||
|
||||
function mff.quests.start_all_periodicity_timers(playername)
|
||||
local qstatus = mff.quests.quest_status[playername]
|
||||
for qname, _ in pairs(qstatus) do
|
||||
mff.quests.start_periodicity_timer(playername, qname)
|
||||
end
|
||||
end
|
||||
|
||||
function mff.quests.set_quest_ended(playername, questname, metadata)
|
||||
local qstatus = mff.quests.quest_status[playername]
|
||||
local qname = questname:sub(mff.QPREFIX:len()+1)
|
||||
local qinfo = mff.quests.quests[qname]
|
||||
if qinfo.periodicity ~= nil and qinfo.periodicity >= 1 then
|
||||
qstatus[qname] = -(os.time() + qinfo.periodicity)
|
||||
mff.quests.start_periodicity_timer(playername, qname)
|
||||
else
|
||||
qstatus[qname] = nil
|
||||
end
|
||||
end
|
||||
|
||||
-- Register the quests defined above
|
||||
for qname, quest in pairs(mff.quests.quests) do
|
||||
quests.register_quest(mff.QPREFIX .. qname, {
|
||||
title = quest.title,
|
||||
description = quest.desc,
|
||||
max = quest.max,
|
||||
autoaccept = true,
|
||||
callback = mff.quests.set_quest_ended
|
||||
})
|
||||
end
|
||||
|
||||
-- For quests where you have to dig something, the updates happen here
|
||||
minetest.register_on_dignode(function(pos, oldnode, digger)
|
||||
local qstatus = mff.quests.quest_status[digger:get_player_name()]
|
||||
for qname, quest in pairs(mff.quests.quests) do
|
||||
if qstatus[qname] ~= nil and qstatus[qname] >= 0 then
|
||||
if quest.objective.dig then
|
||||
if table.contains(quest.objective.dig, oldnode.name) then
|
||||
quests.update_quest(digger:get_player_name(), mff.QPREFIX .. qname, 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
-- TODO load data
|
||||
--[[
|
||||
for playername in players do
|
||||
mff.quests.start_all_periodicity_timers(playername)
|
||||
end
|
||||
]]
|
||||
|
||||
minetest.register_on_joinplayer(function (player)
|
||||
-- TODO do nothing
|
||||
mff.quests.quest_status[player:get_player_name()] = {}
|
||||
mff.quests.start_quest(player:get_player_name(), "testdiggydiggyhole")
|
||||
end)
|
||||
|
||||
minetest.register_on_leaveplayer(function (player)
|
||||
-- TODO do nothing
|
||||
mff.quests.quest_status[player:get_player_name()] = nil
|
||||
end)
|
||||
|
||||
minetest.register_on_shutdown(function()
|
||||
-- TODO save data
|
||||
end)
|
0
mods/mff/modpack.txt
Normal file
0
mods/mff/modpack.txt
Normal file
Reference in New Issue
Block a user