------------------------------------------------Load tweak file------------------------------------------------

require( "config/game_tweak.cfg" );

------------------------------------------------Requires------------------------------------------------

require( "package/typedef.lua" );

DebugOut( "Quests : variables defined (file : package/quests/q_variables_define.lua)" ); 

-- type of variables to save. If you want to add another one, plz refer it to a C++ programmer.
local int = 0;
local float = 1;
local string = 2;

-- variables to save. DO NOT save variables that can't change during the game
tab_saved_variables = 
{
	G_banquet_ended = int;
	G_preparation = int;
	G_banquet_payed = int;
	
	G_stone_circle_ended = int;
	G_stone_lune_ended = int;
	G_stone_vent_ended = int;
	G_stone_ent_ended = int;
	G_collection_all_ended = int;	
}


G_banquet_quest_name = "Q_banquet";

G_banquet_brew = "Q_banquet_brewing";
G_banquet_play = "Q_banquet_playing";
G_banquet_cook = "Q_banquet_cooking";
G_banquet_dance = "Q_banquet_dancing";

G_hermit_faery = "Q_hermit_fairie_collecting";
G_nature_training = "Q_nature_training";

G_collection_moral = G_collection_passive_moral;
G_collection_speed = G_collection_passive_speed;
G_collection_gather = G_collection_gather_factor;
G_collection_faerie = G_collection_faerie_gained_per_action;

--Facteur infinite quests
--G_infinite_quest_factor = 0.5; || More information in the game_tweak file
--Facteur de féérie
--G_faerie_standard_gain_per_quest = 10; || More information in the game_tweak file
--G_faerie_standard_gain_per_action = 0.05; || More information in the game_tweak file
G_faerie_standard_gain_per_infinite_action = G_infinite_quest_factor * G_faerie_standard_gain_per_action;
--Facteur d'XP
--G_xp_standard_gain_per_action = 0.005; || More information in the game_tweak file
G_xp_standard_gain_per_infinite_action = G_infinite_quest_factor * G_xp_standard_gain_per_action;


G_collection_fee_end_gain = G_collection_end_base_gain * G_collection_fee_rarity_factor;
G_collection_lune_end_gain = G_collection_end_base_gain * G_collection_lune_rarity_factor;
G_collection_ents_end_gain = G_collection_end_base_gain * G_collection_ents_rarity_factor;
G_collection_vent_end_gain = G_collection_end_base_gain * G_collection_vent_rarity_factor;

G_firefly_last_crusade_guiding_min_users = 2 * G_check_factor;

-------------------------------------------------------------------------------------
------------------------------ QUESTS FAERIE GAIN -----------------------------------
-------------------------------------------------------------------------------------

------------------------------ TUTORIAL QUESTS ------------------------------
G_verb_crystal_faerie_gain = 5
G_free_hermit_faerie_gain = 10
G_place_hermit_seed_faerie_gain = 5

------------------------------ FIFREFLY KINGDOM------------------------------
G_firefly_fruit_feed_faerie_gain = 70
G_firefly_syrup_feed_faerie_gain = 110
G_firefly_lamp_fix_faerie_gain = 320
G_firefly_guiding_faerie_gain = 350

------------------------------ GOLDEN SYRUP ------------------------------
G_bee_flower_faerie_gain = 300
G_spoon_fix_faerie_gain = 30
G_alambic_fix_faerie_gain = 200
G_honey_gather_faerie_gain = 75
G_flower_gather_faerie_gain = 65
G_alambic_brewing_faerie_gain = 170

------------------------------ LEGENDARY MELODY ------------------------------
G_muse_faerie_gain = 5
G_xylo_clean_faerie_gain = 140
G_xylo_learn_faerie_gain = 200

------------------------------ ORCHARD SEEDS ------------------------------
G_hermit_seed_plant_faerie_gain = 45
G_garden_seed_plant_faerie_gain = 50

------------------------------ SWAMP ------------------------------
G_swamp_clean_faerie_gain = 70
G_watering_can_faerie_gain = 135
G_swamp_seed_deposit_faerie_gain = 90
G_swamp_seed_growing_faerie_gain = 110

------------------------------ WORLD HISTORY ------------------------------
G_tree_runes_faerie_gain = 60
G_ruins_clean_faerie_gain = 65
G_ruins_learn_faerie_gain = 150

------------------------------ MIRRORS------------------------------
G_mirror_cleaning_faerie_gain = 80
G_mirror_fixing_faerie_gain = 120

------------------------------ SECONDARY QUESTS ------------------------------

G_compass_faerie_gain = 100
G_ruins_hand_faerie_gain = 45
G_fairy_light_faerie_gain = 300
G_mushroom_faerie_gain = 80
G_mill_faerie_gain = 200



G_fairy_task_position_x = -160;
G_fairy_task_position_y = -350;

function MoveFairyToTaskBar()
	SetFaeryWait(true)
	SetFaeryPositionScreen( G_fairy_task_position_x, G_fairy_task_position_y, G_tutorial_fairy_speed*2, "CreateTimerToResetFairy" )
	return true
end

function CreateTimerToResetFairy()
	CreateTimer( "T_reset_fairy", 3, "ResumeFairyBrain" )
	return true
end

function ResumeFairyBrain()
	SetFaeryWait(false)
	DeferDelete("T_reset_fairy")
	return true
end



function F_dialogbox(box_title, box_text, image_name, target_name)
  PauseGame(true);
  DebugOut ("penser à faire un seul script pour les dialogue box")
  if not (image_name==nil or target_name==nil)
  then
  	gTempFunction = 
		function() 
			DisplayDialog {	
				"scripts/targetimgokbox.lua",
				body = box_text,
				title = box_title,
				image = image_name,
				target = target_name,
			};
		end;
	table.insert( gCommandQueue,gTempFunction );
  else
	if not (image_name==nil)
	then
		gTempFunction = 
			function() 
				DisplayDialog {	
					"scripts/imgokbox.lua",
					body = box_text,
					title = box_title,
					image = image_name,
				};
			end;
		table.insert( gCommandQueue,gTempFunction );
	else
	  if not (target_name==nil)
	  then
	    gTempFunction = 
			function() 
				DisplayDialog {	
					"scripts/targetokbox.lua",
					body = box_text,
					title = box_title,
					target = target_name,
				};
			end;
		table.insert( gCommandQueue,gTempFunction );
	   else
	    gTempFunction = 
			function() 
				DisplayDialog {	
					"scripts/okbox.lua",
					body = box_text,
					title = box_title,
				};
			end;
		table.insert( gCommandQueue,gTempFunction );		
	  end
	end
  end
  PauseGame(false);
end
------------------------------------------------------------------------------------------------
function F_immediate_dialogbox(box_title, box_text, image_name, target_name)
  PauseGame(true);
  DebugOut ("penser à faire un seul script pour les dialogue box")
  if not (image_name==nil or target_name==nil)
  then
	DisplayDialog {	
		"scripts/targetimgokbox.lua",
		body = box_text,
		title = box_title,
		image = image_name,
		target = target_name,
	};
  else
	if not (image_name==nil)
	then
		DisplayDialog {	
			"scripts/imgokbox.lua",
			body = box_text,
			title = box_title,
			image = image_name,
		};
	else
	  if not (target_name==nil)
	  then
			DisplayDialog {	
				"scripts/targetokbox.lua",
				body = box_text,
				title = box_title,
				target = target_name,
			};
	   else
			DisplayDialog {	
				"scripts/okbox.lua",
				body = box_text,
				title = box_title,
			};	
	  end
	end
  end
  PauseGame(false);
end

-------------------------- Fx and Sounds Functions ------------------------------------------------
---------------- Sounds ------------------
-- Brush
function PlayBrushSound( sOwnerName )
	PlaySound( "sounds/action/brush.ogg", true, FXSound, sOwnerName );
	return true
end

function KillBrushSound( sOwnerName )
	KillSound( "sounds/action/brush.ogg", FXSound, sOwnerName );
	return true
end

--Clean
function PlayCleanSound( sOwnerName )
	PlaySound( "sounds/action/clean.ogg", true, FXSound, sOwnerName );
	return true
end

function KillCleanSound( sOwnerName )
	KillSound( "sounds/action/clean.ogg", FXSound, sOwnerName );
	return true
end

--Cook
function PlayCookSound( sOwnerName )
	PlaySound( "sounds/action/cook.ogg", true, FXSound, sOwnerName );
	return true
end

function KillCookSound( sOwnerName )
	KillSound( "sounds/action/cook.ogg", FXSound, sOwnerName );
	return true
end

--Cultivate
function PlayCultivateSound( sOwnerName )
	PlaySound( "sounds/action/cultivate.ogg", true, FXSound, sOwnerName );
	return true
end

function KillCultivateSound( sOwnerName )
	KillSound( "sounds/action/cultivate.ogg", FXSound, sOwnerName );
	return true
end

--Drink
function PlayDrinkSound( sOwnerName )
	PlaySound( "sounds/action/drink.ogg", true, FXSound, sOwnerName );
	return true
end

function KillDrinkSound( sOwnerName )
	KillSound( "sounds/action/drink.ogg", FXSound, sOwnerName );
	return true
end

--DropApple
function PlayDropAppleSound( sOwnerName )
	PlaySound( "sounds/action/drop_apple.ogg", true, FXSound, sOwnerName );
	return true
end

function KillDropAppleSound( sOwnerName )
	KillSound( "sounds/action/drop_apple.ogg", FXSound, sOwnerName );
	return true
end

--Eat
function PlayEatSound( sOwnerName )
	PlaySound( "sounds/action/eat.ogg", true, FXSound, sOwnerName );
	return true
end

function KillEatSound( sOwnerName )
	KillSound( "sounds/action/eat.ogg", FXSound, sOwnerName );
	return true
end

--Gather
function PlayGatherSound( sOwnerName )
	PlaySound( "sounds/action/gather.ogg", true, FXSound, sOwnerName );
	return true
end

function KillGatherSound( sOwnerName )
	KillSound( "sounds/action/gather.ogg", FXSound, sOwnerName );
	return true
end

--Inspect
function PlayInvestigateSound( sOwnerName )
	PlaySound( "sounds/action/investigate.ogg", true, FXSound, sOwnerName );
	return true
end

function KillInvestigateSound( sOwnerName )
	KillSound( "sounds/action/investigate.ogg", FXSound, sOwnerName );
	return true
end

--Brew
function PlayBrewSound( sOwnerName )
	PlaySound( "sounds/action/make_a_potion.ogg", true, FXSound, sOwnerName );
	return true
end

function KillBrewSound( sOwnerName )
	KillSound( "sounds/action/make_a_potion.ogg", FXSound, sOwnerName );
	return true
end

--Music
function PlayMusicSound( sOwnerName )
	--PlayCharacterMusic( sOwnerName );
	return true
end

function KillMusicSound( sOwnerName )
	--KillCharacterMusic( sOwnerName );
	return true
end

--Take Object
function PlayTakeObjectSound( sOwnerName )
	PlaySound( "sounds/action/take_object.ogg", false, FXSound, sOwnerName );
	return true
end

--function KillTakeObjectSound( sOwnerName )
--KillSound( "sounds/action/take_object.ogg", FXSound, sOwnerName );
--return true
--end

--Deposit Object
function PlayDepositObjectSound( sOwnerName )
	PlaySound( "sounds/action/put_object.ogg", false, FXSound, sOwnerName );
	return true
end

--function KillDepositObjectSound( sOwnerName )
--KillSound( "sounds/action/put_object.ogg", FXSound, sOwnerName );
--return true
--end

--Read
function PlayReadSound( sOwnerName )
	PlaySound( "sounds/action/read.ogg", true, FXSound, sOwnerName );
	return true
end

function KillReadSound( sOwnerName )
	KillSound( "sounds/action/read.ogg", FXSound, sOwnerName );
	return true
end

--Repair
function PlayRepairSound( sOwnerName )
	PlaySound( "sounds/action/repair.ogg", true, FXSound, sOwnerName );
	return true
end

function KillRepairSound( sOwnerName )
	KillSound( "sounds/action/repair.ogg", FXSound, sOwnerName );
	return true
end

--Mill Repair
function PlayMillRepairSound( sOwnerName )
	PlaySound( "sounds/objets/water_wheele/water_wheele_repair", true, FXSound, sOwnerName );
	return true
end

function KillMillRepairSound( sOwnerName )
	KillSound( "sounds/objets/water_wheele/water_wheele_repair", FXSound, sOwnerName );
	return true
end

--Exploration
function PlayExplorationSound( sOwnerName )
	PlaySound( "sounds/action/search.ogg", true, FXSound, sOwnerName );
	return true
end

function KillExplorationSound( sOwnerName )
	KillSound( "sounds/action/search.ogg", FXSound, sOwnerName );
	return true
end

---------------- FXs ------------------
--Music
function PlayMusicFX( sOwnerName )
	PlayFX( Air, "fx/musique_v1.lua", sOwnerName, 0, 0 );
	PlayFX( Air, "fx/musique_v2.lua", sOwnerName, 0, 0 );
	PlayFX( Air, "fx/musique_v3.lua", sOwnerName, 0, 0 );
	PlayFX( Air, "fx/musique_lueur.lua", sOwnerName, 0, 0 );
	return true
end

function KillMusicFX( sOwnerName )
	KillFX( Air,"fx/musique_v1.lua",sOwnerName );
	KillFX( Air,"fx/musique_v2.lua",sOwnerName );
	KillFX( Air,"fx/musique_v3.lua",sOwnerName );
	KillFX( Air,"fx/musique_lueur.lua",sOwnerName );
	return true
end

function IsMusicFXPlaying( sOwnerName )
	return IsFXPlaying( Air, "fx/musique_v1.lua", sOwnerName )
end

--Lecture
function PlayInspectFX( sOwnerName )
	PlayFX( Air, "fx/lecture_v2.lua", sOwnerName, 0, 0 );
	PlayFX( Air, "fx/lueurs_v1.lua", sOwnerName, 0, 0 );
	return true
end

function KillInspectFX( sOwnerName )
	KillFX( Air,"fx/lecture_v2.lua",sOwnerName );
	KillFX( Air,"fx/lueurs_v1.lua",sOwnerName );
	return true
end

--Gather
function PlayGatherFX( sOwnerName )
	PlayFX( Air, "fx/cultiver.lua", sOwnerName, 0, 0 );
	return true
end

function KillGatherFX( sOwnerName )
	KillFX( Air, "fx/cultiver.lua", sOwnerName );
	return true
end

--Fume Bar
function PlayFumeBarFX( sOwnerName )
	PlayFX( Fogs, "fx/fume_bar_4.lua", "LD_banquet_food", 100, -123 );
	return true
end

function KillFumeBarFX( sOwnerName )
	KillFX( Fogs, "fx/fume_bar_4.lua", "LD_banquet_food" );
	return true
end

function IsFumeBarFXPlaying( sOwnerName )
	return IsFXPlaying( Fogs, "fx/fume_bar_4.lua", "LD_banquet_food" )
end

--Exploration
function PlayExplorationFX( sOwnerName )
	PlayFX( Air, "fx/fouille_v2.lua", sOwnerName, 18, 0 );
	PlayFX( Air, "fx/fouille_v2_bis.lua", sOwnerName, 17, -1 );
	PlayFX( Air, "fx/lueurs_v2.lua", sOwnerName, 0, 0 );
	return true
end

function KillExplorationFX( sOwnerName )
	KillFX( Air,"fx/fouille_v2.lua",sOwnerName );
	KillFX( Air,"fx/fouille_v2_bis.lua",sOwnerName );
	KillFX( Air,"fx/lueurs_v2.lua",sOwnerName );
	return true
end

--Repair
function PlayRepairFX( sOwnerName )
	PlayFX( Air, "fx/etincelles.lua", sOwnerName, 0, 0 );
	return true
end

function KillRepairFX( sOwnerName )
	KillFX( Air,"fx/etincelles.lua",sOwnerName );
	return true
end

--Cultivate
function PlayCultivateFX( sOwnerName )
	PlayFX( Air, "fx/cultiver.lua", sOwnerName, 0, 0 );
	return true
end

function KillCultivateFX( sOwnerName )
	KillFX( Air, "fx/cultiver.lua", sOwnerName );
	return true
end

------------------------------------------------------------- Function to test if the end conditions have been completed and start the end animatic if so ---------
function EndGame()
	if( IsQuestCompleted( "Q_mirrors" ) and
		IsQuestCompleted( "Q_firefly_kingdom" ) and
		IsQuestCompleted( "Q_Stone_Faery" ) ) then
		
		SetVisible( "LD_mirror_A_repaired", false );
		SetVisible( "LD_mirror_B_repaired", false );
		SetVisible( "LD_mirror_C_repaired", false );
		SetVisible( "LD_mirror_D_repaired", false );
		SetVisible( "LD_mirror_E_repaired", false );
		SetVisible( "LD_mirror_F_repaired", false );
		
		DisableInput(true);
		SetFaeryWait( true );
		UnselectCurrent();
		DisplayInformation( "endgame_begin", "backgrounds/dialog/vignette_fee", "", 0, "F_move_on_to_firefly_mirror", true );
		
	end
	return true
end

function F_move_on_to_firefly_mirror()
	MoveCamera( 1314, 37, G_vitesse_camera_fin, "F_time_on_firefly_mirror" );
	return true
end

function F_time_on_firefly_mirror()
	CreateTimer( "T_firefly_mirror", G_temps_sur_mirroir_fin, "F_move_on_to_fruit_mirror" );
end

function F_move_on_to_fruit_mirror()
	MoveCamera( 1854, 928, G_vitesse_camera_fin, "F_time_on_fruit_mirror" );
	DeferDelete( "T_firefly_mirror" );
	return true
end

function F_time_on_fruit_mirror()
	CreateTimer( "T_fruit_mirror", G_temps_sur_mirroir_fin, "F_move_on_to_telescope_mirror" );
end

function F_move_on_to_telescope_mirror()
	MoveCamera( 23, 701, G_vitesse_camera_fin, "F_time_on_telescope_mirror" );
	DeferDelete( "T_fruit_mirror" );
	return true
end

function F_time_on_telescope_mirror()
	CreateTimer( "T_telescope_mirror", G_temps_sur_mirroir_fin, "F_move_on_to_watering_can_mirror" );
end

function F_move_on_to_watering_can_mirror()
	MoveCamera( -92, 1598, G_vitesse_camera_fin, "F_time_on_watering_can_mirror" );
	DeferDelete( "T_telescope_mirror" );
	return true
end

function F_time_on_watering_can_mirror()
	CreateTimer( "T_watering_can_mirror", G_temps_sur_mirroir_fin, "F_move_on_to_circle_mirror" );
end

function F_move_on_to_circle_mirror()
	MoveCamera( -1943, 1004, G_vitesse_camera_fin, "F_time_on_circle_mirror" );
	DeferDelete( "T_watering_can_mirror" );
	return true
end

function F_time_on_circle_mirror()
	CreateTimer( "T_circle_mirror", G_temps_sur_mirroir_fin, "F_move_on_to_muse_mirror" );
end

function F_move_on_to_muse_mirror()
	MoveCamera( -789, 533, G_vitesse_camera_fin, "F_time_on_muse_mirror" );
	DeferDelete( "T_circle_mirror" );
	return true
end

function F_time_on_muse_mirror()
	CreateTimer( "T_muse_mirror", G_temps_sur_mirroir_fin, "F_end_message" );
end

function F_end_message()
	DisplayInformation( "endgame_end", "backgrounds/dialog/vignette_fee", "", 0, "F_end_cinematic", true );
	DeferDelete( "T_muse_mirror" );
	return true
end


function F_end_cinematic()
	HideInformation()
	MuteSoundType( FXSound, true )
	MuteSoundType( MusicSound, true )
	SetCursorAnimation( "default" )
	gTempFunction = 
		function() 
			DoModal("scripts/cinematic_end_1.lua")
		end;
	table.insert( gCommandQueue,gTempFunction );
end

