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

require( "package/quests/q_variables_define.lua" );
DebugOut( "generate secondary quests (file : package/quests/q_secondary_quests.lua)" );

------------------------------------------------------------------------------------------------
------------------------------------------------Verb Crystal------------------------------------------------

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

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

function F_verb_crystal_end()
	if IsGameInLinearTuto() then
		DisplayInformation( "TUTO_drop_villager_next", "backgrounds/dialog/vignette_fee", "", 0, "F_Tuto_move_to_banquet_table", true );
	end
	return true
end

Quest
{
	name = "Q_verb_crystal",
	description = "Q_verb_crystal_desc",
	primary_quest = false,

	Quest_Element
	{
  
		Check
		{
			value_type = "knowledge",
			level = 0 * G_check_factor,
		},
	
		gain_feerie = G_verb_crystal_faerie_gain,

		-- must_be_seen_to_be_completed = false,

		name = "Q_verb_crystal_learning",
		interaction = "LD_verb_crystal",

		callback_end		= "F_verb_crystal_end",

		max_users = 2,
		loop = true,
    
		Clean
		{
			stay_where_dropped = false,
			interaction = "LD_verb_crystal",
			label = "learning",
			XpImproved = Knowledge,
			XpValue    = G_xp_standard_gain_per_infinite_action,
			fixTime = 5,
			fix_factor = 10,
			ratio_bonus_feerie = G_faerie_standard_gain_per_infinite_action,
			callback_done = "F_verb_crystal_stop",
			callback_cancel = "F_verb_crystal_stop",
			callback_retrieve_inprogress = "F_verb_crystal_retrieve",
		},
	},
}

------------------------------------------------------------------------------------------------
------------------------------------------------Compass------------------------------------------------

function F_compass_cleaning_begin( sOwnerName )
	PlayBrushSound( sOwnerName );
	return true
end

function F_compass_cleaning_stop( sOwnerName )
	KillBrushSound( sOwnerName );
	return true
end

function F_compass_cleaning_end()
	SetVisible( "LD_compass", false );
	return true
end


Quest
{
	name = "Q_compass",
	description = "Q_compass_desc",
	primary_quest = false,

	Quest_Element
	{
		Check
		{
		  value_type = "exploration",
		  level = 1 * G_check_factor,
		},
		
		gain_feerie = G_compass_faerie_gain,
	  
		name = "Q_compass_cleaning",
		interaction = "LD_compass",
		
		max_users = 3,
		loop = true,
		
		callback_end = "F_compass_cleaning_end",

		Fix
		{
			stay_where_dropped = false,
			interaction = "LD_compass",
			label = "fixing",

			XpImproved = Exploration,
			XpValue = G_xp_standard_gain_per_infinite_action,
			fixTime = 5,
			fix_factor = 10,
			ratio_bonus_feerie = G_faerie_standard_gain_per_infinite_action,
			callback_inprogress = "F_compass_cleaning_begin",
			callback_done = "F_compass_cleaning_stop",
			callback_cancel = "F_compass_cleaning_stop",
		},
	}, 
}

------------------------------------------------------------------------------------------------

------------------------------------------------Ruins Hand------------------------------------------------


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

function F_ruins_hand_exploring_stop( sOwnerName )
	KillExplorationFX( sOwnerName )
	return true
end

function F_ruins_hand_exploration_end( sOwnerName )
	SetVisible("O_hand_dirty_A",false);
	SetVisible("O_hand_dirty_B",false);
	SetVisible("O_hand_clean_A",true);
	SetVisible("O_hand_clean_B",true);
	return true
end

Quest
{
	name = "Q_ruins_hand",   -- en interne pour débugger mais aussi comme lien de pré-requis
	description = "Q_ruins_hand_desc",

	primary_quest = false,

	Quest_Element
	{

		Check
		{
			value_type = "exploration",
			level = 3 * G_check_factor,
		},

		Check
		{
			is_for_knowledge_tree = true,
			value_type = "exploration",
			level = 1 * G_check_factor,
		},

		gain_feerie = G_ruins_hand_faerie_gain,

		name = "Q_ruins_hand_exploration",   -- en interne pour débugger seulement. Pas de pré-requis si ce n'est les autres éléments situés avant lui.
		interaction = "LD_ruins_hand",     -- name of the source or character that launches this quest

		max_users = 4,
		min_users = 2 * G_check_factor,
		loop = true,

		callback_end = "F_ruins_hand_exploration_end",

		-- character actions
		Clean
		{
			stay_where_dropped = false,
			interaction = "LD_ruins_hand",
			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_hand_exploring_stop",
			callback_cancel = "F_ruins_hand_exploring_stop",
			callback_retrieve_inprogress = "F_ruins_hand_exploring_retrieve",
		},
	},

}

------------------------------------------------------------------------------------------------

------------------------------------------------Fairy Lights------------------------------------------------
function F_fairy_lights_end()
	SetCleanable( "SD_lampion", true);
end

function F_fairy_light_01_fixing_end()
	SetVisible( "LD_fairy_light_01", false )
	return true
end

function F_fairy_light_02_fixing_end()
	SetVisible( "LD_fairy_light_02", false )
	return true
end

function F_fairy_light_03_fixing_end()
	SetVisible( "LD_fairy_light_03", false )
	return true
end

Quest
{
	name = "Q_fairy_lights",   -- en interne pour débugger mais aussi comme lien de pré-requis
	description = "Q_fairy_light_01_desc",
	--gain_feerie = G_faerie_standard_gain_per_quest,
	primary_quest = false,

	callback_end = "F_fairy_lights_end",
 
	Quest_Element
	{
		prerequisites  = {"Q_firefly_kingdom_fruit_feeding"},

		Check
		{
			value_type = "nature",
			level = 2 * G_check_factor,
		},
		
		Check
		{
			is_for_knowledge_tree = true,
			value_type = "nature",
			level = 1 * G_check_factor,
		},
		loop = true,
		gain_feerie = G_fairy_light_faerie_gain,
		
		name = "Q_fairy_light_01_fixing",   -- en interne pour débugger seulement. Pas de pré-requis si ce n'est les autres éléments situés avant lui.
		interaction = "LD_fairy_light_01",     -- name of the source or character that launches this quest
		
		max_users = 1,
		stay_where_dropped = false,
		
		callback_end = "F_fairy_light_01_fixing_end",

		-- character actions
		Gather
		{
			stay_where_dropped = false,
			source = "id_firefly_gather_stock",
			label = "collecting",
			collectTime = 5, 
			gather_factor  = G_food_gather_factor,
			ratio_bonus_feerie = G_faerie_standard_gain_per_action,
		},
		
		Fix
		{
			stay_where_dropped = false,
			interaction = "LD_fairy_light_01",
			label = "fixing",

			XpImproved = Nature,
			XpValue    = G_xp_standard_gain_per_action,
			fixTime = 10,
			fix_factor = 10,
			ratio_bonus_feerie = G_faerie_standard_gain_per_action,
		},
	},
	
	Quest_Element
	{
		prerequisites  = {"Q_firefly_kingdom_fruit_feeding"},

		Check
		{
			value_type = "nature",
			level = 2 * G_check_factor,
		},
		
		Check
		{
			is_for_knowledge_tree = true,
			value_type = "nature",
			level = 1 * G_check_factor,
		},
		loop = true,
		gain_feerie = G_fairy_light_faerie_gain,
		
		name = "Q_fairy_light_02_fixing",   -- en interne pour débugger seulement. Pas de pré-requis si ce n'est les autres éléments situés avant lui.
		interaction = "LD_fairy_light_02",     -- name of the source or character that launches this quest
		
		max_users = 1,
		
		stay_where_dropped = false,
		
		callback_end = "F_fairy_light_02_fixing_end",

		-- character actions
		Gather
		{
			stay_where_dropped = false,
			source = "id_firefly_gather_stock",
			label = "collecting",
			collectTime = 5, 
			gather_factor  = G_food_gather_factor,
			ratio_bonus_feerie = G_faerie_standard_gain_per_action,
		},
		
		Fix
		{
			stay_where_dropped = false,
			interaction = "LD_fairy_light_02",
			label = "fixing",

			XpImproved = Nature,
			XpValue    = G_xp_standard_gain_per_action,
			fixTime = 10,
			fix_factor = 10,
			ratio_bonus_feerie = G_faerie_standard_gain_per_action,
		},
	},
	
	Quest_Element
	{
		prerequisites  = {"Q_firefly_kingdom_fruit_feeding"},

		Check
		{
			value_type = "nature",
			level = 2 * G_check_factor,
		},
		
		Check
		{
			is_for_knowledge_tree = true,
			value_type = "nature",
			level = 1 * G_check_factor,
		},
		loop = true,
		gain_feerie = G_fairy_light_faerie_gain,
		
		name = "Q_fairy_light_03_fixing",   -- en interne pour débugger seulement. Pas de pré-requis si ce n'est les autres éléments situés avant lui.
		interaction = "LD_fairy_light_03",     -- name of the source or character that launches this quest
		
		max_users = 1,
		stay_where_dropped = false,
		
		callback_end = "F_fairy_light_03_fixing_end",

		-- character actions
		Gather
		{
			stay_where_dropped = false,
			source = "id_firefly_gather_stock",
			label = "collecting",
			CompetenceUsed = Nature,
			collectTime = 5, 
			gather_factor  = G_food_gather_factor,
			ratio_bonus_feerie = G_faerie_standard_gain_per_action,
		},
		
		Fix
		{
			stay_where_dropped = false,
			interaction = "LD_fairy_light_03",
			label = "fixing",

			XpImproved = Nature,
			XpValue    = G_xp_standard_gain_per_action,
			fixTime = 10,
			fix_factor = 10,
			ratio_bonus_feerie = G_faerie_standard_gain_per_action,
		},
	},
}

------------------------------------------------------------------------------------------------
------------------------------------------------Mushroom------------------------------------------------
function F_mushroom_fixing_end()
	SetVisible( "LD_mushroom_light", false );
	PlayFX(Fogs, "fx/lucioles.lua", "LD_mushroom_light_trans", 0, 0);
	return true
end


Quest
{
	name = "Q_mushroom",
	description = "Q_mushroom_desc",
	primary_quest = false,


 
	Quest_Element
	{
		prerequisites  = {"Q_firefly_kingdom_fruit_feeding"},

		Check
		{
			value_type = "nature",
			level = 2 * G_check_factor,
		},
		
		Check
		{
			is_for_knowledge_tree = true,
			value_type = "nature",
			level = 2 * G_check_factor,
		},
		loop = true,
		
		gain_feerie = G_mushroom_faerie_gain,
		
		name = "Q_mushroom_fixing",
		interaction = "LD_mushroom_light",
		
		max_users = 1,
		stay_where_dropped = false,
		
		callback_end = "F_mushroom_fixing_end",

		Gather
		{
			stay_where_dropped = false,
			source = "id_firefly_gather_stock",
			label = "collecting",
			collectTime = 5, 
			gather_factor  = G_food_gather_factor,
			ratio_bonus_feerie = G_faerie_standard_gain_per_action,
		},
		
		Fix
		{
			stay_where_dropped = false,
			interaction = "LD_mushroom_light",
			label = "fixing",

			XpImproved = Nature,
			XpValue    = 2*G_xp_standard_gain_per_action,
			fixTime = 10,
			fix_factor = 10,
			ratio_bonus_feerie = G_faerie_standard_gain_per_action,
		},
	},
}

------------------------------------------------------------------------------------------------
------------------------------------------------Mill------------------------------------------------

function F_fix_mill()
	SetVisible( "LD_broken_mill", false );
	SetVisible( "LD_fixed_mill", true );
	SetVisible( "LD_mill_stock", true );
	SetMillUnlocked( true );
	PlaySound( "sounds/objets/water_wheele/wheele_run.ogg", true, FXSound, "LD_mill_stock" );
end

function F_mill_fixing_begin( sOwnerName )
	PlayMillRepairSound( sOwnerName );
	return true
end

function F_mill_fixing_retrieve( sOwnerName )
	PlayRepairFX( sOwnerName );
	return true;
end

function F_mill_fixing_stop( sOwnerName )
	KillMillRepairSound( sOwnerName );
	KillRepairFX( sOwnerName );
	return true;
end

Quest
{
	name = "Q_mill",   -- en interne pour débugger mais aussi comme lien de pré-requis
	description = "Q_mill_desc",
	
	primary_quest = false,	
  
	Quest_Element
	{

		Check
		{
			value_type = "knowledge",
			level = 2 * G_check_factor,
		},
    
		name = "Q_mill_fixing",   -- en interne pour débugger seulement. Pas de pré-requis si ce n'est les autres éléments situés avant lui.
		interaction = "LD_broken_mill",     -- name of the source or character that launches this quest
	
		callback_end = "F_fix_mill",
	
		gain_feerie = G_mill_faerie_gain,
	
		max_users = 4,
		min_users = 1 * G_check_factor,

		loop = true,
	
		Fix
		{
			stay_where_dropped = false,
			XpImproved = Knowledge,
			XpValue    = G_xp_standard_gain_per_action,
			interaction = "LD_broken_mill",
			label = "fixing",
			fixTime = 10,
			fix_factor = 10,
			ratio_bonus_feerie = G_faerie_standard_gain_per_action,
			callback_inprogress = "F_mill_fixing_begin",
			callback_done = "F_mill_fixing_stop",
			callback_cancel = "F_mill_fixing_stop",
			callback_retrieve_inprogress = "F_mill_fixing_retrieve",
		},
	},
}

------------------------------------------------------------------------------------------------
------------------------------------------------Population------------------------------------------------

function F_population_end()
	DisplayInformation( "max_pop_achieved", "backgrounds/dialog/vignette_fee", "", 0,"", true );
end
Quest
{
	name = "Q_population",
	description = "Q_population_desc",
	primary_quest = false,

	callback_end = "F_population_end",
	
	has_begun = true,
	currently_in_tome = true,
}

------------------------------------------------Zones d'apprentissage------------------------------------------------

function F_learning_zones_nature_first_clic()
	DisplayInformation( "learning_zones_nature_found", "backgrounds/dialog/vignette_fee", "", 0,"", true )
	if IsFXPlaying(Air, "fx/fx_boutique_4.lua", "LD_nature_training") then
		KillFX(Air, "fx/fx_boutique_4.lua", "LD_nature_training")
	end
	SetFlagsMapVisible( "Flag_Nature", true )
	CompleteQuestElement("Q_learning_zones_nature_finding",true)
end

function F_learning_zones_exploration_first_clic()
	
	DisplayInformation( "learning_exploration_nature_found", "backgrounds/dialog/vignette_fee", "", 0,"", true )
	if IsFXPlaying(Air, "fx/fx_boutique_4.lua", "LD_exploration_training") then
		KillFX(Air, "fx/fx_boutique_4.lua", "LD_exploration_training")
	end
	SetFlagsMapVisible( "Flag_Exploration", true )
	CompleteQuestElement("Q_learning_zones_exploration_finding",true)
end

function F_learning_zones_knowledge_first_clic()
	DisplayInformation( "learning_zones_knowledge_found", "backgrounds/dialog/vignette_fee", "", 0,"", true )
	if IsFXPlaying(Air, "fx/fx_boutique_4.lua", "LD_knowledge_training") then
		KillFX(Air, "fx/fx_boutique_4.lua", "LD_knowledge_training")
	end
	SetFlagsMapVisible( "Flag_Savoir", true )
	CompleteQuestElement("Q_learning_zones_knowledge_finding",true)
end

function F_learning_zones_music_first_clic()	
	DisplayInformation( "learning_zones_music_found", "backgrounds/dialog/vignette_fee", "", 0,"", true )
	if IsFXPlaying(Air, "fx/fx_boutique_4.lua", "LD_music_training") then
		KillFX(Air, "fx/fx_boutique_4.lua", "LD_music_training")
	end
	SetFlagsMapVisible( "Flag_Musique", true )
	CompleteQuestElement("Q_learning_zones_music_finding",true)
end

function F_learning_zones_end()

	PopElementTask("TASK_find_training_zones")
	DisplayInformation( "learning_zones_end", "backgrounds/dialog/vignette_fee", "", 0,"F_learning_zones_end_tuto_check", true )
	
end

function F_end_tuto_timer()
		DisplayTutorialCallback("TUTO_end")
		DeferDelete( "T_Tuto_end" );	
	return true
end

function F_learning_zones_end_tuto_check()
	if IsGameInLinearTuto() then
	   CreateTimer( "T_Tuto_end", 8, "F_end_tuto_timer" );	
	end
end

function F_learning_zones_condition_begin()
	return false
end

Quest
{
	name = "Q_learning_zones",
	description = "Q_learning_zones_desc",
	primary_quest = false,
	
	callback_end = "F_learning_zones_end",
	
	Quest_Element
	{
		name = "Q_learning_zones_nature_finding",
		description_done = "Q_learning_zones_nature_finding_done",
		
		interaction = "LD_nature_training",
		must_be_seen_to_be_completed = false,
		callback_firstclic = "F_learning_zones_nature_first_clic",
		condition_begin = "F_learning_zones_condition_begin",
		gain_feerie = 20,
	},
	
	Quest_Element
	{
		name = "Q_learning_zones_music_finding",
		description_done = "Q_learning_zones_music_finding_done",
		
		interaction = "LD_music_training",
		must_be_seen_to_be_completed = false,
		callback_firstclic = "F_learning_zones_music_first_clic",
		condition_begin = "F_learning_zones_condition_begin",
		gain_feerie = 20,
	},
	
	Quest_Element
	{
		name = "Q_learning_zones_knowledge_finding",
		description_done = "Q_learning_zones_knowledge_finding_done",
		
		interaction = "LD_knowledge_training",
		must_be_seen_to_be_completed = false,
		callback_firstclic = "F_learning_zones_knowledge_first_clic",
		condition_begin = "F_learning_zones_condition_begin",
		gain_feerie = 20,
	},
	
	Quest_Element
	{
		name = "Q_learning_zones_exploration_finding",
		description_done = "Q_learning_zones_exploration_finding_done",
		
		interaction = "LD_exploration_training",
		must_be_seen_to_be_completed = false,
		callback_firstclic = "F_learning_zones_exploration_first_clic",
		condition_begin = "F_learning_zones_condition_begin",
		gain_feerie = 20,
	},
}

