Scriptname _00E_NQR01_Functions extends Quest Conditional

Import Utility
Import _00E_QuestFunctions

;=====================================================================================
;              							EVENTS                  					 
;=====================================================================================

Event OnUpdateGameTime()

	if GetStage() == 25
		SetObjectiveDisplayed(0, True, True)
		SetStage(30)
	Elseif GetStage() == 45
		SetObjectiveDisplayed(0, True, True)
		SetStage(50)
	Elseif GetStage() == 61
		SetObjectiveDisplayed(0, True, True)
		SetStage(62)
	Elseif GetStage() == 66
		SetObjectiveDisplayed(0, True, True)
		SetStage(70)
	EndIf
	
EndEvent

Event OnUpdate()

	if bAnimationFired == false && !bSecondAnimation
		Debug.SendAnimationEvent(FS_NQR01_Cinematic_Fake_Tharael_01, "attackPowerStartLeft")
		RegisterForSingleUpdate(0.1)
	elseif bAnimationFired == false && bSecondAnimation
		Debug.SendAnimationEvent(FS_NQR01_Cinematic_Fake_Tharael_01, "attackPowerStartRight")
		RegisterForSingleUpdate(0.1)
	endIf
	
EndEvent

Event OnAnimationEvent(ObjectReference akSource, string asEventName)

	if (akSource == FS_NQR01_Cinematic_Fake_Tharael_01) && (asEventName == "PowerAttack_Start_End") 
	
		UnregisterForAnimationEvent(FS_NQR01_Cinematic_Fake_Tharael_01, "PowerAttack_Start_End")
		bAnimationFired = true
		_00E_FS_NQR05_TharaelTeleportShock.Apply()
		Teleport(FS_NQR01_Cinematic_Fake_Tharael_01, FS_NQR01_Tharael_Teleport_01, false)
		_00E_FS_NQR01_TharaelIntro.Add()
		Wait(0.35)
		FS_NQR01_Cinematic_Fake_Tharael_01.SetGhost(True)
		FS_NQR01_Cinematic_GiantOriginMarker.KnockAreaEffect(500.0, 64)
		_00E_NQR01_Battle05_Parent.PlayIdle(GiantRecoilLarge)
		WPNImpactBladeVsFlesh.Play(_00E_NQR01_Battle05_Parent)
		_00E_NPCOorbaya_HitHeavyM.Play(_00E_NQR01_Battle05_Parent)
		Wait(0.45)
		_00E_FS_NQR01_CrowdGaspM.Play(PlayerREF)
		Teleport(FS_NQR01_Cinematic_Fake_Tharael_01, FS_NQR01_Tharael_Teleport_Withdraw, true)
		Attack02()
				
	elseif (akSource == FS_NQR01_Cinematic_Fake_Tharael_02) && (asEventName == "PowerAttack_Start_End") 
		
		UnregisterForAnimationEvent(FS_NQR01_Cinematic_Fake_Tharael_02, "PowerAttack_Start_End")
		bAnimationFired = true
		; Utility.Wait(0.15)
		Teleport(FS_NQR01_Cinematic_Fake_Tharael_02, FS_NQR01_Tharael_Teleport_02, false)
		Wait(0.35)
		WPNImpactBladeVsFlesh.Play(_00E_NQR01_Battle05_Parent)
		_00E_NPCOorbaya_HitM.Play(_00E_NQR01_Battle05_Parent)
		_00E_NQR01_Battle05_Parent.PlayImpactEffect(PHYBodyDragon)
		GAme.ShakeCamera()
		InitializeCoordinates(_00E_NQR01_Battle05_Parent)
		_00E_SC_TharaelREF.SetAlpha(0.0)
		_00E_SC_TharaelREF.MoveTo(_00E_NQR01_Battle05_Parent, EndLocX, EndLocY, EndLocZ, false)
		_00E_SC_TharaelREF.SetAngle(TargetAngleX, TargetAngleY, TargetAngleZ)
		Teleport(FS_NQR01_Cinematic_Fake_Tharael_02, FS_NQR01_Tharael_Teleport_Withdraw, true)
		Wait(0.45)
		Stab()
	endIf

EndEvent

;=====================================================================================
;              							FUNCTIONS                  					 
;=====================================================================================

;=======================================CINEMATIC=====================================

Function Prepare()

	FS_NQR01_Battle05_CageOpenerREF.Enable()
	FS_NQR01_Battle05_CageOpenerREF.MoveTo(FS_NQR01_Cinematic_OpenerREF)
	Levelsystem.SetAllowIdleChatter(False)
	FS_NQR01_PitFighterFacadeParentREF.Disable()
	FS_NQR01_Cinematic_Stage_01.SetValueInt(1)
	_00E_NQR01_Battle05_Parent.Enable()
	_00E_SC_TharaelREF.Enable()
	FS_NQR01_Cinematic_Fake_Tharael_01.EquipItemEx(_00E_FS_NQR05_Tharael_Dagger, 1, true)
	FS_NQR01_Cinematic_Fake_Tharael_01.EquipItemEx(_00E_FS_NQR05_Tharael_Dagger, 2, true)
	FS_NQR01_Cinematic_Fake_Tharael_02.EquipItemEx(_00E_FS_NQR05_Tharael_Dagger, 1, true)
	FS_NQR01_Cinematic_Fake_Tharael_02.EquipItemEx(_00E_FS_NQR05_Tharael_Dagger, 2, true)
	_00E_SC_TharaelREF.EquipItemEx(_00E_FS_NQR05_Tharael_Dagger, 1, true)
	_00E_SC_TharaelREF.EquipItemEx(_00E_FS_NQR05_Tharael_Dagger, 2, true)
	
	FS_NQR01_Cinematic_Fake_Tharael_01.Enable()
	FS_NQR01_Cinematic_Fake_Tharael_02.Enable()
	_00E_SC_TharaelREF.MoveTo(FS_NQR01_Cinematic_Fake_Tharael_02)
	
	;DEBUG
	; _00E_NQR01_Battle05_Parent.Enable()
	; _00E_NQR01_Battle05_Parent.MoveTo(FS_NQR01_Cinematic_GiantREF)
	; _00E_NQR01_Battle05_Parent.EvaluatePackage()
	;DEBUG
	
EndFunction

Function OpenDoor()

	FS_NQR01_Battle05_CageOpenerREF.PlayIdle(IdleTake)
	Wait(0.5)
	NQR01_SC01_Battle_04_CageDoor.SetOpen(True)
	_00E_Crowd_MQ14CheerM.Play(PlayerREF)

EndFunction

Function Death()

	Game.ShakeCamera(afStrength = 1.0)
	_00E_NQR01_Battle05_Parent.PlayImpactEffect(PHYBodyDragon)
	_00E_NQR01_Battle05_Parent.PlaceAtMe(_00E_FXDustExplosionBig)
	_00E_NPCOorbaya_DeathM.Play(_00E_NQR01_Battle05_Parent)
	Wait(2)
	FS_NQR01_Cinematic_Stage_02.SetValueInt(1)
	
EndFunction

Function InitializeCoordinates(Actor TargetVictim)

	EndLocX = (150*Math.Sin(TargetVictim.GetAngleZ()))
	EndLocY = (150*Math.Cos(TargetVictim.GetAngleZ()))
	EndLocZ = 0

	TargetAngleX = 0.0
	TargetAngleY = 0.0
	TargetAngleZ = TargetVictim.GetAngleZ() + 180

EndFunction

Function Stab()

	_00E_NQR01_Battle05_Parent.SetGhost(False)
	_00E_NQR01_Battle05_Parent.GetActorBase().SetEssential(False)
	
	; Utility.Wait(0.1)
	
	if _00E_SC_TharaelREF.PlayIdleWithTarget(pa_1HMKillMoveGiantA, _00E_NQR01_Battle05_Parent)
		MAGIllusionReleaseAimedSDM.Play(_00E_SC_TharaelREF)
		_00E_FS_NQR05_TharaelTeleportShock.Apply()
		_00E_SC_TharaelREF.SetAlpha(1.0)
		_00E_FS_NQR05_TharaelMaterializeFXS.Play(_00E_SC_TharaelREF)
		MAGIllusionFearExplosionSDM.Play(_00E_SC_TharaelREF)
		;Utility.Wait(2.4)
		Wait(2.0)
		Levelsystem.SlowMotion(2)
	endIf

	_00E_BloodyFXShader.Play(_00E_SC_TharaelREF)
	Wait(2.6)
	Death()
	
EndFunction

Function Teleport(Actor akActor, ObjectReference objLocation, bool bOut = false)

	if !bOut
		_00E_FS_NQR05_TharaelTeleportShockSmallIMOD.Apply()
		_00E_FS_NQR05_TharaelMaterializeFXS.Play(akActor)
	else
		_00E_FS_Tharael_DematerializeFXS.Play(akActor)
		Wait(0.2)
	endIf
	
	akActor.MoveTo(objLocation)
	MAGIllusionReleaseAimedSDM.Play(akActor)
	
EndFunction

Function GiantIntimidate()

	FS_NQR01_Battle05_CageOpenerREF.Disable()
	Debug.SendAnimationEvent(_00E_NQR01_Battle05_Parent, "aggroWarningStart")
	_00E_NPCOorbaya_IdleScreamM.Play(_00E_NQR01_Battle05_Parent)
	
EndFunction

Function Attack01()

	Game.DisablePlayerControls()
	_00E_NQR01_Battle05_Parent.SetGhost(true)
	bAnimationFired = false
	Debug.SendAnimationEvent(FS_NQR01_Cinematic_Fake_Tharael_01, "IdleStop")

	RegisterForAnimationEvent(FS_NQR01_Cinematic_Fake_Tharael_01, "PowerAttack_Start_End")
	
	Wait(0.25)
	Debug.SendAnimationEvent(FS_NQR01_Cinematic_Fake_Tharael_01, "attackPowerStartLeft")
	
	RegisterForSingleUpdate(0.1)

EndFunction

Function Attack02()

	bSecondAnimation = true
	
	Debug.SendAnimationEvent(FS_NQR01_Cinematic_Fake_Tharael_02, "IdleStop")
	
	RegisterForAnimationEvent(FS_NQR01_Cinematic_Fake_Tharael_02, "PowerAttack_Start_End")
	
	Wait(0.25)
	Debug.SendAnimationEvent(FS_NQR01_Cinematic_Fake_Tharael_02, "attackPowerStartRight")
	
	RegisterForSingleUpdate(0.1)

EndFunction

;=======================================CINEMATIC=====================================

Function GiveContract()

	SetObjectiveCompleted(5)
	PlayerREF.AddItem(_00E_NQR01_Contract, 1, false)

EndFunction

Function HandOverContract()

	SetObjectiveCompleted(10)
	PlayerREF.RemoveItem(_00E_NQR01_Contract, 1, false)
	
EndFunction

Function StartArenaBattle(int iObjectiveIndex, Actor akActorParent, Scene scSceneToStart)

	SetObjectiveCompleted(0)
	int iIndex = _00E_FS_NQR04_ArenaDummyFormlist.GetSize()
	While iIndex > 0
		iIndex -= 1
		Actor Dummy = _00E_FS_NQR04_ArenaDummyFormlist.GetAt(iIndex) as Actor
		Dummy.SetGhost(1)
	EndWhile
	Game.DisablePlayerControls()
	_00E_TeleportGlobal.SetValueInt(1)
	FS_NQR01_PitFighterFacadeParentREF.Disable()
	FS_NQR01_NavcutREF.Disable()
	_00E_FS_NQR01_IsCommentatorTalking.SetValueInt(0)
	_00E_FS_NQR01_CurrentlyInCombat.SetValueInt(1)
	akActorParent.Enable()
	SetObjectiveDisplayed(iObjectiveIndex)
	FadeToBlackIMOD.Apply()
	Wait(2)
	FadeToBlackHoldIMOD.ApplyCrossFade(2)
	NQR01_ArenaDoorREF.BlockActivation(True)
	PlayerREF.MoveTo(NQR01_SC01_PlayerStartFightMarker)
	FS_NQR01_ArenaGuardREF.Disable()
	StartCombatKulisse()
	FadeToBlackBackIMOD.ApplyCrossFade(3)
	_00E_FS_Theriantrophist_AllowTemporaryTransform.SetValueInt(1)
	scSceneToStart.ForceStart()
	
EndFunction

Function StartArenaCombat(Formlist flEnemies)

	Game.RequestAutoSave()
	_FS_Phasmalist_ControlQuest.MoveApparitionToPlayer()
	Game.EnablePlayerControls()
	Levelsystem.RemoveSilence()
	Levelsystem.SetAllowIdleChatter(False)
	_00E_FS_NQR01_ArenaBattleMusic.Add()
	
	int iIndex = flEnemies.GetSize()
	
	while iIndex > 0

		iIndex -= 1
		Actor akEnemy = flEnemies.GetAt(iIndex) as Actor
		akEnemy.SetActorValue("Aggression", 3)
		akEnemy.SetGhost(False)
		akEnemy.EvaluatePackage()
		
	endwhile
	
	if flEnemies == _00E_NQR01_Battle05_Enemies
		NQR01_SC01_Battle_04_CageDoor.SetOpen(True)
		_00E_SC_TharaelREF.Enable()
	EndIf

EndFunction

Function StartArenaBattle01()

	StartArenaBattle(15, _00E_NQR01_Battle01_Parent, NQR01_SC01_ArenaBattle_01)
	
EndFunction

Function StartArenaBattle02()

	StartArenaBattle(25, _00E_NQR01_Battle02_Parent, NQR01_SC01_ArenaBattle_02)

EndFunction

Function StartArenaBattle03()

	StartArenaBattle(30, _00E_NQR01_Battle03_Parent, NQR01_SC01_ArenaBattle_03)
	
EndFunction

Function StartArenaBattle04()

	if NQR01_Battle04_EnemyREF == NONE
		NQR01_Battle04_EnemyREF = Game.GetForm(0x00043C13) as Actor
	EndIf

	ArenaBattle_04_Enemy.ForceRefIfEmpty(NQR01_Battle04_EnemyREF)
	
	if NQR01_SC01_ArenaBattle_04 != Game.GetForm(0x00043C12) as Scene
		NQR01_SC01_ArenaBattle_04 = Game.GetForm(0x00043C12) as Scene
	EndIf
	
	StartArenaBattle(45, NQR01_Battle04_EnemyREF, NQR01_SC01_ArenaBattle_04)
	
EndFunction


Function StartArenaBattle05()

	if _00E_NQR01_Battle05_Parent == NONE
		_00E_NQR01_Battle05_Parent = Game.GetForm(0x00043C1C) as Actor
	EndIf
	
	ArenaBattle_05_Enemy.ForceRefIfEmpty(_00E_NQR01_Battle05_Parent)

	StartArenaBattle(35, _00E_NQR01_Battle05_Parent, NQR01_SC01_ArenaBattle_05)
	
EndFunction

Function StopArenaCombat()

	_00E_FS_Theriantrophist_AllowTemporaryTransform.SetValueInt(0)
	_00E_FS_NQR01_ArenaBattleMusic.Remove()
	int CrowdInstance = _00E_Crowd_MQ14CheerM.Play(PlayerREF)
	Sound.SetInstanceVolume(CrowdInstance, 0.8)
	_00E_FS_NQR01_CurrentlyInCombat.SetValueInt(0)
	SetObjectiveCompleted(15)
	FS_NQR01_ArenaGuardREF.StopCombat()
	FS_NQR01_ArenaGuardREF.StopCombatAlarm()
	
EndFunction

Function Register()

	SetObjectiveDisplayed(0, True, True)
	RegisterForSingleUpdateGameTime(24)

EndFunction

Function DisableCorpsesAndAdvanceStage(Formlist flEnemies, int iDesiredStage)

	_00E_TeleportGlobal.SetValueInt(0)
	Levelsystem.SetAllowIdleChatter(True)
	FS_NQR01_ArenaGuardREF.Enable()
	Wait(5)
	FadeToBlackIMOD.Apply()
	Wait(2)
	FadeToBlackHoldIMOD.ApplyCrossFade(2)
	
	int iIndex = flEnemies.GetSize()
	
	while iIndex > 0

		iIndex -= 1

		ObjectReference akEnemy = flEnemies.GetAt(iIndex) as ObjectReference
		akEnemy.RemoveAllItems(FS_NQR01_LootChestREF)
		akEnemy.Disable()
		
	endwhile
	
	iIndex = _00E_FS_NQR04_ArenaDummyFormlist.GetSize()
	While iIndex > 0
		iIndex -= 1
		Actor Dummy = _00E_FS_NQR04_ArenaDummyFormlist.GetAt(iIndex) as Actor
		Dummy.SetGhost(0)
	EndWhile

	PlayerREF.MoveTo(FS_NQR01_ReturnFromArenaMarkerREF)
	_FS_TheriantrophistControlQuest.TransformBackIfTransformed()
	FS_NQR01_PitFighterFacadeParentREF.Enable()
	FS_NQR01_PitFighterFacadeParentREF.MoveTo(FS_NQR01_Fistfighter01_Marker)
	FS_NQR01_Fistfighter02.MoveTo(FS_NQR01_Fistfighter02_Marker)
	FS_NQR01_NavcutREF.Enable()
	FS_NQR01_PitFighterFacadeParentREF.EvaluatePackage()
	FS_NQR01_Fistfighter02.EvaluatePackage()
	FS_NQR01_PitFighterFacadeParentREF.StartCombat(FS_NQR01_Fistfighter02)
	Wait(3)
	FadeToBlackBackIMOD.ApplyCrossFade(1)
	SetStage(iDesiredStage)
	Game.RequestAutoSave()
	
EndFunction

Function StartCombatKulisse()

	NQR01_CrowdParentREF.Enable()

EndFunction


Function GiveRewardBattle01()

	SetObjectiveCompleted(20)
	PlayerREF.AddItem(Gold001, __Config_iBattle01_Reward)
	Levelsystem.GiveEP(__Config_iBattle01_expReward)

EndFunction

Function GiveRewardBattle02()

	SetObjectiveCompleted(20)
	PlayerREF.AddItem(Gold001, __Config_iBattle02_Reward)
	Levelsystem.GiveEP(__Config_iBattle02_expReward)
	
EndFunction

Function GiveRewardBattle03()

	SetObjectiveCompleted(20)
	PlayerREF.AddItem(Gold001, __Config_iBattle03_Reward)
	Levelsystem.GiveEP(__Config_iBattle03_expReward)
	
EndFunction

Function GiveRewardBattle04()

	SetObjectiveCompleted(20)
	PlayerREF.AddItem(Gold001, __Config_iBattle04_Reward)
	Levelsystem.GiveEP(__Config_iBattle04_expReward)

EndFunction

Function GiveRewardBattle05()

	SetObjectiveCompleted(20)
	; Rasha says "can't pay you this time"
	; PlayerREF.AddItem(Gold001, __Config_iBattle05_Reward)
	Levelsystem.GiveEP(__Config_iBattle05_expReward)
	bAfterBattle05TalkStage = 1

EndFunction

Function FinishRashaLine()
	bAfterBattle05TalkStage = 2
EndFunction

Function SetUpSC04()

	_00E_FS_NQR01_Loot.Show()
	_00E_SC_TharaelREF.Enable()
	_00E_SC_TharaelREF.MoveTo(NQR01_SC04_TharaelMarker)

	NQR01_SC04_Tharael.ForceStart()
	_00E_SC_RashaREF.BlockActivation(true)
	
EndFunction

Function DespawnTharael()

	_00E_SC_TharaelREF.Disable()

EndFunction

Function WaitForNextCombat()

	FadeToBlackIMOD.Apply()
	Wait(2)
	FadeToBlackHoldIMOD.ApplyCrossFade(2)

	if GetStage() == 25
		SetStage(30)
	Elseif GetStage() == 45
		SetStage(50)
	Elseif GetStage() == 61
		SetStage(62)
	Elseif GetStage() == 66
		SetStage(70)
	EndIf
	
	FadeToBlackBackIMOD.ApplyCrossFade(1)
	
EndFunction

Function TharaelAppearInArena()
	
	Levelsystem.SetAllowIdleChatter(False)
	_00E_SC_TharaelREF.Enable()
	SetObjectiveCompleted(35)
	_00E_SC_TharaelREF.MoveTo(FS_NQR01_TharaelAppearREF)
	_00E_SC_TharaelREF.SetAlpha(0.0)
	_00E_A2_Ghostwalk_TeleportSound.Play(_00E_SC_TharaelREF)
	_00E_A2_GhostwalkTeleportReappearVFX.Play(_00E_SC_TharaelREF)
	Wait(1.5)
	_00E_NQR01_Battle05_Parent.SetGhost(True)
	_00E_A2_GhostwalkTeleportVFX.Play(_00E_SC_TharaelREF)
	_00E_A2_GhostwalkTeleportReappearVFX.Stop(_00E_SC_TharaelREF)
	_00E_SC_TharaelREF.PlaceAtMe(_00E_A2_GhostwalkImpactExplosion, 1)
	_00E_SC_TharaelREF.SetAlpha(1.0)
	_00E_NQR01_Battle05_Parent.StopCombat()
	_00E_NQR01_Battle05_Parent.StopCombatAlarm()
	Wait(2)
	_00E_SC_TharaelREF.PlayIdle(_00E_IdleThrow)
	Game.ShakeCamera()
	_00E_FS_NQR01_TharaelFlashpowderImod.Apply()
	MAGPowerRacialPacifyFire.Play(PlayerREF)
	_00E_NPCOorbaya_IdleIntimidateM.Play(_00E_NQR01_Battle05_Parent)
	Wait(1.5)
	WPNBowFire.Play(PlayerREF)
	Wait(0.1)
	WPNBowFire.Play(PlayerREF)
	Wait(0.2)
	WPNBowFire.Play(PlayerREF)
	Wait(0.2)
	WPNImpactArrowVsFlesh.Play(PlayerREF)
	Wait(0.3)
	WPNImpactArrowVsFlesh.Play(PlayerREF)
	Wait(0.2)
	WPNImpactArrowVsFlesh.Play(PlayerREF)
	_00E_NQR01_Battle05_Parent.SetGhost(False)
	_00E_NQR01_Battle05_Parent.GetActorBase().SetEssential(False)
	_00E_NQR01_Battle05_Parent.Kill(_00E_SC_TharaelREF)
	
EndFunction

Function TharaelStartCombat()

	Game.RequestAutoSave()
	_00E_A2_GhostwalkTeleportVFX.Stop(_00E_SC_TharaelREF)
	Levelsystem.RemoveSilence()
	Levelsystem.SetAllowIdleChatter(False)
	_00E_FS_NQR01_ArenaBattleMusic.Add()
	Game.EnablePlayerControls()
	Game.SetPlayerAIDriven(False)
	SetObjectiveDisplayed(35, False, False)
	SetObjectiveDisplayed(40)
	_00E_SC_TharaelREF.SetGhost(False)
	Teleport(_00E_SC_TharaelREF, FS_NQR01_TharaelBeamMarker01, true)
	FS_NQR01_Cinematic_Fake_Tharael_01.Disable()
	FS_NQR01_Cinematic_Fake_Tharael_02.Disable()
	_00E_FS_NQR05_TharaelMaterializeFXS.Play(_00E_SC_TharaelREF)
	_00E_SC_TharaelREF.RemoveFromFaction(PlayerAlliesFaction)
	_00E_SC_TharaelREF.StartCombat(PlayerREF)
	_00E_SC_TharaelREF.SetActorValue("Aggression", 3)
	_00E_SC_TharaelREF.EvaluatePackage()

EndFunction

Function TharaelStopCombat()

	_00E_FS_NQR01_ArenaBattleMusic.Remove()
	_00E_FS_NQR01_CurrentlyInCombat.SetValueInt(0)
	SetObjectiveCompleted(40)
	_00E_SC_TharaelREF.StopCombat()
	_00E_SC_TharaelREF.AddToFaction(PlayerAlliesFaction)
	_00E_SC_TharaelREF.SetGhost(True)
	_00E_SC_TharaelREF.ResetHealthAndLimbs()
	_00E_SC_TharaelREF.SetActorValue("Aggression", 1)
	
EndFunction

Function TeleportTharaelAndPlayer()

	Game.DisablePlayerControls()
	_00E_SC_TharaelREF.PlayIdle(IdleMagic_01)
	Debug.SendAnimationEvent(_00E_SC_TharaelREF, "IdleForceDefaultState")
	Wait(1.0)
	Teleport(_00E_SC_TharaelREF, NQR01_SC05_TharelMarker, true)
	_00E_FS_NQR05_TharaelMaterializeFXS.Play(_00E_SC_TharaelREF)
	_00E_SC_TharaelREF.Disable()
	_00E_SC_TharaelREF.MoveTo(NQR01_SC05_TharelMarker)
	_00E_FS_NQR05_TharaelTeleportShockSmallIMOD.Apply()
	Wait(0.5)
	Teleport(PlayerREF, NQR01_SC05_PlayerMarker, true)
	_00E_FS_NQR05_TharaelMaterializeFXS.Play(_00E_SC_TharaelREF)
	_00E_TeleportImod.Apply()
	
	if !FS_NQR01_SC8_IAmInTheWayRatREF.IsDead()
		FS_NQR01_SC8_IAmInTheWayRatREF.Kill(FS_NQR01_SC8_IAmInTheWayRatREF)
	EndIf
	
	_00E_SC_TharaelREF.RemoveItem(_00E_FS_NQR_TharaelsBow, 1, true)
	_00E_SC_TharaelREF.RemoveItem(_00E_FS_NQR_TharaelsArrows, 55, true)
	_00E_NQR01_Battle05_Parent.Disable()
	_FS_TheriantrophistControlQuest.TransformBackIfTransformed()
	
EndFunction

Function StartSC05()

	SetStage(80)
	Game.ForceFirstPerson()
	_00E_TeleportGlobal.SetValueInt(0)
	Levelsystem.SetAllowIdleChatter(True)
	FS_NQR01_ArenaGuardREF.Enable()
	FS_NQR01_PitFighterFacadeParentREF.Enable()
	FS_NQR01_PitFighterFacadeParentREF.MoveTo(FS_NQR01_Fistfighter01_Marker)
	FS_NQR01_Fistfighter02.MoveTo(FS_NQR01_Fistfighter02_Marker)
	FS_NQR01_NavcutREF.Enable()
	FS_NQR01_PitFighterFacadeParentREF.EvaluatePackage()
	FS_NQR01_Fistfighter02.EvaluatePackage()
	FS_NQR01_PitFighterFacadeParentREF.StartCombat(FS_NQR01_Fistfighter02)
	_00E_FS_NQR05_TharaelMaterializeFXS.Stop(_00E_SC_TharaelREF)
	_00E_FS_NQR05_TharaelMaterializeFXS.Stop(PlayerREF)
	_00E_FS_Tharael_DematerializeFXS.Stop(PlayerREF)
	_00E_FS_Tharael_DematerializeFXS.Stop(_00E_SC_TharaelREF)
	_00E_SC_TharaelREF.MoveTo(NQR01_SC05_TharelMarker)
	_00E_SC_TharaelREF.Enable()
	SetObjectiveDisplayed(50)
	Wait(3)
	NQR01_SC05_Explanation.ForceStart()

	Game.EnablePlayerControls()
	
EndFunction

Function GiveRewardEXP(bool bDeclined)

	_00E_SC_TharaelREF.UnEquipItemEx(_00E_FS_NQR05_Tharael_Dagger, 1, true)
	_00E_SC_TharaelREF.UnEquipItemEx(_00E_FS_NQR05_Tharael_Dagger, 2, true)
	Levelsystem.RemoveSilence()
	Levelsystem.RemoveCombatSoundtracks()
	Levelsystem.SetAllowIdleChatter(True)
	NQR01_SC05_Explanation.Stop()
	SetObjectiveCompleted(50)
	Levelsystem.GiveEP(__Config_iRewardEXP)
	Teleport(_00E_SC_TharaelREF, NQR01_SC01_PlayerStartFightMarker, true)
	_00E_SC_TharaelREF.AddItem(_00E_FS_NQR_TharaelsBow, 1, true)
	_00E_SC_TharaelREF.AddItem(_00E_FS_NQR_TharaelsArrows, 55, true)
	_00E_SC_TharaelREF.Disable()
	
	if !bDeclined
		PlayerREF.AddItem(_01E_FS_TeleportrolleUnterstadt, 3)
		FS_NQR02.SetStage(5)
	EndIf
	
EndFunction


;=====================================================================================
;              							PROPERTIES                  					 
;=====================================================================================

_00E_QuestFunctions Property Levelsystem Auto

int __Config_iBattle01_Reward = 150 
int __Config_iBattle02_Reward = 250 
int __Config_iBattle03_Reward = 350
int __Config_iBattle04_Reward = 450
int __Config_iBattle05_Reward = 550

int __Config_iBattle01_expReward = 150
int __Config_iBattle02_expReward = 250
int __Config_iBattle03_expReward = 350
int __Config_iBattle04_expReward = 450
int __Config_iBattle05_expReward = 550

int __Config_iRewardEXP = 1000 

Actor Property PlayerREF Auto
Actor Property _00E_SC_TharaelREF Auto
Actor Property _00E_SC_RashaREF Auto
Actor Property FS_NQR01_ArenaGuardREF Auto
Actor Property FS_NQR01_Fistfighter02 Auto
Actor Property FS_NQR01_PitFighterFacadeParentREF Auto
Actor Property FS_NQR01_SC8_IAmInTheWayRatREF Auto

_00E_Game_SkillmenuSC Property Player Auto

; 1: The Destroyer / Deathviper
; 2: The Wanderer / The Wanderer
; 3: The Prophet / The Prophetess
int Property iPlayerNameIndex = 1 Auto Conditional Hidden

Book Property _00E_NQR01_Contract Auto

ImageSpaceModifier Property FadeToBlackIMOD Auto
ImageSpaceModifier Property FadeToBlackHoldIMOD Auto
ImageSpaceModifier Property FadeToBlackBackIMOD Auto
ImageSpaceModifier Property _00E_TeleportImod Auto
ImageSpaceModifier Property _00E_FS_NQR01_TharaelFlashpowderImod Auto

EffectShader Property _00E_EspionageFXS Auto

Scroll Property _01E_FS_TeleportrolleUnterstadt Auto

Quest Property FS_NQR02 Auto

MusicType Property _00E_Music_Combat_BonehunterNoCond Auto

MiscObject Property Gold001 Auto

Message Property _00E_FS_NQR01_Loot Auto

ObjectReference Property NQR01_SC01_PlayerStartFightMarker Auto
ObjectReference Property NQR01_CrowdParentREF Auto
ObjectReference Property FS_NQR01_ReturnFromArenaMarkerREF Auto
ObjectReference Property NQR01_ArenaDoorREF Auto
ObjectReference Property NQR01_SC04_TharaelMarker Auto
ObjectReference Property NQR01_SC01_Battle_04_CageDoor Auto
ObjectReference Property FS_NQR01_TharaelAppearREF Auto
ObjectReference Property NQR01_SC04_RashaRun001 Auto
ObjectReference Property NQR01_SC05_TharelMarker Auto
ObjectReference Property NQR01_SC05_PlayerMarker Auto
ObjectReference Property FS_NQR01_LootChestREF Auto
ObjectReference Property FS_NQR01_Fistfighter01_Marker Auto
ObjectReference Property FS_NQR01_Fistfighter02_Marker Auto
ObjectReference Property FS_NQR01_NavcutREF Auto
ObjectReference Property FS_NQR01_TharaelBeamMarker01 Auto
ObjectReference Property FS_NQR01_Cinematic_OpenerREF Auto

Formlist Property _00E_NQR01_Battle01_Enemies Auto
Formlist Property _00E_NQR01_Battle02_Enemies Auto
Formlist Property _00E_NQR01_Battle03_Enemies Auto
Formlist Property _00E_NQR01_Battle04_Enemies Auto
Formlist Property _00E_NQR01_Battle05_Enemies Auto
Formlist Property _00E_FS_NQR04_ArenaDummyFormlist Auto

MusicType Property _00E_FS_NQR01_ArenaBattleMusic Auto
MusicType Property _00E_FS_Music_Special_Character_Tharael Auto
	
Idle Property WebIdleExit Auto
Idle Property IdleMagic_01 Auto
Idle Property _00E_IdleThrow Auto
Idle Property IdleTake Auto 

Actor Property _00E_NQR01_Battle01_Parent Auto
Actor Property _00E_NQR01_Battle02_Parent Auto
Actor Property _00E_NQR01_Battle03_Parent Auto
Actor Property _00E_NQR01_Battle05_Parent Auto
Actor Property NQR01_Battle04_EnemyREF Auto
Actor Property FS_NQR01_Battle05_CageOpenerREF Auto

GlobalVariable Property _00E_FS_NQR01_CurrentlyInCombat Auto
GlobalVariable Property FS_NQR01_Cinematic_Stage_01 Auto
GlobalVariable Property FS_NQR01_Cinematic_Stage_02 Auto
GlobalVariable Property _00E_FS_NQR01_IsCommentatorTalking Auto
GlobalVariable Property _00E_TeleportGlobal Auto

ReferenceAlias Property ArenaBattle_04_Enemy Auto
ReferenceAlias Property ArenaBattle_05_Enemy Auto

VisualEffect Property _00E_A2_GhostwalkTeleportVFX Auto
VisualEffect Property _00E_A2_GhostwalkTeleportReappearVFX Auto

Explosion Property _00E_A2_GhostwalkImpactExplosion Auto

Sound Property _00E_A2_Ghostwalk_TeleportSound Auto
Sound Property _00E_Crowd_MQ14CheerM Auto
Sound Property _00E_NPCOorbaya_IdleIntimidateM Auto
Sound Property _00E_NPCOorbaya_IdleScreamM Auto
Sound Property MAGPowerRacialPacifyFire Auto
Sound Property WPNBowFire Auto
Sound Property WPNImpactArrowVsFlesh Auto

Scene Property NQR01_SC01_ArenaBattle_01 Auto
Scene Property NQR01_SC01_ArenaBattle_02 Auto
Scene Property NQR01_SC01_ArenaBattle_03 Auto
Scene Property NQR01_SC01_ArenaBattle_04 Auto
Scene Property NQR01_SC01_ArenaBattle_05 Auto
Scene Property NQR01_SC04_Tharael Auto
Scene Property NQR01_SC05_Explanation Auto

Weapon Property _00E_FS_NQR_TharaelsBow Auto
Ammo Property _00E_FS_NQR_TharaelsArrows Auto

GlobalVariable Property _00E_FS_Theriantrophist_AllowTemporaryTransform Auto

; ==========================CINEMATIC=========================

Actor Property FS_NQR01_Cinematic_Fake_Tharael_01 Auto
Actor Property FS_NQR01_Cinematic_Fake_Tharael_02 Auto
Actor Property FS_NQR01_Cinematic_GiantREF Auto

float TargetAngleX
float TargetAngleY
float TargetAngleZ

float EndLocX
float EndLocY
float EndLocZ

bool bAnimationFired
bool bSecondAnimation

Idle Property pa_1HMKillMoveGiantA Auto
Idle Property GiantRecoilLarge Auto
Idle Property idleForceDefaultState Auto

ImpactDataSet Property PHYBodyDragon Auto

Faction Property PlayerAlliesFaction Auto

Weapon Property _00E_FS_NQR05_Tharael_Dagger Auto

Explosion Property _00E_FXDustExplosionBig Auto

EffectShader Property _00E_BloodyFXShader Auto
EffectShader Property _00E_FS_NQR05_TharaelMaterializeFXS Auto
EffectShader Property _00E_FS_Tharael_DematerializeFXS Auto

MusicType Property _00E_FS_NQR01_TharaelIntro Auto

ImageSpaceModifier Property _00E_FS_NQR05_TharaelTeleportShock Auto
ImageSpaceModifier Property _00E_FS_NQR05_TharaelTeleportShockSmallIMOD Auto

ObjectReference Property FS_NQR01_Tharael_Teleport_01 Auto
ObjectReference Property FS_NQR01_Tharael_Teleport_02 Auto
ObjectReference Property FS_NQR01_Tharael_Teleport_Withdraw Auto
ObjectReference Property FS_NQR01_Cinematic_GiantOriginMarker Auto

Sound Property _00E_NPCOorbaya_HitHeavyM Auto
Sound Property _00E_NPCOorbaya_IdleTauntM Auto
Sound Property _00E_NPCOorbaya_HitM Auto
Sound Property WPNImpactBladeVsFlesh Auto
Sound Property _00E_NPCOorbaya_DeathM Auto
Sound Property MAGIllusionReleaseAimedSDM Auto
Sound Property MAGIllusionFearExplosionSDM Auto
Sound Property _00E_FS_NQR01_CrowdGaspM Auto

; 0: no talk dones
; 1: GiveRewardBattle05 done
; 2: everything done, no more talking with Rasha
Int Property bAfterBattle05TalkStage = 0 Auto Conditional Hidden