ScriptName footprintsVCScript Extends Quest

Quest Property footprintsQuest Auto
Quest Property footprintsSkyUIConfig Auto

Keyword Property footprintsFootstepsEffect Auto
Spell Property footprintsCloakAbility Auto

GlobalVariable Property fp_IsFootprintsDisabled Auto
GlobalVariable Property fp_IsSKSEInstalled Auto
GlobalVariable Property fp_IsSkyUIInstalled Auto

Actor Property PlayerRef Auto

Float VersionNumber
Bool IsVCInstalled


Event OnInit()
	
EndEvent

int Function VersionCheckStart()
	{Returns:
		0 - Error
		1 - Normal/Complete
	}
	;Debug.Trace("~~~~~ Footprints VC:  Version Check Start ~~~~~")
	
	float oldVersion = VersionNumber
	float newVersion = GetModVersionNumber()

	; SKSE Check
	SKSECheck()

	If ( !IsVCInstalled )
		; Do stuff for New User
		Debug.Trace("~~~~~ Footprints VC:  New User. Version is " + newVersion + " ~~~~~")
		IsVCInstalled = True
		SetModVersionNumber()
		footprintsQuest.SetStage( 1 )
	Else
		If ( IsUpdateRequired( oldVersion, newVersion ) )
			; Do stuff for update
			UpdateVersion( oldVersion, newVersion )
			SetModVersionNumber()
		Else
			; No Update Required
			;Debug.Trace( "~~~~~ Footprints VC: Versions match. No Update Required! ~~~~~" )
		EndIf
	EndIf

	; SkyUI Check	
	SkyUICheck()

	return 1
EndFunction

Function SKSECheck()
	;Debug.Trace( "~~~~~ Footprints VC: SKSE Check Running ~~~~~" )
	int iSKSE = SKSE.GetVersionRelease() as int
	;Debug.Trace("~~~~~ Footprints VC: SKSE Integer value is: " + iSKSE + " ~~~~~")
	If ( iSKSE )
		If ( iSKSE > 32 )
			If ( !fp_IsSKSEInstalled.GetValue() )
				; Newly installed SKSE
				;Debug.Trace( "footprintsVCScript - Registering SKSE Release "  + iSKSE )
				fp_IsSKSEInstalled.SetValue( 1 )
			Else
				;Debug.Trace("~~~~~ Footprints VC: SKSE Already Registered ~~~~~")
			EndIf
		ElseIf ( fp_IsSKSEInstalled.GetValue() )
			Debug.Trace( "~~~~~ Footprints VC: SKSE uninstalled, unregistering ~~~~~" )
			fp_IsSKSEInstalled.SetValue( 0 )
		Else
			;Debug.Trace("footprintsVCScript - SKSE not installed, ignoring.")
			fp_IsSKSEInstalled.SetValue( 0 )
		EndIf
	EndIf
EndFunction

Function SkyUICheck()
	; Check for SkyUI here
	;Game.GetFormFromFile(0x00000802, "SkyUI.ESP")
	If ( fp_IsSKSEInstalled.GetValue() )
		Int modIndex = Game.GetModByName( "SkyUI.esp" )
		If ( modIndex != 255 )
			Debug.Trace( "~~~~~ Footprints VC: SkyUI Installed ~~~~~" )
			If ( footprintsSkyUIConfig.IsStopped() )
				Debug.Trace( "~~~~~ Footprints VC: Installing SkyUI MCM ~~~~~" )
				footprintsSkyUIConfig.Start()
			EndIf
		EndIf
	EndIf
EndFunction

bool Function IsUpdateRequired( float __from, float __to )
	Debug.Trace( "~~~~~ Footprints VC: Checking if update is required. (Current Version: " + __from + ") ~~~~~" )
	If ( __from != __to && __from != 0 )
		return True
	ElseIf ( __from == 0 )
		Debug.Trace( "~~~~~ Footprints VC: ERROR - VersionNumber should be set. ~~~~~", 2 )
	EndIf
	return False
EndFunction

bool Function IsVCInstalled()
	return IsVCInstalled
EndFunction

float Function GetModVersionNumber()
	return GetDefault.VersionNumber
EndFunction

float Function GetCurrVersionNumber()
	return VersionNumber
EndFunction

Function SetModVersionNumber()
	VersionNumber = GetModVersionNumber()
EndFunction

Function UpdateVersion( float __from, float __to )
	Debug.Trace( "~~~~~ Footprints VC: Updating Version ~~~~~" )
	
	If ( __from == 0.99 && __to == 1.00 )
		; Nothing needed
	EndIf

EndFunction

; Used in footprintsQuest Fragments
;Function RemoveAllEffects()
;	;Debug.Trace("~~~~~ Footprints VC: Removing All Footsteps effects. ~~~~~")
;	;RemoveAllFootsteps( PlayerRef )
;	
;	If ( PlayerRef.DispelSpell( footprintsCloakAbility ) )
;		;Debug.Trace("~~~~~ Footprints VC: Removing Cloak Ability. ~~~~~")
;		Utility.Wait( 0.1 )
;		PlayerRef.RemoveSpell( footprintsCloakAbility )
;	EndIf
;EndFunction

;Function CleanUp()
;	IsVCInstalled = False
;EndFunction

footprintsDefaults Property GetDefault
	footprintsDefaults Function Get()
		If ( !GetSet )
			GetSet = True
			GetVal = (self as Quest) as footprintsDefaults
		Endif
		return GetVal
	EndFunction
EndProperty
footprintsDefaults GetVal
bool GetSet = False
