Scriptname VampireChangeWeatherFogScript extends activemagiceffect

Weather Property SkyrimFogVampire Auto
imageSpaceModifier Property VampireSunlightISMD01  Auto 
Spell Property VampireRankInvokeFogSpell01 Auto
Spell Property VampireRankInvokeFogSpell02 Auto
Spell Property VampireRankInvokeFogSpell03 Auto
Spell Property VampireRankInvokeFogSpell04 Auto
Spell Property VampireRankInvokeFogSpell05 Auto

PlayerVampireQuestScript Property PlayerVampireQuest  Auto
GlobalVariable Property EnableVampireBloodPoints Auto
GlobalVariable Property RECASTVampireInvokeFog Auto
GlobalVariable Property VampireAbilityTimers Auto
GlobalVariable Property VampireInvokeFogToggle Auto
Idle Property IdlePray Auto

EVENT OnEffectStart(Actor akTarget, Actor akCaster)

	Int InvokeFogInThirdPerson = 1
	
	If VampireInvokeFogToggle.GetValue() == 0

		If Game.GetPlayer().IsInCombat() == False
	
			If Game.GetCameraState() == 0
				InvokeFogInThirdPerson = 0
			EndIf
			
			If InvokeFogInThirdPerson == 0
				Game.ForceThirdPerson()
			EndIf	

			Game.DisablePlayerControls(false, true, false, false, false, false)
			Utility.Wait(2.0)		
			
			Game.GetPlayer().PlayIdle(IdlePray)
			Utility.Wait(2.0)
			
			VampireInvokeFogToggle.SetValue(1)
		
			VampireSunlightISMD01.applyCrossFade(2.0)
			SkyrimFogVampire.ForceActive(true)
			Utility.Wait(1.0)
			imageSpaceModifier.removeCrossFade()
			
			If EnableVampireBloodPoints.GetValue() == 10000  && RECASTVampireInvokeFog.GetValue() == 0
				PlayerVampireQuest.VampireBloodPoints(30)
			EndIf	

			Utility.Wait(1.0)				
			Debug.SendAnimationEvent(Game.GetPlayer(), "IdleForceDefaultState")	
			Game.EnablePlayerControls()
			Utility.Wait(1.0)
			Game.SetPlayerAIDriven(False)	
			
		Else	
	
			VampireInvokeFogToggle.SetValue(1)
		
			VampireSunlightISMD01.applyCrossFade(2.0)
			SkyrimFogVampire.ForceActive(true)
			Utility.Wait(1.0)
			imageSpaceModifier.removeCrossFade()
			
			If EnableVampireBloodPoints.GetValue() == 10000  && RECASTVampireInvokeFog.GetValue() == 0
				PlayerVampireQuest.VampireBloodPoints(30)
			EndIf	

			Utility.Wait(1.0)	
		
		EndIf
		
	Else

		If Game.GetPlayer().IsInCombat() == False
	
			If Game.GetCameraState() == 0
				InvokeFogInThirdPerson = 0
			EndIf
			
			If InvokeFogInThirdPerson == 0
				Game.ForceThirdPerson()
			EndIf	
			
			Game.DisablePlayerControls(false, true, false, false, false, false)
			Utility.Wait(2.0)		
			
			Game.GetPlayer().PlayIdle(IdlePray)
			Utility.Wait(2.0)
			
			VampireInvokeFogToggle.SetValue(0)	
		
			Game.GetPlayer().DispelSpell(VampireRankInvokeFogSpell01)
			Game.GetPlayer().DispelSpell(VampireRankInvokeFogSpell02)
			Game.GetPlayer().DispelSpell(VampireRankInvokeFogSpell03)
			Game.GetPlayer().DispelSpell(VampireRankInvokeFogSpell04)
			Game.GetPlayer().DispelSpell(VampireRankInvokeFogSpell05)
			
			Debug.SendAnimationEvent(Game.GetPlayer(), "IdleForceDefaultState")	
			Game.EnablePlayerControls()
			Utility.Wait(1.0)
			Game.SetPlayerAIDriven(False)	
			
		Else	
	
			VampireInvokeFogToggle.SetValue(0)	
		
			Game.GetPlayer().DispelSpell(VampireRankInvokeFogSpell01)
			Game.GetPlayer().DispelSpell(VampireRankInvokeFogSpell02)
			Game.GetPlayer().DispelSpell(VampireRankInvokeFogSpell03)
			Game.GetPlayer().DispelSpell(VampireRankInvokeFogSpell04)
			Game.GetPlayer().DispelSpell(VampireRankInvokeFogSpell05)
		
		EndIf
	
	EndIf	
	
	If InvokeFogInThirdPerson == 0
		;Utility.Wait(1.0)
		Game.ForceFirstPerson()
	EndIf		
	
EndEvent

Event OnEffectFinish(Actor akTarget, Actor akCaster)
	
	Utility.Wait(4.0)		
	
	Weather.ReleaseOverride()
	
	If RECASTVampireInvokeFog.GetValue() <= 1
		RECASTVampireInvokeFog.SetValue(1)
	EndIf	
	
	If RECASTVampireInvokeFog.GetValue() == 1
	
		RECASTVampireInvokeFog.SetValue(2)
		If VampireAbilityTimers.GetValue() == 0
			Debug.Notification("You need to wait before attempting to invoke fog again")	
			Utility.WaitGameTime(6)
			Utility.Wait(0.1)
			If Game.GetPlayer().HasSpell(VampireRankInvokeFogSpell01) || Game.GetPlayer().HasSpell(VampireRankInvokeFogSpell02) || Game.GetPlayer().HasSpell(VampireRankInvokeFogSpell03) || Game.GetPlayer().HasSpell(VampireRankInvokeFogSpell04) || Game.GetPlayer().HasSpell(VampireRankInvokeFogSpell05)
				Debug.Notification("Invoke Fog is available for use")
			EndIf	
		EndIf	
		RECASTVampireInvokeFog.SetValue(0)
		
	EndIf	
	
	VampireInvokeFogToggle.SetValue(0)
	
EndEvent
