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
GlobalVariable Property SuH_PCSheartXP auto
GlobalVariable Property SuH_SETsexdrops auto
GlobalVariable Property SuH_SETinvact auto
GlobalVariable Property SuH_Lsuccubusprowl auto
GlobalVariable Property SuH_Lspermlover auto
GlobalVariable Property SuH_Lmilklover auto
GlobalVariable Property SuH_Lperfectorgasm auto
GlobalVariable Property SuH_Lspeciallover auto
GlobalVariable Property SuH_Lcaringlover auto
GlobalVariable Property SuH_Lmagicallover auto
GlobalVariable Property SuH_Llastinglover auto
GlobalVariable Property SuH_Lhumandesires auto
GlobalVariable Property SuH_Lanimaldesires auto
GlobalVariable Property SuH_Lmasochist auto
GlobalVariable Property SuH_Lmilkdrinker auto
GlobalVariable Property SuH_SETdrainconsent 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
Spell Property SuH_sp_HealthyDelights auto
Spell Property SuH_sp_ShiningDelights auto
Spell Property SuH_sp_SugaryDelights auto
Spell Property SuH_sp_HealthyMilk auto
Spell Property SuH_sp_ShiningMilk auto
Spell Property SuH_sp_SugaryMilk auto
Spell Property SuH_NPCsmastery auto
Spell Property SuH_NPCssubmit auto
Spell Property SuH_NPCstraining auto
Spell Property SuH_NPCsnconsent auto
Spell Property SuH_NPCsnattacker auto
Spell Property SuH_NPCsnvictim auto
Spell Property SuH_CHAinact auto
Spell Property SuH_csGrace auto
Spell Property SuH_essential auto
Spell Property SuH_sp_spermlover auto
Spell Property SuH_sp_HealthyDelights2 auto
Spell Property SuH_sp_ShiningDelights2 auto
Spell Property SuH_sp_SugaryDelights2 auto
Spell Property SuH_sp_seductivedelights auto
Spell Property SuH_sp_milklover auto
Spell Property SuH_sp_HealthyMilk2 auto
Spell Property SuH_sp_ShiningMilk2 auto
Spell Property SuH_sp_SugaryMilk2 auto
Spell Property SuH_sp_seductivemilk auto
Spell Property SuH_sp_perfectorgasm auto
Spell Property SuH_sp_speciallover auto
Spell Property SuH_sp_caringlover auto
Spell Property SuH_sp_magicallover auto
Spell Property SuH_sp_lastinglover auto
Spell Property SuH_sp_humandesires auto
Spell Property SuH_sp_animaldesires auto
Spell Property SuH_sp_masochist auto
Spell Property SuH_sp_milkdrinker auto
;end/
;ent/ Magic Effects
MagicEffect Property SuH_sp_perfectorgasmeffect auto
MagicEffect Property SuH_sp_HealthyDelights2effect auto
MagicEffect Property SuH_sp_ShiningDelights2effect auto
MagicEffect Property SuH_sp_SugaryDelights2effect auto
MagicEffect Property SuH_sp_HealthyMilk2effect auto
MagicEffect Property SuH_sp_ShiningMilk2effect auto
MagicEffect Property SuH_sp_SugaryMilk2effect auto
MagicEffect Property SuH_NPCsuccubuseffect 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
Ingredient Property SuH_MilkWarm auto
Ingredient Property SuH_MilkSweet auto
Ingredient Property SuH_MilkSmooth auto
Ingredient Property SuH_MilkCreamy auto
;end/
;ent/ Actors
Actor Property PlayerRef Auto
;end/
;ent/ Variables
;end/

;ent/ MOD Update
function MODupdate()
	float MODversion = SuH_MODversion.GetValue()
	;ent/ Previous Patches
	If MODversion < 2.1
		if MODversion != 0
			debug.Notification("Succubus Heart : Applying Patch 2.1")
		endIf
		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)
	endIf
	If MODversion < 2.4
		If MODversion != 0
			debug.Notification("Succubus Heart : Applying Patch 2.4")
		endIf
		int x = SuH_PCSheartXP.GetValue() as int
		x += 500
		SuH_PCSheartXP.SetValue(x)
		SuH_MODversion.SetValue(2.4)
	endIf
	If MODversion < 2.61
		if MODversion != 0
			debug.Notification("Succubus Heart : Applying Patch 2.61")
			if playerRef.HasSpell(SuH_sp_HealthyDelights2) || playerRef.HasSpell(SuH_sp_ShiningDelights2) || playerRef.HasSpell(SuH_sp_SugaryDelights2) || playerRef.HasSpell(SuH_sp_seductivedelights) || playerRef.HasSpell(SuH_sp_HealthyDelights) || playerRef.HasSpell(SuH_sp_ShiningDelights) || playerRef.HasSpell(SuH_sp_SugaryDelights)
				playerRef.AddSpell(SuH_sp_spermlover)
				playerRef.RemoveSpell(SuH_sp_HealthyDelights)
				playerRef.RemoveSpell(SuH_sp_HealthyDelights2)
				playerRef.RemoveSpell(SuH_sp_ShiningDelights)
				playerRef.RemoveSpell(SuH_sp_ShiningDelights2)
				playerRef.RemoveSpell(SuH_sp_SugaryDelights)
				playerRef.RemoveSpell(SuH_sp_SugaryDelights2)
				playerRef.RemoveSpell(SuH_sp_seductivedelights)
			endIf

			if playerRef.HasSpell(SuH_sp_HealthyMilk2) || playerRef.HasSpell(SuH_sp_ShiningMilk2) || playerRef.HasSpell(SuH_sp_SugaryMilk2) || playerRef.HasSpell(SuH_sp_seductivemilk) || playerRef.HasSpell(SuH_sp_HealthyMilk) || playerRef.HasSpell(SuH_sp_ShiningMilk) || playerRef.HasSpell(SuH_sp_SugaryMilk)
				playerRef.AddSpell(SuH_sp_milklover)
				playerRef.RemoveSpell(SuH_sp_HealthyMilk)
				playerRef.RemoveSpell(SuH_sp_HealthyMilk2)
				playerRef.RemoveSpell(SuH_sp_ShiningMilk)
				playerRef.RemoveSpell(SuH_sp_ShiningMilk2)
				playerRef.RemoveSpell(SuH_sp_SugaryMilk)
				playerRef.RemoveSpell(SuH_sp_SugaryMilk2)
				playerRef.RemoveSpell(SuH_sp_seductivemilk)
			endIf
		endIf
		
	endIf
	;end/
	;ent/ Current Patch (DEVpatch)
	If MODversion < 2.62
		if MODversion != 0 && MODversion < 2.612
			Debug.Notification("Succubus Heart : Installing DEVpatch 2.612")
			if playerRef.HasSpell(SuH_sp_succubusprowl)
				SuH_Lsuccubusprowl.SetValue(1)
			endIf
			if playerRef.HasSpell(SuH_sp_spermlover)
				SuH_Lspermlover.SetValue(1)
			endIf
			if playerRef.HasSpell(SuH_sp_milklover)
				SuH_Lmilklover.SetValue(1)
			endIf
			if playerRef.HasSpell(SuH_sp_perfectorgasm)
				SuH_Lperfectorgasm.SetValue(1)
			endIf
			if playerRef.HasSpell(SuH_sp_speciallover)
				SuH_Lspeciallover.SetValue(1)
			endIf
			if playerRef.HasSpell(SuH_sp_caringlover)
				SuH_Lcaringlover.SetValue(1)
			endIf
			if playerRef.HasSpell(SuH_sp_magicallover)
				SuH_Lmagicallover.SetValue(1)
			endIf
			if playerRef.HasSpell(SuH_sp_lastinglover)
				SuH_Llastinglover.SetValue(1)
			endIf
			if playerRef.HasSpell(SuH_sp_humandesires)
				SuH_Lhumandesires.SetValue(1)
			endIf
			if playerRef.HasSpell(SuH_sp_animaldesires)
				SuH_Lanimaldesires.SetValue(1)
			endIf
			if playerRef.HasSpell(SuH_sp_masochist)
				SuH_Lmasochist.SetValue(1)
			endIf
			if playerRef.HasSpell(SuH_sp_milkdrinker)
				SuH_Lmilkdrinker.SetValue(1)
			endIf
			SuH_SETdrainconsent.SetValue(0.5)
			Debug.Notification("Succubus Heart : DEVpatch 2.612 Installed")
		endIf
		SuH_MODversion.SetValue(2.612)
	endIf
	debug.Notification("Succubus Heart : Running DevBuild -2.613-")
	;end/
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)
	actor[] aniActor = SexLab.HookActors(argString)
	
	;ent/ Animation Variables
	int i = 0
	int femalePres = 0
	int malePres = 0
	int crePres = 0
	int sucpres = 0
	;end/
	
	i = 0
	while i < aniActor.Length
		;ent/ Gender Check
		int Agender = SexLab.GetGender(aniActor[i])
		if Agender == 1
			femalePres += 1
		elseIf Agender == 0
			malePres += 1
		elseIf Agender >= 2
			crePres += 1
		endIf
		if aniActor[i].HasMagicEffect(SuH_NPCsuccubuseffect)
			sucpres += 1
		endIf
		;end/
		;ent/ Apply OnAct
		aniActor[i].AddSpell(SuH_CHAinact, false)
		if SuH_SETinvact.GetValue()
			aniActor[i].AddSpell(SuH_essential, false)
		endIf
		;end/
	i += 1
	endWhile
	
	if Thread.HasPlayer
		;ent/ Animation Variables
		int NPCgenders = 0
		int pGender = SexLab.GetGender(playerRef)
		;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/ Type Effects
		actor victim = SexLab.HookVictim(argString)
		if victim != none
			i = 0
			while i < aniActor.Length
				if aniActor[i] == victim
					if aniActor[i] == playerRef
						aniActor[i].AddSpell(SuH_PCSsubmit, false)
					elseIf aniActor[i].HasMagicEffect(SuH_NPCsuccubuseffect)
						aniActor[i].AddSpell(SuH_NPCssubmit, false)
					else
						aniActor[i].AddSpell(SuH_NPCsvictim, false)
					endIf
				else
					if aniActor[i] == playerRef
						aniActor[i].AddSpell(SuH_PCSmastery, false)
					elseif aniActor[i].HasMagicEffect(SuH_NPCsuccubuseffect)
						aniActor[i].AddSpell(SuH_NPCsmastery, false)
					else
						aniActor[i].AddSpell(SuH_NPCsattacker, false)
					endIf
				endIf
			i += 1
			endWhile
		else
			i = 0
			while i < aniActor.Length
				if aniActor[i] == playerRef
					aniActor[i].AddSpell(SuH_PCStraining, false)
				elseif aniActor[i].HasMagicEffect(SuH_NPCsuccubuseffect)
					aniActor[i].AddSpell(SuH_NPCstraining, false)
				else
					aniActor[i].AddSpell(SuH_NPCsconsent, false)
				endIf
			i += 1
			endWhile
		endIf
		;end/
	elseIf sucpres > 0
		;ent/ Type Effects
		actor victim = SexLab.HookVictim(argString)
		if victim != none
			i = 0
			while i < aniActor.Length
				if aniActor[i] == victim
					if aniActor[i].HasMagicEffect(SuH_NPCsuccubuseffect)
						aniActor[i].AddSpell(SuH_NPCssubmit, false)
					else
						aniActor[i].AddSpell(SuH_NPCsnvictim, false)
					endIf
				else
					if aniActor[i].HasMagicEffect(SuH_NPCsuccubuseffect)
						aniActor[i].AddSpell(SuH_NPCsmastery, false)
					else
						aniActor[i].AddSpell(SuH_NPCsnattacker, false)
					endIf
				endIf
			i += 1
			endWhile
		else
			i = 0
			while i < aniActor.Length
				if aniActor[i].HasMagicEffect(SuH_NPCsuccubuseffect)
					aniActor[i].AddSpell(SuH_NPCstraining, false)
				else
					aniActor[i].AddSpell(SuH_NPCsnconsent, 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 mcrePres = 0
	int fcrePres = 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
			mcrePres += 1
		elseIf Agender == 3
			fcrePres
		endIf
		;end/
		;ent/ Player Passives (always act)
		if orgaActor[i] == playerRef
			if playerRef.HasMagicEffect(SuH_sp_perfectorgasmeffect)
				float pH = playerRef.GetBaseActorValue("health")
				float pS = playerRef.GetBaseActorValue("stamina")
				float pM = playerRef.GetBaseActorValue("magicka")
				float cH = playerRef.GetActorValue("health")
				float cM = playerRef.GetActorValue("magicka")
				float cS = playerRef.GetActorValue("stamina")
				float hheal = (pH - cH)*0.75
				float mheal = (pM - cM)*0.75
				float sheal = (pS - cS)*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])
		int SETsexdrops = SuH_SETsexdrops.GetValue() as int
		;ent/ Sperm Function
		if SETsexdrops == 0 || SETsexdrops == 1
			if Agender == 1 && malePres > 0 || Agender == 1 && mcrePres > 0 || Agender == 3 && malePres > 0 || Agender == 3 && mcrePres > 0
				;ent/ Give Female Sperm
				int givers = (malePres + mcrePres)
				int K = 0
				while K < givers
					int random = Utility.RandomInt(0, 92)
					if random >= 0 && random <= 22
						orgaActor[i].AddItem(SuH_SpermSticky, 2, true)
						orgaActor[i].EquipItem(SuH_SpermSticky, false, true)
					elseIf random >= 23 && random <= 44
						orgaActor[i].AddItem(SuH_SpermSweet, 2, true)
						orgaActor[i].EquipItem(SuH_SpermSweet, false, true)
					elseIf random >= 46 && random <= 67
						orgaActor[i].AddItem(SuH_SpermThick, 2, true)
						orgaActor[i].EquipItem(SuH_SpermThick, false, true)
					elseIf random >= 69 && random <= 90
						orgaActor[i].AddItem(SuH_SpermWarm, 2, true)
						orgaActor[i].EquipItem(SuH_SpermWarm, false, true)
					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 sperm!")
						endIf
					endIf
					K += 1
				endWhile
				;end/
			elseIf femalePres < 1
				;ent/ bleh
				int givers = (malePres + mcrePres)
				int K = 0
				while K < givers
					int random = Utility.RandomInt(0, 92)
					if random >= 0 && random <= 22
						orgaActor[i].AddItem(SuH_SpermSticky, 2, true)
						orgaActor[i].EquipItem(SuH_SpermSticky, false, true)
					elseIf random >= 23 && random <= 44
						orgaActor[i].AddItem(SuH_SpermSweet, 2, true)
						orgaActor[i].EquipItem(SuH_SpermSweet, false, true)
					elseIf random >= 46 && random <= 67
						orgaActor[i].AddItem(SuH_SpermThick, 2, true)
						orgaActor[i].EquipItem(SuH_SpermThick, false, true)
					elseIf random >= 69 && random <= 90
						orgaActor[i].AddItem(SuH_SpermWarm, 2, true)
						orgaActor[i].EquipItem(SuH_SpermWarm, false, true)
					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 sperm!")
						endIf
					endIf
					K += 1
				endWhile
				;end/
			endIf
		endIf
		;end/
		;ent/ Milk Function
		if SETsexdrops == 0 || SETsexdrops == 2
			if Agender == 1 && femalePres > 1 || Agender == 1 && fcrePres > 0 || Agender == 3 && femalePres > 0 || Agender == 3 && fcrePres > 1
				;ent/ Give Female Milk
					int givers = (femalePres + fcrePres - 1)
					int K = 0
					while K < givers
						int random = Utility.RandomInt(0,3)
						if random == 0
							orgaActor[i].AddItem(SuH_MilkCreamy, 2, true)
							orgaActor[i].EquipItem(SuH_MilkCreamy, false, true)
						elseIf random == 1
							orgaActor[i].AddItem(SuH_MilkSmooth, 2, true)
							orgaActor[i].EquipItem(SuH_MilkSmooth, false, true)
						elseIf random == 2
							orgaActor[i].AddItem(SuH_MilkSweet, 2, true)
							orgaActor[i].EquipItem(SuH_MilkSweet, false, true)
						else
							orgaActor[i].AddItem(SuH_MilkWarm, 2, true)
							orgaActor[i].EquipItem(SuH_MilkWarm, false, true)
						endIf
					K += 1
					endWhile
				;end/
			elseIf Agender == 0 && femalePres > 0 || Agender == 0 && fcrePres > 0 || Agender == 2 && femalePres > 0 || Agender == 2 && fcrePres > 0
				;ent/ Give Male
					int givers = (femalePres + fcrePres)
					int K = 0
					while K < givers
						int random = Utility.RandomInt(0,3)
						if random == 0
							orgaActor[i].AddItem(SuH_MilkCreamy, 2, true)
							orgaActor[i].EquipItem(SuH_MilkCreamy, false, true)
						elseIf random == 1
							orgaActor[i].AddItem(SuH_MilkSmooth, 2, true)
							orgaActor[i].EquipItem(SuH_MilkSmooth, false, true)
						elseIf random == 2
							orgaActor[i].AddItem(SuH_MilkSweet, 2, true)
							orgaActor[i].EquipItem(SuH_MilkSweet, false, true)
						else
							orgaActor[i].AddItem(SuH_MilkWarm, 2, true)
							orgaActor[i].EquipItem(SuH_MilkWarm, false, true)
						endIf
					K += 1
					endWhile
				;end/
			endIf
		endIf
		;end/
		i += 1
	endWhile
	;end/
endEvent

Event DanieManage(string eventName, string argString, float argNum, form sender)
	sslThreadController Thread = SexLab.HookController(argString)
	actor[] endActor = SexLab.HookActors(argString)
	int i = 0
	while i < endActor.Length
		endActor[i].RemoveSpell(SuH_essential)
		if endActor[i] == playerRef
			endActor[i].RemoveSpell(SuH_PCSmastery)
			endActor[i].RemoveSpell(SuH_PCSsubmit)
			endActor[i].RemoveSpell(SuH_PCStraining)
		else
			endActor[i].RemoveSpell(SuH_NPCsattacker)
			endActor[i].RemoveSpell(SuH_NPCsconsent)
			endActor[i].RemoveSpell(SuH_NPCsvictim)
			endActor[i].RemoveSpell(SuH_NPCsnvictim)
			endActor[i].RemoveSpell(SuH_NPCsnattacker)
			endActor[i].RemoveSpell(SuH_NPCsnconsent)
			endActor[i].RemoveSpell(SuH_NPCsmastery)
			endActor[i].RemoveSpell(SuH_NPCstraining)
			endActor[i].RemoveSpell(SuH_NPCssubmit)
		endIf
		endActor[i].RemoveSpell(SuH_CHAinact)
	i += 1
	endWhile
endEvent