ScriptName SuH_Main extends Quest

;#Include
SexLabFramework property SexLab auto
	
;Globals
GlobalVariable Property SuH_NPChdry auto
GlobalVariable Property SuH_NPCmdry auto
GlobalVariable Property SuH_NPCsdry auto
	
;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
	
MagicEffect Property SuH_sp_perfectorgasmeffect auto
	
;Function 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
	
;Function Actors
Actor Property PlayerRef Auto
	
;integers
int maleActs = 0
	
;Initialization
Event OnInit()
	RegisterForModEvent("AnimationStart","DanisManage")
	RegisterForModEvent("AnimationEnd","DanieManage")
	RegisterForModEvent("OrgasmStart","DorgsManage")
	RegisterForModEvent("OrgasmEnd","DorgeManage")
EndEvent

Event DanisManage(string eventName, string argString, float argNum, form sender)
	sslThreadController Thread = SexLab.HookController(argString)
	
	if Thread.HasPlayer
		actor victim = SexLab.HookVictim(argString)
		if victim != none
			if Thread.IsVictim(playerRef)
				actor[] rapeActor = SexLab.HookActors(argString)
				int 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)
				int 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)
			int 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
	endIf
endEvent

Event DorgsManage(string eventName, string argString, float argNum, form sender)
	sslThreadController Thread = SexLab.HookController(argString)
	
	actor[] orgaActor = SexLab.HookActors(argString)
	if orgaActor.Length != 1 && orgaActor.Length != 0
		int malePres = 0
		int i = 0
		while i < orgaActor.Length
			if orgaActor[i] == playerRef
				if playerRef.HasMagicEffect(SuH_sp_perfectorgasmeffect)
					float playerHealth = Game.GetPlayer().GetBaseActorValue("health")
					float playerStamina = Game.GetPlayer().GetBaseActorValue("stamina")
					float playerMagicka = Game.GetPlayer().GetBaseActorValue("magicka")
					float chealth = Game.GetPlayer().GetActorValue("health")
					float cmagicka = Game.GetPlayer().GetActorValue("magicka")
					float cstamina = Game.GetPlayer().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)
					Game.Getplayer().RestoreActorValue("health",hheal)
					Game.Getplayer().RestoreActorValue("magicka",mheal)
					Game.Getplayer().RestoreActorValue("stamina",sheal)
				endIf
			endIf
			int Agender = SexLab.GetGender(orgaActor[i])
			if Agender == 1
			else
				malePres += 1
			endIf
		i += 1
		endWhile
		if malePres > 0
			i = 0
			while i < orgaActor.Length
				actor Bactor = orgaActor[i]
				i += 1
				int Bgender = SexLab.GetGender(Bactor)
				If Bgender == 1
					int K = 0
					while K < malePres
						int random = Utility.RandomInt(0, 95)
						if random >= 0 && random <= 20
							Bactor.AddItem(SuH_SpermSticky, 2, true)
							Bactor.EquipItem(SuH_SpermSticky, false, true)
						elseIf random >= 21 && random <= 22
							Bactor.AddItem(SuH_SpermSticky, 3, true)
							Bactor.EquipItem(SuH_SpermSticky, false, true)
							if Bactor == playerRef
								debug.Notification("That was quite the load...")
							endIf
						elseIf random >= 23 && random <= 43
							Bactor.AddItem(SuH_SpermSweet, 2, true)
							Bactor.EquipItem(SuH_SpermSweet, false, true)
						elseIf random >= 44 && random <= 45
							Bactor.AddItem(SuH_SpermSweet, 3, true)
							Bactor.EquipItem(SuH_SpermSweet, false, true)
							if Bactor == playerRef
								debug.Notification("That was quite the load...")
							endIf
						elseIf random >= 46 && random <= 66
							Bactor.AddItem(SuH_SpermThick, 2, true)
							Bactor.EquipItem(SuH_SpermThick, false, true)
						elseIf random >= 67 && random <= 68
							Bactor.AddItem(SuH_SpermThick, 3, true)
							Bactor.EquipItem(SuH_SpermThick, false, true)
							if Bactor == playerRef
								debug.Notification("That was quite the load...")
							endIf
						elseIf random >= 69 && random <= 89
							Bactor.AddItem(SuH_SpermWarm, 2, true)
							Bactor.EquipItem(SuH_SpermWarm, false, true)
						elseIf random >= 90 && random <= 91
							Bactor.AddItem(SuH_SpermWarm, 3, true)
							Bactor.EquipItem(SuH_SpermWarm, false, true)
							if Bactor == playerRef
								debug.Notification("That was quite the load...")
							endIf
						elseIf random == 92
							Bactor.AddItem(SuH_SpermPerfect, 2, true)
							Bactor.EquipItem(SuH_SpermPerfect, false, true)
							if Bactor == playerRef
								debug.Notification("PERFECTION! The perfect load!")
							endIf
						else
							if Bactor == playerRef
								debug.Notification("Seems this one's dry...")
							endIf
						endIf
					K += 1
					endWhile
				endIf
			i += 1
			endWhile
		endIf
	endIf
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
		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)
endEvent





