Scriptname SuH_spellES_horsepet extends activemagiceffect  

SuH_Fun property _Fun auto
DialogueFollowerScript Property DialogueFollower Auto
Quest Property pDialogueFollower  Auto
ObjectReference Property SuH_realm_petreturn Auto 

GlobalVariable property SuH_PETactive auto
GlobalVariable property SuH_PETactivedog auto
GlobalVariable property SuH_PETactivewolf auto
GlobalVariable property SuH_PETactivehorse auto
GlobalVariable property SuH_PETactiveskeever auto
GlobalVariable property SuH_PETactivefamiliar auto
GlobalVariable property SuH_PETactivebear auto
GlobalVariable property SuH_PETactivesabrecat auto
GlobalVariable property SuH_PETactivedraugr auto
GlobalVariable property SuH_PETactivetroll auto
GlobalVariable property SuH_PETactivespriggan auto
GlobalVariable property SuH_PETactivehorker auto
GlobalVariable property SuH_PETactivefalmer auto
GlobalVariable property SuH_PEThorseunlock auto
GlobalVariable property SuH_PEThorsedesire auto

Actor property PlayerRef auto
Actor property SuH_actor_dog auto
Actor property SuH_actor_wolf auto
Actor property SuH_actor_horse auto
Actor property SuH_actor_skeever auto
actor property SuH_actor_familiar auto
actor property SuH_actor_bear auto
actor property SuH_actor_sabrecat auto
actor property SuH_actor_draugr auto
actor property SuH_actor_troll auto
actor property SuH_actor_spriggan auto
actor property SuH_actor_horker auto
actor property SuH_actor_falmer auto

Event OnEffectStart(Actor akTarget, Actor akCaster)
	int PETactive = SuH_PETactive.GetValue() as int
	string summonPET = "none"
	int x = 0
	
	if SuH_PETactivehorse.GetValue()
	else
		if SuH_PEThorseunlock.GetValue()
			x = SuH_PEThorsedesire.GetValue() as int
			if x > 99
				summonPET = "horse"
			endIf
		endIf
	endIf
	
	if PETactive > 0 && summonPET != "none"
		if SuH_PETactivedog.getValue()
			(pDialogueFollower as DialogueFollowerScript).DismissAnimal()
			SuH_actor_dog.MoveTo(SuH_realm_petreturn)
			SuH_PETactivedog.SetValue(0)
			x -= 1
			SuH_PETactive.SetValue(x)
		elseif SuH_PETactivewolf.getValue()
				(pDialogueFollower as DialogueFollowerScript).DismissAnimal()
				SuH_actor_wolf.MoveTo(SuH_realm_petreturn)
				SuH_PETactivewolf.SetValue(0)
				x -= 1
				SuH_PETactive.SetValue(x)
		elseif SuH_PETactivehorse.getValue()
				(pDialogueFollower as DialogueFollowerScript).DismissAnimal()
				SuH_actor_horse.MoveTo(SuH_realm_petreturn)
				SuH_PETactivehorse.SetValue(0)
				x -= 1
				SuH_PETactive.SetValue(x)
		elseif SuH_PETactiveskeever.getValue()
				(pDialogueFollower as DialogueFollowerScript).DismissAnimal()
				SuH_actor_skeever.MoveTo(SuH_realm_petreturn)
				SuH_PETactiveskeever.SetValue(0)
				x -= 1
				SuH_PETactive.SetValue(x)
		elseif SuH_PETactivefamiliar.getValue()
				(pDialogueFollower as DialogueFollowerScript).DismissAnimal()
				SuH_actor_familiar.MoveTo(SuH_realm_petreturn)
				SuH_PETactivefamiliar.SetValue(0)
				x -= 1
				SuH_PETactive.SetValue(x)
		elseif SuH_PETactivebear.getValue()
				(pDialogueFollower as DialogueFollowerScript).DismissAnimal()
				SuH_actor_bear.MoveTo(SuH_realm_petreturn)
				SuH_PETactivebear.SetValue(0)
				x -= 1
				SuH_PETactive.SetValue(x)
		elseif SuH_PETactivesabrecat.getValue()
				(pDialogueFollower as DialogueFollowerScript).DismissAnimal()
				SuH_actor_sabrecat.MoveTo(SuH_realm_petreturn)
				SuH_PETactivesabrecat.SetValue(0)
				x -= 1
				SuH_PETactive.SetValue(x)
		elseif SuH_PETactivedraugr.getValue()
				(pDialogueFollower as DialogueFollowerScript).DismissAnimal()
				SuH_actor_draugr.MoveTo(SuH_realm_petreturn)
				SuH_PETactivedraugr.SetValue(0)
				x -= 1
				SuH_PETactive.SetValue(x)
		elseif SuH_PETactivetroll.getValue()
				(pDialogueFollower as DialogueFollowerScript).DismissAnimal()
				SuH_actor_troll.MoveTo(SuH_realm_petreturn)
				SuH_PETactivetroll.SetValue(0)
				x -= 1
				SuH_PETactive.SetValue(x)
		elseif SuH_PETactivespriggan.getValue()
				(pDialogueFollower as DialogueFollowerScript).DismissAnimal()
				SuH_actor_spriggan.MoveTo(SuH_realm_petreturn)
				SuH_PETactivespriggan.SetValue(0)
				x -= 1
				SuH_PETactive.SetValue(x)
		elseif SuH_PETactivehorker.getValue()
				(pDialogueFollower as DialogueFollowerScript).DismissAnimal()
				SuH_actor_horker.MoveTo(SuH_realm_petreturn)
				SuH_PETactivehorker.SetValue(0)
				x -= 1
				SuH_PETactive.SetValue(x)
		elseif SuH_PETactivefalmer.getValue()
				(pDialogueFollower as DialogueFollowerScript).DismissAnimal()
				SuH_actor_falmer.MoveTo(SuH_realm_petreturn)
				SuH_PETactivefalmer.SetValue(0)
				x -= 1
				SuH_PETactive.SetValue(x)
		endIf
	endIf
	
	if summonPET != "none"
		If summonPET == "horse"
			SuH_actor_horse.MoveTo(PlayerRef)
			(DialogueFollower as DialogueFollowerScript).SetAnimal(SuH_actor_horse)
			SuH_PETactivehorse.SetValue(1)
			x += 1
			SuH_PETactive.SetValue(x)
			debug.Notification("Horse [Incubus] has been summoned!")
		endIf
	endIf
endEvent