Scriptname SuH_SuQuest extends Quest

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

ObjectReference Property SuH_realm_petreturn Auto 

GlobalVariable Property SuH_PCSdesire auto
GlobalVariable Property SuH_PCSforce auto
GlobalVariable Property SuH_PCSdesiregain auto
GlobalVariable Property SuH_SETdesiredrain auto
GlobalVariable Property SuH_SETspecialdeath auto
GlobalVariable Property SuH_SETdesirecap auto
GlobalVariable Property SuH_CHKsdinact auto
GlobalVariable Property SuH_PETactive auto
GlobalVariable Property SuH_PETactivedog auto
GlobalVariable Property SuH_PETactivewolf auto
GlobalVariable Property SuH_PETactivehorse auto
GlobalVariable Property SuH_PETdogdesire auto
GlobalVariable Property SuH_PETdoglevel auto
GlobalVariable Property SuH_PETwolfdesire auto
GlobalVariable Property SuH_PETwolflevel auto
GlobalVariable Property SuH_PEThorsedesire auto
GlobalVariable Property SuH_PEThorselevel auto
Actor Property PlayerRef auto
Actor Property SuH_actor_dog auto
Actor Property SuH_actor_wolf auto
Actor Property SuH_actor_horse auto
Spell Property SuH_dyna_ability auto
Spell Property SuH_dyna_player auto
Spell Property SuH_spell_sexualenrage auto
Spell Property SuH_spell_sexualentice auto
Spell property SuH_sex_inact auto

int drainMessage
int desireDelay
int sdDelay
int petDelay

Event OnInit()
	PlayerRef.AddSpell(SuH_dyna_player, FALSE) ; Add dynamic player script
	RegisterForSingleUpdate(5.0) ; Tick in 5 seconds
endEvent

Event OnUpdate()
	If PlayerRef.HasSpell(SuH_dyna_ability) ; If dynamic script is applying
		PlayerRef.RemoveSpell(SuH_dyna_ability) ; Remove dynamic run script
	else ; if dynamic script is not applying
		PlayerRef.AddSpell(SuH_dyna_ability, FALSE) ; AddSpell dynamic run script
	endIf
	desireDelay += 1
	if desireDelay > 4
		float desireV = (SuH_PCSdesiregain.GetValue()) + SuH_PCSdesire.GetValue()
		SuH_PCSdesire.SetValue(desireV)
		if desireV >= SuH_SETdesirecap.GetValue() && SuH_SETdesiredrain.GetValue()
			if drainMessage == 0
				debug.notification("Succubus Heart : Desire has begun to drain status!")
				drainMessage = 1
			endIf
			float h = PlayerRef.GetBaseActorValue("health")
			float m = PlayerRef.GetBaseActorValue("magicka")
			float s = PlayerRef.GetBaseActorValue("stamina")
			float x = 0.0
			if h > 10.0
				PlayerRef.SetActorValue("health", h - 1.0)
				x += 1.0
			endIf
			if m > 10.0
				PlayerRef.SetActorValue("magicka", m - 1.0)
				x += 1.0
			endIf
			if s > 10.0
				PlayerRef.SetActorValue("stamina", s - 1.0)
				x += 1.0
			endIf
			float y = SuH_PCSforce.GetValue()
			SuH_PCSforce.SetValue(y+x)
			PlayerRef.AddSpell(SuH_spell_sexualentice)
			PlayerRef.AddSpell(SuH_spell_sexualenrage)
		elseif desireV >= 300
			PlayerRef.AddSpell(SuH_spell_sexualentice)
			PlayerRef.AddSpell(SuH_spell_sexualenrage)
			drainMessage = 0
		elseif desireV >= 120
			PlayerRef.AddSpell(SuH_spell_sexualenrage)
			PlayerRef.RemoveSpell(SuH_spell_sexualentice)
			drainMessage = 0
		else
			PlayerRef.RemoveSpell(SuH_spell_sexualenrage)
			PlayerRef.RemoveSpell(SuH_spell_sexualentice)
			drainMessage = 0
		endIf
		desireDelay = 0
	endIf
	; Death Override Mode
	If SuH_SETspecialdeath.GetValue() && PlayerRef.IsBleedingOut() == True	
		SuH_CHKsdinact.SetValue(1)
		PlayerRef.SetNoBleedoutRecovery(true)
		sdDelay += 1
		if sdDelay > 9
			_Fun.SDrespawn()
			sdDelay = 0
		endIf
	elseif SuH_CHKsdinact.GetValue()
		PlayerRef.SetNoBleedoutRecovery(true)
		sdDelay += 1
		if sdDelay > 9
			_Fun.SDrespawn()
			sdDelay = 0
		endIf
	endIf
	;Pet Cell Calculation
	petDelay += 1
	if petDelay > 4
		int dogd = SuH_PETdogdesire.GetValue() as int
		int wolfd = SuH_PETwolfdesire.GetValue() as int
		int horsed = SuH_PEThorsedesire.GetValue() as int
		int x = SuH_PETactive.GetValue() as int
		If x > 0
			if SuH_PETactivedog.GetValue()	
				if SuH_actor_dog.HasSpell(SuH_sex_inact)
				else
					if dogd < 1
						(pDialogueFollower as DialogueFollowerScript).DismissAnimal()
						SuH_actor_dog.MoveTo(SuH_realm_petreturn)
						SuH_PETactivedog.SetValue(0)
						x -= 1
						SuH_PETactive.SetValue(x)
						debug.Notification("Dog [Incubus] has run out of Desire and has returned to the Succubus Realm")
					else
						SuH_PETdogdesire.SetValue(dogd - 5) ; 1 per second (5 becaues of script delay)
						if (SuH_actor_dog.GetCurrentLocation() != playerRef.GetCurrentLocation())
							SuH_actor_dog.MoveTo(PlayerRef)
						endIf
					endif
				endIf
			elseif SuH_PETactivewolf.GetValue()	
				if SuH_actor_wolf.HasSpell(SuH_sex_inact)
				else
					if wolfd < 1
						(pDialogueFollower as DialogueFollowerScript).DismissAnimal()
						SuH_actor_wolf.MoveTo(SuH_realm_petreturn)
						SuH_PETactivewolf.SetValue(0)
						x -= 1
						SuH_PETactive.SetValue(x)
						debug.Notification("Wolf [Incubus] has run out of Desire and has returned to the Succubus Realm")
					else
						SuH_PETwolfdesire.SetValue(wolfd - 5) ; 1 per second (5 becaues of script delay)
						if (SuH_actor_wolf.GetCurrentLocation() != playerRef.GetCurrentLocation())
							SuH_actor_wolf.MoveTo(PlayerRef)
						endIf
					endif
				endIf
			elseif SuH_PETactivehorse.GetValue()	
				if SuH_actor_horse.HasSpell(SuH_sex_inact)
				else
					if horsed < 1
						(pDialogueFollower as DialogueFollowerScript).DismissAnimal()
						SuH_actor_horse.MoveTo(SuH_realm_petreturn)
						SuH_PETactivehorse.SetValue(0)
						x -= 1
						SuH_PETactive.SetValue(x)
						debug.Notification("Horse [Incubus] has run out of Desire and has returned to the Succubus Realm")
					else
						SuH_PEThorsedesire.SetValue(horsed - 5) ; 1 per second (5 becaues of script delay)
						if (SuH_actor_horse.GetCurrentLocation() != playerRef.GetCurrentLocation())
							SuH_actor_horse.MoveTo(PlayerRef)
						endIf
					endif
				endIf
			endIf
		else
			int dogl = SuH_PETdoglevel.GetValue() as int
			int wolfl = SuH_PETwolflevel.GetValue() as int
			int horsel = SuH_PEThorselevel.GetValue() as int
			int dogc = (100*dogl)+100
			int wolfc = (100*wolfl)+100
			int horsec = (100*horsel)+100
			int dogg = (1+dogc)*5 ; *5 is for the script's 5 second delay
			int wolfg = (1+wolfc)*5
			int horseg = (1+horsec)*5
			if dogd < dogc
				SuH_PETdogdesire.SetValue(dogd + dogg)
			endIf
			if wolfd < wolfc
				SuH_PETwolfdesire.SetValue(wolfd + wolfg)
			endIf
			if horsed < horsec
				SuH_PEThorsedesire.SetValue(horsed + horseg)
			endIf
		endIf
		petDelay = 0
	endIf
	RegisterForSingleUpdate(1.0) ; Tick in 1 seconds
endEvent