Scriptname SuH_dynaES_active extends activemagiceffect  

SuH_Fun property _Fun auto
Faction Property SuH_Tracker auto
Faction property SuH_petfaction auto
Actor Property PlayerRef auto
GlobalVariable Property SuH_SETcombatseduction auto
GlobalVariable Property SuH_SETnpc2npchealth auto
GlobalVariable Property SuH_SETnpc2pchealth auto
GlobalVariable Property SuH_SETdeathdrops auto
GlobalVariable Property SuH_CHKcsplayerattack auto
GlobalVariable Property SuH_rank_violence auto
GlobalVariable Property SuH_rank_violence2 auto
GlobalVariable Property SuH_rank_violence3 auto
GlobalVariable Property SuH_rank_violenceCD auto
GlobalVariable Property SuH_SETinvactmale auto
GlobalVariable Property SuH_SETinvactfemale auto
GlobalVariable Property SuH_SETinvactmalecreature auto
GlobalVariable Property SuH_SETinvactfemalecreature auto
Ingredient Property SuH_ing_soulofforce auto
Ingredient Property SuH_ing_soulofexperience auto
Ingredient Property SuH_ing_souloflife auto
Ingredient Property SuH_ing_soulofmagic auto
Ingredient Property SuH_ing_soulofpower auto
Ingredient Property SuH_ing_soulofdesire auto
Spell Property SuH_sex_CScd auto

actor char
int diedonce
int procscript
int csCD

Event OnEffectStart(Actor akTarget, Actor akCaster)
	char = akTarget
	char.AddToFaction(SuH_Tracker)
	;_Fun.INVact(char)
EndEvent

Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)
	int procall = 0
	if procscript == 0 ; Check if script is already calculating
		procscript = 1
		procall = 1
	endIf
	Actor attChar = akAggressor as Actor ; Set Attacker as usable actor reference
	if procall == 1 && attChar != char
		if attChar == PlayerRef ; Calculate for player attacking NPC
			if char.HasSpell(SuH_sex_CScd) || char.IsInFaction(SuH_petfaction)
			elseif SuH_SETcombatseduction.GetValue()
				if SuH_CHKcsplayerattack.GetValue() ; If player is already attacking, do nothing
				else
					SuH_CHKcsplayerattack.SetValue(1) ; Set player is attacking
					float charHealthPercent = (char.GetActorValue("health") / char.GetBaseActorValue("health"))
					if charHealthPercent <= SuH_SETnpc2pchealth.GetValue()
						actor[] animActor = new actor[2] ; Create Array of actors
						animActor[0] = attChar ; Set attChar
						animActor[1] = char ; Set char
						_Fun.ANIMcalc(animActor, char) ; Send aggressive act to SuH_Fun
					endIf
					SuH_CHKcsplayerattack.SetValue(0) ; Set player is no longer attacking
				endIf
			endIf
			; Calculate Violence Passive
			if SuH_rank_violenceCD.GetValue()
				;do nothing, on cooldown
			else
				float x = SuH_rank_violence.GetValue()
				float y = SuH_rank_violence2.GetValue()
				float z = SuH_rank_violence3.GetValue()
				if x > 0
					_Fun.STATcalc(char, stat="Health", aEffect=x)
					_Fun.STATcalc(playerRef, stat="Health", aEffect=x)
				endIf
				if y > 0
					_Fun.STATcalc(char, stat="Magicka", aEffect=y)
					_Fun.STATcalc(playerRef, stat="Magicka", aEffect=y)
				endIf
				if z > 0
					_Fun.STATcalc(char, stat="Stamina", aEffect=z)
					_Fun.STATcalc(playerRef, stat="Stamina", aEffect=z)
				endIf
				endIf
		else ; Calculate for NPC attacking NPC
			if SuH_SETcombatseduction.GetValue()
				float charHealthPercent = (char.GetActorValue("health") / char.GetBaseActorValue("health"))
				if charHealthPercent <= SuH_SETnpc2npchealth.GetValue()
					actor[] animActor = new actor[2] ; Create Array of actors
					animActor[0] = attChar ; Set attChar
					animActor[1] = char ; Set char
					_Fun.ANIMcalc(animActor, char) ; Send aggressive act to SuH_Fun
				endIf
			endIf
		endIf
	endIf
	if procall == 1
		procscript = 0 ; Mark as no longer running
	endIf
endEvent

Event Ondying(Actor akKiller)
	if SuH_SETdeathdrops.GetValue() && diedonce == 0
		int ran = Utility.RandomInt(0,49)
		if ran < 14
			char.AddItem(SuH_ing_soulofforce, 1, false)
		elseIf ran < 28
			char.AddItem(SuH_ing_soulofexperience, 1, false)
		elseIf ran < 41
			char.AddItem(SuH_ing_soulofdesire, 1, false)
		elseIf ran < 44
			char.AddItem(SuH_ing_souloflife, 1, false)
		elseIf ran < 47
			char.AddItem(SuH_ing_soulofmagic, 1, false)
		elseIf ran < 50
			char.AddItem(SuH_ing_soulofpower, 1, false)
		endIf
	endIf
	diedonce = 1
endEvent