Scriptname __LALLJourneyHomeScript extends Quest conditional

;Lets stay hecking organized!

;Essentials
__LALLActorQuestScript Property SexThread Auto
SexlabFramework Property SexLab Auto
Actor Property PlayerRef Auto
DialogueFollowerScript Property FollowerQuest Auto
Quest Property ThisQuest Auto

;Zaz
zbfBondageShell Property Zaz Auto
zbfSlot Property ZSlot Auto Hidden

;Actors
Actor Property Feria Auto
Actor Property Oengul Auto
Actor Property Ambarys Auto
Actor Property DreamDragon Auto

;Object Refs
ObjectReference Property PlayerShackle Auto
ObjectReference Property FeriaShackle Auto
ObjectReference Property SafeKeepingChest Auto
ObjectReference Property DreamSequenceMoveTo Auto
ObjectReference Property DreamExitMarker Auto
ObjectReference Property FeriaDreamMoveToMarker Auto
ObjectReference Property DragonLandingPerch Auto
ObjectReference[] Property AmbarysMoveTo Auto
ObjectReference[] Property zbfShackles Auto
ObjectReference Property AmbarysTo Auto
ObjectReference Property MapMarkerHome Auto

;Int vars
Int Property OengulSeduced Auto Conditional Hidden
Int Property OengulAiTweak Auto Conditional Hidden
Int Property OengulQuestComplete Auto Conditional Hidden
Int Property NiranyeQuest Auto Conditional Hidden
Int Property NiranyeQuestComplete Auto Conditional Hidden
Int Property HilleviQuest Auto Conditional Hidden
Int Property HelleviQuestComplete Auto Conditional Hidden
Int Property FoodItemCounter Auto hidden
Int Property MomTalked Auto Conditional Hidden
Int Property DadTalked Auto Conditional Hidden
Int Property AmbarysSafetyCounter Auto Hidden
Int Property HelgenOrNot Auto
; 0 - not talked. 1 - going to hall 2 - in hall 3 - after hall
Int Property OengulStage Auto Conditional Hidden


;Ref Aliases
ReferenceAlias[] Property NPCRefs Auto

;Misc
Weather Property BlizzardWeather  Auto  
Scene Property AmbarysScene Auto
Armor Property WinterCoat Auto
Outfit Property FeriaCoatOutfit Auto
Idle Property SleepNod Auto
Formlist Property FoodFormlist Auto
Weapon Property AmbarysCrop Auto
Outfit Property DragonslayerSet Auto
Weapon Property DragonboneSword Auto
Perk Property DreamPlayerImmunityPerk Auto
Weapon Property FeriaWeaponReward Auto
ImageSpaceModifier Property Blackscreen  Auto  
Message Property HelgenMSG Auto
Faction Property CurrentFollowerFaction Auto
Sound Property SilenceTimer Auto


;Unbound
GlobalVariable Property IsUnbound Auto


Function ShackleActor(actor toShackle,ObjectReference theFurniture, bool tf)
if tf == true
Zaz.SlotActor(toShackle)
ZSlot = zaz.FindSlot(toShackle)
ZSlot.SetFurniture(theFurniture)
elseif tf == false
ZSlot = zaz.FindSlot(toShackle)
ZSlot.SetFurniture(none)
zaz.UnslotActor(toShackle)
endif
EndFunction


Function TalkedToParent(int which)
if which == 1
;mom
MomTalked = 1
elseif which == 2
;dad
DadTalked = 1
endif
EndFunction

;Fix for Feria getting seperated during split scene
Function CheckFeriaDistance()
if Feria.GetDistance(PlayerRef) > 10000
Feria.MoveTo(PlayerRef)
endif

EndFunction

Function HomeMapMarker(bool tf)
MapMarkerHome.EnableFastTravel(tf)
EndFunction


Function SecondDreamEnter()
;nuuuu
EndFunction

Function SecondDreamExit()
;nuuuu
EndFunction

Function FeriaUnfollow()
FollowerQuest.DismissFollower()
Feria.SetFactionRank(CurrentFollowerFaction,-1)
EndFunction

Function AtHomeSleepThoughts()
Game.FadeOutGame(true,true,0.1,3)
;add imod
Blackscreen.Apply(1)
debug.messagebox("You collapse into your bed, tired from the journey.")
utility.wait(2.0)
debug.messagebox("Listening to the sound of the blizzard outside, it's a miracle you made it home at all.")
utility.wait(4.0)
debug.messagebox("You fall into a gentle and warm sleep.")
utility.wait(4.0)
Game.FadeOutGame(false,true,0.1,3)
Blackscreen.Remove()

debug.messagebox("I wonder how Feria is doing? And mom and dad?")
EndFunction

Function BlackOutScene()
Game.ForceFirstPerson()
Game.DisablePlayerControls(true,true,false,false,true,true,true,false)
Blackscreen.Apply()
M[18].Show()
;debug.messagebox("I... I'm getting sleepy...")
utility.wait(5.0)
ThisQuest.SetStage(40)
EndFunction

Message[] Property M Auto


Function ComeBackScene()
M[0].Show()
;debug.messagebox("I... I... I hear... noise? Nearby? I have to go check it out...!")
Game.FadeOutGame(false,true,0.1,4)
Blackscreen.Remove()
Game.EnablePlayerControls(true,true,true,true,true,true,true,true)
utility.wait(5.0)
;debug.messagebox("Feria...? Where did... you go...?")
;debug.messagebox("I have to press on.")
M[1].Show()
M[2].Show()


EndFunction


Function DreamSequenceEnter()
;Tell Feria to wait up so she doesnt follow us
FollowerQuest.FollowerWait()

Game.FadeOutGame(true,true,0.1,3)
;Place player's items in safekeeping chest
;PlayerRef.RemoveAllItems(SafeKeepingChest)
PlayerRef.AddPerk(DreamPlayerImmunityPerk)
Feria.MoveTo(FeriaDreamMoveToMarker)
DreamDragon.SetForcedLandingMarker(DragonLandingPerch)
;Equip dragonstuff armor
Form Item1 = DragonslayerSet.GetNthPart(0)
Form item2 = DragonslayerSet.GetNthPart(1)
Form Item3 = DragonslayerSet.GetNthpart(2)
Form Item4 = DragonslayerSet.GetNthPart(3)
Form item5 = DragonslayerSet.GetNthPart(4)
PlayerRef.EquipItem(Item1)
PlayerRef.EquipItem(Item2)
PlayerRef.EquipItem(Item3)
PlayerRef.EquipItem(Item4)
PlayerRef.EquipItem(Item5)
PlayerRef.EquipItem(DragonboneSword)
PlayerRef.MoveTo(DreamSequenceMoveTo)

M[3].Show()
M[4].Show()
;debug.messagebox("Mmmnn.. H..Hey? This sure is a very vivid dream.")
;debug.messagebox("Ooo! A dragonslaying dream!")
EndFunction

Function DreamSequenceExit()
Utility.Wait(7.0)
PlayerRef.RemovePerk(DreamPlayerImmunityPerk)
Game.DisablePlayerControls(true,true,true,false,true,false,true,false)
;PlayerRef.RemoveAllitems()
;SafekeepingChest.RemoveAllitems(PlayerRef)
RemoveDragonGear()
PlayerRef.MoveTo(DreamExitMarker)
Game.FadeOutGame(true,true,0.1,5)
debug.sendAnimationEvent(PlayerRef,"IdleLaydown")
Utility.Wait(2.0)
M[5].Show()
M[6].Show()
;debug.messagebox("Wow! What an epic dream!")
;debug.messagebox("Oh.. I still have my journey with Feria to undertake. I should find her and let her know I'm awake.")
debug.sendAnimationEvent(PlayerRef,"IdleLaydown_Exit")
PlayerRef.PlayIdle(SleepNod)
Game.EnablePlayerControls(true,true,true,true,true,true,true,true)
EndFunction


Function RemoveDragonGear()
Form Item1 = DragonslayerSet.GetNthPart(0)
Form item2 = DragonslayerSet.GetNthPart(1)
Form Item3 = DragonslayerSet.GetNthpart(2)
Form Item4 = DragonslayerSet.GetNthPart(3)
Form item5 = DragonslayerSet.GetNthPart(4)
PlayerRef.RemoveItem(Item1,1)
PlayerRef.RemoveItem(Item2,1)
PlayerRef.RemoveItem(Item3,1)
PlayerRef.RemoveItem(Item4,1)
PlayerRef.RemoveItem(Item5,1)
PlayerRef.RemoveItem(DragonboneSword)
EndFunction



Function FeriaFollowAgain()
FollowerQuest.FollowerFollow()
EndFunction

Function NiranyeReward()
NiranyeQuest = 4
NiranyeQuestComplete = 1
Form Item1 = FeriaCoatOutfit.GetNthPart(0)
Form Item2 = FeriaCoatOutfit.GetNthPart(1)
Form Item3 = FeriaCoatOutfit.GetNthPart(2)
Form Item4 = FeriaCoatOutfit.GetNthPart(3)
PlayerRef.AddItem(Item1,1)
PlayerRef.AddItem(Item2,1)
PlayerRef.AddItem(Item3,1)
Feria.SetOutfit(FeriaCoatOutfit)
Ambarys.Resurrect()
CheckAllObjectives()
EndFunction

Function HilleviReward()
HelleviQuestComplete = 1
HilleviQuest = 4
Give25FoodItems()
CheckAllObjectives()
EndFunction

Function Give25FoodItems()
if FoodItemCounter <= 25
PlayerRef.AddItem(PickFoodItem(),1)
FoodItemCounter = FoodItemCounter + 1
Give25FoodItems()
endif
EndFunction

Form Function PickFoodItem()
int random = Utility.RandomInt(0,10)
return FoodFormlist.GetAt(random)
EndFunction

Function SetNiranyeQuest(int to)
NiranyeQuest = to
CheckAllObjectives()
EndFunction

Function SetHilleviQuest(int to)
HilleviQuest = to
CheckAllObjectives()
EndFunction

Function ShacklePlayerAndFeria()
Game.FadeOutGame(true,true,0.1,3)
PlayerRef.MoveTo(AmbarysMoveTo[0])
Feria.MoveTo(AmbarysMoveTo[1])
Feria.RemoveAllItems(SafekeepingChest,true,true)
ShackleActor(PlayerRef,zbfShackles[0],true)
ShackleActor(Feria,zbfShackles[1],true)
utility.wait(0.5)
Ambarys.MoveTo(AmbarysTo)
AmbarysScene.Start()
NiranyeQuest = 2
Ambarys.EquipItem(AmbarysCrop,false,true)
Game.ForceFirstPerson()
;Game.DisablePlayerControls(true,true,true,false,true,true,true,true)
M[7].Show()
M[8].Show()
;debug.messagebox("Ugh... that drink must've knocked me out.")
;debug.messagebox("Hm? It looks like he didn't tie my arms very tight. Maybe if I pull a bit...")
StartTimer()
EndFunction

Function PlayerBreaksFree()
ShackleActor(PlayerRef,zbfShackles[0],false)
M[9].Show()
;debug.messagebox("My arm slipped free from the shackle! I'm free now. I should help Feria.")
Game.EnablePlayerControls(true,true,true,true,true,true,true,true)
ThisQuest.SetObjectiveDisplayed(13)
UnregisterForUpdate()
EndFunction

Function FreeFeria()
ShackleActor(Feria,zbfShackles[1],false)
EndFunction

Function StartTimer()
RegisterForUpdate(5.0)
if SilenceTimer.PlayAndWait(PlayerRef) == true
PlayerBreaksFree()
UnregisterForUpdate()
endif
EndFunction

Function OengulScene()
;Sexlab.QuickStart(PlayerRef,Oengul,Feria,none,none,none,none,"threesome")
actor[] partytime = new actor[3]
partytime[0] = PlayerRef
partytime[1] = Feria
partytime[2] = Oengul
OengulSeduced = SexThread.FillIntThread2(partytime,1,"threesome")
EndFunction

Function AlwaysBadWeather()
if Weather.GetCurrentWeather() != BlizzardWeather
BlizzardWeather.SetActive()
endif
EndFunction

Function SetOengulAI(int to)
OengulAiTweak = to
if to == 2
OengulQuestComplete = 1
Feria.AddItem(FeriaWeaponReward,1)
CheckAllObjectives()
endif
endFunction

Function OengulStage(int to)
OengulStage = to
CheckAllObjectives()
if OengulStage == 5

endif
EndFunction

Event OnUpdate()
int stage = ThisQuest.GetStage()

if NiranyeQuest == 2 && stage == 10
debug.notification("You tug and pull against the shackles but to no avail")
AmbarysSafetyCounter += 1
if AmbarysSafetyCounter >= 7
PlayerBreaksFree()
endif
endif

if stage >= 30 && stage < 45
AlwaysBadWeather()
endif

EndEvent

Function CheckAllObjectives()
if OengulQuestComplete == 1 && HelleviQuestComplete == 1 && NiranyeQuestComplete == 1
ThisQuest.SetObjectiveDisplayed(19)
endif
EndFunction

Function AskHelgen(int aiButton = 9)
;Float Unbound = IsUnbound.GetValue()
;if Unbound != 1
;aiButton = HelgenMSG.Show()
;if aiButton == 0
;ArthLAL.SetAddonQuestStage(47,ThisQuest)
;ArthLALChargenQuest.SetStage(30)
;ThisQuest.SetObjectiveCompleted(40)
;ThisQuest.SetObjectiveDisplayed(45)
;HelgenOrNot = 0
;elseif aiButton == 1
;Go through Helgen
;ThisQuest.SetStage(50)
;ThisQuest.SetObjectiveCompleted(40)
;ThisQuest.SetObjectiveDisplayed(45)
;HelgenOrNot = 1
;endif
;else
;Move me to Helgen
;endif

UnboundHelgenMove()
EndFunction

ObjectReference Property HelgenMarker Auto

Function UnboundHelgenMove()
Game.EnablePlayerControls(true,true,true,true,true,true,true,true)
PlayerRef.MoveTo(HelgenMarker)
ThisQuest.SetStage(55)
M[10].Show()
;debug.messagebox("That was a close call!  Helgen was destroyed by a dragon. Ulfric and Tullius are nowhere to be found. I'm lucky I was able to slip away!")
EndFunction




Function Stage10Thoughts()
M[11].Show()
M[12].Show()
M[13].Show()
;debug.messagebox("Feria's right. We're going to need winter coats if we're going to survive the trip back to whiterun.")
;debug.messagebox("At least now me and her have good 'bartering skills.' Maybe I should talk to some people in town to see what we can find.")
;debug.messagebox("We're going to need 2 coats and some travel supplies. Food would be nice, too.")
EndFunction

Function FoundBurnedHome()
M[14].Show()
;debug.messagebox("Wh... what happened to my house!? Where are mom and dad!?")
EndFunction

Function FoundBurnedHome2()
M[15].Show()
M[16].Show()
;debug.messagebox("It... it looks like mom and dad died inside of the house. I... I'm an orphan now.")
;debug.messagebox("It looks like I'm on my own. The dragons... I'll get my revenge on them! I'll get my revenge on them all!")
EndFunction

Function Stage60Thoughts()
if IsUnbound.GetValue() != 1
M[17].Show()
;debug.messagebox("That was a close call... A dragon? That's crazy, considering I just dreampt about one. I... I should be brave and go back to Helgen to see if everyone is okay...!")
endif
EndFunction

;Cleanup function for NPCs
Function PostQuestCleanup()
NPCRefs[0].TryToClear()
NPCRefs[1].TryToClear()
NPCRefs[2].TryToClear()
NPCRefs[3].TryToClear()
NPCRefs[4].TryToClear()
EndFunction