Scriptname SuH_dynaES_player extends activemagiceffect  

SuH_Fun property _Fun auto
actor property playerRef auto
GlobalVariable property SuH_SETcombatseduction auto
GlobalVariable property SuH_SETpc2npchealth auto
GlobalVariable property SuH_SETspecialdeath auto
GlobalVariable property SuH_rank_masochist auto
GlobalVariable property SuH_rank_masochist2 auto
GlobalVariable property SuH_rank_savingessence auto
GlobalVariable property SuH_rank_savingessenceCD auto
GlobalVariable property SuH_PCSdesire auto
GlobalVariable property SuH_PCSstacksperm auto
GlobalVariable property SuH_PCSstackmilk auto
GlobalVariable property SuH_CHKcsplayersubmit auto
GlobalVariable property SuH_CHKsdinact auto

int procscript

Event OnEffectStart(Actor akTarget, Actor akCaster)
	
EndEvent

Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)
	int procall = 0
	if procscript == 0
		procscript = 1
		procall = 1
	endif
		;Masochist Stamina Passive
	int maso2 = SuH_rank_masochist2.GetValue() as int
	float phealth = playerRef.GetBaseActorValue("health")
	float nphealth = phealth - maso2
	if nphealth > 10
		playerRef.RestoreActorValue("Stamina", maso2*5)
	endIf
	; Process ALL cutoff
	if procall == 1
	if nphealth >= 10
		playerRef.SetActorValue("health", nphealth)
	endIf
	Actor attChar = akAggressor as Actor ; Set Attacker as usable actor reference
	float charHealthPercent = (playerRef.GetActorValue("health") / playerRef.GetBaseActorValue("health"))
			;Masochist Desire Passive
		int maso = Math.Floor(5 * SuH_rank_masochist.GetValue())
		int x = Math.Floor(maso + SuH_PCSdesire.GetValue())
		SuH_PCSdesire.SetValue(x)
			;Saving Essence Passive
		int rank = SuH_rank_savingessence.GetValue() as int
		int cd = SuH_rank_savingessenceCD.GetValue() as int
		if charHealthPercent <= 0.3 && rank > 0 && CD == 0
			int sperm = SuH_PCSstacksperm.GetValue() as int
			int milk = SuH_PCSstackmilk.GetValue() as int
			if sperm > 0 || milk > 0
				int tstack = sperm + milk
				if tstack > 0
					x = (rank*2)*tstack
					playerRef.RestoreActorValue("health", x)
					SuH_rank_savingessenceCD.SetValue(1)
					debug.Notification("Saving Essence now on cooldown!")
				endIf        
						;No Longer Used
			; X and Y must land as evenly as possible
			; X = RanInt1 Y = RanInt2 Z = Subtracted Value
			;if (X=Y) K = Math.Floor(Z*0.5)
			;	if ((K*2) =Z) X -= K , Y -= K
			;	else  X -= K+1 , Y -= K
			;elseif (X>Y) J = X-Y , K = Math.Floor((Z-J)*0.5)
			;	if ((K*2) = Z-j) X -= K+J , Y -= K
			;	else  X -= K+J+1 , Y -= K
			;elseif (Y>X) J = Y-X , K = Math.Floor((Z-J)*0.5)
			;	if ((k*2) = Z-j) X -= K , Y -= K+J
			;	else  X -= K+1 , Y -= K+J
			; if sperm > 0 || milk > 0
				; int tstack = sperm + milk
				; if tstack <= 10
					; x = (rank*2)*tstack
					; playerRef.RestoreActorValue("health", x)
					; SuH_PCSstacksperm.SetValue(0)
					; SuH_PCSstackmilk.SetValue(0)
				; elseIf sperm == milk
					; x = (rank*2)*10
					; playerRef.RestoreActorValue("health", x)
					; sperm -= 5
					; milk -= 5
					; SuH_PCSstacksperm.SetValue(sperm)
					; SuH_PCSstackmilk.SetValue(milk)
				; elseIf sperm > milk
					; x = (rank*2)*10
					; playerRef.RestoreActorValue("health", x)
					; int j = sperm - milk
					; if j > 10
						; sperm -= 10
						; SuH_PCSstacksperm.SetValue(sperm)
					; else
						; int k = Math.Floor((10 - j)*0.5)
						; if (k*2) == (10 - j)
							; sperm -= (k+j)
							; milk -= k
							; SuH_PCSstacksperm.SetValue(sperm)
							; SuH_PCSstackmilk.SetValue(milk)
						; else
							; sperm -= (k+j+1)
							; milk -= k
							; SuH_PCSstacksperm.SetValue(sperm)
							; SuH_PCSstackmilk.SetValue(milk)
						; endIf
					; endIf
				; else ; milk > sperm
					; x = (rank*2)*10
					; playerRef.RestoreActorValue("health", x)
					; int j = milk - sperm
					; if j > 10
						; milk -= 10
						; SuH_PCSstackmilk.SetValue(milk)
					; else
						; int k = Math.Floor((10 - j)*0.5)
						; if (k*2) == (10 - j)
							; milk -= (k+j)
							; sperm -= k
							; SuH_PCSstacksperm.SetValue(sperm)
							; SuH_PCSstackmilk.SetValue(milk)
						; else
							; milk -= (k+j+1)
							; sperm -= k
							; SuH_PCSstacksperm.SetValue(sperm)
							; SuH_PCSstackmilk.SetValue(milk)
						; endIf
					; endIf
				; endIf        
			endIf
		endIf
		charHealthPercent = (playerRef.GetActorValue("health") / playerRef.GetBaseActorValue("health"))
		if attChar != playerRef
				;Combat Seduction
			if SuH_SETcombatseduction.GetValue()
				if SuH_CHKcsplayersubmit.GetValue()
					;do nothing
				else
					SuH_CHKcsplayersubmit.SetValue(1)
					if charHealthPercent <= SuH_SETpc2npchealth.GetValue()
						actor[] animActor = new actor[2] ; Create Array of actors
						animActor[0] = attChar ; Set Aggressor
						animActor[1] = playerRef ; Set player
						_Fun.ANIMcalc("0", animActor, playerRef) ; Send aggressive act to SuH_Fun
					endIf
					SuH_CHKcsplayersubmit.SetValue(0)
				endIf
			endIf
		endIf
	endIf
	if procall == 1
		procscript = 0
	endIf
endEvent