ScriptName SuH_Main extends Quest

;ent/ #Include
SexLabFramework property SexLab auto
;end/
;ent/ Globals
GlobalVariable Property SuH_NPChdry auto
GlobalVariable Property SuH_NPCmdry auto
GlobalVariable Property SuH_NPCsdry auto
GlobalVariable Property SuH_MODversion auto
GlobalVariable Property SuH_NPCgenders auto
;end/	
;ent/ Spells
Spell Property SuH_PCSsubmit auto
Spell Property SuH_PCStraining auto
Spell Property SuH_PCSmastery auto
Spell Property SuH_NPCsvictim auto
Spell Property SuH_NPCsattacker auto
Spell Property SuH_NPCsconsent auto
Spell Property SuH_ss_focusshot auto
Spell Property SuH_ss_sexualenrage auto
Spell Property SuH_ss_silentkiss auto
Spell Property SuH_sp_succubusprowl auto
;end/
;ent/ Magic Effects
MagicEffect Property SuH_sp_perfectorgasmeffect auto
;end/
;ent/ Items
Ingredient Property SuH_SpermSticky auto
Ingredient Property SuH_SpermSweet auto
Ingredient Property SuH_SpermThick auto
Ingredient Property SuH_SpermWarm auto
Ingredient Property SuH_SpermPerfect auto
;end/
;ent/ Actors
Actor Property PlayerRef Auto
;end/
;ent/ Variables
int maleActs = 0
;end/

;ent/ MOD Update
function MODupdate()
	float MODversion = SuH_MODversion.GetValue()
	If MODversion < 2.1
		debug.Notification("Succubus Heart : Applying Patch 2.1")
		playerRef.AddSpell(SuH_ss_focusshot)
		playerRef.AddSpell(SuH_ss_sexualenrage)
		playerRef.AddSpell(SuH_ss_silentkiss)
		playerRef.AddSpell(SuH_sp_succubusprowl)
		SuH_MODversion.SetValue(2.1)
		debug.Notification("Succubus Heart : Version 2.1 Installed!")
	endIf
	If MODversion < 2.3
		debug.Notification("Succubus Heart : Version 2.3 Installed!")
		SuH_MODversion.SetValue(2.3)
	endIf
endFunction
;end/
;Initialization
Event OnInit()
	RegisterForModEvent("AnimationStart","DanisManage")
	RegisterForModEvent("AnimationEnd","DanieManage")
	RegisterForModEvent("OrgasmStart","DorgsManage")
	RegisterForModEvent("OrgasmEnd","DorgeManage")
	
	MODupdate()
EndEvent

Event DanisManage(string eventName, string argString, float argNum, form sender)
	sslThreadController Thread = SexLab.HookController(argString)
	
	if Thread.HasPlayer
		;ent/ Animation Variables
		actor[] aniActor = SexLab.HookActors(argString)
		int femalePres = 0
		int malePres = 0
		int crePres = 0
		int NPCgenders = 0
		int pGender = SexLab.GetGender(playerRef)
		;ent/
		;ent/ Loop 1 -Gender -Player Passives (on Gender)
		int i = 0
		while i < aniActor.Length
			int Agender = SexLab.GetGender(aniActor[i])
			if Agender == 0
				femalePres += 1
			elseIf Agender == 1
				malePres += 1
			elseIf Agender == 2
				crePres += 1
			endIf
			i += 1
		endWhile
		;end/
		;ent/ Set NPCgenders
		If crePres > 0
			SuH_NPCgenders.SetValue(3) ;creature
		elseIf pGender == 1 ;Female
			if malePres > 0
				SuH_NPCgenders.SetValue(2) ;male
			else
				SuH_NPCgenders.SetValue(1) ;female
			endIf	
		elseIf pGender == 0 ;Male
			if malePres > 1
				SuH_NPCgenders.SetValue(2) ;male
			else
				SuH_NPCgenders.SetValue(1) ;female
			endIf
		endIf
		;end/
		;ent/ Loop 2 -Type Effects
		actor victim = SexLab.HookVictim(argString)
		if victim != none
			if Thread.IsVictim(playerRef)
				actor[] rapeActor = SexLab.HookActors(argString)
				i = 0
				while i < rapeActor.Length
					if rapeActor[i] == playerRef
						rapeActor[i].AddSpell(SuH_PCSsubmit, false)
					else
						rapeActor[i].AddSpell(SuH_NPCsattacker, false)
					endIf
				i += 1
				endWhile
			else
				actor[] rapeActor = SexLab.HookActors(argString)
				i = 0
				while i < rapeActor.Length
					if rapeActor[i] == playerRef
						rapeActor[i].AddSpell(SuH_PCSmastery, false)
					else
						rapeActor[i].AddSpell(SuH_NPCsvictim, false)
					endIf
				i += 1
				endWhile
			endIf
		else
			actor[] consActor = SexLab.HookActors(argString)
			i = 0
			while i < consActor.Length
				if consActor[i] == playerRef
					consActor[i].AddSpell(SuH_PCStraining, false)
				else
					consActor[i].AddSpell(SuH_NPCsconsent, false)
				endIf
				i += 1
			endWhile
		endIf
		;end/
	endIf
endEvent

Event DorgsManage(string eventName, string argString, float argNum, form sender)
	sslThreadController Thread = SexLab.HookController(argString)
	
	;ent/ Orgasm Variables
	actor[] orgaActor = SexLab.HookActors(argString)
	int femalePres = 0
	int malePres = 0
	int crePres = 0
	;end/
	;ent/ Loop 1 -Gender -Player Passives (Always act)
	int i = 0
	while i < orgaActor.Length
		;ent/ Gender Catch
		int Agender = SexLab.GetGender(orgaActor[i])
		if Agender == 0
			malePres += 1
		elseIf Agender == 1
			femalePres += 1
		elseIf Agender == 2
			crePres += 1
		endIf
		;end/
		;ent/ Player Passives (always act)
		if orgaActor[i] == playerRef
			if playerRef.HasMagicEffect(SuH_sp_perfectorgasmeffect)
				float playerHealth = playerRef.GetBaseActorValue("health")
				float playerStamina = playerRef.GetBaseActorValue("stamina")
				float playerMagicka = playerRef.GetBaseActorValue("magicka")
				float chealth = playerRef.GetActorValue("health")
				float cmagicka = playerRef.GetActorValue("magicka")
				float cstamina = playerRef.GetActorValue("stamina")
				float hheal = Math.Floor((playerHealth - chealth)*0.75)
				float mheal = Math.Floor((playerHealth - cmagicka)*0.75)
				float sheal = Math.Floor((playerHealth - cstamina)*0.75)
				playerRef.RestoreActorValue("health",hheal)
				playerRef.RestoreActorValue("magicka",mheal)
				playerRef.RestoreActorValue("stamina",sheal)
			endIf
		endIf
		;end/
		i += 1
	endWhile
	;end/
	;ent/ Loop 2 -Sperm - MultiActor Passives
	i = 0
	While i < orgaActor.Length
		int Agender = SexLab.GetGender(orgaActor[i])
		;ent/ Sperm Function
			if Agender == 1 && malePres > 0 || Agender == 1 && crePres > 0
				;ent/ Give Female Sperm
				int givers = (malePres + crePres)
				int K = 0
				while K < givers
					int random = Utility.RandomInt(0, 95)
					if random >= 0 && random <= 20
						orgaActor[i].AddItem(SuH_SpermSticky, 2, true)
						orgaActor[i].EquipItem(SuH_SpermSticky, false, true)
					elseIf random >= 21 && random <= 22
						orgaActor[i].AddItem(SuH_SpermSticky, 3, true)
						orgaActor[i].EquipItem(SuH_SpermSticky, false, true)
						if orgaActor[i] == playerRef
							debug.Notification("That was quite the load...")
						endIf
					elseIf random >= 23 && random <= 43
						orgaActor[i].AddItem(SuH_SpermSweet, 2, true)
						orgaActor[i].EquipItem(SuH_SpermSweet, false, true)
					elseIf random >= 44 && random <= 45
						orgaActor[i].AddItem(SuH_SpermSweet, 3, true)
						orgaActor[i].EquipItem(SuH_SpermSweet, false, true)
						if orgaActor[i] == playerRef
							debug.Notification("That was quite the load...")
						endIf
					elseIf random >= 46 && random <= 66
						orgaActor[i].AddItem(SuH_SpermThick, 2, true)
						orgaActor[i].EquipItem(SuH_SpermThick, false, true)
					elseIf random >= 67 && random <= 68
						orgaActor[i].AddItem(SuH_SpermThick, 3, true)
						orgaActor[i].EquipItem(SuH_SpermThick, false, true)
						if orgaActor[i] == playerRef
							debug.Notification("That was quite the load...")
						endIf
					elseIf random >= 69 && random <= 89
						orgaActor[i].AddItem(SuH_SpermWarm, 2, true)
						orgaActor[i].EquipItem(SuH_SpermWarm, false, true)
					elseIf random >= 90 && random <= 91
						orgaActor[i].AddItem(SuH_SpermWarm, 3, true)
						orgaActor[i].EquipItem(SuH_SpermWarm, false, true)
						if orgaActor[i] == playerRef
							debug.Notification("That was quite the load...")
						endIf
					elseIf random == 92
						orgaActor[i].AddItem(SuH_SpermPerfect, 2, true)
						orgaActor[i].EquipItem(SuH_SpermPerfect, false, true)
						if orgaActor[i] == playerRef
							debug.Notification("PERFECTION! The perfect load!")
						endIf
					else
						if orgaActor[i] == playerRef
							debug.Notification("Seems this one's dry...")
						endIf
					endIf
					K += 1
				endWhile
				;ent/
			elseIf femalePres < 1
				;ent/ bleh
				int givers = (malePres + crePres)
				int K = 0
				while K < givers
					int random = Utility.RandomInt(0, 95)
					if random >= 0 && random <= 20
						orgaActor[i].AddItem(SuH_SpermSticky, 2, true)
						orgaActor[i].EquipItem(SuH_SpermSticky, false, true)
					elseIf random >= 21 && random <= 22
						orgaActor[i].AddItem(SuH_SpermSticky, 3, true)
						orgaActor[i].EquipItem(SuH_SpermSticky, false, true)
						if orgaActor[i] == playerRef
							debug.Notification("That was quite the load...")
						endIf
					elseIf random >= 23 && random <= 43
						orgaActor[i].AddItem(SuH_SpermSweet, 2, true)
						orgaActor[i].EquipItem(SuH_SpermSweet, false, true)
					elseIf random >= 44 && random <= 45
						orgaActor[i].AddItem(SuH_SpermSweet, 3, true)
						orgaActor[i].EquipItem(SuH_SpermSweet, false, true)
						if orgaActor[i] == playerRef
							debug.Notification("That was quite the load...")
						endIf
					elseIf random >= 46 && random <= 66
						orgaActor[i].AddItem(SuH_SpermThick, 2, true)
						orgaActor[i].EquipItem(SuH_SpermThick, false, true)
					elseIf random >= 67 && random <= 68
						orgaActor[i].AddItem(SuH_SpermThick, 3, true)
						orgaActor[i].EquipItem(SuH_SpermThick, false, true)
						if orgaActor[i] == playerRef
							debug.Notification("That was quite the load...")
						endIf
					elseIf random >= 69 && random <= 89
						orgaActor[i].AddItem(SuH_SpermWarm, 2, true)
						orgaActor[i].EquipItem(SuH_SpermWarm, false, true)
					elseIf random >= 90 && random <= 91
						orgaActor[i].AddItem(SuH_SpermWarm, 3, true)
						orgaActor[i].EquipItem(SuH_SpermWarm, false, true)
						if orgaActor[i] == playerRef
							debug.Notification("That was quite the load...")
						endIf
					elseIf random == 92
						orgaActor[i].AddItem(SuH_SpermPerfect, 2, true)
						orgaActor[i].EquipItem(SuH_SpermPerfect, false, true)
						if orgaActor[i] == playerRef
							debug.Notification("PERFECTION! The perfect load!")
						endIf
					else
						if orgaActor[i] == playerRef
							debug.Notification("Seems this one's dry...")
						endIf
					endIf
					K += 1
				endWhile
				;end/
			endIf
		;end/
		i += 1
	endWhile
	;end/
endEvent

Event DanieManage(string eventName, string argString, float argNum, form sender)
	sslThreadController Thread = SexLab.HookController(argString)
	
	if Thread.HasPlayer
		actor[] endActor = SexLab.HookActors(argString)
		int i = 0
		while i < endActor.Length
			if endActor[i] == playerRef
				endActor[i].RemoveSpell(SuH_PCSsubmit)
				endActor[i].RemoveSpell(SuH_PCStraining)
				endActor[i].RemoveSpell(SuH_PCSmastery)
			endIf
			if endActor[i] != playerRef
				if endActor[i].GetActorValue("health") <= 1
					endActor[i].DamageActorValue("health", 1.0)
				endIf
				endActor[i].RemoveSpell(SuH_NPCsvictim)
				endActor[i].RemoveSpell(SuH_NPCsconsent)
				endActor[i].RemoveSpell(SuH_NPCsattacker)
			endIf
		i += 1
		endWhile
		SuH_NPChdry.SetValue(0)
		SuH_NPCmdry.SetValue(0)
		SuH_NPCsdry.SetValue(0)
	endIf
endEvent





