--NoPiramidComplete = true;
--NoUtopiaObj = true;
Piramid1Visit = nil;
Piramid2Visit = nil;
Piramid3Visit = nil;
Piramid4Visit = nil;
Hero_at_the_Tomb = nil;
visited = 0;
rase = GetPlayerRace(1);
diff = GetDifficulty() + 1;
StartDialogScene("/Timerkhan/TEST/S1/DialogScene.xdb#xpointer(/DialogScene)")


SetRegionBlocked('PiramidFog', true, PLAYER_2);
SetRegionBlocked('PiramidFog', true, PLAYER_4);
SetRegionBlocked('PiramidFog', true, PLAYER_5);
SetRegionBlocked('Utopia_Vision', true, PLAYER_2);
SetRegionBlocked('Utopia_Vision', true, PLAYER_4);
SetRegionBlocked('Utopia_Vision', true, PLAYER_5);
SetRegionBlocked('Ridde', true, PLAYER_2);
SetRegionBlocked('Ridde', true, PLAYER_4);
SetRegionBlocked('Ridde', true, PLAYER_5);

------------- SURVIVE HERO --------------
HeroRase = function()
if rase == 0 then
DeployReserveHero('Christian', 98, 34, 0)
startThread(Hum_Survive)
elseif rase == 1 then
DeployReserveHero('Ossir', 98, 34, 0)
startThread(Elf_Survive)
elseif rase == 2 then
DeployReserveHero('Sufi', 98, 34, 0)
startThread(Mag_Survive)
elseif rase == 3 then
DeployReserveHero('Inagost', 98, 34, 0)
startThread(Dunegon_Survive)
elseif rase == 4 then
DeployReserveHero('Gles', 98, 34, 0)
startThread(Necromant_Survive)
end
end

Hum_Survive = function()
sleep(5);
while IsHeroAlive( 'Christian' ) == true do sleep(10); end;
print('dead');
SetObjectiveState('Prim3Sur', OBJECTIVE_FAILED);
sleep(2);
Loose();
end;

Elf_Survive = function()
sleep(5);
while IsHeroAlive( 'Ossir' ) == true do sleep(10); end;
print('dead');
SetObjectiveState('Prim3Sur', OBJECTIVE_FAILED);
sleep(2);
Loose();
end;

Mag_Survive = function()
sleep(5);
while IsHeroAlive( 'Sufi' ) == true do sleep(10); end;
print('dead');
SetObjectiveState('Prim3Sur', OBJECTIVE_FAILED);
sleep(2);
Loose();
end;

Dunegon_Survive = function()
sleep(5);
while IsHeroAlive( 'Inagost' ) == true do sleep(10); end;
print('dead');
SetObjectiveState('Prim3Sur', OBJECTIVE_FAILED);
sleep(2);
Loose();
end;

Necromant_Survive = function()
sleep(5);
while IsHeroAlive( 'Gles' ) == true do sleep(10); end;
print('dead');
SetObjectiveState('Prim3Sur', OBJECTIVE_FAILED);
sleep(2);
Loose();
end;

SetObjectEnabled ('skel', nil);

Easter = function(hero)
Trigger(OBJECT_TOUCH_TRIGGER, 'skel', nil)
PlayVisualEffect( "/Effects/_(Effect)/Spells/Weakness.xdb#xpointer(/Effect)", hero, "tag2", 0, 0, 0, 0, 0 );
MarkObjectAsVisited('skel', hero)
sleep(10)
StartDialogScene("/Timerkhan/TEST/S3/DialogScene.xdb#xpointer(/DialogScene)")
end

Trigger(OBJECT_TOUCH_TRIGGER, 'skel', 'Easter')

---- OBELISK AND DRAGON TONGUE SWORD ----
SetObjectiveProgress('Prim1Artifact', 0, PLAYER_1);
print ("Etap bolshogo puti - ", GetObjectiveProgress('Prim1Artifact', PLAYER_1));

SetObjectEnabled ('Obelisk', nil);
Trigger (OBJECT_TOUCH_TRIGGER,'Obelisk','ObeliskRead');

function ObeliskRead ()
	if IsPlayerHeroesInRegion (PLAYER_1, 'Obelisk_Zone') then
    if rase == 0 then
    StartDialogScene("/Timerkhan/TEST/TEST_2_1/DialogScene.xdb#xpointer(/DialogScene)")
    elseif rase == 1 then
    StartDialogScene("/Timerkhan/TEST/TEST_2_5/DialogScene.xdb#xpointer(/DialogScene)")
    elseif rase == 2 then
    StartDialogScene("/Timerkhan/TEST/TEST_2_3/DialogScene.xdb#xpointer(/DialogScene)")
    elseif rase == 3 then
    StartDialogScene("/Timerkhan/TEST/TEST_2_2/DialogScene.xdb#xpointer(/DialogScene)")
    elseif rase == 4 then
    StartDialogScene("/Timerkhan/TEST/TEST_2_4/DialogScene.xdb#xpointer(/DialogScene)")
    end
    sleep(8)
	  MessageBox (GetMapDataPath().."Obelisk.txt");
	  if GetObjectiveState ('Prim1Artifact') == OBJECTIVE_ACTIVE and visited == 0 then
		SetObjectEnabled ('Piramid1', nil);
		Trigger (OBJECT_TOUCH_TRIGGER,'Piramid1','SecretTomb',nil);
		local visited = 1;
		SetObjectiveProgress('Prim1Artifact', 1, PLAYER_1);
		sleep (5);
		print ("Etap bolshogo puti - ", GetObjectiveProgress('Prim1Artifact', PLAYER_1));
		Trigger (OBJECT_TOUCH_TRIGGER,'Obelisk',nil);
	  end;
	end;
end;

function SecretTomb (heroname)
	Hero_at_the_Tomb = heroname;
	QuestionBox(GetMapDataPath().."Tomb.txt", 'SecretTombCombat');
end;


function SecretTombCombat ()
	StartCombat (Hero_at_the_Tomb, nil, 3, CREATURE_SHADOW_DRAGON, 25 + 4 * diff, CREATURE_DEMILICH, 45 + 5* diff, CREATURE_SHADOW_DRAGON, 25 + 4 * diff, nil, nil,
  '/Scenes/CombatArenas/Subterra_abyss.xdb#xpointer(/AdventureFlybyScene)');
	sleep (4);
	if IsHeroAlive (Hero_at_the_Tomb) then
        GiveArtefact (Hero_at_the_Tomb, ARTIFACT_DRAGON_FLAME_TONGUE);
	SetObjectiveState ('Prim1Artifact', OBJECTIVE_COMPLETED);
	Trigger (OBJECT_TOUCH_TRIGGER,'Piramid1', nil);
    end;	
end;

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

Trigger (OBJECT_TOUCH_TRIGGER,'Utopia','UtopiaVizit');

function UtopiaVizit (heroname)
	sleep(12);
	if IsHeroAlive(heroname) then	
		GiveExp(heroname, 2000);
		AddHeroCreatures(heroname, CREATURE_BLACK_DRAGON, 5);
		SetObjectiveState ('Sec2Utopia', OBJECTIVE_COMPLETED);
		MessageBox(GetMapDataPath().."Utopia.txt")
	end;	
end;
---------------- SECONDARY OBJECTIVE - PIRAMIDE ------
--Trigger (REGION_ENTER_AND_STOP_TRIGGER, 'Piramid_Vision', 'SeePiramid');

--function SeePiramid ()
	 --if IsObjectVisible(1, 'Piramid1') and NoPiramidObj then
	--EnableFog (95,10,GROUND, 5, ENABLE);
--	OpenRegionFog(1, 'PiramidFog');	
--	SetObjectiveState ('Sec1Piramid', OBJECTIVE_ACTIVE);
--	print ('see piramid');
--	Trigger (REGION_ENTER_WITHOUT_STOP_TRIGGER, 'Piramid_Vision', nil);
--	NoPiramidObj = false;	
	--startThread (CheckPiramid);
 --end;
--end;

--function CheckPiramid ()
--	while 1 do
--		if Piramid1Visit and Piramid2Visit and Piramid3Visit and Piramid4Visit and NoPiramidComplete then
--		--if PiramidVisited == 4 then
--			SetObjectiveState ('Sec1Piramid', OBJECTIVE_COMPLETED);
--			NoPiramidComplete = false;
--		end;
--		sleep (5);
--	end;
--end;

function ComeToPiramid1 (heroname)
	sleep(7);
	if IsHeroAlive(heroname) then	
		if GetObjectOwner (heroname) == PLAYER_1 then
			Piramid1Visit = true;
--			print ('You vizit piramid number 1');
			if Piramid2Visit and Piramid3Visit and Piramid4Visit then
			sleep (4);
				MessageBox (GetMapDataPath().."Pirmid_End.txt");
				GiveExp(heroname, 10000);
				SetObjectiveState ('Sec1Piramid', OBJECTIVE_COMPLETED);
			end;
		end;	
		Trigger (OBJECT_TOUCH_TRIGGER,'Piramid1',nil);
	end;
end;

function ComeToPiramid2 (heroname)
	sleep(7);
	if IsHeroAlive(heroname) then	
		if GetObjectOwner (heroname) == PLAYER_1 then
			Piramid2Visit = true;
--			print ('You vizit piramid number 2');
			if Piramid1Visit and Piramid3Visit and Piramid4Visit then
				sleep (4);
				MessageBox (GetMapDataPath().."Pirmid_End.txt");
				GiveExp(heroname, 10000);			
				SetObjectiveState ('Sec1Piramid', OBJECTIVE_COMPLETED);
			end;		
		end;
		Trigger (OBJECT_TOUCH_TRIGGER,'Piramid2',nil);
	end;
end;

function ComeToPiramid3 (heroname)
	sleep(7);
	if IsHeroAlive(heroname) then	
		if GetObjectOwner (heroname) == PLAYER_1 then
			Piramid3Visit = true;
--			print ('You vizit piramid number 3');
			if Piramid1Visit and Piramid2Visit and Piramid4Visit then
				sleep (4);
				MessageBox (GetMapDataPath().."Pirmid_End.txt");
				GiveExp(heroname, 10000);			
				SetObjectiveState ('Sec1Piramid', OBJECTIVE_COMPLETED);
			end;		
		end;
		Trigger (OBJECT_TOUCH_TRIGGER,'Piramid3',nil);
	end;
end;

function ComeToPiramid4 (heroname)
	sleep(7);
	if IsHeroAlive(heroname) then	
		if GetObjectOwner (heroname) == PLAYER_1 then
			Piramid4Visit = true;
--			print ('You vizit piramid number 4');
			if Piramid1Visit and Piramid2Visit and Piramid3Visit then
				sleep (4);
				MessageBox (GetMapDataPath().."Pirmid_End.txt");
				GiveExp(heroname, 10000);		
				SetObjectiveState ('Sec1Piramid', OBJECTIVE_COMPLETED);
			end;
		end;
		Trigger (OBJECT_TOUCH_TRIGGER,'Piramid4',nil);
	end;
end;

Trigger (OBJECT_TOUCH_TRIGGER,'Piramid1','ComeToPiramid1');
Trigger (OBJECT_TOUCH_TRIGGER,'Piramid2','ComeToPiramid2');
Trigger (OBJECT_TOUCH_TRIGGER,'Piramid3','ComeToPiramid3');
Trigger (OBJECT_TOUCH_TRIGGER,'Piramid4','ComeToPiramid4');
--------------------------------------------------------------////////DB////////
Trigger( REGION_ENTER_AND_STOP_TRIGGER, "water","SecretWater2" ,nil);

function SecretWater2 (heroname)
	Hero_at_the_Sea = heroname;
	startThread(SecretWaterCombat2);
end;


function SecretWaterCombat2 ()
	WENumber = 20*GetDifficulty(void);
	StartCombat (Hero_at_the_Sea, nil, 2, CREATURE_WATER_ELEMENTAL, WENumber, CREATURE_WATER_ELEMENTAL, WENumber); 	
end;
------------------------------------------------------///Piramid_secondary////////
Trigger( REGION_ENTER_AND_STOP_TRIGGER, "PiramidFog","Secret_piramid");

function Secret_piramid (heroname)
	print("Thread Secret_piramid");
	Hero_at_the_Sea = heroname;
	SetObjectiveState ('Sec1Piramid', OBJECTIVE_ACTIVE);
	Trigger( REGION_ENTER_AND_STOP_TRIGGER, "PiramidFog",nil);
--	print ('Objective_seondary_piramid_active');
end;
-----------------------------------------------------////Utopia_secondary/////////
Trigger( REGION_ENTER_AND_STOP_TRIGGER, "Utopia_Vision","Secret_Utopia",nil );

function Secret_Utopia (heroname)
	Hero_at_the_Sea = heroname;
	SetObjectiveState ('Sec2Utopia', OBJECTIVE_ACTIVE);
end;
-----------------------------------------------------------------///////////////
------------------ SECONDARY OBJECTIVE - PIRAMIDE END ------
Trigger (OBJECTIVE_STATE_CHANGE_TRIGGER, 'Prim1Artifact', 'CheckVictory');
Trigger (OBJECTIVE_STATE_CHANGE_TRIGGER, 'Prim2DefAll', 'CheckVictory');

function CheckVictory ()
	if GetObjectiveState ('Prim1Artifact') == OBJECTIVE_COMPLETED and GetObjectiveState ('Prim2DefAll') == OBJECTIVE_COMPLETED	then
    StartDialogScene("/Timerkhan/TEST/S2/DialogScene.xdb#xpointer(/DialogScene)")
    sleep(5)
		Win ();
	end;
end;

--while 1 do
-- sleep (5);
 -- SeePiramid ();
-- CheckPiramid ();
CheckVictory ();
--end;
HeroRase ();