ScriptName SuH_NPCsconsentScript extends ActiveMagicEffect

SexLabFramework property SexLab auto

GlobalVariable Property SuH_PCShpabsorb auto
GlobalVariable Property SuH_PCSmpabsorb auto
GlobalVariable Property SuH_PCSspabsorb auto
GlobalVariable Property SuH_SETdrainkill auto
GlobalVariable Property SuH_SETconsentdrain auto
GlobalVariable Property SuH_SETdrainconsent auto

MagicEffect property SuH_sp_speciallovereffect auto
MagicEffect property SuH_sp_caringlovereffect auto
MagicEffect property SuH_sp_magicallovereffect auto
MagicEffect property SuH_sp_lastinglovereffect auto

Spell property SuH_NPCsvictim auto

Actor Property playerRef Auto

actor c

int pHa
int pMa
int pSa
int cHd
int cMd
int cSd
int switch
int invalid
int cL
int statCap

float aMOD

Event OnEffectStart(Actor akTarget, Actor akCaster)
	c = akTarget
	aMOD = SuH_SETdrainconsent.GetValue()
	pHa = SuH_PCShpabsorb.GetValue() as int
	pMa = SuH_PCSmpabsorb.GetValue() as int
	pSa = SuH_PCSspabsorb.GetValue() as int
	switch = 0
	cL = c.GetLevel()
	statCap = Math.Floor(100+(5*cL))
	if SuH_SETconsentdrain.GetValue()
		invalid = 0
	else
		invalid = 1
	endIf
	
	RegisterForSingleUpdate(5.0)
endEvent

Event OnUpdate()
	;ent/ cXd
	cHd += pHa
	cMd += pMa
	cSd += pSa
	;end/
	float fhealth = c.GetBaseActorValue("health")
	float fmagicka = c.GetBaseActorValue("magicka")
	float fstamina = c.GetBaseActorValue("stamina")
	
	if playerRef.HasMagicEffect(SuH_sp_speciallovereffect)
		float chealth = c.GetActorValue("health")
		float hheal = math.Floor((fhealth - chealth)*0.1)
		c.RestoreActorValue("health",hheal)
		float cmagicka = c.GetActorValue("magicka")
		float mheal = math.Floor((fmagicka - cmagicka)*0.1)
		c.RestoreActorValue("magicka",mheal)
		float cstamina = c.GetActorValue("stamina")
		float sheal = math.Floor((fstamina - cstamina)*0.1)
		c.RestoreActorValue("stamina",sheal)
	endIf
	if playerRef.HasMagicEffect(SuH_sp_caringlovereffect)
		if fhealth < statCap
			fhealth += 1
			c.SetActorValue("health",fhealth)
		endIf
	endIf
	if playerRef.HasMagicEffect(SuH_sp_magicallovereffect)
		if fmagicka < statCap
			fmagicka += 1
			c.SetActorValue("magicka",fmagicka)
		endIf
	endIf
	if playerRef.HasMagicEffect(SuH_sp_lastinglovereffect)
		if fhealth < statCap
			fstamina += 1
			c.SetActorValue("stamina",fstamina)
		endIf
	endIf
	
	switch += 1
	if switch >= 6
		if SexLab.IsValidActor(c)
			invalid = 1
			c.RemoveSpell(SuH_NPCsvictim)
		else
			switch = 0
		endIf
	endIf
	RegisterForSingleUpdate(5.0)
endEvent

Event onEffectFinish(Actor akTarget, Actor akCaster)
if invalid == 0
	int cH = c.GetBaseActorValue("health") as int
	int cM = c.GetBaseActorValue("magicka") as int
	int cS = c.GetBaseActorValue("stamina") as int
	int SETdrainkill = SuH_SETdrainkill.GetValue() as int
	
	int h = cH - Math.Floor(cHd*aMOD)
	int m = cM - Math.Floor(cMd*aMOD)
	int s = cS - Math.Floor(cSd*aMOD)
	int x = 0
	
	if s <= cS
		c.SetActorValue("stamina", s)
	else
		x = s - cS
		cHd += x
		c.SetActorValue("stamina", 0)
	endIf
	
	if m <= cM
		c.SetActorValue("magicka", m)
	else
		x = m - cM
		cHd += x
		c.SetActorValue("magicka", 0)
	endIf
	
	if h <= cH
		c.SetActorValue("health", h)
	else
		c.SetActorValue("health", 0)
	endIf
	
	cH = c.GetBaseActorValue("health") as int
	if SETdrainkill == 1 || SETdrainkill == 2
		if cH < 1
			c.DamageActorValue("health", 1.0)
		endIf
	endIf
endIf
endEvent