2015-07-22 00:04:54 +02:00
mff.quests = { }
mff.QPREFIX = " mff_quests: "
2015-07-27 01:49:32 +02:00
mff.QNOPREFIX = function ( s ) return s : sub ( mff.QPREFIX : len ( ) + 1 ) end
2015-07-22 00:04:54 +02:00
2015-09-04 15:09:54 +02:00
quests.set_hud_position ( 1 , 0.31 )
quests.set_hud_offset ( - 200 , 0 )
2015-08-25 20:50:14 +02:00
2015-07-22 00:04:54 +02:00
mff.quests . quests = {
2015-07-27 01:49:32 +02:00
still_testing_quests = {
title = " Stone digger " ,
2016-05-07 21:23:43 +02:00
description = " DAILY QUEST! \n Get five Super Apple at the end! " ,
2015-07-27 01:49:32 +02:00
repeating = 60 * 60 * 24 ,
2016-05-07 21:23:43 +02:00
awards = {
[ " maptools:superapple " ] = 5 ;
} ,
2015-07-27 01:49:32 +02:00
tasks = {
diggy = {
2015-09-06 15:35:40 +02:00
title = " Dig 100 stone " ,
2016-05-08 22:25:27 +02:00
description = " Old man : Show me you can dig through stone, and I will reward you. " ,
2015-09-06 15:35:40 +02:00
max = 100 ,
2015-07-27 01:49:32 +02:00
objective = {
dig = { " default:stone " }
}
}
}
} ,
still_testing_quests2 = {
title = " Coal digger " ,
2016-05-07 21:23:43 +02:00
description = " DAILY QUEST! \n Get two Diamond and a Mese Crystal at the end! " ,
2015-07-27 01:49:32 +02:00
repeating = 60 * 60 * 24 ,
2016-05-07 21:23:43 +02:00
awards = {
[ " default:diamond " ] = 2 ;
[ " default:mese_crystal " ] = 1
} ,
2015-07-27 01:49:32 +02:00
tasks = {
diggy = {
2016-05-07 21:23:43 +02:00
title = " Dig 25 coal " ,
description = " Natsu, the Pyromancer : I like fire more than anything in the world! Prove me it's also your case and I will reward you. " ,
max = 25 ,
2015-07-27 01:49:32 +02:00
objective = {
dig = { " default:stone_with_coal " }
}
}
}
} ,
still_testing_quests3 = {
title = " Shiny diamonds " ,
2016-05-07 21:23:43 +02:00
description = " DAILY QUEST! \n Get two mithril ingot at the end! " ,
2015-07-27 01:49:32 +02:00
repeating = 60 * 60 * 24 ,
2016-05-07 21:23:43 +02:00
awards = {
2016-06-03 21:52:52 +02:00
[ " default:mithril_ingot " ] = 2
2016-05-07 21:23:43 +02:00
} ,
2015-07-27 01:49:32 +02:00
tasks = {
diggy = {
2016-05-07 21:23:43 +02:00
title = " Dig 10 diamonds " ,
2016-05-09 01:41:18 +02:00
description = " Masamune, the Blacksmith : Hello little adventurer. Aaarrh, I hate diamonds! I work only with strong materials, dig diamonds and I will reward you with my favorite mineral. " ,
2016-05-08 22:25:27 +02:00
max = 10 ,
2015-07-27 01:49:32 +02:00
objective = {
dig = { " default:stone_with_diamond " }
}
}
2015-07-22 00:04:54 +02:00
}
2015-10-17 12:48:01 +02:00
} ,
2016-06-14 21:44:41 +02:00
still_testing_quests4 = {
title = " Gold fever " ,
description = " DAILY QUEST! \n Get one locked furnace at the end! " ,
repeating = 60 * 60 * 24 ,
awards = {
[ " default:furnace_locked " ] = 1
} ,
tasks = {
diggy = {
title = " Dig 30 Gold " ,
description = " Go search for some gold, but don't catch the gold fever! " ,
max = 30 ,
objective = {
dig = { " default:stone_with_gold " }
}
}
}
} ,
still_testing_quests5 = {
title = " Great miner " ,
description = " DAILY QUEST! \n Get one mithril pickaxe at the end! " ,
repeating = 60 * 60 * 24 ,
awards = {
[ " default:pick_mithril " ] = 1
} ,
tasks = {
diggy = {
title = " Dig 10 mithril " ,
description = " Prove That You're a great miner, Find the Most Precious ore. " ,
max = 10 ,
objective = {
dig = { " default:stone_with_mithril " }
}
}
}
} ,
still_testing_quests6 = {
title = " Woodsman " ,
description = " DAILY QUEST! \n Get one locked chest at the end! " ,
repeating = 60 * 60 * 24 ,
awards = {
[ " default:chest_locked " ] = 1
} ,
tasks = {
diggy = {
title = " Dig 30 jungletree " ,
description = " Go into the jungle and cut tree, We always need wood. " ,
max = 30 ,
objective = {
dig = {
" default:jungletree " ,
" moretrees:jungletree_trunk " ,
}
}
}
}
} ,
2015-11-22 22:56:14 +01:00
--[[ Disabled, Mesecons levers now use right click
2015-10-17 12:48:01 +02:00
levermaniac = {
title = " Levermaniac " ,
description = " For some reason you've become obsessed with Mesecons's lever, causing you to insanely switch the levers on and off at an amazing speed. \n Doctors have diagnosed a strange brain damage, but said you'd be rewarded with a Super Apple if you can assist them in their research about the disease. \n They simply ask you to flip a lever 5 times, but won't come to inspect and study you afterwards, which may suggest they also are brain damaged. " ,
repeating = 60 * 60 * 24 ,
max = 5 ,
awards = { [ " maptools:superapple " ] = 1 } ,
objective = {
punch = { " mesecons_walllever:wall_lever " }
}
2015-11-22 22:56:14 +01:00
} ] ]
2015-07-22 00:04:54 +02:00
}
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 )
quests.start_quest ( playername , mff.QPREFIX .. qname , meta )
end
2015-07-27 01:49:32 +02:00
function mff . quests . handle_quest_end ( playername , questname , metadata )
for item , count in pairs ( mff.quests . quests [ mff.QNOPREFIX ( questname ) ] . awards ) do
2015-08-18 15:01:34 +02:00
local p = minetest.get_player_by_name ( playername )
if p then
minetest.add_item ( p : getpos ( ) , { name = item , count = count , wear = 0 , metadata = " " } )
end
2015-07-22 00:04:54 +02:00
end
end
-- Register the quests defined above
for qname , quest in pairs ( mff.quests . quests ) do
2015-07-27 01:49:32 +02:00
quest.completecallback = mff.quests . handle_quest_end
2015-10-17 12:48:01 +02:00
local ret , err = quests.register_quest ( mff.QPREFIX .. qname , quest )
if not ret then
minetest.log ( " error " , " mff_quests: failed registering " .. qname .. " : " .. err )
end
2015-07-22 00:04:54 +02:00
end
2015-09-06 15:35:40 +02:00
-- The callback function parameters are as follows:
-- questname, questdef,
-- taskname (nil?), taskdef (nil?),
-- objective_container (that is, either questdef or taskdef),
-- objective (=objectives_container.objectives),
-- function_to_update_the_objective_progress(value)
local function iterate_through_objectives ( pname , callback )
2015-07-22 00:04:54 +02:00
for qname , quest in pairs ( mff.quests . quests ) do
2015-07-27 01:49:32 +02:00
if quest.tasks then
for tname , task in pairs ( quest.tasks ) do
2015-10-17 12:48:01 +02:00
if quests.is_task_disabled ( pname , mff.QPREFIX .. qname , tname ) == false then
2015-09-06 15:35:40 +02:00
callback ( qname , quest , tname , task , task , task.objective , function ( value )
quests.update_quest_task ( pname , mff.QPREFIX .. qname , tname , value )
end )
2015-07-22 00:04:54 +02:00
end
end
2015-09-06 15:35:40 +02:00
else
2015-10-17 12:48:01 +02:00
if quests.get_quest_progress ( pname , mff.QPREFIX .. qname ) ~= nil then
callback ( qname , quest , nil , nil , quest , quest.objective , function ( value )
quests.update_quest ( pname , mff.QPREFIX .. qname , value )
end )
end
2015-07-22 00:04:54 +02:00
end
end
2015-09-06 15:35:40 +02:00
end
local function contains_node_or_group ( table , element )
for _ , value in pairs ( table ) do
if value == element or -- Simple node match
( value : len ( ) > 6 and value : sub ( 0 , 6 ) == " group: " and
minetest.get_item_group ( element , value : sub ( 7 ) ) > 0 ) then -- Group
return true
end
end
return false
end
-- Quest objective: node digging
minetest.register_on_dignode ( function ( pos , oldnode , digger )
if not digger or digger.is_fake_player then return end
local pname = digger : get_player_name ( )
iterate_through_objectives ( pname , function ( _ , _ , _ , _ , _ , objective , update )
if objective.dig and contains_node_or_group ( objective.dig , oldnode.name ) then
update ( 1 )
end
end )
end )
-- Quest objective: node punching
minetest.register_on_punchnode ( function ( pos , node , puncher , pointed_thing )
if not puncher or puncher.is_fake_player then return end
local pname = puncher : get_player_name ( )
iterate_through_objectives ( pname , function ( _ , _ , _ , _ , _ , objective , update )
if objective.punch and contains_node_or_group ( objective.punch , node.name ) then
update ( 1 )
end
end )
end )
-- Quest objective: node placement
minetest.register_on_placenode ( function ( pos , newnode , placer , oldnode , itemstack , pointed_thing )
if not placer or placer.is_fake_player then return end
local pname = placer : get_player_name ( )
iterate_through_objectives ( pname , function ( _ , _ , _ , _ , _ , objective , update )
if objective.place and contains_node_or_group ( objective.place , newnode.name ) then
update ( 1 )
end
end )
2015-07-22 00:04:54 +02:00
end )
minetest.register_on_joinplayer ( function ( player )
2015-07-27 01:49:32 +02:00
local playername = player : get_player_name ( )
2016-06-14 21:44:41 +02:00
for qname , _ in pairs ( mff.quests . quests ) do
2015-07-27 01:49:32 +02:00
if not quests.quest_restarting_in ( playername , mff.QPREFIX .. qname ) then
mff.quests . start_quest ( playername , qname )
end
end
2015-07-30 00:48:46 +02:00
end )