ScriptName SuH_SuQuest extends Quest
{Dragon from Succubus Valley}

;#Include
SexLabFramework property SexLab auto

;Function Actors
Actor Property PlayerRef Auto

GlobalVariable Property SuH_PCSheartXP auto
GlobalVariable Property SuH_PCSheartXPgain auto
GlobalVariable Property SuH_PCSseductionpoints auto
GlobalVariable Property SuH_SETallowdynamic auto
GlobalVariable Property SuH_PCSinactive auto
GlobalVariable Property SuH_PCSdesire auto
GlobalVariable Property SuH_PCSdesireGen auto
GlobalVariable Property SuH_PCSdesireMulti auto
GlobalVariable Property SuH_SETdesireeffects auto

MagicEffect property SuH_sp_trainingstateeffect auto
MagicEffect property SuH_sp_hungerstateeffect auto
MagicEffect property SuH_sp_focusedstateeffect auto
MagicEffect property SuH_sp_bracingstateeffect auto
MagicEffect property SuH_sp_succubusprowleffect auto

Spell Property SuH_dyna_cloakability auto
Spell Property SuH_dyna_ability auto
Spell Property SuH_dyna_player auto
Spell Property SuH_ss_silentkiss auto
Spell Property SuH_ss_sexualenrage auto
Spell Property SuH_desire_stage0 auto
Spell Property SuH_desire_stage1 auto
Spell Property SuH_desire_stage2 auto
Spell Property SuH_ss_succubuskiss auto
Spell Property SuH_ss_selfsatisfy auto

int dyna
int dynaSwitch
int itimer
int desireRecord
int desireStage
int desireScanned
	
;Initialization
Event OnInit()
	RegisterForSingleUpdate(5.0)
EndEvent

; Desire Effects Equiation
function desireEffects(int iDesire, int dDesire)
	int pDesire = SuH_PCSdesire.GetValue() as int
	int SETeffect = SuH_SETdesireeffects.GetValue() as int
	pDesire += iDesire
	pDesire -= dDesire
	if pDesire < 1
		SuH_PCSdesire.SetValue(0)
	else
		SuH_PCSdesire.SetValue(pDesire)
	endIf
		; Deire Effects
	if pDesire >= 500 && desireStage != 2
		if desireStage < 1
			playerRef.RemoveSpell(SuH_desire_stage0)
			playerRef.AddSpell(SuH_ss_silentkiss, false)
			playerRef.AddSpell(SuH_ss_sexualenrage, false)
			playerRef.AddSpell(SuH_ss_succubuskiss, false)
			playerRef.AddSpell(SuH_ss_selfsatisfy, false)
		elseIf desireStage < 2
			playerRef.RemoveSpell(SuH_desire_stage1)
			playerRef.AddSpell(SuH_ss_succubuskiss)
		endIf
		if SETeffect == 1
			playerRef.AddSpell(SuH_desire_stage2, false)
		endIf
		desireStage = 2
		debug.Notification("Succubus Heart : Desire above 500")
	elseIf pDesire >= 100 && pDesire < 500 && desireStage != 1
		if desireStage > 1
			playerRef.RemoveSpell(SuH_desire_stage2)
			playerRef.RemoveSpell(SuH_ss_succubuskiss)
		elseif desireStage < 1
			playerRef.RemoveSpell(SuH_desire_stage0)
			playerRef.AddSpell(SuH_ss_silentkiss, false)
			playerRef.AddSpell(SuH_ss_sexualenrage, false)
			playerRef.AddSpell(SuH_ss_selfsatisfy, false)
		endIf
		if SETeffect == 1
			playerRef.AddSpell(SuH_desire_stage1, false)
		endIf
		desireStage = 1
		debug.Notification("Succubus Heart : Desire above 100")
	elseIf pDesire < 100 && desireStage != 0
		if desireStage >= 1
			playerRef.RemoveSpell(SuH_ss_silentkiss)
			playerRef.RemoveSpell(SuH_ss_sexualenrage)
			playerRef.RemoveSpell(SuH_desire_stage1)
			playerRef.RemoveSpell(SuH_ss_succubuskiss)
			playerRef.RemoveSpell(SuH_ss_selfsatisfy)
		endIf
		if SETeffect == 1
			playerRef.AddSpell(SuH_desire_stage0, false)
		endIf
		desireStage = 0
		debug.Notification("Succubus Heart : Desire below 100")
	endIf
endFunction

Event OnUpdate();
	;ent/ Dynamic Script
	playerRef.AddSpell(SuH_dyna_cloakability, false);
	playerRef.AddSpell(SuH_dyna_player, false);
	if DynaSwitch == 1
		PlayerRef.RemoveSpell(SuH_dyna_cloakability);
		dynaSwitch = 0
	else
		DynaSwitch = 1
	endIf
	;end/
	;ent/ Inactive Timer
	itimer = SuH_PCSinactive.GetValue() as int
	itimer += 1
	SuH_PCSinactive.SetValue(itimer)
	;end/
	;ent/ Desire
	int pDesireGen = SuH_PCSdesireGen.GetValue() as int
	float pDesireMulti = SuH_PCSdesireMulti.GetValue()
	int iDesire = Math.Floor((pDesireGen+(itimer/30))*pDesireMulti)
	desireEffects(iDesire, 0)
	;end/
	;ent/ Meditation
	if playerRef.HasMagicEffect(SuH_sp_trainingstateeffect)
		float HeartXP = SuH_PCSheartXP.GetValue()
		float heartXPgain = SuH_PCSheartXPgain.GetValue()
		float Hxp = Math.Floor(HeartXP+(1*heartXPgain*0.01))
		SuH_PCSheartXP.SetValue(Hxp)
	elseIf playerRef.HasMagicEffect(SuH_sp_hungerstateeffect)
		float fstat = playerRef.GetBaseActorValue("health")
		if fstat < 1
		else
			float HeartXP = SuH_PCSheartXP.GetValue()
			float heartXPgain = SuH_PCSheartXPgain.GetValue()
			fstat -= 1
			float Hxp = Math.Floor(HeartXP+(3*heartXPgain*0.01))
			SuH_PCSheartXP.SetValue(Hxp)
			playerRef.SetActorValue("health", fstat)
		endIf
	elseIf playerRef.HasMagicEffect(SuH_sp_focusedstateeffect)
		float fstat = playerRef.GetBaseActorValue("magicka")
		if fstat < 1
		else
			float HeartXP = SuH_PCSheartXP.GetValue()
			float heartXPgain = SuH_PCSheartXPgain.GetValue()
			fstat -= 1
			float Hxp = Math.Floor(HeartXP+(3*heartXPgain*0.01))
			SuH_PCSheartXP.SetValue(Hxp)
			playerRef.SetActorValue("magicka", fstat)
		endIf
	elseIf playerRef.HasMagicEffect(SuH_sp_bracingstateeffect)
		float fstat = playerRef.GetBaseActorValue("stamina")
		if fstat < 1
		else
			float HeartXP = SuH_PCSheartXP.GetValue()
			float heartXPgain = SuH_PCSheartXPgain.GetValue()
			fstat -= 1
			float Hxp = Math.Floor(HeartXP+(3*heartXPgain*0.01))
			SuH_PCSheartXP.SetValue(Hxp)
			playerRef.SetActorValue("stamina", fstat)
		endIf
	endIf
	;end/
	
	RegisterForSingleUpdate(5.0)
endEvent