;BEGIN FRAGMENT CODE - Do not edit anything between this and the end comment
;NEXT FRAGMENT INDEX 81
Scriptname QF_MQ103A_0002D75C Extends Quest Hidden

;BEGIN ALIAS PROPERTY FriendlyFollower01
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_FriendlyFollower01 Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY ExteriorDefender1
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_ExteriorDefender1 Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY KorvanjundMeetingPoint
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_KorvanjundMeetingPoint Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY ObjDraugr01
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_ObjDraugr01 Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY EnemyEavesdrop01a
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_EnemyEavesdrop01a Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY EbonyClaw
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_EbonyClaw Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY Hadvar
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_Hadvar Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY ExteriorDefender4
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_ExteriorDefender4 Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY FriendlyFollower04
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_FriendlyFollower04 Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY LockedGateLever02
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_LockedGateLever02 Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY Cell01ExitDoor
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_Cell01ExitDoor Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY BookMarker
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_BookMarker Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY Cell02ExitDoor
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_Cell02ExitDoor Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY Ulfric
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_Ulfric Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY Sifnar
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_Sifnar Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY Book
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_Book Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY DeadDraugrHeadTarget
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_DeadDraugrHeadTarget Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY ExteriorDefender5
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_ExteriorDefender5 Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY ObjDraugr05
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_ObjDraugr05 Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY Stage61EntranceMarker01
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_Stage61EntranceMarker01 Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY PreQuestDungeonDisabler
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_PreQuestDungeonDisabler Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY GeneralTullius
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_GeneralTullius Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY LegateRikke
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_LegateRikke Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY ObjDraugr03
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_ObjDraugr03 Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY FriendlyFollower03
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_FriendlyFollower03 Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY ExteriorDefender3
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_ExteriorDefender3 Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY DraugrBossMinion02
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_DraugrBossMinion02 Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY AmbushTarget
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_AmbushTarget Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY CaptainMetilius
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_CaptainMetilius Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY EnemyEavesdrop01b
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_EnemyEavesdrop01b Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY Korvanjund
;ALIAS PROPERTY TYPE locationalias
locationalias Property Alias_Korvanjund Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY Stage61EntranceMarker02
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_Stage61EntranceMarker02 Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY ObjDraugr04
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_ObjDraugr04 Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY FriendlyFollower02
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_FriendlyFollower02 Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY ExteriorDefender2
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_ExteriorDefender2 Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY ObjDraugr06
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_ObjDraugr06 Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY DraugrBoss
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_DraugrBoss Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY 03WarpMarker
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_03WarpMarker Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY HallOfStoriesDoor
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_HallOfStoriesDoor Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY Cell02FriendlyMoveToPoint
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_Cell02FriendlyMoveToPoint Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY DraugrBossMinion01
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_DraugrBossMinion01 Auto
;END ALIAS PROPERTY

;BEGIN ALIAS PROPERTY ObjDraugr02
;ALIAS PROPERTY TYPE ReferenceAlias
ReferenceAlias Property Alias_ObjDraugr02 Auto
;END ALIAS PROPERTY

;BEGIN FRAGMENT Fragment_5
Function Fragment_5()
;BEGIN CODE
; start quest on Imperial side
; debug.trace("MQ Quickstart " + self)
; TODO - see what stages of MQ102A we want to set as quickstart
MQ102A.setstage(1)
MQ102A.setstage(80)
MQ102A.setstage(100)
; END TODO section
CWStartObj.SetStage(100) ; join legion objective complete
setstage(10)
; debug.trace("MQ Quickstart " + self)
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_30
Function Fragment_30()
;BEGIN CODE
; Rikke reaches book chamber
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_60
Function Fragment_60()
;BEGIN CODE
; player hits first trigger in interior
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_75
Function Fragment_75()
;BEGIN CODE
;Player has entered book room
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_25
Function Fragment_25()
;BEGIN CODE
SetStage(1)
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_71
Function Fragment_71()
;BEGIN AUTOCAST TYPE MQ103QuestScript
Quest __temp = self as Quest
MQ103QuestScript kmyQuest = __temp as MQ103QuestScript
;END AUTOCAST
;BEGIN CODE
;Triggered at end of first phase of Attack 03 scene, forcing friendlies to move into cell 02

Alias_EnemyEavesdrop01a.GetActorReference().Kill()
Alias_EnemyEavesdrop01b.GetActorReference().Kill()

kmyQuest.InteriorAttack.Stop()
kmyQuest.InteriorAttack02.Stop()
kmyQuest.MQ103aInteriorAttack03.Start()

if (Game.GetPlayer().GetParentCell() != Alias_LegateRikke.GetReference().GetParentCell())
	(Alias_LegateRikke.GetActorReference().GetCombatTarget()).Kill()
	Alias_LegateRikke.GetActorReference().StopCombat()
	Alias_LegateRikke.GetReference().MoveTo(Alias_Cell02FriendlyMoveToPoint.GetReference())
	Alias_LegateRikke.GetActorReference().EvaluatePackage()
endif

if Alias_Hadvar.GetActorReference().IsDead() == 0 && (Game.GetPlayer().GetParentCell() != Alias_Hadvar.GetReference().GetParentCell())
	(Alias_Hadvar.GetActorReference().GetCombatTarget()).Kill()
	Alias_Hadvar.GetActorReference().StopCombat()
	Alias_Hadvar.GetReference().MoveTo(Alias_Cell02FriendlyMoveToPoint.GetReference())
	Alias_Hadvar.GetActorReference().EvaluatePackage()
endif

if Alias_FriendlyFollower01.GetActorReference().IsDead() == 0 && (Game.GetPlayer().GetParentCell() != Alias_FriendlyFollower01.GetReference().GetParentCell())
	(Alias_FriendlyFollower01.GetActorReference().GetCombatTarget()).Kill()
	Alias_FriendlyFollower01.GetActorReference().StopCombat()
	Alias_FriendlyFollower01.GetReference().MoveTo(Alias_Cell02FriendlyMoveToPoint.GetReference())
	Alias_FriendlyFollower01.GetActorReference().EvaluatePackage()
endif

if Alias_FriendlyFollower02.GetActorReference().IsDead() == 0 && (Game.GetPlayer().GetParentCell() != Alias_FriendlyFollower02.GetReference().GetParentCell())
	(Alias_FriendlyFollower02.GetActorReference().GetCombatTarget()).Kill()
	Alias_FriendlyFollower02.GetActorReference().StopCombat()
	Alias_FriendlyFollower02.GetReference().MoveTo(Alias_Cell02FriendlyMoveToPoint.GetReference())
	Alias_FriendlyFollower02.GetActorReference().EvaluatePackage()
endif
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_4
Function Fragment_4()
;BEGIN AUTOCAST TYPE MQ103QuestScript
Quest __temp = self as Quest
MQ103QuestScript kmyQuest = __temp as MQ103QuestScript
;END AUTOCAST
;BEGIN CODE
;LockedGate01.disable()
;SetObjectiveCompleted(50) ;COMPLETE Find a way to open the gate
;SetObjectiveDisplayed(55) ;DISPLAY Follow Legate Rikke
; TEMP - switch factions to get them to work right

;Alias_EnemyEavesdrop01a.GetActorRef().RemoveFromFaction(MQ103DefenderFaction)
;Alias_EnemyEavesdrop01b.GetActorRef().RemoveFromFaction(MQ103DefenderFaction)
;Alias_EnemyEavesdrop01a.GetActorRef().AddToFaction(MQ103DefenderFaction)
;Alias_EnemyEavesdrop01b.GetActorRef().AddToFaction(MQ103DefenderFaction)
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_11
Function Fragment_11()
;BEGIN AUTOCAST TYPE MQ103QuestScript
Quest __temp = self as Quest
MQ103QuestScript kmyQuest = __temp as MQ103QuestScript
;END AUTOCAST
;BEGIN CODE
setObjectiveCompleted(10)
; player is sent to Korvanjund
setObjectiveDisplayed(20)
kmyQuest.KorvanjundMapMarker.AddToMap()
; enable friendly soldiers
Alias_PreQuestDungeonDisabler.GetReference().Disable()
ImperialAttackEnableMarker.enable()

; move Hadvar, give him equipment, make him aggressive
If kmyquest.MQ102A.IsRunning()
kmyquest.MQ102A.setStage(52) ;stops the Hadvar Riverwood scene, and prevents it from happening again
endif
If kmyquest. MQ102B.IsRunning()
kmyquest.MQ102B.setStage(52) ;stops the Ralof Riverwood scene, and prevents it from happening again
endif

Alias_Hadvar.GetRef().moveto(KorvanjundMeetingPoint)
Alias_Hadvar.GetActorRef().AddToFaction(CWImperialFactionNPC)
Alias_Hadvar.GetActorRef().SetActorValue("Aggression", 1)
Alias_Hadvar.GetActorRef().SetOutfit(HadvarOutfit)
Alias_Hadvar.TryToEnable()
kmyquest.CWs.BuddyDialogueAllowed = true
; TODO everything else necessary to set up Korvanjund...
;RegisterForUpdate(2)
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_14
Function Fragment_14()
;BEGIN AUTOCAST TYPE MQ103QuestScript
Quest __temp = self as Quest
MQ103QuestScript kmyQuest = __temp as MQ103QuestScript
;END AUTOCAST
;BEGIN CODE
; player arrives at Korvanjund
Alias_LegateRikke.GetReference().moveto(KorvanjundMeetingPoint)
; start exterior intro scene
kmyQuest.ExteriorIntro.Start()
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_54
Function Fragment_54()
;BEGIN CODE
; debug.trace(self + " stage 45")
; player aggros defenders
setStage(50)
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_74
Function Fragment_74()
;BEGIN AUTOCAST TYPE MQ103QuestScript
Quest __temp = self as Quest
MQ103QuestScript kmyQuest = __temp as MQ103QuestScript
;END AUTOCAST
;BEGIN CODE
;QuickStart to last room and scene

Alias_PreQuestDungeonDisabler.GetReference().Disable()
ImperialAttackEnableMarker.enable()

SetStage(170)

kmyquest.ExteriorAttack.Stop()
kmyquest.ExteriorIntro.Stop()
kmyquest.MQ103aInteriorAttack03.Stop()
MQ103aExteriorAttack.Stop()
MQ103aInteriorAttack02.Stop()

Alias_FriendlyFollower01.GetReference().Enable()
Alias_FriendlyFollower02.GetReference().Enable()

Alias_FriendlyFollower01.GetReference().MoveTo(Game.GetPlayer())
Alias_FriendlyFollower02.GetReference().MoveTo(Game.GetPlayer())
Alias_Hadvar.GetReference().MoveTo(Game.GetPlayer())
Alias_LegateRikke.GetReference().MoveTo(Game.GetPlayer())

kmyquest.MQ103aBookRoom.Start()
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_64
Function Fragment_64()
;BEGIN CODE
; trigger boss Minions
Alias_DraugrBossMinion01.GetReference().Activate(Alias_DraugrBossMinion01.GetReference())
utility.wait(0.78)
Alias_DraugrBossMinion02.GetReference().Activate(Alias_DraugrBossMinion02.GetReference())
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_37
Function Fragment_37()
;BEGIN CODE
;Player tried open the door with the wrong combination.  Stage only sets the first time the player does it.
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_2
Function Fragment_2()
;BEGIN CODE
;SetObjectiveCompleted(45) ; COMPLETED Follow Legate Rikke
;SetObjectiveDisplayed(50) ;DISPLAY Find a way to open the gate
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_69
Function Fragment_69()
;BEGIN CODE
;Make sure enemies outside are dead, in case player skipped ahead.
Alias_ExteriorDefender1.GetActorReference().Kill()
Alias_ExteriorDefender2.GetActorReference().Kill()
Alias_ExteriorDefender3.GetActorReference().Kill()
Alias_ExteriorDefender4.GetActorReference().Kill()
Alias_ExteriorDefender5.GetActorReference().Kill()

Alias_LegateRikke.GetReference().MoveTo(Alias_Stage61EntranceMarker01.GetReference())
Alias_LegateRikke.GetActorReference().EvaluatePackage()

if Alias_Hadvar.GetActorReference().IsDead() == 0
	Alias_Hadvar.GetReference().MoveTo(Alias_Stage61EntranceMarker02.GetReference())
	Alias_Hadvar.GetActorReference().EvaluatePackage()
endif

if Alias_FriendlyFollower01.GetActorReference().IsDead() == 0
	Alias_FriendlyFollower01.GetReference().MoveTo(Alias_Stage61EntranceMarker01.GetReference())
	Alias_FriendlyFollower01.GetActorReference().EvaluatePackage()
endif

if Alias_FriendlyFollower02.GetActorReference().IsDead() == 0
	Alias_FriendlyFollower02.GetReference().MoveTo(Alias_Stage61EntranceMarker02.GetReference())
	Alias_FriendlyFollower02.GetActorReference().EvaluatePackage()
endif

if Alias_FriendlyFollower03.GetActorReference().IsDead() == 0
	Alias_FriendlyFollower03.GetReference().MoveTo(Alias_Stage61EntranceMarker01.GetReference())
	Alias_FriendlyFollower03.GetActorReference().EvaluatePackage()
endif

if Alias_FriendlyFollower04.GetActorReference().IsDead() == 0
	Alias_FriendlyFollower04.GetReference().MoveTo(Alias_Stage61EntranceMarker02.GetReference())
	Alias_FriendlyFollower04.GetActorReference().EvaluatePackage()
endif

SetStage(60)
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_77
Function Fragment_77()
;BEGIN AUTOCAST TYPE MQ103QuestScript
Quest __temp = self as Quest
MQ103QuestScript kmyQuest = __temp as MQ103QuestScript
;END AUTOCAST
;BEGIN CODE
;Failsafe to make sure they are all activated, and attacking
Alias_DraugrBoss.GetReference().Activate(Alias_DraugrBoss.GetReference())
Alias_DraugrBossMinion01.GetReference().Activate(Alias_DraugrBossMinion01.GetReference())
Alias_DraugrBossMinion02.GetReference().Activate(Alias_DraugrBossMinion02.GetReference())
Alias_DraugrBoss.GetActorReference().RemoveFromFaction(kmyquest.DunPrisonerFaction)
Alias_DraugrBossMinion01.GetActorReference().RemoveFromFaction(kmyquest.DunPrisonerFaction)
Alias_DraugrBossMinion02.GetActorReference().RemoveFromFaction(kmyquest.DunPrisonerFaction)
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_38
Function Fragment_38()
;BEGIN CODE
;Player opens the Hall of Stories door.
;SetObjectiveCompleted(60) ;COMPLETE Open Hall of Stories Door
;SetObjectiveDisplayed(65) ;DISPLAY Follow Legate Rikke
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_47
Function Fragment_47()
;BEGIN CODE
;Player is told to open the locked gate
;SetObjectiveCompleted(65) ;COMPLETE Follow Legate Rikke
;SetObjectiveDisplayed(70) ;DISPLAY Open locked gate
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_42
Function Fragment_42()
;BEGIN CODE
;Player opens door out of draugr room, also unleashes the sleeping draugr
;SetObjectiveCompleted(70) ;COMPLETE Open Locked Gate
;SetObjectiveDisplayed(72) ;DISPLAY Defeat Draugr
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_9
Function Fragment_9()
;BEGIN CODE
; finished first part of Rikke conversation
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_62
Function Fragment_62()
;BEGIN CODE
; Rikke learns situation from soldier
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_72
Function Fragment_72()
;BEGIN CODE
;Player is ready to enter, or has entered, the HOS
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_66
Function Fragment_66()
;BEGIN CODE
; boss dead
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_49
Function Fragment_49()
;BEGIN CODE
; player has found book
; complete book objective
SetStage(180)
;utility.wait(3)
; trigger draugr boss
;setStage(174)
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_7
Function Fragment_7()
;BEGIN CODE
setObjectiveDisplayed(10)
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_32
Function Fragment_32()
;BEGIN CODE
; player brings crown to Ulfric instead of Tullius
Game.GetPlayer().removeitem(Alias_Book.GetReference(), 1)

SetObjectiveFailed (80)
SetObjectiveDisplayed(90)

; player joins Sons of Skyrim
CW.SetStage(12)

setStage(200)
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_28
Function Fragment_28()
;BEGIN CODE
; trigger eavesdrop conversation
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_46
Function Fragment_46()
;BEGIN CODE
;Player is told to open HOS door
;SetObjectiveCompleted(55) ;COMPLETE Follow Legate Rikke
;SetObjectiveDisplayed(60) ;DISPLAY Open Hall of Stories Door
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_76
Function Fragment_76()
;BEGIN CODE
; trigger boss
Alias_DraugrBoss.GetReference().Activate(Alias_DraugrBoss.GetReference())
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_18
Function Fragment_18()
;BEGIN AUTOCAST TYPE MQ103QuestScript
Quest __temp = self as Quest
MQ103QuestScript kmyQuest = __temp as MQ103QuestScript
;END AUTOCAST
;BEGIN CODE
; player has gotten the book for the Imperials
SetObjectiveCompleted(40) ; completed - retrieve the book

Alias_Hadvar.GetActorReference().AddToFaction(kmyquest.CWBuddies)

; disable Metilius
;Alias_CaptainMetilius.TryToDisable()
; complete all "dungeon" objectives, just in case
;SetObjectiveCompleted(45)
;SetObjectiveCompleted(50)
;SetObjectiveCompleted(55)
;SetObjectiveCompleted(60)
;SetObjectiveCompleted(65)
;SetObjectiveCompleted(70)
;SetObjectiveCompleted(72)
SetObjectiveDisplayed(80); DISPLAYED Give the book to tullius
UnregisterForUpdate()
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_16
Function Fragment_16()
;BEGIN CODE
; all defenders are dead
;SetObjectiveCompleted(30)
;SetObjectiveDisplayed(45)
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_78
Function Fragment_78()
;BEGIN CODE
;Set when the player is near enough to hear rikke talk about the ambush
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_36
Function Fragment_36()
;BEGIN CODE
;Player has picked up the Ebony Claw
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_58
Function Fragment_58()
;BEGIN CODE
; Hadvar greets player at Korvanjund
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_23
Function Fragment_23()
;BEGIN AUTOCAST TYPE MQ103QuestScript
Quest __temp = self as Quest
MQ103QuestScript kmyQuest = __temp as MQ103QuestScript
;END AUTOCAST
;BEGIN CODE
CompleteAllObjectives()
; release reservation of Korvanjund
KorvanjundReserved.Clear()

kmyquest.CW03.setstage(10)

ImperialAttackEnableMarker.disable()

Stop()
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_68
Function Fragment_68()
;BEGIN CODE
;Gets set when player hits trigger right near exterior door.  For deciding if Rikke and friends should just move on instead of waiting for the player.
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_0
Function Fragment_0()
;BEGIN AUTOCAST TYPE MQ103QuestScript
Quest __temp = self as Quest
MQ103QuestScript kmyQuest = __temp as MQ103QuestScript
;END AUTOCAST
;BEGIN CODE
; debug.trace(self + " stage 50")
; begin attack on Korvanjund
SetObjectiveCompleted(20)
;SetObjectiveDisplayed(30)
SetObjectiveDisplayed(40)
; make enemies of player
MQ103DefenderFaction.SetEnemy(PlayerFaction)
; remove all temporary friend factions
Alias_ExteriorDefender1.GetActorRef().RemoveFromFaction(TempFriendsFaction)
Alias_ExteriorDefender2.GetActorRef().RemoveFromFaction(TempFriendsFaction)
Alias_ExteriorDefender3.GetActorRef().RemoveFromFaction(TempFriendsFaction)
Alias_ExteriorDefender4.GetActorRef().RemoveFromFaction(TempFriendsFaction)
Alias_ExteriorDefender5.GetActorRef().RemoveFromFaction(TempFriendsFaction)
; start exterior attack scene
kmyQuest.ExteriorIntro.Stop()
kmyQuest.ExteriorAttack.Start()
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_20
Function Fragment_20()
;BEGIN AUTOCAST TYPE MQ103QuestScript
Quest __temp = self as Quest
MQ103QuestScript kmyQuest = __temp as MQ103QuestScript
;END AUTOCAST
;BEGIN CODE
; player speaks to Tullius
Game.GetPlayer().removeitem(Alias_Book.GetReference(), 1)
SetObjectiveCompleted (80)

;SetObjectiveDisplayed(90)
; start transition scene
;MQ104A.setstage(10)
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_56
Function Fragment_56()
;BEGIN CODE
; Rikke hits trigger after first big room
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_73
Function Fragment_73()
;BEGIN AUTOCAST TYPE MQ103QuestScript
Quest __temp = self as Quest
MQ103QuestScript kmyQuest = __temp as MQ103QuestScript
;END AUTOCAST
;BEGIN CODE
;LockedGate01.disable()
;SetObjectiveCompleted(50) ;COMPLETE Find a way to open the gate
;SetObjectiveDisplayed(55) ;DISPLAY Follow Legate Rikke
; TEMP - switch factions to get them to work right
;debug.MessageBox("Stage 81 has been set!")
Alias_EnemyEavesdrop01a.GetActorRef().RemoveFromFaction(MQ103DefenderFaction)
Alias_EnemyEavesdrop01b.GetActorRef().RemoveFromFaction(MQ103DefenderFaction)
Alias_EnemyEavesdrop01a.GetActorRef().AddToFaction(MQ103DefenderFaction)
Alias_EnemyEavesdrop01b.GetActorRef().AddToFaction(MQ103DefenderFaction)
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_43
Function Fragment_43()
;BEGIN CODE
;Player, and friends, have defeated all the draugr in the draugr room
;SetObjectiveCompleted(72) ;COMPLETE  Defeat Draugr
;SetObjectiveDisplayed(74) ;DISPLAY Find the Book
;END CODE
EndFunction
;END FRAGMENT

;BEGIN FRAGMENT Fragment_80
Function Fragment_80()
;BEGIN AUTOCAST TYPE MQ103QuestScript
Quest __temp = self as Quest
MQ103QuestScript kmyQuest = __temp as MQ103QuestScript
;END AUTOCAST
;BEGIN CODE
;Player has entered the book room.  Warping friendlies to him if they aren't already in this cell, and are alive.

Alias_ObjDraugr01.GetActorReference().Kill()
Alias_ObjDraugr02.GetActorReference().Kill()
Alias_ObjDraugr03.GetActorReference().Kill()
Alias_ObjDraugr04.GetActorReference().Kill()
Alias_ObjDraugr05.GetActorReference().Kill()
Alias_ObjDraugr06.GetActorReference().Kill()

kmyQuest.InteriorAttack.Stop()
kmyQuest.InteriorAttack02.Stop()
kmyQuest.MQ103aInteriorAttack03.Stop()
kmyQuest.MQ103aBookRoom.Start()

if (Game.GetPlayer().GetParentCell() != Alias_LegateRikke.GetReference().GetParentCell())
	Alias_LegateRikke.GetReference().MoveTo(Alias_03WarpMarker.GetReference())
	Alias_LegateRikke.GetActorReference().EvaluatePackage()
endif

if Alias_Hadvar.GetActorReference().IsDead() == 0 && (Game.GetPlayer().GetParentCell() != Alias_Hadvar.GetReference().GetParentCell())
	Alias_Hadvar.GetReference().MoveTo(Alias_03WarpMarker.GetReference())
	Alias_Hadvar.GetActorReference().EvaluatePackage()
endif

if Alias_FriendlyFollower01.GetActorReference().IsDead() == 0 && (Game.GetPlayer().GetParentCell() != Alias_FriendlyFollower01.GetReference().GetParentCell())
	Alias_FriendlyFollower01.GetReference().MoveTo(Alias_03WarpMarker.GetReference())
	Alias_FriendlyFollower01.GetActorReference().EvaluatePackage()
endif

if Alias_FriendlyFollower02.GetActorReference().IsDead() == 0 && (Game.GetPlayer().GetParentCell() != Alias_FriendlyFollower02.GetReference().GetParentCell())
	Alias_FriendlyFollower02.GetReference().MoveTo(Alias_03WarpMarker.GetReference())
	Alias_FriendlyFollower02.GetActorReference().EvaluatePackage()
endif
;END CODE
EndFunction
;END FRAGMENT

;END FRAGMENT CODE - Do not edit anything between this and the begin comment

scene Property MQ103aExteriorAttack  Auto  

scene Property MQ103aInteriorAttack02  Auto  

ObjectReference Property LockedGate01  Auto  

Quest Property MQ102A  Auto  

ObjectReference Property ImperialAttackEnableMarker  Auto  
{enables everything to set up the battle at Korvanjund}

ObjectReference Property KorvanjundMeetingPoint  Auto  

Faction Property TempFriendsFaction  Auto  
{faction that exterior soldiers are in on both sides
to prevent fighting prior to quest triggering it}

Quest Property MQ104A  Auto  

Faction Property MQ103DefenderFaction  Auto  
{faction used by the MQ103 defenders}

Faction Property PlayerFaction  Auto  

Quest Property CW  Auto  

Quest Property MQ104B  Auto  

Quest Property MQ103B  Auto  

Faction Property CWImperialFactionNPC  Auto  

LocationAlias Property KorvanjundReserved  Auto  

Outfit Property HadvarOutfit  Auto  

Quest Property CWStartObj  Auto  
