------------------------------------------------Variables------------------------------------------------

require( "package/quests/q_variables_define.lua" );
DebugOut( "generate main quests (file : package/quests/q_world_history.lua)" );

--####################################################################################################
--############################### QUETE 1 : HISTOIRE DU MONDE FEERIQUE ###############################
--####################################################################################################



------------------------------------------------------------------------------------------------------
------------------------------------Functions Part 1 : Tree Runes-------------------------------------
------------------------------------------------------------------------------------------------------
function F_tree_runes_first_click()
	if IsFXPlaying(Air, "fx/fx_boutique_4.lua", "LD_tree_runes") then
		KillFX(Air, "fx/fx_boutique_4.lua", "LD_tree_runes")
	end
	DisplayInformation( "tree_ruins_start_text", "backgrounds/dialog/vignette_fee", "", 0, "", true )
	PopElementTask("TASK_find_tree_runes")
end

function F_tree_runes_first_time()
	--DisplayHelpInformation( "TIP_banquet", "backgrounds/dialog/vignette_fee", "", 0, "", true )
	-- SetTipToShow( "TIP_nb_character_on_quest" ) 
end

function F_tree_runes_end()
	SetVisible( "LD_tree_runes", false )
	SetCleanable( "SD_livre", true)
	PopElementTask("TASK_decipher_tree_runes")
	PopElementTask("TASK_decipher_tree_runes_ongoing")
	F_tree_runes_end_new_tasks()
	DisplayInformation( "tree_ruins_end_text", "backgrounds/dialog/vignette_fee", "", 0, "", true )
	DisplayQuestElementInTome( "Q_world_history_ruins_exploring", true )
	-- SetTipToShow( "TIP_train" ) 
end

function F_tree_runes_end_new_tasks()
	if not IsQuestElementCompleted("Q_world_history_ruins_exploring") then
		PushTask("TASK_go_stele","TASK_go_stele",2.5)
		PushTask("TASK_clean_stele","TASK_clean_stele",2)
		PushTask("TASK_find_stele","TASK_find_stele",1)
		SetFirstClickable( "LD_ruins_stele_exploration",true )
	end

	PlayFX(Air, "fx/fx_boutique_4.lua", "LD_ruins_stele_exploration", 0, 0)
end

function F_tree_runes_learning_retrieve( sOwnerName )
	PlayInspectFX( sOwnerName )
	return true
end

function F_tree_runes_learning_stop( sOwnerName )
	KillInspectFX( sOwnerName );
	return true
end

function F_tree_runes_cancel()
	if GetNumberOfUsersUsingQuestElement("Q_world_history_tree_runes_learning") <= 0 then
		PopElementTask("TASK_decipher_tree_runes_ongoing")
		MoveFairyToTaskBar()
	end
	return true
end

function F_tree_runes_begin()
	PushTask("TASK_decipher_tree_runes_ongoing","TASK_decipher_tree_runes_ongoing",-0.1)	
end

------------------------------------------------------------------------------------------------------
-----------------------------------Functions Part 2 : Ruins exploration-------------------------------
------------------------------------------------------------------------------------------------------

function F_ruins_stele_exploring_end()
	DisplayInformation( "ruins_stele_exploring_end_text", "backgrounds/dialog/vignette_fee", "", 0, "", true )
	SetVisible( "LD_ruins_stele_exploration", false )
	SetVisible( "LD_ruins_stele_dirty", false )
	PopElementTask("TASK_clean_stele")
	PopElementTask("TASK_clean_stele_ongoing")
	
	SetVisible( "LD_ruins_stele_knowledge", true )
	SetCleanable( "SD_mapmonde", true)
	DisplayQuestElementInTome( "Q_world_history_ruins_learning", true )
	DisplayHelpInformation( "TIP_feed", "backgrounds/dialog/vignette_fee", "", 0, "", true )
	-- SetTipToShow( "TIP_feed" ) 
end

function F_ruins_stele_exploring_retrieve( sOwnerName )
	PlayExplorationFX( sOwnerName )
	return true
end

function F_ruins_stele_exploring_inprogress( sOwnerName )
	PlayBrushSound( sOwnerName )
	return true
end

function F_ruins_stele_exploring_stop( sOwnerName )
	KillExplorationFX( sOwnerName )
	KillBrushSound( sOwnerName )
	return true
end


function F_ruins_stele_exploring_first_time()
	--DisplayHelpInformation( "TIP_recolt", "backgrounds/dialog/vignette_fee", "", 0, "", true )
	--DisplayHelpInformation( "TIP_train", "backgrounds/dialog/vignette_fee", "", 0, "", true )
end



function F_ruins_stele_exploring_first_click()
	if IsFXPlaying(Air, "fx/fx_boutique_4.lua", "LD_ruins_stele_exploration") then
		KillFX(Air, "fx/fx_boutique_4.lua", "LD_ruins_stele_exploration")
	end
	PopElementTask("TASK_find_stele")
	DisplayInformation( "ruins_stele_found_text", "backgrounds/dialog/vignette_fee", "", 0, "", true )
end

function F_ruins_stele_exploring_begin()
	PushTask("TASK_clean_stele_ongoing","TASK_clean_stele_ongoing",1.9)	
end

function F_ruines_exploring_cancel()
	if GetNumberOfUsersUsingQuestElement("Q_world_history_ruins_exploring") <= 0 then
		PopElementTask("TASK_clean_stele_ongoing")
		MoveFairyToTaskBar()
	end
	return true
end


------------------------------------------------------------------------------------------------------
--------------------------------------Functions Part 3 : Ruins learning-------------------------------
------------------------------------------------------------------------------------------------------

function F_ruins_stele_learning_end()
	DisplayInformation( "ruins_stele_learning_end_text", "backgrounds/dialog/vignette_fee", "", 0, "", true )
	SetVisible( "LD_ruins_stele_knowledge", false )
    DisplayQuestElementInTome( "Q_firefly_kingdom_fruit_feeding", true )
	SetFirstClickable( "LD_firefly_tree_fruit",true )
	SetVisible("Luciole",true)
	PlayFX(Air, "fx/fx_boutique_4.lua", "Luciole", 0, 0)
	PopElementTask("TASK_go_stele_ongoing")
	PopElementTask("TASK_go_stele")
	PushTask("TASK_feed_firefly","TASK_feed_firefly",4)
	PushTask("TASK_go_firefly","TASK_go_firefly",3)
	DisplayHelpInformation( "TIP_recolt", "backgrounds/dialog/vignette_fee", "", 0, "", true )
	-- SetTipToShow( "TIP_banquet" )
end


function F_ruins_stele_learning_retrieve( sOwnerName )
	PlayInspectFX( sOwnerName )
	return true
end

function F_ruins_stele_learning_stop( sOwnerName )
	KillInspectFX( sOwnerName )
	return true
end

function F_ruins_stele_learning_first_time()	
	DisplayHelpInformation( "TIP_collections", "backgrounds/dialog/vignette_fee", "", 0, "", true )
	ShowCollectionObjectOnScreen(-1592, 161, FAERY)
end

function F_ruins_stele_learning_begin()
	PushTask("TASK_go_stele_ongoing","TASK_go_stele_ongoing",2.4)	
end

function F_ruins_stele_learning_cancel()
	if GetNumberOfUsersUsingQuestElement("Q_world_history_ruins_learning") <= 0 then
		PopElementTask("TASK_go_stele_ongoing")
		SetFaeryPositionScreen( G_fairy_task_position_x, G_fairy_task_position_y, G_tutorial_fairy_speed*2, "" )
		MoveFairyToTaskBar()
	end
	return true
end

--======================================================================================================
--=========================================Quest Description============================================
--======================================================================================================
Quest
{
	name = "Q_world_history",
	description = "Q_world_history_desc",
	
	
	
	---------------------------Part 1 : Tree runes ---------------------
	
	Quest_Element
	{
		name = "Q_world_history_tree_runes_learning",
		
		description_done = "Q_world_history_tree_runes_learning_done",
		
		Check
		{
			value_type = "knowledge",
			level = 0 * G_check_factor,
		},
		
		interaction = "LD_tree_runes",     -- name of the source or character that launches this quest
		callback_firstclic = "F_tree_runes_first_click",
		callback_first_time = "F_tree_runes_first_time",
		callback_begin = "F_tree_runes_begin",
		callback_cancel = "F_tree_runes_cancel",
		callback_end = "F_tree_runes_end",
		
		max_users = 2,
		loop = true,
		
		gain_feerie = G_tree_runes_faerie_gain,
		
		Inspect
		{
			stay_where_dropped = false,
			interaction = "LD_tree_runes",
			label = "fixing",

			XpImproved = Knowledge,
			XpValue    = G_xp_standard_gain_per_action,
			fixTime = 5,
			fix_factor = 10,
			ratio_bonus_feerie = G_faerie_standard_gain_per_action,
			callback_done = "F_tree_runes_learning_stop",
			callback_cancel = "F_tree_runes_learning_stop",
			callback_retrieve_inprogress = "F_tree_runes_learning_retrieve",
		},
	},
	
	---------------------------Part 2 : Ruins exploration ---------------------
	
	Quest_Element
	{
		name = "Q_world_history_ruins_exploring",
		zone = "Z_ruins",
		
		prerequisites  = {"Q_world_history_tree_runes_learning"},
		
		callback_firstclic = "F_ruins_stele_exploring_first_click",
		callback_first_time = "F_ruins_stele_exploring_first_time",
		callback_end = "F_ruins_stele_exploring_end",
		callback_begin = "F_ruins_stele_exploring_begin",
		callback_cancel = "F_ruines_exploring_cancel",
		
		Check
		{
			value_type = "exploration",
			level = 1 * G_check_factor,
		},
		
		gain_feerie = G_ruins_clean_faerie_gain,

		interaction = "LD_ruins_stele_exploration",     -- name of the source or character that launches this quest
    
		max_users = 3,

		loop = true,
	
		see_x = -1800,
		see_y = 300,
	
		-- character actions
		Clean
		{
			stay_where_dropped = false,
			interaction = "LD_ruins_stele_exploration",
			label = "exploring",

			XpImproved = Exploration,
			XpValue    = G_xp_standard_gain_per_action,
			fixTime = 5,
			fix_factor = 10,
			ratio_bonus_feerie = G_faerie_standard_gain_per_action,
			callback_done = "F_ruins_stele_exploring_stop",
			callback_cancel = "F_ruins_stele_exploring_stop",
			callback_retrieve_inprogress = "F_ruins_stele_exploring_retrieve",
			callback_inprogress = "F_ruins_stele_exploring_inprogress",
		},
	},
	
	---------------------------Part 3 : Ruins learning ---------------------
	
	Quest_Element
	{
		name = "Q_world_history_ruins_learning",
		description_done = "Q_world_history_ruins_learning_done",
		
		zone = "Z_ruins",
		prerequisites  = {"Q_world_history_ruins_exploring"},
		
		Check
		{
			value_type = "knowledge",
			level = 1 * G_check_factor,
		},
		
		gain_feerie = G_ruins_learn_faerie_gain,

		
		interaction = "LD_ruins_stele_knowledge",     -- name of the source or character that launches this quest
		callback_end = "F_ruins_stele_learning_end",
        callback_first_time = "F_ruins_stele_learning_first_time",
		callback_begin = "F_ruins_stele_learning_begin",
		callback_cancel = "F_ruins_stele_learning_cancel",

		max_users = 8,
		loop = true,
		
		see_x = -1800,
		see_y = 300,

		-- character actions
		Inspect
		{
			stay_where_dropped = false,
			interaction = "LD_ruins_stele_knowledge",
			label = "learning",

			XpImproved = Knowledge,
			XpValue    = G_xp_standard_gain_per_action,
			fixTime = 5,
			fix_factor = 10,
			ratio_bonus_feerie = G_faerie_standard_gain_per_action,
			callback_done = "F_ruins_stele_learning_stop",
			callback_cancel = "F_ruins_stele_learning_stop",
			callback_retrieve_inprogress = "F_ruins_stele_learning_retrieve",
		},
	},
}
