Scriptname VampireLordFix extends ActiveMagicEffect  

; EXPERIMENTAL!
; It seems to work flawlessly for me on a character that hasn't started Dawnguard.
; I am not certain if this will break things in Dawnguard quests later on ... USE AT YOUR OWN RISK.

Race Property DLC1VampireBeastRace Auto
Globalvariable Property VampireCannotTurnVL Auto
Globalvariable Property DLC1VampireLordDisallow Auto
Quest Property DLC1PlayerVampireQuest  Auto
CompanionsHousekeepingScript Property C00 auto
Perk Property DLC1VampireActivationBlocker Auto
Perk Property DLC1VampireTurnPerk Auto
Spell Property DLC1VampireChange Auto
Spell Property DLC1VampireChange2 Auto
Spell Property DLC1VampireChangeFX Auto
Spell Property DLC1RevertForm Auto


Event OnEffectStart(Actor Target, Actor Caster)

	If Game.GetPlayer().GetRace() != DLC1VampireBeastRace
	
		Debug.Notification("You are not currently in Vampire Lord form.")
		VampireCannotTurnVL.SetValue(0)
		DLC1PlayerVampireQuest.Stop()
		DLC1VampireLordDisallow.SetValue(0)	

		Utility.Wait(1.0)
		
		Game.GetPlayer().RemovePerk(DLC1VampireActivationBlocker)
		Game.GetPlayer().RemovePerk(DLC1VampireTurnPerk)			
		Game.GetPlayer().DispelSpell(DLC1VampireChange)
		Game.GetPlayer().DispelSpell(DLC1VampireChange2)
		Game.GetPlayer().DispelSpell(DLC1VampireChangeFX)
		Game.GetPlayer().RemoveSpell(DLC1VampireChange)
		Game.GetPlayer().DispelSpell(DLC1RevertForm)		
		Game.GetPlayer().RemoveSpell(DLC1RevertForm)
		
		Debug.Notification("You have been cured of becoming a Vampire Lord.")		
		
		Utility.Wait(1.0)			
		
		Debug.Notification("If you wish to remain cured, please crouch/sneak for the next 10 seconds.")
		Utility.Wait(1.0)			
		Debug.Notification("Stand up if you wish to reset Vampire Lord.")
		
		Utility.Wait(4.0)		
		
		If Game.GetPlayer().IsSneaking() == False
		
			If (C00.PlayerHasBeastBlood)
				C00.CurePlayer()
				Debug.Notification("Lycanthropy, if present, has been cured.")				
			EndIf		

			Utility.Wait(3.0)
			
			Game.GetPlayer().RemoveSpell(DLC1VampireChange)
			Game.GetPlayer().AddSpell(DLC1VampireChange)
			Game.GetPlayer().RemovePerk(DLC1VampireTurnPerk)			
			Game.GetPlayer().AddPerk(DLC1VampireTurnPerk)

			Utility.Wait(1.0)
			
			Debug.Notification("You can now turn into a Vampire Lord again.")
			;DLC1PlayerVampireQuest.Start()
			
		ElseIF Game.GetPlayer().IsSneaking() == True 
		
			Debug.Notification("You remain unable to become a Vampire Lord.")		
		
		EndIf

	ElseIf Game.GetPlayer().GetRace() == DLC1VampireBeastRace
	
		Debug.Notification("You are currently in Vampire Lord form.")
		Game.GetPlayer().RemoveSpell(DLC1VampireChange)
		Game.GetPlayer().RemoveSpell(DLC1RevertForm)		
		Game.GetPlayer().AddSpell(DLC1RevertForm)
		Utility.Wait(1.0)		
		Debug.Notification("Only the Revert Spell has been reset.")		
		
	EndIf		
		
EndEvent
