Scriptname _00E_MQ15_Functions extends Quest  

Import _00E_QuestFunctions
Import Utility

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

Function SetUp()

	akTealor = _00E_MC_TealorREF
	akYuslan = _00E_MC_YuslanREF

	If MQ14_SC05_PropSwitcher.IsDisabled()
		MQ14_SC05_PropSwitcher.Enable()
	EndIf

	_00E_MC_LeoraREF.MoveTo(MQ15_SC01_LeoraMarker)
	MQ15_SC02_EldritchBarrierREF.Enable()
	
	int iIndex = MQ15_NPCsToDisable.GetSize() - 1
	
	while iIndex >= 0 
		ObjectReference akActorToDisable = MQ15_NPCsToDisable.GetAt(iIndex) as ObjectReference
		akActorToDisable.Disable()
		iIndex -= 1
	endwhile
	
	ChooseCompanion()
	
	_00E_SuntempleChroniker02REF.Enable()
	_00E_SuntempleChroniker02REF.MoveTo(MQ12b_SC14_TealorMarkerREF)
	MQ16_StubbornGuardREF.MoveTo(MQ07a_SC13_PlayerTeleport)
	
	If akCompanion.IsDisabled()
		akCompanion.Enable()
	EndIf
	
	akCompanion.MoveTo(MQ15_SC01_CompanionBenchMarker)
	MQ15_SC02_DoorREF.BlockActivation(True)

EndFunction

Function ChooseCompanion()
		
	If MQ14.akCompanion
		Companion.ForceRefTo(MQ14.akCompanion)
		InjuredCompanion.ForceRefTo(MQ14.akInjuredCompanion)
	Else
		Companion.ForceRefTo(_00E_MC_JesparREF)
		InjuredCompanion.ForceRefTo(_00E_MC_CaliaREF)
	EndIf
	
	akCompanion = Companion.GetActorReference()
	akInjuredCompanion = InjuredCompanion.GetActorReference()
	
	If akInjuredCompanion.GetActorBase() == _00E_MC_Calia
		akInjuredCompanion.SetOutfit(_00E_MC_Calia_SimpleClothingBarefeet)
	Else
		akInjuredCompanion.SetOutfit(MinerClothesOutfit01NoBoots)
	EndIf

EndFunction

Function MoveYuslanAndTealorFailsave()
	
	_00E_MC_TealorREF.MoveTo(MQ15_SC03_TealorMarker)
	_00E_MC_YuslanREF.MoveTo(MQ15_SC03_YuslanMarker)
	
EndFunction

Function MoveNPCsToForbiddenRoom()

	_00E_MC_TealorREF.MoveTo(MQ15_SC03_TealorMarker)
	_00E_MC_TealorREF.SetOutfit(_25E_HolyOrder_WardenOutfitNoHelmetNoCape)
	_00E_MC_TealorREF.AddItem(_01E_20Huetergrossschwert, 1)
	_00E_MC_TealorREF.UnequipItem(_01E_20Hueterschwert)
	_00E_MC_TealorREF.RemoveItem(_01E_20Hueterschwert, 1)
	
	if akCompanion == _00E_MC_CaliaREF
		akCompanion.ResetInventory()
	EndIf
	
	_00E_MC_YuslanREF.Enable()
	
	_00E_MC_YuslanREF.MoveTo(MQ15_SC03_YuslanMarker)

	MQ15_SC03_ForbiddenRoom.ForceStart()
	
EndFunction

Function MoveCompanion()

	akCompanion.MoveTo(MQ15_SC03_CompanionMoveMarker)

EndFunction

Function UnsealDoor()

	MQ15_SC03_DustMarker02.PlaceAtMe(FallingDustExplosion01)
	MQ15_SC03_DustMarker01.PlaceAtMe(FXdustDropMedExplosion)
	MQ15_SC03_Door.SetOpen(True)
	MAGConjurePortalOpenM.Play(MQ15_SC03_Door)
	DRSMetalGateHighHrothgarOpenM.Play(MQ15_SC03_Door)
	MQ15_SC03_DoorSeal01.PlaceAtMe(_00E_A2_WellOfLifeExplosionVisual)
	MQ15_SC03_DoorSeal02.PlaceAtMe(_00E_A2_WellOfLifeExplosionVisual)
	Wait(1)
	Debug.SendAnimationEvent(_00E_MC_TealorREF, "IdleForceDefaultState")
	
EndFunction

Function StartSC04()

	_00E_MC_YuslanREF.EquipItem(Torch01RedDesat)

	MQ15_SC04_TravelToTunnels.ForceStart()
	
	_00E_QuestFunctions.SetNPCAsCompanion(_00E_MC_TealorREF, True, 850, 550, 850)
	_00E_QuestFunctions.SetNPCAsCompanion(_00E_MC_YuslanREF, True, 650, 550, 850)
	_00E_QuestFunctions.SetNPCAsCompanion(akCompanion, True, 650, 700, 200)
	
EndFunction

Function TealorBreakWall()

	_00E_MC_TealorREF.PlayIdle(_00E_IdleStomp)
	Wait(0.5)
	_00E_MC_TealorREF.PlaceAtMe(TG08BShockwaveExplosion)
	Game.ShakeCamera(afStrength = 0.5)
	ShockFXShader.Play(MQ15_SC05_WallREF)
	Wait(1)
	MQ15_SC05_WallREF.Activate(_00E_MC_TealorREF)
	MQ15_SC05_WallREF.PlayAnimation("openStart")

EndFunction

Function StartSC05()

	_00E_MC_YuslanREF.UnequipItem(Torch01RedDesat)
	Debug.SendAnimationEvent(_00E_MC_YuslanREF, "IdleForceDefaultState")

	MQ15_SC05_Undercity.ForceStart()
	
EndFunction

Function ChopHead()

	_00E_MC_JesparREF.StopCombatAlarm()
	_00E_MC_JesparREF.StopCombat()
	_00E_MC_TealorREF.StopCombatAlarm()
	_00E_MC_TealorREF.StopCombat()
	_00E_MC_YuslanREF.StopCombatAlarm()
	_00E_MC_YuslanREF.StopCombat()
	MQ15_SC05_OldGuyREF.SetGhost(False)
	MQ15_SC05_DaughterREF.SetGhost(False)
	
	MQ15_SC05_OldGuyREF.PlayIdle(IdleHeadChop)

EndFunction

Function KillFailsave()
	
	_00E_MC_JesparREF.StopCombatAlarm()
	_00E_MC_JesparREF.StopCombat()
	_00E_MC_TealorREF.StopCombatAlarm()
	_00E_MC_TealorREF.StopCombat()
	_00E_MC_YuslanREF.StopCombatAlarm()
	_00E_MC_YuslanREF.StopCombat()
	MQ15_SC05_OldGuyREF.SetGhost(False)
	MQ15_SC05_DaughterREF.SetGhost(False)
	MQ15_SC05_DaughterREF.Kill(MQ15_SC05_DaughterREF)
	
	if !MQ15_SC05_OldGuyREF.IsDead()	
		MQ15_SC05_NehrimeseAssholeREF.PlayIdleWithTarget(pa_2HMKillMoveDecapSlash, MQ15_SC05_OldGuyREF)
	EndIf

EndFunction

Function PortToDumpMarker(Actor akPortActor)

	akPortActor.MoveTo(_00E_NPCDumpMarker)

EndFunction

Function StartSC06()

	_00E_QuestFunctions.SetNPCAsCompanion(_00E_MC_TealorREF, False)
	_00E_QuestFunctions.SetNPCAsCompanion(_00E_MC_YuslanREF, False)
	_00E_QuestFunctions.SetNPCAsCompanion(akCompanion, False)
	
	MQ15_SC06_YuslanDissolve.ForceStart()
	
EndFunction

Function DissolveRocks()

	
	_00E_MC_YuslanREF.PlayIdle(IdleCO2Ceremony2Blessing)
	_00E_MAGEldritchCharge500M.Play(MQ15_SC05_RockRef01)
	MQ15_SC06_EffectLight.Enable()
	_00E_EldritchDrainImodIntro.Apply()
	_00E_A1_DevourSoul_DisintegrateFXS.Play(MQ15_SC05_RockRef01)
	_00E_A1_DevourSoul_DisintegrateFXS.Play(MQ15_SC05_RockRef02)
	_00E_A1_DevourSoul_DisintegrateFXS.Play(MQ15_SC05_RockRef03)
	_00E_A1_DevourSoul_DisintegrateFXS.Play(MQ15_SC05_RockRef04)
	Utility.Wait(3)
	MQ15_SC05_RockRef04.Disable()
	MQ15_SC05_RockRef03.Disable()
	MQ15_SC05_RockRef02.Disable()
	MQ15_SC05_RockRef01.Disable()
	MQ15_SC06_EffectLight.Disable()
	
EndFunction

Function GiveEP()

	Levelsystem.GiveEP(__Config_iRewardEXP)
	MQ16.SetStage(5)
	
EndFunction

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

int Property __Config_iRewardEXP = 1000 Auto

_00E_QuestFunctions Property Levelsystem Auto

Quest Property MQ16 Auto

_00E_MQ14_Functions Property MQ14 Auto

Actor Property akTealor Auto Hidden
Actor Property akYuslan Auto Hidden
Actor Property akCompanion Auto Hidden
Actor Property akInjuredCompanion Auto Hidden

Actor Property _00E_SuntempleChroniker02REF Auto
Actor Property MQ16_StubbornGuardREF Auto
Actor Property _00E_MC_TealorREF Auto
Actor Property _00E_MC_YuslanREF Auto
Actor Property _00E_MC_LeoraREF Auto
Actor Property _00E_MC_JesparREF Auto
Actor Property _00E_MC_CaliaREF Auto
Actor Property MQ15_SC05_DaughterREF Auto
Actor Property MQ15_SC05_OldGuyREF Auto
Actor Property MQ15_SC05_NehrimeseAssholeREF Auto
Actor Property PlayerREF Auto

EffectShader Property ShockFXShader Auto

Outfit Property _00E_MC_Calia_SimpleClothingBarefeet Auto
Outfit Property MinerClothesOutfit01NoBoots Auto

ActorBase Property _00E_MC_Calia Auto

EffectShader Property _00E_A1_DevourSoul_DisintegrateFXS Auto

ObjectReference Property MQ15_SC01_LeoraMarker Auto
ObjectReference Property MQ15_SC02_EldritchBarrierREF Auto
ObjectReference Property MQ15_SC01_CompanionBenchMarker Auto
ObjectReference Property MQ14_SC05_PropSwitcher Auto
ObjectReference Property MQ15_SC03_YuslanMarker Auto
ObjectReference Property MQ15_SC03_TealorMarker Auto
ObjectReference Property MQ15_SC03_CompanionMoveMarker Auto
ObjectReference Property MQ15_SC03_DoorSeal01 Auto
ObjectReference Property MQ15_SC03_DoorSeal02 Auto
ObjectReference Property MQ15_SC03_DustMarker01 Auto
ObjectReference Property MQ15_SC03_DustMarker02 Auto
ObjectReference Property MQ15_SC03_Door Auto
ObjectReference Property MQ15_SC05_WallREF Auto
ObjectReference Property MQ15_SC05_RockRef01 Auto
ObjectReference Property MQ15_SC05_RockRef02 Auto
ObjectReference Property MQ15_SC05_RockRef03 Auto
ObjectReference Property MQ15_SC05_RockRef04 Auto
ObjectReference Property MQ15_SC06_EffectLight Auto
ObjectReference Property _00E_NPCDumpMarker Auto
ObjectReference Property MQ15_SC02_DoorREF Auto
ObjectReference Property MQ12b_SC14_TealorMarkerREF Auto
ObjectReference Property MQ07a_SC13_PlayerTeleport Auto

ImageSpaceModifier Property _00E_EldritchDrainImodIntro Auto

Formlist Property MQ15_NPCsToDisable Auto

Explosion Property _00E_A2_WellOfLifeExplosionVisual Auto
Explosion Property FallingDustExplosion01 Auto
Explosion Property FXdustDropMedExplosion Auto
Explosion Property TG08BShockwaveExplosion Auto

Outfit Property _25E_HolyOrder_WardenOutfitNoHelmetNoCape Auto

Light Property Torch01RedDesat Auto

Weapon Property _01E_20Huetergrossschwert Auto
Weapon Property _01E_20Hueterschwert Auto

Idle Property _00E_IdleStomp Auto
Idle Property IdleCO2Ceremony2Blessing Auto
Idle Property IdleHeadChop Auto
Idle Property pa_2HMKillMoveDecapSlash Auto

Sound Property DRSMetalGateHighHrothgarOpenM Auto
Sound Property MAGConjurePortalOpenM Auto
Sound Property _00E_MAGEldritchCharge500M Auto

Scene Property MQ15_SC01_Flavor_Leora Auto
Scene Property MQ15_SC02_Flavor_Gate Auto
Scene Property MQ15_SC03_ForbiddenRoom Auto
Scene Property MQ15_SC04_TravelToTunnels Auto
Scene Property MQ15_SC05_Undercity Auto
Scene Property MQ15_SC06_YuslanDissolve Auto

ReferenceAlias Property Companion Auto
ReferenceAlias Property InjuredCompanion Auto