Scriptname VCA_AffinityCheckCait Extends TopicInfo Hidden Const

Function Fragment_End(ObjectReference akSpeakerRef)

	Int CompanionIndex = 0

	GlobalVariable DisplayMode = Game.GetFormFromFile(0x01003614, "VisibleCompanionAffinity.esp") as GlobalVariable
	FormList ThresholdMessageList = Game.GetFormFromFile(0x01003603, "VisibleCompanionAffinity.esp") as FormList
	
	FormList DisplayMessageList
	
	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
	
	ShowAffinity(akSpeakerRef, DisplayMessageList.GetAt(CompanionIndex) 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)
	GlobalVariable DisplayMode = Game.GetFormFromFile(0x01003614, "VisibleCompanionAffinity.esp") as GlobalVariable
	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
