ScriptName VCA_Affinity_Holotape_QuestScript extends Quest conditional

;-- Properties --------------------------------------

GlobalVariable Property DisplayMode Auto
GlobalVariable Property TerminalColor Auto
GlobalVariable Property SupportItemSorting Auto

GlobalVariable Property CompanionCount Auto

FormList Property CompanionReferenceList Auto
FormList Property CompanionAvailabilityList Auto
FormList Property ThresholdMessageList Auto

Float Property IsCompanion = 0 Auto conditional
Float Property IsDanseSynth = 0 Auto conditional

Faction Property CurrentCompanionFaction Auto
Faction Property HasBeenCompanionFaction Auto

Quest Property BoS302Quest Auto

Message Property ColorPickerInfoMessage Auto

Message Property ItemSortingOFFMessage Auto
Message Property ItemSortingONMessage Auto
Form Property Affinity_List_Item Auto
Form Property Affinity_List_Sortable_Item Auto
Form Property Affinity_Holotape_Item Auto
Form Property Affinity_Holotape_Sortable_Item Auto

;-- Variables ---------------------------------------

FormList DisplayMessageList

;-- Functions ---------------------------------------

Function ProgramStart()

	If ( DisplayMode.GetValue() == 0 )
		DisplayMessageList = ThresholdMessageList.GetAt(0) as FormList
	ElseIf( DisplayMode.GetValue() == 1 )
		DisplayMessageList = ThresholdMessageList.GetAt(1) as FormList
	ElseIf( DisplayMode.GetValue() == 2 )
		DisplayMessageList = ThresholdMessageList.GetAt(2) as FormList
	ElseIf( DisplayMode.GetValue() == 3 )
		DisplayMessageList = ThresholdMessageList.GetAt(3) as FormList
	EndIf

	IsCompanion = 0
	CompanionCount.SetValue(0)
	Int i = 0
	While i < CompanionReferenceList.GetSize()
		Actor akCompanion = CompanionReferenceList.GetAt(i) as Actor
		If (akCompanion.IsInFaction(CurrentCompanionFaction) || akCompanion.IsInFaction(HasBeenCompanionFaction))
			GlobalVariable IsCompanionActor = CompanionAvailabilityList.GetAt(i) as GlobalVariable
			IsCompanionActor.SetValue(1)
			CompanionCount.SetValue(CompanionCount.GetValue() + 1)
			If ( i == 3 && BoS302Quest.IsObjectiveCompleted(10) )
				IsDanseSynth = 1
			EndIf
		EndIf
		i += 1
	EndWhile
EndFunction

Function ShowAffinityCait()
	ShowAffinity(CompanionReferenceList.GetAt(0) as ObjectReference, DisplayMessageList.GetAt(0) as FormList)
EndFunction

Function ShowAffinityCodsworth()
	ShowAffinity(CompanionReferenceList.GetAt(1) as ObjectReference, DisplayMessageList.GetAt(1) as FormList)
EndFunction

Function ShowAffinityCurie()
	ShowAffinity(CompanionReferenceList.GetAt(2) as ObjectReference, DisplayMessageList.GetAt(2) as FormList)
EndFunction

Function ShowAffinityDanse()
	ShowAffinity(CompanionReferenceList.GetAt(3) as ObjectReference, DisplayMessageList.GetAt(3) as FormList)
EndFunction

Function ShowAffinityDeacon()
	ShowAffinity(CompanionReferenceList.GetAt(4) as ObjectReference, DisplayMessageList.GetAt(4) as FormList)
EndFunction

Function ShowAffinityHancock()
	ShowAffinity(CompanionReferenceList.GetAt(5) as ObjectReference, DisplayMessageList.GetAt(5) as FormList)
EndFunction

Function ShowAffinityLongfellow()
	ShowAffinity(CompanionReferenceList.GetAt(6) as ObjectReference, DisplayMessageList.GetAt(6) as FormList)
EndFunction

Function ShowAffinityMacCready()
	ShowAffinity(CompanionReferenceList.GetAt(7) as ObjectReference, DisplayMessageList.GetAt(7) as FormList)
EndFunction

Function ShowAffinityNick()
	ShowAffinity(CompanionReferenceList.GetAt(8) as ObjectReference, DisplayMessageList.GetAt(8) as FormList)
EndFunction

Function ShowAffinityPiper()
	ShowAffinity(CompanionReferenceList.GetAt(9) as ObjectReference, DisplayMessageList.GetAt(9) as FormList)
EndFunction

Function ShowAffinityPreston()
	ShowAffinity(CompanionReferenceList.GetAt(10) as ObjectReference, DisplayMessageList.GetAt(10) as FormList)
EndFunction

Function ShowAffinityStrong()
	ShowAffinity(CompanionReferenceList.GetAt(11) as ObjectReference, DisplayMessageList.GetAt(11) as FormList)
EndFunction

Function ShowAffinityX688()
	ShowAffinity(CompanionReferenceList.GetAt(12) as ObjectReference, DisplayMessageList.GetAt(12) as FormList)
EndFunction

Function ShowAffinity(ObjectReference akCompRef, FormList MessageList)
	Actor akComp = akCompRef as Actor
	Float IsRomantic = akComp.getValue(followersscript.GetScript().CA_IsRomantic)
	Float CurrentThreshold = akComp.getValue(followersscript.GetScript().CA_CurrentThreshold)
	Bool IsDaed = akComp.IsDead()
	float CurrentAffinity = akComp.getValue(followersscript.GetScript().CA_Affinity)
	If (DisplayMode.GetValue() < 3)
		CurrentAffinity = CurrentAffinity / 10
	EndIf
	Message ThresholdMessage = MessageList.GetAt(getThresholdIndex(CurrentThreshold, IsRomantic, IsDaed)) as Message
	ThresholdMessage.show(CurrentAffinity, 0, 0, 0, 0, 0, 0, 0, 0)
EndFunction

Int Function getThresholdIndex(Float CurrentTreshold, Float IsRomantic, Bool IsDead)
	If (IsDead)
		Return 0
	ElseIf (IsRomantic > 0)
		Return 6
	ElseIf (CurrentTreshold == 1000)
		Return 5
	ElseIf (CurrentTreshold == 500)
		Return 4
	ElseIf (CurrentTreshold == -500)
		Return 2
	ElseIf (CurrentTreshold == -1000)
		Return 1
	Else
		Return 3
	EndIf
EndFunction

Function ChangeColor(Float Color)
	TerminalColor.SetValue(Color)
EndFunction

Function ChangeDisplayMode(Float Mode)
	DisplayMode.SetValue(Mode)
EndFunction

Function ChangeItemSorting(Float Mode)
	SupportItemSorting.SetValue(Mode)
	If Mode == 0
		Game.GetPlayer().RemoveItem(Affinity_List_Sortable_Item, 1, False)
		Game.GetPlayer().RemoveItem(Affinity_Holotape_Sortable_Item, 1, False)
		Game.GetPlayer().AddItem(Affinity_List_Item, 1, False)
		Game.GetPlayer().AddItem(Affinity_Holotape_Item, 1, False)
		ItemSortingOFFMessage.show(0, 0, 0, 0, 0, 0, 0, 0, 0)
	Else
		Game.GetPlayer().RemoveItem(Affinity_List_Item, 1, False)
		Game.GetPlayer().RemoveItem(Affinity_Holotape_Item, 1, False)
		Game.GetPlayer().AddItem(Affinity_List_Sortable_Item, 1, False)
		Game.GetPlayer().AddItem(Affinity_Holotape_Sortable_Item, 1, False)
		ItemSortingONMessage.show(0, 0, 0, 0, 0, 0, 0, 0, 0)
	EndIf
EndFunction

Function ColorPickerInfoShow()
	ColorPickerInfoMessage.show(0, 0, 0, 0, 0, 0, 0, 0, 0)
EndFunction
