Scriptname SuH_spellES_petself extends activemagiceffect  

SuH_Fun property _Fun auto
DialogueFollowerScript Property DialogueFollower Auto
Quest Property pDialogueFollower  Auto
GlobalVariable property SuH_PETdogunlock auto
GlobalVariable property SuH_PETwolfunlock auto
GlobalVariable property SuH_PEThorseunlock auto
GlobalVariable property SuH_PETskeeverunlock auto
GlobalVariable property SuH_PETfamiliarunlock auto
GlobalVariable property SuH_PETbearunlock auto
GlobalVariable property SuH_PETsabrecatunlock auto
GlobalVariable property SuH_PETdraugrunlock auto
GlobalVariable property SuH_PETtrollunlock auto
GlobalVariable property SuH_PETsprigganunlock auto
GlobalVariable property SuH_PEThorkerunlock auto
GlobalVariable property SuH_PETfalmerunlock auto
GlobalVariable property SuH_PEThuskyunlock auto
GlobalVariable property SuH_PETbristleunlock auto
GlobalVariable property SuH_PETseekerunlock auto
GlobalVariable property SuH_PETgargoyleunlock auto
GlobalVariable property SuH_PETnetchunlock auto
GlobalVariable property SuH_PETrieklingunlock auto
GlobalVariable property SuH_PETspiderunlock auto
Actor property PlayerRef auto
Message property SuH_menu_petself auto

; Pets Menu
; 0 Train Pet
; 1 Summon Random Pet
; 2 Summon Horse Pet
; 3 Return Pet
; 4 Cancel

Event OnEffectStart(Actor akTarget, Actor akCaster)
	if akCaster == PlayerRef
		string activepet = _Fun.SoulPetActiveIDReturn() ;get active petID
		string sumpet = "none"
		Int i = SuH_menu_petself.Show()
		;ent/ Train Pet
		if i == 0
			actor petactor = _Fun.SoulPetActiveReturn()
			if petactor != none
				actor[] animActor = new actor[2]
				animActor[0] = petactor
				animActor[1] = PlayerRef
				_Fun.ANIMcalc(animActor)
			else
				Debug.Notification("Train Pet - No active pets found!")
			endIf
		;end/
		;ent/ Summon Random Pet
		elseif i == 1
			int chkdog = 0 ;0 Pet Values (unchecked/rolled/invalid)
			int chkwolf = 0 ;1
			int chkhorse = 0 ;2
			int chkskeever = 0 ;3
			int chkfamiliar = 0 ;4
			int chkbear = 0 ;5
			int chksabrecat = 0 ;6
			int chkdraugr = 0 ;7
			int chktroll = 0 ;8
			int chkspriggan = 0 ;9
			int chkhorker = 0 ;10
			int chkfalmer = 0 ;11
			int chkhusky = 0 ;12
			int chkbristle = 0 ;13
			int chkseeker = 0 ;14
			int chkgargoyle = 0 ;15
			int chknetch = 0 ;16
			int chkriekling = 0 ;17
			int chkspider = 0 ;18
			int chkcount = 0 ; Times we've 'checked' for a valid pet
			int chkavail = 0 ; Valid Pet checks we have available
			int chkfail = 0 ; Invalid Pet checks
			int chkrand = 0 ; Have we checked the rolled pet?
			int petFound = 0 ; Have we found a pet to summon?
			int reroll = 1 ; Should we reroll for a pet?
			int x = 0 ; Common Variable
			; NOTES : chkpet has 3 values [0=unchecked][1=checked but rolled out][2=unavailable]
			while reroll != 0
				chkavail = 18 - chkfail ; # of pets (0 counts as 1)
				chkcount = 0
				chkrand = 0
				int rand = Utility.RandomInt(0,chkavail) ; Select Random Pet
				
				if chkrand == 0 && chkdog != 2
					if chkcount == rand
						chkrand = 1
						if SuH_PETdogunlock.GetValue()
							if activepet == "dog"
								chkdog = 2
								chkfail += 1
							else
								sumpet = "dog"
								petFound = 1
							endIf
						else
							chkdog = 2
							chkfail += 1
						endIf
					else
						chkdog = 1
						chkcount += 1
					endIf
				endIf
				if chkrand == 0 && chkwolf != 2
					if chkcount == rand
						chkrand = 1
						if SuH_PETwolfunlock.GetValue()
							if activepet == "wolf"
								chkwolf = 2
								chkfail += 1
							else
								sumpet = "wolf"
								petFound = 1
							endIf
						else
							chkwolf = 2
							chkfail += 1
						endIf
					else
						chkwolf = 1
						chkcount += 1
					endIf
				endIf
				if chkrand == 0 && chkhorse != 2
					if chkcount == rand
						chkrand = 1
						if SuH_PEThorseunlock.GetValue()
							if activepet == "horse"
								chkhorse = 2
								chkfail += 1
							else
								sumpet = "horse"
								petFound = 1
							endIf
						else
							chkhorse = 2
							chkfail += 1
						endIf
					else
						chkhorse = 1
						chkcount += 1
					endIf
				endIf
				if chkrand == 0 && chkskeever != 2
					if chkcount == rand
						chkrand = 1
						if SuH_PETskeeverunlock.GetValue()
							if activepet == "skeever"
								chkskeever = 2
								chkfail += 1
							else
									sumpet = "skeever"
									petFound = 1
							endIf
						else
							chkskeever = 2
							chkfail += 1
						endIf
					else
						chkskeever = 1
						chkcount += 1
					endIf
				endIf
				if chkrand == 0 && chkfamiliar != 2
					if chkcount == rand
						chkrand = 1
						if SuH_PETfamiliarunlock.GetValue()
							if activepet == "familiar"
								chkfamiliar = 2
								chkfail += 1
							else
									sumpet = "familiar"
									petFound = 1
							endIf
						else
							chkfamiliar = 2
							chkfail += 1
						endIf
					else
						chkfamiliar = 1
						chkcount += 1
					endIf
				endIf
				if chkrand == 0 && chkbear != 2
					if chkcount == rand
						chkrand = 1
						if SuH_PETbearunlock.GetValue()
							if activepet == "bear"
								chkbear = 2
								chkfail += 1
							else
									sumpet = "bear"
									petFound = 1
							endIf
						else
							chkbear = 2
							chkfail += 1
						endIf
					else
						chkbear = 1
						chkcount += 1
					endIf
				endIf
				if chkrand == 0 && chksabrecat != 2
					if chkcount == rand
						chkrand = 1
						if SuH_PETsabrecatunlock.GetValue()
							if activepet == "sabrecat"
								chksabrecat = 2
								chkfail += 1
							else
									sumpet = "sabrecat"
									petFound = 1
							endIf
						else
							chksabrecat = 2
							chkfail += 1
						endIf
					else
						chksabrecat = 1
						chkcount += 1
					endIf
				endIf
				if chkrand == 0 && chkdraugr != 2
					if chkcount == rand
						chkrand = 1
						if SuH_PETdraugrunlock.GetValue()
							if activepet == "draugr"
								chkdraugr = 2
								chkfail += 1
							else
									sumpet = "draugr"
									petFound = 1
							endIf
						else
							chkdraugr = 2
							chkfail += 1
						endIf
					else
						chkdraugr = 1
						chkcount += 1
					endIf
				endIf
				if chkrand == 0 && chktroll != 2
					if chkcount == rand
						chkrand = 1
						if SuH_PETtrollunlock.GetValue()
							if activepet == "troll"
								chktroll = 2
								chkfail += 1
							else
									sumpet = "troll"
									petFound = 1
							endIf
						else
							chktroll = 2
							chkfail += 1
						endIf
					else
						chktroll = 1
						chkcount += 1
					endIf
				endIf
				if chkrand == 0 && chkspriggan != 2
					if chkcount == rand
						chkrand = 1
						if SuH_PETsprigganunlock.GetValue()
							if activepet == "spriggan"
								chkspriggan = 2
								chkfail += 1
							else
									sumpet = "spriggan"
									petFound = 1
							endIf
						else
							chkspriggan = 2
							chkfail += 1
						endIf
					else
						chkspriggan = 1
						chkcount += 1
					endIf
				endIf
				if chkrand == 0 && chkhorker != 2
					if chkcount == rand
						chkrand = 1
						if SuH_PEThorkerunlock.GetValue()
							if activepet == "horker"
								chkhorker = 2
								chkfail += 1
							else
									sumpet = "horker"
									petFound = 1
							endIf
						else
							chkhorker = 2
							chkfail += 1
						endIf
					else
						chkhorker = 1
						chkcount += 1
					endIf
				endIf
				if chkrand == 0 && chkfalmer != 2
					if chkcount == rand
						chkrand = 1
						if SuH_PETfalmerunlock.GetValue()
							if activepet == "falmer"
								chkfalmer = 2
								chkfail += 1
							else
									sumpet = "falmer"
									petFound = 1
							endIf
						else
							chkfalmer = 2
							chkfail += 1
						endIf
					else
						chkfalmer = 1
						chkcount += 1
					endIf
				endIf
				if chkrand == 0 && chkhusky != 2
					if chkcount == rand
						chkrand = 1
						if SuH_PEThuskyunlock.GetValue()
							if activepet == "husky"
								chkhusky = 2
								chkfail += 1
							else
									sumpet = "husky"
									petFound = 1
							endIf
						else
							chkhusky = 2
							chkfail += 1
						endIf
					else
						chkhusky = 1
						chkcount += 1
					endIf
				endIf
				if chkrand == 0 && chkbristle != 2
					if chkcount == rand
						chkrand = 1
						if SuH_PETbristleunlock.GetValue()
							if activepet == "bristle"
								chkbristle = 2
								chkfail += 1
							else
									sumpet = "bristle"
									petFound = 1
							endIf
						else
							chkbristle = 2
							chkfail += 1
						endIf
					else
						chkbristle = 1
						chkcount += 1
					endIf
				endIf
				if chkrand == 0 && chkseeker != 2
					if chkcount == rand
						chkrand = 1
						if SuH_PETseekerunlock.GetValue()
							if activepet == "seeker"
								chkseeker = 2
								chkfail += 1
							else
									sumpet = "seeker"
									petFound = 1
							endIf
						else
							chkseeker = 2
							chkfail += 1
						endIf
					else
						chkseeker = 1
						chkcount += 1
					endIf
				endIf
				if chkrand == 0 && chkgargoyle != 2
					if chkcount == rand
						chkrand = 1
						if SuH_PETgargoyleunlock.GetValue()
							if activepet == "gargoyle"
								chkgargoyle = 2
								chkfail += 1
							else
									sumpet = "gargoyle"
									petFound = 1
							endIf
						else
							chkgargoyle = 2
							chkfail += 1
						endIf
					else
						chkgargoyle = 1
						chkcount += 1
					endIf
				endIf
				if chkrand == 0 && chknetch != 2
					if chkcount == rand
						chkrand = 1
						if SuH_PETnetchunlock.GetValue()
							if activepet == "netch"
								chknetch = 2
								chkfail += 1
							else
									sumpet = "netch"
									petFound = 1
							endIf
						else
							chknetch = 2
							chkfail += 1
						endIf
					else
						chknetch = 1
						chkcount += 1
					endIf
				endIf
				if chkrand == 0 && chkriekling != 2
					if chkcount == rand
						chkrand = 1
						if SuH_PETrieklingunlock.GetValue()
							if activepet == "riekling"
								chkriekling = 2
								chkfail += 1
							else
									sumpet = "riekling"
									petFound = 1
							endIf
						else
							chkriekling = 2
							chkfail += 1
						endIf
					else
						chkriekling = 1
						chkcount += 1
					endIf
				endIf
				if chkrand == 0 && chkspider != 2
					if chkcount == rand
						chkrand = 1
						if SuH_PETspiderunlock.GetValue()
							if activepet == "spider"
								chkspider = 2
								chkfail += 1
							else
									sumpet = "spider"
									petFound = 1
							endIf
						else
							chkspider = 2
							chkfail += 1
						endIf
					else
						chkspider = 1
						chkcount += 1
					endIf
				endIf
				
				if petFound == 1
					reroll = 0
				elseif chkfail >= 18
					reroll = 0
					debug.Notification("Succubus Heart - No valid pets found!")
				endIf
			endWhile
			
			if sumpet != "none"
			endIf
		;end/
		;ent/ Summon Horse Pet
		elseif i == 2
			sumpet = "none"
			int x = 0
			if activepet == "horse"
			else
				if SuH_PEThorseunlock.GetValue()
					sumpet = "horse"
				else
					debug.Notification("Succubus Heart - No valid pets found!")
				endIf
			endIf
		;end/
		;ent/ Return Pet
		elseif i == 3
			_Fun.SoulPetSummon(none)
		;end/
		;ent/ Cancel
		else
		;end/
		endIf
		
		if sumpet != "none"
			_Fun.SoulPetSummon(sumpet)
		endIf
	endIf
endEvent