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

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

--####################################################################################################
--############################ QUETE 6 : LES GRAINES DU VERGER #######################################
--####################################################################################################
------------------------------------------------------------------------------------------------------
--------------------------Functions Part 1 : Apporter graine au verger -------------------------------
------------------------------------------------------------------------------------------------------
function F_hermit_seed_dropped_going_begin()
	local tGoers = GetQuestElementUsers( "Q_hermit_seed_dropped_going" );
	SetTakenObject( tGoers[1], "LD_hermit_seed_dropped" )
	if IsGameInLinearTuto() then
		SetTutorialDrop( "", "" )
	end
	return true
end

function F_hermit_seed_dropped_going_cancel( sOwnerName )
	SetPosition( "LD_hermit_seed_dropped", 1650, 750 )
	SetTakenObject( sOwnerName, "" )
	if IsGameInLinearTuto() then
		DisplayTutorialCallback( "TUTO_hermit_seed_cancel" )
	end
	return true
end

function F_hermit_seed_dropped_going_end()
	local tGoers = GetQuestElementUsers( "Q_hermit_seed_dropped_going" );
	SetTakenObject( tGoers[1], "" )
	SetVisible( "LD_hermit_seed_dropped", false );
	SetVisible( "LD_hermit_seed", true )
	SetCleanable( "SD_boule", true);
	DisplayQuestElementInTome( "Q_hermit_seed_growing", true )
	DisplayQuestElementInTome( "Q_garden_seed_growing", true )
	return true
end

function F_hermit_seed_dropped_going_getprogress()
	value = 100.00
	if( IsQuestElementCompleted( "Q_hermit_seed_dropped_going" ) ) then
		value = 0.00
	end
	return value
end
------------------------------------------------------------------------------------------------------
------------------------------Functions Part 2 : Planter graine ermite -------------------------------
------------------------------------------------------------------------------------------------------

function F_seed_growing_begin()
	PushTask("TASK_grow_seeds_ongoing","TASK_grow_seeds_ongoing",4.9)
end

function F_seed_growing_cancel()
	if GetNumberOfUsersUsingQuestElement("Q_hermit_seed_growing") + GetNumberOfUsersUsingQuestElement("Q_garden_seed_growing")  <= 0 then
		PopElementTask("TASK_grow_seeds_ongoing")
		MoveFairyToTaskBar()
	end
	return true
end

function F_seed_growing_first_time()
	-- DisplayInformation( "TIP_nb_character_on_quest", "backgrounds/dialog/vignette_fee", "", 0, "", true )
	DisplayHelpInformation( "TIP_secondary_quests", "backgrounds/dialog/vignette_fee", "", 0, "", true )
end

------------------------------------------------------------------------------------------------------
------------------------------Functions Part 3 : Planter graine verger -------------------------------
------------------------------------------------------------------------------------------------------
function F_seedstree_growing_begin( sOwnerName )
	PlayCultivateSound( sOwnerName );
	return true
end

function F_seedstree_growing_retrieve( sOwnerName )
	PlayCultivateFX( sOwnerName );
	return true
end

function F_seedstree_growing_stop( sOwnerName )
	KillCultivateSound( sOwnerName );
	KillCultivateFX( sOwnerName );
	return true
end

function F_seedstree_end( sOwnerName )
	
	if( IsQuestElementCompleted( "Q_garden_seed_growing" ) ) then
		SetVisible( "LD_garden_seed", false );
		SetVisible( "LD_garden_seed_grown", true );
	end
	if( IsQuestElementCompleted( "Q_hermit_seed_growing" ) ) then
		SetVisible( "LD_hermit_seed", false );
		SetVisible( "LD_hermit_seed_grown", true );
	end
	if IsQuestElementCompleted("Q_garden_seed_growing") and IsQuestElementCompleted("Q_hermit_seed_growing") then
		SetVisible ( "LD_garden_empty", false )
		SetVisible ( "LD_garden_seed_grown", false )
		SetVisible ( "LD_hermit_seed_grown", false )
		SetVisible ( "LD_tree_seed", true )
		SetVisible ( "O_orchard_tree", true )
		DisplayQuestElementInTome( "Q_tree_seed_going", true )
		
		PopElementTask("TASK_grow_seeds_ongoing")
		
		if not IsQuestElementCompleted("Q_swamp_sage_lookingafter") then
			DisplayInformation( "tree_seed_end", "backgrounds/dialog/vignette_fee", "", 0, "F_tree_seed_end_new_task", true )
		end
	end
	return true
end

function F_tree_seed_end_new_task()
	if  not IsQuestElementCompleted("Q_swamp_sage_lookingafter") and not IsQuestElementBegin("Q_swamp_sage_lookingafter") then
		SetFirstClickable( "Sage", true )
		PushTask("TASK_go_sage","TASK_go_sage",6)
		PushTask("TASK_help_sage","TASK_help_sage",7)
		PlayFX(Air, "fx/fx_boutique_4.lua", "Sage", 0, 0)
	end
end

function F_orchard_seeds_end()
	PopElementTask("TASK_grow_seeds")
end

--======================================================================================================
--=========================================Quest Description============================================
--======================================================================================================
Quest
{
	name = "Q_orchard_seeds",
	description = "Q_orchard_seeds_desc",
	callback_end = "F_orchard_seeds_end",
	--------------------------Part 1 : Apporter graine au verger -------------------------------
	
	-- prerequisites  = {"Q_hermit_fairie"},
  
	Quest_Element
	{
		name = "Q_hermit_seed_dropped_going",
		
		Check
		{
			value_type = "nature",
			level = 0 * G_check_factor,
		},
		gain_feerie = G_place_hermit_seed_faerie_gain,

		
		interaction = "LD_hermit_seed_dropped",
		
		object_to_see = "LD_hermit_seed_deposit",
		
		percentage = false,
		
		max_users = 1,
		stay_where_dropped  = false,
		callback_begin = "F_hermit_seed_dropped_going_begin",
		callback_cancel = "F_hermit_seed_dropped_going_cancel", 
		callback_end = "F_hermit_seed_dropped_going_end",
		callback_getprogress= "F_hermit_seed_dropped_going_getprogress",
		

		
		Deposite
		{
			label = "gardening",
			stock = "LD_hermit_seed_deposit",
			
			callback_inprogress = "F_seedstree_growing_begin",
			callback_done = "F_seedstree_growing_done",
			callback_cancel = "F_seedstree_growing_stop",
			callback_retrieve_inprogress = "F_seedstree_growing_retrieve",
		},
	},
	------------------------------Part 2 : Planter graine ermite -------------------------------
	Quest_Element
	{
		name = "Q_hermit_seed_growing",
		prerequisites = {"Q_hermit_seed_dropped_going"},
		
		Check
		{
			value_type = "nature",
			level = 1 * G_check_factor,
		},
		
		gain_feerie = G_hermit_seed_plant_faerie_gain,
	  
		callback_end = "F_seedstree_end",
		callback_begin = "F_seed_growing_begin",
		callback_cancel = "F_seed_growing_cancel",
		callback_first_time = "F_seed_growing_first_time",
		
		interaction = "LD_hermit_seed",
		
		max_users = 2,
		loop = true,

		Fix
		{
			stay_where_dropped = false,
			interaction = "LD_hermit_seed",
			label = "gardening",
			XpImproved = Nature,
			XpValue    = G_xp_standard_gain_per_action,
			fixTime = 5,
			fix_factor = 10,
			ratio_bonus_feerie = G_faerie_standard_gain_per_action,

			callback_inprogress = "F_seedstree_growing_begin",
			callback_done = "F_seedstree_growing_stop",
			callback_cancel = "F_seedstree_growing_stop",
			callback_retrieve_inprogress = "F_seedstree_growing_retrieve",
		},
	},
	
	------------------------------ Part 3 : Planter graine verger -------------------------------
	Quest_Element
	{
		name = "Q_garden_seed_growing",
		
		Check
		{
			value_type = "nature",
			level = 1 * G_check_factor,
		},
		
		gain_feerie = G_garden_seed_plant_faerie_gain,
	  
		
		interaction = "LD_garden_seed",
		
		callback_begin = "F_seed_growing_begin",
		callback_cancel = "F_seed_growing_cancel",
		callback_end = "F_seedstree_end",
		callback_first_time = "F_seed_growing_first_time",
		max_users = 2,
		loop = true,
		
		

		Fix
		{
			stay_where_dropped = false,
			interaction = "LD_garden_seed",
			label = "gardening",
			XpImproved = Nature,
			XpValue    = G_xp_standard_gain_per_action,
			fixTime = 5,
			fix_factor = 10,
			ratio_bonus_feerie = G_faerie_standard_gain_per_action,

			callback_inprogress = "F_seedstree_growing_begin",
			callback_done = "F_seedstree_growing_stop",
			callback_cancel = "F_seedstree_growing_stop",
			callback_retrieve_inprogress = "F_seedstree_growing_retrieve",
		},
	},
}
