Scriptname SLAppPCSexQuestScript extends SLApproachBaseQuestScript Conditional 

Function startApproach(Actor akRef)
	ImportPlayerStatus()
	SetPlayerLevel()
	PCApproachOngoing = True
	maxTime = SLApproachMain.SLApproachTimelimit
	ProstitutionChance(akref)
	SetCharacter(akRef)
	if akref == StayingActor.GetReference() as Actor
		if selectedScene == SLApproachHouseStayScene
			akref.addtofaction(slapp_VisitingScenePlayFaction)
			slappUtil.log("Selected scene is stayingguestevent, roll rape chance.")
		endif
	else
		talkingActor.ForceRefTo(akRef)
		if (selectedScene == SLApproachAskForSexQuestScene) || (selectedScene == SLAppAskingNameToPCScene)
			slappUtil.log("Selected scene is sex to pc, roll rape chance.")
		endif
	endif
	self.rollRapeChance(akRef)
	SLApproachRapeToggle.setvalue(willRape as int)
	if SLA_BaboDialogue.getvalue() == 1
		;AkWorld = akref.getworldspace() ; haven't decided whether to add it or not.
		;if Akworld == Whiterunworld
		;	if PlayerRef.isinfaction(WhiterunOrcFuckToyTitleRank)
		;		SLApproachPlayerHouseWhiterun.addform(akref)
		;	endif			
		;elseif Akworld == Solitudeworld
		;endif
	endif
	selectedScene.Start()
	;approachEnding = True
	parent.startApproach(akRef)
	if SLApproachMain.debugLogFlag
		Debug.notification("StartApproach," + (selectedScene.getname() as string) + "starts from " + (akRef.GetBaseObject().GetName() as string))
	endif
EndFunction

Function SetPlayerLevel()
	int DLevel = SLApproachMain.SLADeviationLevel
	SLAStandardLevelMaximumNPCGlobal.value = PlayerRef.getlevel() + DLevel
	SLAStandardLevelMinimumNPCGlobal.value = PlayerRef.getlevel() - DLevel
	fPlayerSpeechCraft = PlayerRef.GetActorValue("Speechcraft")
	SlappSpeechAV.setvalue(fPlayerSpeechCraft)
EndFunction



Function SetCharacter(actor akRef)

Int Character

if !akRef.isinfaction(slapp_Characterfaction)
	if !akRef.isinfaction(SLAX_AggressiveFaction)
		actorbase akRefbase = akRef.getbaseobject() as actorbase
		
		if akRefbase.isunique()
			Character = Utility.randomint(SLApproachMain.SLANPCUniqueCharacterMin, SLApproachMain.SLANPCUniqueCharacterMax);0Mild,1Timid,2Confident,3Aggressive,4Rapist
		else
			if akRef.getactorvalue("Morality") <= SLApproachMoralGlobal.getvalue() || akRef.isinfaction(slapp_ThugFaction) || akRef.isinfaction(slapp_SpoiledKid)
				Character = Utility.randomint(3,4);0Mild,1Timid,2Confident,3Aggressive,4Rapist
			else
				Character = Utility.randomint(SLApproachMain.SLANPCCharacterMin, SLApproachMain.SLANPCCharacterMax);0Mild,1Timid,2Confident,3Aggressive,4Rapist	
			endif
		endif
		
		if SLApproachMain.SLACurrentActorisChild == true
			if Character >= 3 && !akRef.isinfaction(slapp_SpoiledKid)
				Character = 2
			endif
		endif
		;if akRef.isinfaction(SLApproachMain.BaboViceGuardCaptainFaction) 
		;	Character = 3
		;endif
		akRef.addtofaction(slapp_Characterfaction)
		akRef.addtofaction(SLAX_AggressiveFaction)
		akRef.setfactionrank(slapp_Characterfaction, Character)
		akRef.setfactionrank(SLAX_AggressiveFaction, Character)
	else
		akRef.addtofaction(slapp_Characterfaction)
		akRef.setfactionrank(slapp_Characterfaction, akRef.getfactionrank(SLAX_AggressiveFaction) as int)
	endif
endif

EndFunction


Function approachEndingSwitch(Bool Switch)
	approachEnding = Switch
EndFunction

int Function ProstitutionNPCMoney(Actor akRef) ; How much NPC has money.

 
Armor HeadArmor = akRef.GetWornForm(0x00000001) as Armor
Armor BodyArmor = akRef.GetWornForm(0x00000004) as Armor
Armor HandsArmor = akRef.GetWornForm(0x00000008) as Armor
Armor AmuletArmor = akRef.GetWornForm(0x00000020) as Armor
Armor RingArmor = akRef.GetWornForm(0x00000040) as Armor
Armor FeetArmor = akRef.GetWornForm(0x00000080) as Armor

int ArmorValue = 0
int RichValue = 0

if HeadArmor
	ArmorValue += HeadArmor.GetGoldValue() as int
endif

if BodyArmor
	ArmorValue += BodyArmor.GetGoldValue() as int
endif

if HandsArmor
	ArmorValue += HandsArmor.GetGoldValue() as int
endif

if AmuletArmor
	ArmorValue += AmuletArmor.GetGoldValue() as int
endif

if RingArmor
	ArmorValue += RingArmor.GetGoldValue() as int
endif

if FeetArmor
	ArmorValue += FeetArmor.GetGoldValue() as int
endif

int LevelValue = akref.getlevel() * 10

if akref.wornhaskeyword(ClothingPoor)
	Richvalue = 5
elseif akref.wornhaskeyword(ClothingRich)
	Richvalue = 1500
else
	Richvalue = 500
endif

Int Totalvalue = Armorvalue + LevelValue + RichValue

Return Totalvalue

EndFunction

int Function ProstitutionPlayerValue(); How much will you offer

int ValueMax = SLApproachProstitutionMax.getvalue() as int
int ValueMin = SLApproachProstitutionMin.getvalue() as int
int extravalue
	extravalue += slappUtil.NudeCalc(PlayerRef);from0~70
	extravalue += slappUtil.AppearanceCalc();from0~75
int PValue = Utility.randomint(ValueMin, ValueMax)
	extravalue += Pvalue 
SLApproachProstitutionValue.setvalue(extravalue)
UpdateCurrentInstanceGlobal(SLApproachProstitutionValue)
if SLApproachMain.debugLogFlag
	Debug.notification("Your prostitution value is: " + extravalue)
endif
Return Pvalue

EndFunction

Function ProstitutionChance(Actor akref)

int NPCMoney = ProstitutionNPCMoney(akref)
int PlayerValue = ProstitutionPlayerValue()

float AcceptChance = ((NPCMoney / PlayerValue) * 100) as float

if AcceptChance >= 100
	ProstitutionAcceptChance = 100
Else
	ProstitutionAcceptChance = AcceptChance
EndIf

If PlayerValue >= NPCMoney
	SLApproachMain.SLAProstitution = false
;	SLApproachProstitutionFraudChance.setvalue();WIP
else
	SLApproachMain.SLAProstitution = true
endif

Endfunction

Function rollRapeChance(Actor akRef)
	if (SLApproachMain.enableRapeFlag)
		if (SLApproachMain.enableSLHHFlag)
			SLHHwillRape = true
		else
			SLHHwillRape = false
		endif
		if (akRef.IsEquipped(SLAppRingBeast))
			willRape = true
			return
		endif
		
		int chance = akRef.GetFactionRank(arousalFaction)
		chance += slappUtil.HomeAlone();from-50~50
		chance += slappUtil.CharacterCalc(akRef);from-25~25
		chance += slappUtil.LightLevelCalc(akRef);from-50~25
		chance += slappUtil.TimeCalc();from-25~25
		chance += slappUtil.NudeCalc(PlayerRef);from0~70
		chance += slappUtil.AppearanceCalc();from0~75
;		chance += 5;50+145+5 = 200
		chance = chance / 10
		chance = slappUtil.ValidateChance(chance);From 0 to 150
		chance += SLApproachMain.userAddingRapePointPc;Range(-100, 100)

		int roll = Utility.RandomInt(0, 150)
		SLAFactorScore.value = chance; Why did I do this? Never know.. Perhaps I'll need this to sort npcs some other time.
		if (roll < chance)
			willRape  = true
		else
			willRape  = false
		endif
	else
		willRape = false
	endif
EndFunction

Function ChanceRollMisc(Actor akRef, Actor akActor, float baseChanceMultiplier, int SceneType = 1)

	string akRefName = akRef.GetActorBase().GetName()
	int roll
	int result
	
	if SLApproachMain.debugLogFlag
		Debug.notification("ChanceRollMisc started")
	endif

	int StandardlevelRangeminimum = (akActor.getlevel() - SLApproachMain.SLADeviationLevel)
	int StandardlevelRangemaximum = (akActor.getlevel() + SLApproachMain.SLADeviationLevel)
	int pt_gll = slappUtil.LightLevelCalc(akRef)
	int pt_time = slappUtil.TimeCalc()
	int pt_nude = slappUtil.NudeCalc(akActor)
	int pt_Appearance = slappUtil.AppearanceCalc()
	int pt_bed = slappUtil.BedCalc(akActor) / 2
	int chance = SexUtil.GetArousal(akRef, akActor); get the value of NPC's arousal.
	; Chance Calculation ---------------------------------
	;chance += slappUtil.RelationCalc(akRef, akActor);(-60~50)
	chance += pt_gll;from-50~25
	chance += pt_time;from-25~25
	chance += pt_nude;from0~70
	chance += pt_Appearance;from0~75
	chance += pt_bed;-30or20
	

	if SLA_DDI.getvalue() == 1
		(SLApproach_ExternalMods as SLApproachExternalScript).CheckDD(akActor)
	endif
	if sla_slsurvival.getvalue() == 1
		(SLApproach_ExternalMods as SLApproachExternalScript).SLSurvivalLicenseCheck()
	endif
	
	roll = Utility.randomint(0, SLApproachMain.userAddingPointPc + SLApproachMain.userAddingaskingnamePointPc)
	
	If (roll <= SLApproachMain.userAddingaskingnamePointPc) && (SLApproachMain.userAddingaskingnamePointPc > 0)
		SLAMiscDialogueType.setvalue(1)
	Elseif (roll <= (SLApproachMain.userAddingPointPc + SLApproachMain.userAddingaskingnamePointPc)) && (SLApproachMain.userAddingPointPc > 0)
		SLAMiscDialogueType.setvalue(2)
	Elseif (roll <= (SLApproachMain.userAddingPointPc + SLApproachMain.userAddingaskingnamePointPc + SLApproachMain.userAddingSpankingAssPointPc)) && (SLApproachMain.userAddingSpankingAssPointPc > 0)
		SLAMiscDialogueType.setvalue(3)
	else
		SLAMiscDialogueType.setvalue(0)
	Endif
	
	ImportPlayerStatus()
	SetPlayerLevel()
	talkingActor.clear()
	talkingActor.ForceRefTo(akRef)
	ProstitutionChance(akref)
	self.rollRapeChance(akRef)
	SLApproachRapeToggle.setvalue(willRape as int)
	parent.RegisterForSingleUpdate(60)
	
	if SceneType == 1
		selectedScene = SLAppAskingKid02Scene
	elseif SceneType == 2
		selectedScene = SLAppAskingMiscScene
	endif
	
	
	PCApproachOngoing = True
	;SLApproachBase.RegisterAnimationEvent()
	ready()
	selectedScene.forceStart()
EndFunction

bool Function chanceRoll(Actor akRef, Actor akActor, float baseChanceMultiplier);triggered directly from SLApproachApplyEffect
	string akRefName = akRef.GetActorBase().GetName()
	int roll
	int result
	
	if SLApproachMain.debugLogFlag
		Debug.notification("ChanceRoll started")
	endif
	
;	if !(self.isPrecheckValid(akRef, akActor, true))
;		return false
;	endif
	
	
	if !(akActor.GetPlayerControls())
		return false
	endif

	int chance = SexUtil.GetArousal(akRef, akActor); get the value of NPC's arousal.
	if (chance < SLApproachMain.lowestArousalNPC)
		slappUtil.log(ApproachName + ": " + akRefName + " :Canceled by NPC's Arousal: " + chance)
		return false
	elseif (SexUtil.GetArousal(akActor, akRef) < SLApproachMain.lowestArousalPC)
		slappUtil.log(ApproachName + ": " + akRefName + " :Canceled by PC's Arousal: ---")
		return false
	endif

	int StandardlevelRangeminimum = (akActor.getlevel() - SLApproachMain.SLADeviationLevel)
	int StandardlevelRangemaximum = (akActor.getlevel() + SLApproachMain.SLADeviationLevel)

	If akref.getlevel() < StandardlevelRangeminimum
		if SLApproachMain.SLALowerLevelNPC == false
			Return false
		endif
	Elseif akref.getlevel() > StandardlevelRangemaximum
		if SLApproachMain.SLAhigherLevelNPC == false
			Return false
		endif
	Elseif (akref.getlevel() >= StandardlevelRangeminimum) && (akref.getlevel() <= StandardlevelRangemaximum)
		if SLApproachMain.SLAStandardLevelNPC == false
			Return false
		endif
	EndIf
	
	int pt_gll = slappUtil.LightLevelCalc(akRef)
	int pt_time = slappUtil.TimeCalc()
	int pt_nude = slappUtil.NudeCalc(akActor)
	int pt_Appearance = slappUtil.AppearanceCalc()
	int pt_bed = slappUtil.BedCalc(akActor) / 2

	; Chance Calculation ---------------------------------
	;chance += slappUtil.RelationCalc(akRef, akActor);(-60~50);Old
	chance += pt_gll;from-50~25
	chance += pt_time;from-25~25
	chance += pt_nude;from0~70
	chance += pt_Appearance;from0~75
	chance += pt_bed;-30or20
	;chance -= 15

	if Parent.PrecheckShota(akRef)
		if !akRef.isinfaction(slapp_KidFaction)
			akRef.addtofaction(slapp_KidFaction)
		endif
	endif

	if SLA_DDI.getvalue() == 1
		(SLApproach_ExternalMods as SLApproachExternalScript).CheckDD(akActor)
	endif
	if sla_slsurvival.getvalue() == 1
		(SLApproach_ExternalMods as SLApproachExternalScript).SLSurvivalLicenseCheck()
	endif

	;roll = self.GetDiceRoll()
	roll = Utility.randomint(0, SLApproachMain.userAddingPointPc + SLApproachMain.userAddingaskingnamePointPc + SLApproachMain.userAddingSpankingAssPointPc);
	

	If (roll <= SLApproachMain.userAddingaskingnamePointPc) && ((SLApproachMain.userAddingaskingnamePointPc) > 0)
		; for asking name ---------------------------------
		roll = GetDiceRoll()

		if akRef.isinfaction(slapp_VisitingFaction)
			result = GetResult(chance, SLApproachMain.userAddingVisitorPointPc, baseChanceMultiplier)
			slappUtil.log(ApproachName + ": " + akRefName + " :Kiss: " + roll + " < " + result)
			SLAFactorScore.value = result

			if (roll < result)
				int randomi = Utility.randomint(1, 2);1 common, 2 Ask for Drink
				akRef.Setactorvalue("Variable06", randomi)
				selectedScene = SLApproachHouseStayScene
				if SLApproachMain.debugLogFlag
					debug.notification("SLAPP House Visitor Start")
				endif
				return true ; for asking name
			endif
		else
			result = GetResult(chance, SLApproachMain.userAddingAskingNamePointPc, baseChanceMultiplier)
			slappUtil.log(ApproachName + ": " + akRefName + " :Kiss: " + roll + " < " + result)
			SLAFactorScore.value = result
			if (roll < result)
				;if SLApproachMain.SLACurrentActorisChild == true
				;	selectedScene = SLAppAskingKidScene
				;else
					selectedScene = SLAppAskingNameToPCScene
					If SLApproachMain.enableBDFlag
						if (akRef.isinfaction(SLApproachMain.BaboViceGuardCaptainFaction))
							selectedScene = SLAppViceGuardCaptainScene
						elseIf (akRef.isinfaction(SLApproachMain.BaboAggressiveBoyFriend))
							selectedScene = SLAppAggressiveBFPCScene
						EndIf
					EndIf
				;endif
				if SLApproachMain.debugLogFlag
					debug.notification("SLAPP Asking name Start")
				endif
				return true ; for asking name
			endif
		endif
	Elseif (roll <= (SLApproachMain.userAddingPointPc + SLApproachMain.userAddingaskingnamePointPc)) && (SLApproachMain.userAddingPointPc > 0)
		; for asking Sex ---------------------------------

		if SLA_DDI.getvalue() == 1
			if akActor.IsEquipped(SLApproachDDIYokeList)
				return false
			endif
		endif

		roll = GetDiceRoll()
		
		if akRef.isinfaction(slapp_VisitingFaction)
			result = GetResult(chance, SLApproachMain.userAddingVisitorPointPc, baseChanceMultiplier)
			slappUtil.log(ApproachName + ": " + akRefName + " :Kiss: " + roll + " < " + result)
			SLAFactorScore.value = result

			if (roll < result)
				int randomi = Utility.randomint(3, 4);3Flirt, 4ask for Sex
				akRef.Setactorvalue("Variable06", randomi)
				selectedScene = SLApproachHouseStayScene
				if SLApproachMain.debugLogFlag
					debug.notification("SLAPP House Visitor Sex Start")
				endif
				return true ; for asking sex
			endif
		else
			result = GetResult(chance, SLApproachMain.userAddingPointPc, baseChanceMultiplier)

			slappUtil.log(ApproachName + ": " + akRefName + " :Sex: " + roll + " < " + result)
			SLAFactorScore.value = result
			if (roll < result)
				;if SLApproachMain.SLACurrentActorisChild == true
				;	selectedScene = SLAppAskingKidScene
				;else
					selectedScene = SLApproachAskForSexQuestScene
					If SLApproachMain.enableBDFlag
						if (akRef.isinfaction(SLApproachMain.BaboViceGuardCaptainFaction))
							selectedScene = SLAppViceGuardCaptainScene
						elseIf (akRef.isinfaction(SLApproachMain.BaboAggressiveBoyFriend))
							selectedScene = SLAppAggressiveBFPCScene
						EndIf
					EndIf
				;endif
				if SLApproachMain.debugLogFlag
					debug.notification("SLAPP Asking Sex Start")
				endif
				return true ; for sex
			endif
		endif
	Elseif (roll <= (SLApproachMain.userAddingPointPc + SLApproachMain.userAddingaskingnamePointPc + SLApproachMain.userAddingSpankingAssPointPc)) && (SLApproachMain.userAddingSpankingAssPointPc > 0)
		; for Sexual Harrassment ---------------------------------

		if SLA_DDI.getvalue() == 1
			if akActor.IsEquipped(SLApproachDDIYokeList)
				return false
			endif
		endif

		roll = GetDiceRoll()
		
		if akRef.isinfaction(slapp_VisitingFaction)
			result = GetResult(chance, SLApproachMain.userAddingVisitorPointPc, baseChanceMultiplier)
			slappUtil.log(ApproachName + ": " + akRefName + " :Kiss: " + roll + " < " + result)
			SLAFactorScore.value = result

			if (roll < result)
				int randomi = Utility.randomint(3, 4);3Flirt, 4ask for Sex
				akRef.Setactorvalue("Variable06", randomi)
				selectedScene = SLApproachHouseStayScene
				if SLApproachMain.debugLogFlag
					debug.notification("SLAPP House Visitor Sex Start")
				endif
				return true ; for asking sex
			endif
		else
			result = GetResult(chance, SLApproachMain.userAddingPointPc, baseChanceMultiplier)

			slappUtil.log(ApproachName + ": " + akRefName + " :Sex: " + roll + " < " + result)
			SLAFactorScore.value = result
			if (roll < result)
				;if SLApproachMain.SLACurrentActorisChild == true
				;	selectedScene = SLAppAskingKidScene
				;else
					selectedScene = SLApproachSpankingScene
					If SLApproachMain.enableBDFlag
						if (akRef.isinfaction(SLApproachMain.BaboViceGuardCaptainFaction))
							selectedScene = SLAppViceGuardCaptainSpankScene
						elseIf (akRef.isinfaction(SLApproachMain.BaboAggressiveBoyFriend))
							;Nothing now
						EndIf
					EndIf
				;endif
				if SLApproachMain.debugLogFlag
					debug.notification("SLAPP Spanking Start")
				endif
				return true ; for sex
			endif
		endif
	EndIf
	return false
EndFunction

Function CheckEndApproach()
	Actor akRef = talkingActor.GetReference() as Actor
	if SLApproachMain.debugLogFlag
		Debug.notification("Child: CheckEndApproach")
	endif
	
	if akRef
		if akRef.isindialoguewithplayer() == true
			return
		else
			endApproachForce()
		endif
	else
		endApproachForce()
	endif
EndFunction

Function endApproach(bool force = false)
	if SLApproachMain.debugLogFlag
		Debug.notification("Child: EndApproach")
	endif
	int retryTime = 30
	Actor akRef = talkingActor.GetReference() as Actor
	Actor akstayingRef
	if stayingActor
		akstayingRef = stayingActor.GetReference() as Actor
	endif
	
	
	if (!force && SLApproachAskForSexQuestFollowPlayerScene.isPlaying())
		slappUtil.log(ApproachName + ": Now following scene is playing, retry.")
		parent.RegisterForSingleUpdate(retryTime)
	elseif (!force && SLAppHousevisitScene.isPlaying())
		slappUtil.log(ApproachName + ": Now following scene is playing, retry.")
		parent.RegisterForSingleUpdate(retryTime)
	elseif (!force && akRef && akRef.IsInDialogueWithPlayer())
		slappUtil.log(ApproachName + ": Now IsInDialogueWithPlayer, retry.")
		parent.RegisterForSingleUpdate(retryTime)
	else
		SLApproachKissResist.setvalue(0)
		PCApproachOngoing = false
		approachEnding = false
		selectedScene.Stop()
		SLApproachAskForSexQuestFollowPlayerScene.Stop()
		SLAppHousevisitScene.Stop()
		SLApproachHouseStayScene.stop()
		if akstayingRef.isinfaction(slapp_VisitingScenePlayFaction)
			akstayingRef.removefromfaction(slapp_VisitingScenePlayFaction)
		endif		
		HelperQuest.Stop()
		talkingActor.clear()
		SLApproachAskForSexQuest.SetStage(100)
	endif
EndFunction


Function endApproachForce(ReferenceAlias akRef = None)
;	PCApproachOngoing = false
	UnregisterForUpdate()
	parent.endApproachForce(talkingActor)
	endApproach(true)
EndFunction


Function StartSex(Actor akActor, Actor akSpeaker, bool rape = false)
	If rape
		SLApproachRapedTimes.setvalue(SLApproachRapedTimes.getvalue() + 1)
	else
		SLApproachNormalSexTimes.setvalue(SLApproachNormalSexTimes.getvalue() + 1)
	endif
	SexUtil.StartSexActors(akSpeaker, akActor, rape)
	;Debug.notification(akSpeaker + "StartSex")
EndFunction

Function StartSexHook(Actor akActor, Actor akSpeaker, bool rape = false, String EventRegisterDummy, String EventName, int Chance, Bool Worse)
	SexUtil.BaboDialogueRandomintSet(Chance, Worse)
	If rape
		SLApproachRapedTimes.setvalue(SLApproachRapedTimes.getvalue() + 1)
	else
		SLApproachNormalSexTimes.setvalue(SLApproachNormalSexTimes.getvalue() + 1)
	endif
	SexUtil.StartSexActorsHook(akSpeaker, akActor, rape, true, EventRegisterDummy, EventName)
	;Debug.notification(akSpeaker + "StartSex")
EndFunction

Function ProstitutionStartSex(Actor akActor, Actor akSpeaker)
	SLApproachProstitutionTimes.setvalue(SLApproachProstitutionTimes.getvalue() + 1)
;	ProstitutionPaid(); This will be changed
	SexUtil.StartSexActorsHook(akSpeaker, akActor, false, true, "AfterProst", "AfterProstitute")
EndFunction

Function StartSexMulti(Actor akActor, Actor akSpeaker, Actor Helper, bool rape = false)
	If rape
		SLApproachRapedTimes.setvalue(SLApproachRapedTimes.getvalue() + 1)
	else
		SLApproachNormalSexTimes.setvalue(SLApproachNormalSexTimes.getvalue() + 1)
	endif
	SexUtil.StartSexMultiActors(akSpeaker, akActor, Helper, rape)
EndFunction

Function StopScene()
	self.followSceneStop()
	self.endApproach(false)
;	PCApproachOngoing = false
EndFunction

Function GotoPrivateRoom(actor akactor, Bool ToSexCell)
	SLApproachMain.TeleporttoSexCell(akactor, ToSexCell)
EndFunction


Function enjoy()
	actor akactor = talkingActor.GetReference() as Actor
	if SLApproachMain.SLAProstitutionFollow
		self.ProstitutionStartSex(PlayerRef, akactor)
		self.ProstitutionPlus(akactor)
	else
		self.StartSex(PlayerRef, akactor)
		self.AcquaintancePlus(akactor, false, true)
	endif
	Parent.ResetSexRejectCount(akactor)
	Utility.wait(1.0)
	Self.StopScene()
EndFunction

Function enjoyStayingActor()
	actor akactor = stayingActor.GetReference() as Actor
	self.StartSex(PlayerRef, akactor)
	self.AcquaintancePlus(akactor, false, true)
	Parent.ResetSexRejectCount(akactor)
	Utility.wait(1.0)
	Self.StopScene()
EndFunction

Function Sexforreconciliation(Actor akSpeaker, int Possibility)
	Self.CoolDown(akSpeaker, Possibility)
	slappUtil.DetectPlayerAttire(akSpeaker, 4, 0)
	;SLApproachNormalSexTimes.setvalue(SLApproachNormalSexTimes.getvalue() + 1)
	self.StartSex(PlayerRef, akSpeaker)
	Self.StopScene()
EndFunction

Function enjoyMulti(Actor akSpeaker)
	;SLApproachNormalSexTimes.setvalue(SLApproachNormalSexTimes.getvalue() + 1)
	slappUtil.DetectPlayerAttire(akSpeaker, 4, 0)
	self.StartSexMulti(talkingActor.GetReference() as Actor, PlayerRef, akSpeaker, false)
	Self.StopScene()
EndFunction

Function NothingEnd(actor akactor = none)
	if akactor
		slappUtil.DetectPlayerAttire(akactor, 0, 0)
	endif
	Self.StopScene()
EndFunction

Function FirstMetEnd(Actor akSpeaker)
	Parent.AddtoAquaintanceFactionSimple(akSpeaker, SLApproachMain.SLAAquaintanceChance)
	slappUtil.DetectPlayerAttire(akSpeaker, 1, 0)
	Self.StopScene()
EndFunction

Function IgnoreHarrassment(Actor akSpeaker)
int Chance = SLApproachMain.SLADislikeChance - 10
	Parent.AddtoDislikeFaction(akSpeaker, Chance, false)
	Parent.sexRelationshipDown(akSpeaker, PlayerRef, SLApproachMain.SLARelationshipChance)
	slappUtil.DetectPlayerAttire(akSpeaker, 0, 1)
	Self.StopScene()
EndFunction

Function Ignore(Actor akSpeaker)
int Chance = SLApproachMain.SLADislikeChance + 20
	Parent.AddtoDislikeFaction(akSpeaker, Chance, false)
	Parent.sexRelationshipDown(akSpeaker, PlayerRef, SLApproachMain.SLARelationshipChance)
	slappUtil.DetectPlayerAttire(akSpeaker, 0, 0)
	Self.StopScene()
EndFunction

Function Disappointed(Actor akSpeaker)
	Parent.AddtoDisappointedFaction(akSpeaker, 100, 0)
	slappUtil.DetectPlayerAttire(akSpeaker, 0, 0)
	Self.StopScene()
EndFunction

Function DisappointedPlus(Actor akSpeaker)
	Parent.AddtoDisappointedFaction(akSpeaker, 100, 1)
	slappUtil.DetectPlayerAttire(akSpeaker, 0, 0)
	Self.StopScene()
EndFunction

Topic Property SLApproachTalkAboutWearingsNPCComplainWearingNormal Auto

Function ComplainAboutWearings(Actor akSpeaker)
	Self.Disagree(akSpeaker, false)
	akspeaker.say(SLApproachTalkAboutWearingsNPCComplainWearingNormal)
EndFunction

Function GiftGive(Actor akSpeaker)
int Number = Utility.randomint(1, 3)
	PlayerRef.additem(SLAPPAffectionMiscLVL, Number)
	Parent.GiftFaction(akSpeaker)
	Utility.wait(1.0)
	slappUtil.DetectPlayerAttire(akSpeaker, 3, 0)
	SLApproachGiftTimes.setvalue(SLApproachGiftTimes.getvalue() + 1)
	Self.AcquaintancePlusCalc(akSpeaker, false)
	Self.StopScene()
EndFunction

Function AcquaintanceForce(Actor akSpeaker, Bool HadSex)
	Parent.AddtoAquaintanceFaction(akSpeaker, 100, HadSex)
	Parent.sexRelationshipUp(akSpeaker, PlayerRef, 100)
	slappUtil.DetectPlayerAttire(akSpeaker, 1, 0)
	Self.StopScene()
EndFunction

Function Acquaintance(Actor akSpeaker)
	Self.AcquaintanceCalc(akSpeaker)
	slappUtil.DetectPlayerAttire(akSpeaker, 1, 0)
	Self.StopScene()
EndFunction

Function AcquaintancePlus(Actor akSpeaker, Bool StopQuest = True, Bool HadSex = True)
	Self.AcquaintancePlusCalc(akSpeaker, Hadsex)
	if Hadsex
		slappUtil.DetectPlayerAttire(akSpeaker, 4, 0)
	else
		slappUtil.DetectPlayerAttire(akSpeaker, 1, 0)
	endif
	if StopQuest == true
		Self.StopScene()
	endif	 
EndFunction

Function AcquaintanceCalc(Actor akSpeaker)
	Parent.AddtoAquaintanceFaction(akSpeaker, SLApproachMain.SLAAquaintanceChance, false)
	Parent.sexRelationshipUp(akSpeaker, PlayerRef, SLApproachMain.SLARelationshipChance)
EndFunction

Function AcquaintancePlusCalc(Actor akSpeaker, Bool HadSex = True)
Int AcquaintanceChance = SLApproachMain.SLAAquaintanceChance + 20
Int RelationshipChance = SLApproachMain.SLARelationshipChance + 20
	Parent.AddtoAquaintanceFaction(akSpeaker, AcquaintanceChance, Hadsex)
	Parent.sexRelationshipUp(akSpeaker, PlayerRef, RelationshipChance)
EndFunction

Function KissEnd(Actor akSpeaker)
	Parent.AddtoKissFaction(akSpeaker, 0)
	Parent.AddtoAquaintanceFaction(akSpeaker, SLApproachMain.SLAAquaintanceChance, false)
	Parent.sexRelationshipUp(akSpeaker, PlayerRef, SLApproachMain.SLARelationshipChance)
	slappUtil.DetectPlayerAttire(akSpeaker, 3, 0)
	Self.StopScene()
EndFunction

Function ProstitutionPlus(Actor akSpeaker)
	Parent.AddtoProstitutionFaction(akSpeaker)
	slappUtil.DetectPlayerAttire(akSpeaker, 5, 0)
	Self.StopScene()
EndFunction


Function CoolDown(Actor akSpeaker, int chance = 20)
	int roll = Utility.RandomInt(0, 100)
	chance += ((SLABreastsSlide.value / 10) + (SLAButtsSlide.value / 10) + (SLAAppearanceSlide.value / 10)) as int
	if roll <= chance
		Int RelationshipChance = SLApproachMain.SLARelationshipChance + 20
		if akspeaker.isinfaction(slapp_DislikeFaction)
			if Parent.RankDownDislikeFaction(PlayerRef) == 0
				Parent.AddtoReconciliationFaction(PlayerRef)
			endif
			Parent.sexRelationshipUp(akSpeaker, PlayerRef, RelationshipChance)
		endif
	endif
Self.StopScene()	 
EndFunction

Function NoSpankFaction(actor akactor, int chance)
	int roll = Utility.RandomInt(0, 100)
	chance += (PlayerRef.getactorvalue("Speechcraft") / 10) as int
	chance += (SLAAppearanceSlide.value / 10) as int
	chance -= (SLAButtsSlide.value / 10) as int
	chance -= slappUtil.CharacterCalc(akactor);from-25~25
	chance -= slappUtil.NudeCalc(PlayerRef);from0~70
	if roll <= chance
		Parent.AddtoNoSpankFaction(akactor)
	endif
;slapp_NoSpankFaction

EndFunction

Function NoMolestFaction(actor akactor, int chance)
	int roll = Utility.RandomInt(0, 100)
	chance += (PlayerRef.getactorvalue("Speechcraft") / 10) as int
	chance += (SLAAppearanceSlide.value / 10) as int
	chance -= (SLABreastsSlide.value / 10) as int
	chance -= (SLAButtsSlide.value / 10) as int
	chance -= slappUtil.CharacterCalc(akactor);from-25~25
	chance -= slappUtil.NudeCalc(PlayerRef);from0~70
	if roll <= chance
		Parent.AddtoNoMolestFaction(akactor)
	endif
	slappUtil.DetectPlayerAttire(akactor, 0, 5)
EndFunction

Function NoMolestFactionReconciliation(actor akactor, int chance)
	int roll = Utility.RandomInt(0, 100)
	chance += (PlayerRef.getactorvalue("Speechcraft") / 10) as int
	chance += (SLAAppearanceSlide.value / 10) as int
	chance -= (SLABreastsSlide.value / 10) as int
	chance -= (SLAButtsSlide.value / 10) as int
	chance -= slappUtil.CharacterCalc(akactor);from-25~25
	chance -= slappUtil.NudeCalc(PlayerRef);from0~70
	if roll <= chance
		Parent.AddtoNoMolestFaction(akactor)
	endif
	Self.CoolDown(akactor, chance)
	slappUtil.DetectPlayerAttire(akactor, 0, 5)
EndFunction

Function Visited()
	PCVisitingBefore = false
	PCVisitingon = false
	PCVisitingafter = false
	Parent.AddtoVisitiedFaction(VisitorRef)
	Self.StopScene() ;Why?
EndFunction

Function Stayed()
	PCVisitingBefore = false
	PCVisitingon = false
	PCVisitingafter = false
	Parent.AddtoStayedFaction(VisitorRef)
	stayingactor.clear()
	Self.StopScene()
EndFunction

Function VisitedbutFailed()
	PCVisitingBefore = false
	PCVisitingon = false
	PCVisitingafter = false
	If VisitorRef
		Parent.AddtoVisitiedFailedFaction(VisitorRef)
	EndIf
	Self.StopScene() 
EndFunction

Function GuardPunishmentEnd(Actor akactor)
	akactor.addtofaction(slapp_PunishingGuard)
	SLApproachGuardPunishmentTimes.setvalue(SLApproachGuardPunishmentTimes.getvalue() + 1)
	self.disagree(akactor, false)
	FollowerRef.clear()
	Debug.SendAnimationEvent(PlayerRef, "IsBleedingOut")
EndFunction

Function disagree(Actor akactor, Bool Prostitution = false)
	int factionrank
	int RejectCount
	factionrank = akactor.getfactionrank(slapp_AquaintedFaction)
	RejectCount = akactor.getfactionrank(slapp_SexRejectCountFaction)
	if factionrank >= 3
		if RejectCount >= 3
			Parent.AddtoDislikeFaction(akactor, SLApproachMain.SLADislikeChance)
		else
			Parent.CountSexRejectTime(akactor)
		endif
	else
		Parent.AddtoDislikeFaction(akactor, SLApproachMain.SLADislikeChance)
	endif
	slappUtil.DetectPlayerAttire(akactor, 0, 0)
	if Prostitution
		slappUtil.DetectPlayerAttire(akactor, 0, 2)
		SLApproachProstitutionTryTimes.setvalue(SLApproachProstitutionTryTimes.getvalue() + 1)
	else
		slappUtil.DetectPlayerAttire(akactor, 0, 1)
	endif
	Self.StopScene()
EndFunction

Function RefuseVisit(Actor akSpeaker, Bool Prostitution = false)
	disagree(akSpeaker, Prostitution)
	CleartheHouse()
EndFunction

Function disagreePlus(Actor akSpeaker, Bool Prostitution = false)
int Chance = SLApproachMain.SLADislikeChance + 20
	Parent.AddtoDislikeFaction(akSpeaker, Chance)
	Parent.sexRelationshipDown(akSpeaker, PlayerRef, SLApproachMain.SLARelationshipChance)
	slappUtil.DetectPlayerAttire(akSpeaker, 0, 0)
	if Prostitution
		slappUtil.DetectPlayerAttire(akSpeaker, 0, 2)
		SLApproachProstitutionTryTimes.setvalue(SLApproachProstitutionTryTimes.getvalue() + 1)
	else
		slappUtil.DetectPlayerAttire(akSpeaker, 0, 1)
	endif
	Self.StopScene()
EndFunction

Function rapedBy(Actor akSpeaker)

;Actor ActorRaper = talkingActor.GetReference() as Actor
int Chance = SLApproachMain.SLADislikeChance
	HelperQuest.Start()
	SLApproachRapedTimes.setvalue(SLApproachRapedTimes.getvalue() + 1)
	If (SLApproachMain.enableSLHHFlag)
		Self.followSceneStop()
		slappUtil.DetectPlayerAttire(akSpeaker, 0, 6)
		Utility.wait(1.0)
		SLHHActivate(akSpeaker, None)
		if SLApproachMain.debugLogFlag
			Debug.notification(akSpeaker + "SLHH Activated")
		endif

	Else
		slappUtil.DetectPlayerAttire(akSpeaker, 0, 7)
		Parent.AddtoDislikeFaction(akSpeaker, Chance, True)
		self.StartSexMulti(PlayerRef, akSpeaker, HelpRaperRef.GetReference() as Actor, true)
		Self.StopScene()
	EndIf
EndFunction

Function rapedByLover(Actor akSpeaker)

int Chance = SLApproachMain.SLADislikeChance
	HelperQuest.Start()
	SLApproachRapedTimes.setvalue(SLApproachRapedTimes.getvalue() + 1)
	If (SLApproachMain.enableSLHHFlag)
		Self.followSceneStop()
		slappUtil.DetectPlayerAttire(akSpeaker, 0, 6)
		Utility.wait(1.0)
		SLHHActivate(akSpeaker, None)
		if SLApproachMain.debugLogFlag
			Debug.notification(akSpeaker + "SLHH Activated")
		endif

	Else
		slappUtil.DetectPlayerAttire(akSpeaker, 0, 7)
		Parent.CountRapeTime(akSpeaker)
		self.StartSexMulti(PlayerRef, akSpeaker, HelpRaperRef.GetReference() as Actor, true)
		Self.StopScene()
	EndIf
EndFunction


Function rapedPlusBy(Actor akSpeaker)
;Actor ActorRaper = talkingActor.GetReference() as Actor
int Chance = SLApproachMain.SLADislikeChance + 20
	Parent.sexRelationshipDown(akSpeaker, PlayerRef, SLApproachMain.SLARelationshipChance)
	HelperQuest.Start()
	SLApproachRapedTimes.setvalue(SLApproachRapedTimes.getvalue() + 1)
	If (SLApproachMain.enableSLHHFlag)
		Self.followSceneStop()
		slappUtil.DetectPlayerAttire(akSpeaker, 0, 6)
		Utility.wait(1.0)
		SLHHActivate(akSpeaker, None)
		if SLApproachMain.debugLogFlag
			Debug.notification(akSpeaker + "SLHH Activated")
		endif
	Else
		slappUtil.DetectPlayerAttire(akSpeaker, 0, 7)
		Parent.AddtoDislikeFaction(akSpeaker, Chance, True)
		self.StartSexMulti(PlayerRef, akSpeaker, HelpRaperRef.GetReference() as Actor, true)
		Self.StopScene()
	EndIf
EndFunction

Function SmanSex(Actor akSpeaker, Bool Rape)

int Chance
	HelperQuest.Start()
	if Rape
		Chance = SLApproachMain.SLADislikeChance
		SLApproachRapedTimes.setvalue(SLApproachRapedTimes.getvalue() + 1)
		Parent.AddtoDislikeFaction(akSpeaker, Chance, True)
		slappUtil.DetectPlayerAttire(akSpeaker, 0, 7)
	else
		slappUtil.DetectPlayerAttire(akSpeaker, 4, 0)
	endif

	;self.StartSexMulti(PlayerRef, akSpeaker, HelpRaperRef.GetReference() as Actor, true)
	SexUtil.StartSexSmall(akSpeaker, PlayerRef, rape, false, "", "")
	Self.StopScene()
EndFunction


Function Baborape(Actor akSpeaker)
;Actor ActorRaper = talkingActor.GetReference() as Actor
	HelperQuest.Start()
	SLApproachRapedTimes.setvalue(SLApproachRapedTimes.getvalue() + 1)
	If (SLApproachMain.enableSLHHFlag)
		Self.followSceneStop()
		slappUtil.DetectPlayerAttire(akSpeaker, 0, 6)
		Utility.wait(1.0)
		SLHHActivate(akSpeaker, None)
		if SLApproachMain.debugLogFlag
			Debug.notification(akSpeaker + "SLHH Activated")
		endif
	Else
		slappUtil.DetectPlayerAttire(akSpeaker, 0, 7)
		Self.StartSexHook(PlayerRef, akSpeaker, true, "BDA", "BaboDialogueAfter", 100, true)
		Utility.wait(1.0)
		Self.StopScene()
	EndIf
EndFunction

Function Baboenjoy(Actor akSpeaker)
	slappUtil.DetectPlayerAttire(akSpeaker, 4, 0)
	Self.StartSexHook(PlayerRef, akSpeaker, true, "BDA", "BaboDialogueAfter", 40, true)
	Utility.wait(1.0)
	Self.StopScene()
EndFunction

Function BaboNothingEnd(Actor akSpeaker)
	slappUtil.DetectPlayerAttire(akSpeaker, 0, 0)
	BaboDialogueSLAPPTrigger(akSpeaker, false, 10)
	Self.StopScene()
EndFunction

Globalvariable Property SLApproachGuardPunishmentTimes Auto


Function GuardSLHHChoke(Actor akSpeaker)

int Chance = SLApproachMain.SLADislikeChance
	HelperQuest.Start()

	If (SLApproachMain.enableSLHHFlag)
		Self.followSceneStop()
		Utility.wait(1.0)
		Self.SLHHChokeActivate(akSpeaker, None, 1)
		NPCtalkingActor = akSpeaker
		if SLApproachMain.debugLogFlag
			Debug.notification(akSpeaker + "GuardSLHHChoke")
		endif
	Else
		Parent.AddtoDislikeFaction(akSpeaker, Chance, True)
		Self.StopScene()
		if SLApproachMain.debugLogFlag
			Debug.notification(akSpeaker + "GuardSLHHChoke no SLHH")
		endif
	EndIf
EndFunction

Function SLHHChoke(Actor akSpeaker, int Type);0Sex 1NoSex
int Chance = SLApproachMain.SLADislikeChance
	HelperQuest.Start()
	SLApproachRapedTimes.setvalue(SLApproachRapedTimes.getvalue() + 1)
	If (SLApproachMain.enableSLHHFlag)
		slappUtil.DetectPlayerAttire(akSpeaker, 0, 6)
		Self.followSceneStop()
		Utility.wait(1.0)
		Self.SLHHChokeActivate(akSpeaker, None, Type)
	Else
		Parent.AddtoDislikeFaction(akSpeaker, Chance, True)
		slappUtil.DetectPlayerAttire(akSpeaker, 0, 7)
		self.StartSexMulti(PlayerRef, akSpeaker, HelpRaperRef.GetReference() as Actor, true)
		Self.StopScene()
	EndIf
EndFunction

Function PreDrinkEvent(Actor akSpeaker)
	if Parent.DrinkEvent(PlayerRef, willrape)
		SLAppAfterDrink.forcestart()
	else
		if akspeaker.isinfaction(slapp_DislikeFaction)
			slappUtil.DetectPlayerAttire(akSpeaker, 2, 0)
			Self.CoolDown(akSpeaker, 25)
		else
			;Self.Acquaintance(akSpeaker)
			slappUtil.DetectPlayerAttire(akSpeaker, 2, 0)
			Self.AcquaintanceCalc(akSpeaker)
			Self.StopScene()
		endif
	endif
EndFunction

Function DrinkRapedby(Actor akSpeaker, int Sex)
;Actor ActorRaper = talkingActor.GetReference() as Actor
int Chance = SLApproachMain.SLADislikeChance
	HelperQuest.Start()
	SLApproachRapedTimes.setvalue(SLApproachRapedTimes.getvalue() + 1)
	If (SLApproachMain.enableSLHHFlag)
		Self.followSceneStop()
		slappUtil.DetectPlayerAttire(akSpeaker, 0, 6)
		Utility.wait(1.0)
		SLHHDrinkActivate(akSpeaker, None, Sex)
		if SLApproachMain.debugLogFlag
			Debug.notification(akSpeaker + "SLHHDrinkActivate")
		endif

	Else
		slappUtil.DetectPlayerAttire(akSpeaker, 0, 7)
		Parent.AddtoDislikeFaction(akSpeaker, Chance, True)
		self.StartSexMulti(PlayerRef, akSpeaker, HelpRaperRef.GetReference() as Actor, true)
		Self.StopScene()
	EndIf
EndFunction

Function SLHHConsequneceBad(Actor akactor)
int Chance
int Factionrank
if SLApproachMain.enableBDFlag
	if !akactor.isinfaction(SLApproachMain.BaboViceGuardCaptainFaction)
		Chance = SLApproachMain.SLADislikeChance + 10
		Parent.AddtoDislikeFaction(akactor, Chance, false)
		Parent.AddtoRapeFailFaction(akactor, Chance, false)
	endif
else
	Factionrank = akactor.getfactionrank(slapp_AquaintedFaction)
	Chance = SLApproachMain.SLADislikeChance + 10
	if Factionrank >= 3
		Parent.CountRapeTime(akactor)
	else
		Parent.AddtoDislikeFaction(akactor, Chance, false)
	endif
	Parent.AddtoRapeFailFaction(akactor, Chance, false)
endif
	Self.StopScene()
EndFunction

Function SLHHConsequneceWorse(Actor akactor, int Type)

int Chance
int Factionrank

if SLApproachMain.enableBDFlag
	iF akactor.isinfaction(SLApproachMain.BaboViceGuardCaptainFaction)
		Self.StopScene()
		return
	endif
endif

if Type == 3
	if akactor.isinfaction(GuardDialogueFaction)
		FollowerRef.forcerefto(akactor)
		SLAppGuardPunishmentScene.forcestart()
	endif
endif

Factionrank = akactor.getfactionrank(slapp_AquaintedFaction)
Chance = SLApproachMain.SLADislikeChance + 20

if Factionrank >= 3
	Parent.AddtoDislikeFaction(akactor, Chance, True)
else
	Parent.CountRapeTime(akactor)
endif 

Self.StopScene()
EndFunction

Function PrePaid(Bool Prepaid)
if Prepaid
	SLApproachMain.SLAProstitutionpayway = 0 ;pre-paid
	ProstitutionPaid()
else
	SLApproachMain.SLAProstitutionpayway = 1 ;post-paid
endif
Endfunction

Function ProstitutionPaid()
	PlayerRef.additem(gold001, SLApproachProstitutionValue.getvalue() as int)
EndFunction

Function ProstitutionRefund()
	PlayerRef.removeitem(gold001, SLApproachProstitutionValue.getvalue() as int)
EndFunction

Function travelWith(Actor akSpeaker, Bool Prostitution = false)
	self.SetStage(15)
	Parent.ChangeStateStage(1)
	SLApproachAskForSexQuestFollowPlayerScene.Start()
if Prostitution
	SLApproachMain.SLAProstitutionFollow = True
else
	SLApproachMain.SLAProstitutionFollow = false
endif
EndFunction

Function travelWithForMulti(Actor akSpeaker); Not available
	self.SetStage(20)
	Parent.ChangeStateStage(1)
	SLApproachAskForSexQuestFollowPlayerScene.Start()
EndFunction

Function followSceneStop()

	if SLAppAfterBackHugMolest.isplaying()
		SLAppAfterBackHugMolest.Stop()
	endif
	
	if SLAppAfterKiss.isplaying()
		SLAppAfterKiss.Stop()
	endif

	if SLAppAskingNameToPCScene.isplaying()
		SLAppAskingNameToPCScene.stop()
	endif
	
	if SLAppAskingKidScene.isplaying()
		SLAppAskingKidScene.stop()
	endif

	if SLAppAskingKid02Scene.isplaying()
		SLAppAskingKid02Scene.stop()
	endif
	
	if SLAppAskingMiscScene.isplaying()
		SLAppAskingMiscScene.stop()
	endif

	if SLApproachSpankingScene.isplaying()
		SLApproachSpankingScene.stop()
	endif
	
	if (SLApproachHouseStayScene.isplaying())
		SLApproachHouseStayScene.stop()
	endif
	
	if (SLApproachAskForSexQuestScene.isplaying())
		SLApproachAskForSexQuestScene.Stop()
	endif

	if (SLAppViceGuardCaptainScene.isplaying())
		SLAppViceGuardCaptainScene.Stop()
	endif

	if (SLAppViceGuardCaptainSpankScene.isplaying())
		SLAppViceGuardCaptainSpankScene.Stop()
	endif

	if (SLApproachAskForSexQuestFollowPlayerScene.isPlaying())
		SLApproachAskForSexQuestFollowPlayerScene.Stop()
	endif
EndFunction

Function playKiss(Actor akRef)
	SexUtil.PlayKiss(akRef, PlayerRef)
EndFunction

Function playHug(Actor akRef)
	SexUtil.PlayHug(akRef, PlayerRef, SLApproachMain.enableForceThirdPersonHug)
EndFunction


;-------------------------SLHH Mod -----------------------

Function ExternalTrigger(Form akRef, Bool Worse, int Type)
if SLApproachMain.debugLogFlag
	Debug.notification("ExternalTrigger")
endif
	If Worse
		SLHHConsequneceWorse(akRef as actor, Type)
	Else
		SLHHConsequnecebad(akRef as actor)
	Endif

EndFunction

;-----------------Register HouseLocation-----------------
;variable 06 1~4
;1 - Normal Chat
;2 - eroticclothes
;3 - Drink
;4 - Asking Sex

;5 - Inviting Friends
;6 - Bandit Assualt
;7 - Begging Money;BaboDialogue
;8 - Underwear Thief



Bool Function iGetFormIndex()
	Location CurrentLocation = PlayerRef.GetCurrentLocation()
	Formlist CurrentFormlist
	VisitorRef = None

	if CurrentLocation && CurrentLocation.haskeyword(LocTypePlayerHouse)
		if CurrentLocation == WhiterunBreezehomelocation
			CurrentFormlist = SLApproachPlayerHouseWhiterun
			SLApproachCurrentPlayerHouse.setvalue(1)
		elseif CurrentLocation == BYOHHouse1LocationInterior
			CurrentFormlist = SLApproachPlayerHouseBYOH01
			SLApproachCurrentPlayerHouse.setvalue(2)
		elseif CurrentLocation == BYOHHouse2LocationInterior
			CurrentFormlist = SLApproachPlayerHouseBYOH02
			SLApproachCurrentPlayerHouse.setvalue(3)
		elseif CurrentLocation == BYOHHouse3LocationInterior
			CurrentFormlist = SLApproachPlayerHouseBYOH03
			SLApproachCurrentPlayerHouse.setvalue(4)
		elseif CurrentLocation == SolitudeProudspireManorLocation
			CurrentFormlist = SLApproachPlayerHouseSolitude
			SLApproachCurrentPlayerHouse.setvalue(5)
		elseif CurrentLocation == MarkarthVlindrelHallLocation
			CurrentFormlist = SLApproachPlayerHouseMarkarth
			SLApproachCurrentPlayerHouse.setvalue(6)
		elseif CurrentLocation == RiftenHoneysideLocation
			CurrentFormlist = SLApproachPlayerHouseRiften
			SLApproachCurrentPlayerHouse.setvalue(7)
		elseif CurrentLocation == WindhelmHjerimLocation
			CurrentFormlist = SLApproachPlayerHouseWindhelm
			SLApproachCurrentPlayerHouse.setvalue(8)
		elseif CurrentLocation.HasRefType(SLAppCustomHouseLocKeyword)
			SLApproachCurrentPlayerHouse.setvalue(20)
		else
			SLApproachCurrentPlayerHouse.setvalue(0)
			return false
		endif

		if SLApproachMain.debugLogFlag
			Debug.notification("PlayerHouse " + SLApproachCurrentPlayerHouse.getvalue() as int)
		endif

		int iindex = CurrentFormlist.getsize()
		If iindex > 0
			iindex -= 1
			VisitorRef = CurrentFormlist.getat(Utility.randomint(1, iindex)) as actor

			if VisitorRef && SLApproachMain.debugLogFlag
				String VisitorStringRef = VisitorRef.GetBaseObject().getname() as string
				Debug.notification("Visitor's name is " + VisitorStringRef + "in " + iindex)
			elseif SLApproachMain.debugLogFlag
				Debug.notification("Visitor is not present")
			endif
		else
			if SLApproachMain.debugLogFlag
				Debug.notification("No Index")
			endif
		EndIf

		If VisitorRef == None
			if SLApproachMain.debugLogFlag
				Debug.notification("There's silence in my home.")
			endif
		endif
	Else
		if SLApproachMain.debugLogFlag
			Debug.notification("No Player House")
		endif
	Endif

	Return VisitorRef as Bool
EndFunction

Bool Function KnockKnock()
	If Utility.RandomInt(1, 100) > SLApproachPC.SLAHouseVisitChance
		Return False
	EndIf

	If !SLApproachScanningPlayerHouse.isrunning()
		Return False
	EndIf

	PCApproachOngoing = True

PlayerHouseCenterMarker.ForceRefto(ExternalPlayerHouseCenterMarker.getreference())
PlayerHouseDoor.ForceRefto(ExternalPlayerHouseDoor.getreference())
PlayerHouseCOC.ForceRefto(ExternalPlayerHouseCOC.getreference())
FollowerRef.ForceRefto(ExternalFollowerRef.getreference())

talkingActor.ForceRefTo(VisitorRef)

rollRapeChance(VisitorRef)
SLApproachRapeToggle.setvalue(willRape as int)
PCVisitingBefore = true
PCVisitingAfter = false
VisitorKnocking(VisitorRef)

Return True
EndFunction

Function VisitorKnocking(actor visitor)

Alias_VisitorRef.Clear()
Alias_VisitorRef.ForceRefTo(visitor)

SLApproachScanningPlayerHouse.setstage(10)
Self.setstage(50)

;Moving a visitor in front of a door
;Dialogues are required
SLAPPTemporaryVisitorBackMarker.moveto(visitor)
if SLApproachCurrentPlayerHouse.getvalue() == 1
	visitor.moveto(SLApproachMain.SLAPPXmarkerFrontDoorWhiterunRef)
elseif SLApproachCurrentPlayerHouse.getvalue() == 2
	visitor.moveto(SLApproachMain.SLAPPXmarkerFrontDoorBYOH01Ref)
elseif SLApproachCurrentPlayerHouse.getvalue() == 3
	visitor.moveto(SLApproachMain.SLAPPXmarkerFrontDoorBYOH02Ref)
elseif SLApproachCurrentPlayerHouse.getvalue() == 4
	visitor.moveto(SLApproachMain.SLAPPXmarkerFrontDoorBYOH03Ref)
elseif SLApproachCurrentPlayerHouse.getvalue() == 5
	visitor.moveto(SLApproachMain.SLAPPXmarkerFrontDoorSolitudeRef)
elseif SLApproachCurrentPlayerHouse.getvalue() == 6
	visitor.moveto(SLApproachMain.SLAPPXmarkerFrontDoorMarkarthRef)
elseif SLApproachCurrentPlayerHouse.getvalue() == 7
	visitor.moveto(SLApproachMain.SLAPPXmarkerFrontDoorRiftenRef)
elseif SLApproachCurrentPlayerHouse.getvalue() == 8
	visitor.moveto(SLApproachMain.SLAPPXmarkerFrontDoorWindhelmRef)
elseif SLApproachCurrentPlayerHouse.getvalue() == 20
	visitor.moveto(SLAPPTemporaryVisitorMarker)
else
;Nothing
endif

	PCVisitingBefore = false
	PCVisitingon = true
	PCVisitingafter = false

EndFunction

Function VisitorEntering(actor visitor, objectreference entrance)
	PCVisitingBefore = false
	PCVisitingon = false
	PCVisitingafter = true
	slappUtil.HomeAlone();Detect actors around Player
	SetCharacter(visitor);Double check
	
	visitor.moveto(entrance)
	selectedScene = SLAppHousevisitScene
	selectedScene.forcestart()
	maxTime = (SLApproachMain.SLApproachTimelimit) + 30
	parent.startApproach(visitor)
EndFunction

Function registerHouse(Location akLocation)
actor akactor = talkingActor.GetReference() as Actor
If aklocation == WhiterunBreezehomeLocation
	SLApproachPlayerHouseWhiterun.addform(akactor)
elseif aklocation == BYOHHouse1LocationInterior
	SLApproachPlayerHouseBYOH01.addform(akactor)
elseif aklocation == BYOHHouse2LocationInterior
	SLApproachPlayerHouseBYOH02.addform(akactor)
elseif aklocation == BYOHHouse3LocationInterior
	SLApproachPlayerHouseBYOH03.addform(akactor)
elseif aklocation == SolitudeProudspireManorLocation
	SLApproachPlayerHouseSolitude.addform(akactor)
elseif aklocation == MarkarthVlindrelHallLocation
	SLApproachPlayerHouseMarkarth.addform(akactor)
elseif aklocation == RiftenHoneysideLocation
	SLApproachPlayerHouseRiften.addform(akactor)
elseif aklocation == WindhelmHjerimLocation
	SLApproachPlayerHouseWindhelm.addform(akactor)
EndIf
NothingEnd(akactor)
EndFunction

Function RegisterCustomHouse(int HouseNumber)
actor akactor = talkingActor.GetReference() as Actor
if HouseNumber == 1
	SLApproachPlayerHouseCustom01.addform(akactor)
elseif HouseNumber == 2
	SLApproachPlayerHouseCustom02.addform(akactor)
elseif HouseNumber == 3
	SLApproachPlayerHouseCustom03.addform(akactor)
elseif HouseNumber == 4
	SLApproachPlayerHouseCustom04.addform(akactor)
elseif HouseNumber == 5
	SLApproachPlayerHouseCustom05.addform(akactor)
elseif HouseNumber == 6
	SLApproachPlayerHouseCustom06.addform(akactor)
elseif HouseNumber == 7
	SLApproachPlayerHouseCustom07.addform(akactor)
elseif HouseNumber == 8
	SLApproachPlayerHouseCustom08.addform(akactor)
elseif HouseNumber == 9
	SLApproachPlayerHouseCustom09.addform(akactor)
elseif HouseNumber == 10
	SLApproachPlayerHouseCustom10.addform(akactor)
endif
NothingEnd(akactor)
EndFunction

Function UnregisterHouse(Actor akspeaker, int type)
	SLApproachPlayerHouseWhiterun.RemoveAddedForm(akspeaker)
	SLApproachPlayerHouseBYOH01.RemoveAddedForm(akspeaker)
	SLApproachPlayerHouseBYOH02.RemoveAddedForm(akspeaker)
	SLApproachPlayerHouseBYOH03.RemoveAddedForm(akspeaker)
	SLApproachPlayerHouseSolitude.RemoveAddedForm(akspeaker)
	SLApproachPlayerHouseMarkarth.RemoveAddedForm(akspeaker)
	SLApproachPlayerHouseRiften.RemoveAddedForm(akspeaker)
	SLApproachPlayerHouseWindhelm.RemoveAddedForm(akspeaker)
	if type == 1; No complain
		akspeaker.addtofaction(slapp_NoVisitFaction)
	elseif type == 2; complain
		akspeaker.addtofaction(slapp_NoVisitFaction)
		disagree(akspeaker, false)
	elseif type == 3; Rape
		akspeaker.addtofaction(slapp_NoVisitFaction)
		disagree(akspeaker, false)
		rapedPlusBy(akspeaker)
	endif
EndFunction

Function registerHouseTest(Location akLocation, Actor akactor)
If aklocation == WhiterunBreezehomeLocation
	SLApproachPlayerHouseWhiterun.addform(akactor)
elseif aklocation == BYOHHouse1LocationInterior
	SLApproachPlayerHouseBYOH01.addform(akactor)
elseif aklocation == BYOHHouse2LocationInterior
	SLApproachPlayerHouseBYOH02.addform(akactor)
elseif aklocation == BYOHHouse3LocationInterior
	SLApproachPlayerHouseBYOH03.addform(akactor)
elseif aklocation == SolitudeProudspireManorLocation
	SLApproachPlayerHouseSolitude.addform(akactor)
elseif aklocation == MarkarthVlindrelHallLocation
	SLApproachPlayerHouseMarkarth.addform(akactor)
elseif aklocation == RiftenHoneysideLocation
	SLApproachPlayerHouseRiften.addform(akactor)
elseif aklocation == WindhelmHjerimLocation
	SLApproachPlayerHouseWindhelm.addform(akactor)
EndIf
EndFunction

Function PreVisitorEntering()
;debug.notification("The visitor is entering.")
	ObjectReference PHCOC = PlayerHouseCOC.getreference()
	SLApproachScanningPlayerHouse.setstage(50)
	Self.setstage(60)
	if PHCOC
		VisitorEntering(VisitorRef, PHCOC)
	Else
		VisitorEntering(VisitorRef, PlayerRef)
	Endif
	SLAKnockCount.setvalue(0)

EndFunction

Function FirstVisit(Bool Rape)
	Actor akRef = talkingActor.GetReference() as Actor
	talkingactor.clear()
	stayingactor.forcerefto(akRef)
	SLAppHousevisitScene.stop()
	self.StayingTimeRegister(Rape)
EndFunction

Function StayingTimeRegister(Bool Rape)
	SLApproachScanningPlayerHouse.setstage(70); This indicates a visitor is gonna stay.
	SLApproachVisitorStaying.setvalue(1)
	(stayingactor.GetReference() as Actor).addtofaction(slapp_VisitingFaction)
	(stayingactor.GetReference() as Actor).Setactorvalue("Variable06", 0)
	if rape
		(stayingactor.GetReference() as Actor).addtofaction(slapp_VisitingRapistFaction)
	endif
	RegisterForSingleUpdateGameTime(SLApproachStayingTime.getvalue() as int)
EndFunction

Event OnUpdateGameTime()
;End of a visiting scenario.
if (stayingactor.GetReference() as Actor).isinfaction(slapp_VisitingEventFaction)
	(stayingactor.GetReference() as Actor).removefromfaction(slapp_VisitingEventFaction);Not used for now. It's gonna be used as Byebye contents
	;int randomi = Utility.randomint(5, 8); for future contents
	;(stayingactor.GetReference() as Actor).Setactorvalue("Variable06", randomi)
	RegisterForSingleUpdateGameTime(SLApproachStayingTime.getvalue() as int)
else
	CleartheHouse()
endif
EndEvent

Function CleartheHouse()
	SLApproachVisitorStaying.setvalue(0)
	(stayingactor.GetReference() as Actor).removefromfaction(slapp_VisitingFaction)
	(stayingactor.GetReference() as Actor).Setactorvalue("Variable06", 0)
	if (stayingactor.GetReference() as Actor).isinfaction(slapp_VisitingRapistFaction)
		(stayingactor.GetReference() as Actor).addtofaction(slapp_VisitedRapistFaction)
		(stayingactor.GetReference() as Actor).removefromfaction(slapp_VisitingRapistFaction)
	endif
	SLApproachScanningVisitor.stop()
	SLApproachScanningPlayerHouse.stop()
	Stayed()
EndFunction

Function HeSpanked(actor akactor)
	if SLApproachMain.debugLogFlag
		Debug.notification("HeSpanked")
	endif
Self.NothingEnd(akactor)
Game.EnablePlayerControls()
EndFunction

Function SpankDialogueStop(actor akactor)
	akactor.removespell(SLApproachSpankAura)
	akactor.removespell(SLApproachMolestAura)
EndFunction

Function SpankTimeOut(actor akactor)
	if SLApproachMain.debugLogFlag
		Debug.notification("SpankTimeOut")
	endif
	
	If SLApproachMain.enableBDFlag
		if (akactor.isinfaction(SLApproachMain.BaboViceGuardCaptainFaction))
				BaboDialogueSLAPPTrigger(akactor, false, 20)
			return
		endif
	endif
	
	if !akactor.IsInDialogueWithPlayer()
		SLApproachSpankAura2nd.cast(PlayerRef, akactor)
		Game.EnablePlayerControls()
	endif
EndFunction

Function SpankTimeOut2nd(actor akactor)
	if SLApproachMain.debugLogFlag
		Debug.notification("SpankTimeOut2nd")
	endif
	
	if !akactor.isinfaction(slapp_SpankFaction)
		akactor.addtofaction(slapp_SpankFaction)
	else
		akactor.setfactionrank(slapp_SpankFaction, 1 + akactor.getfactionrank(slapp_SpankFaction))
	endif
EndFunction

Function MolestTimeOut(actor akactor)
	if SLApproachMain.debugLogFlag
		Debug.notification("MolestTimeOut")
	endif
	
	if !akactor.isinfaction(slapp_MolestFaction)
		akactor.addtofaction(slapp_MolestFaction)
	else
		akactor.setfactionrank(slapp_MolestFaction, 1 + akactor.getfactionrank(slapp_MolestFaction))
	endif

	Self.NothingEnd(akactor)
EndFunction

;##########################
;########ResistBar#########
;##########################

SLAPQTEWidgetEx Property StruggleBar Auto
Quest Property SLApproach_Config Auto

Bool LeftRight = True
Int StrafeL
Int StrafeR
Float FillDifficulty = 0.0
Float FillThreshold = 0.0
Int ResistTime = 0
int Time = 0
Float DownedTime ; How much time the player will stay downed.
GlobalVariable property SLApproachHarassmentType Auto
GlobalVariable property SLApproachKissResist Auto
GlobalVariable property SLApproachFlirtType Auto
Scene Property SLAppAfterKiss Auto
Scene Property SLAppAfterBackHugMolest Auto
Scene Property SLApproachTeasingHouseScene Auto

Function HugKissEnd(Actor akactor)
	Parent.FlirtAnim(akactor, False, 5)
	Utility.wait(12.0)
	Parent.RestoreControl(akactor)
	Self.Acquaintance(akactor)
EndFunction

Function StartFlirt(Actor akactor, int FlirtType, bool HouseVisit)
	SLApproachFlirtType.setvalue(FlirtType)
	Parent.FlirtAnim(akactor, True, FlirtType)
	if HouseVisit
		SLApproachTeasingHouseScene.forcestart()
	endif
EndFunction

Function StartHarassment(actor akactor, int HarassmentType)
	SLApproachHarassmentType.setvalue(HarassmentType)
	NPCActor = akactor
	GotoState("Harassment")
EndFunction

Function StartSweetKiss(actor akactor, int KissType)
	SLApproachSweetKissType.setvalue(KissType)
	NPCActor = akactor
	Self.CoolDown(akactor, 50)
	GotoState("SweetKiss")
EndFunction

Function SpankTest(actor akactor, int Scenarioe = 0)
	SLA_SpankingScenarioGlobal.setvalue(0)
	ForceAllocation(akactor)
	SpankSceneStart(akactor, Scenarioe)
Endfunction

Function SpankSceneStart(actor akactor, int Scenarioe = 0)
int CharacterRank = akactor.getfactionrank(slapp_Characterfaction)
int RandomChance = Utility.randomint(0, 90)
int iProbability = 10

if Scenarioe == 1
	NPCActor = akactor
	GotoState("BackHug")
elseif Scenarioe == 2
	NPCActor = akactor
	GotoState("BackHugMolest")
elseif Scenarioe == 3
	slappUtil.DetectPlayerAttire(akactor, 0, 3)
	SLApproachMolestTimes.setvalue(SLApproachMolestTimes.getvalue() + 1)
	SLApproachSpankTimes.setvalue(SLApproachSpankTimes.getvalue() + 1)
	Parent.AcyclePairedMotion(akactor, 0, -54, -27, 1)
else
	if CharacterRank > 0
		iProbability = CharacterRank * 30
	endif

	if iProbability >= RandomChance && !akactor.isinfaction(slapp_NoSpankFaction)
		slappUtil.DetectPlayerAttire(akactor, 0, 3)
		SLApproachMolestTimes.setvalue(SLApproachMolestTimes.getvalue() + 1)
		SLApproachSpankTimes.setvalue(SLApproachSpankTimes.getvalue() + 1)
		Parent.AcyclePairedMotion(akactor, 0, -54, -27, 1)
	else
		NPCActor = akactor
		if akactor.isinfaction(slapp_DislikeFaction) || !akactor.isinfaction(slapp_NoMolestFaction)
			GotoState("BackHugMolest")
		else
			GotoState("BackHug")
		endif
	endif
endif

SLApproachSpankingScene.stop()

EndFunction

State Harassment

	Event OnBeginState()
		slappUtil.DetectPlayerAttire(NPCActor, 0, 4)
		slappUtil.UnequipShieldSimple(NPCActor)
		SLApproachForcedKissTimes.setvalue(SLApproachForcedKissTimes.getvalue() + 1)
		SLApproachMolestTimes.setvalue(SLApproachMolestTimes.getvalue() + 1)
		SLApproachHarassmentType.setvalue(1);2 is not ready. It will be removed once 2 is ready.
		Parent.KissAnim(NPCActor, 1)
		utility.wait(1.5)
		DownedTime = 15.0 + SLApproachMain.SLAPStrafeDifficulty
		FillThreshold = 0.1
		StruggleBarDisplay(true)
		RegisterForSingleUpdate(1.0)
	EndEvent
	
	Event OnUpdate() ; Loop to check the situation every 1 second.
		Time += 1
		;Actor akRef = talkingActor.GetReference() as Actor
		If StruggleBar.Percent >= 1.0
			KissResistSuccess(NPCActor)
			Return
		Elseif Time > DownedTime
			KissResistFailed(NPCActor)
			Return
		Endif
		if Time == 7.0
			Parent.PlayKissSound()
		endif
	StruggleBar.Alpha = 100.0
	RegisterForSingleUpdate(1.0)
	EndEvent
	
EndState

State SweetKiss

	Event OnBeginState()
		slappUtil.DetectPlayerAttire(NPCActor, 3, 0)
		slappUtil.UnequipShieldSimple(NPCActor)
		SLApproachSweetKissTimes.setvalue(SLApproachSweetKissTimes.getvalue() + 1)
		if SLApproachSweetKissType.getvalue() == 1
			Parent.KissAnim(NPCActor, 3)
		elseif SLApproachSweetKissType.getvalue() == 2
			Parent.KissAnim(NPCActor, 4)
		endif
		utility.wait(3.0)
		DownedTime = 15.0 + SLApproachMain.SLAPStrafeDifficulty
		FillThreshold = 0.1
		StruggleBarDisplay(true)
		RegisterForSingleUpdate(1.0)
	EndEvent
	
	Event OnUpdate() ; Loop to check the situation every 1 second.
		Time += 1
		int slaexposure = (sla_Framework as slaFrameworkScr).GetActorExposure(NPCActor)
		(sla_Framework as slaFrameworkScr).SetActorExposure(NPCActor, slaexposure - 1)
		If StruggleBar.Percent >= 1.0
			SimpleMotionStop(NPCActor)
			Return
		Endif
		if Time == 7.0
			Parent.PlayKissSound()
			Time = 0
		endif
	StruggleBar.Alpha = 100.0
	RegisterForSingleUpdate(1.0)
	EndEvent

EndState

State BackHug

	Event OnBeginState()
		slappUtil.DetectPlayerAttire(NPCActor, 0, 5)
		slappUtil.UnequipShieldSimple(NPCActor)
		SLApproachMolestTimes.setvalue(SLApproachMolestTimes.getvalue() + 1)
		SLApproachBackHugTimes.setvalue(SLApproachBackHugTimes.getvalue() + 1)
		Parent.AcyclePairedMotion(NPCActor, 0, 0, -50, 2)
		utility.wait(3.0)
		DownedTime = 15.0 + SLApproachMain.SLAPStrafeDifficulty
		FillThreshold = 0.1
		StruggleBarDisplay(true)
		RegisterForSingleUpdate(1.0)
	EndEvent
	
	Event OnUpdate() ; Loop to check the situation every 1 second.
		Time += 1
		int slaexposure = (sla_Framework as slaFrameworkScr).GetActorExposure(NPCActor)
		(sla_Framework as slaFrameworkScr).SetActorExposure(NPCActor, slaexposure - 1)
		If StruggleBar.Percent >= 1.0
			SimpleMotionStop(NPCActor)
			Return
		Endif
		;if Time == 7.0
			;Parent.PlayKissSound();panting Sound will be added in future updates
		;	Time = 0
		;endif
	StruggleBar.Alpha = 100.0
	RegisterForSingleUpdate(1.0)
	EndEvent

EndState

State BackHugMolest

	Event OnBeginState()
		slappUtil.DetectPlayerAttire(NPCActor, 0, 5)
		slappUtil.UnequipShieldSimple(NPCActor)
		SLApproachMolestTimes.setvalue(SLApproachMolestTimes.getvalue() + 1)
		SLApproachBackHugMolestTimes.setvalue(SLApproachBackHugMolestTimes.getvalue() + 1)
		Parent.AcyclePairedMotion(NPCActor, 0, 0, -50, 3)
		utility.wait(3.0)
		SLAppBackHugMolest.forcestart()
		DownedTime = 20.0 + SLApproachMain.SLAPStrafeDifficulty
		FillThreshold = 0.1
		StruggleBarDisplay(true)
		RegisterForSingleUpdate(1.0)
	EndEvent
	
	Event OnUpdate() ; Loop to check the situation every 1 second.
		Time += 1
		;Actor akRef = talkingActor.GetReference() as Actor
		int slaexposure = (sla_Framework as slaFrameworkScr).GetActorExposure(NPCActor)
		(sla_Framework as slaFrameworkScr).SetActorExposure(NPCActor, slaexposure + 1)
		
		If StruggleBar.Percent >= 1.0
			BackHugResistSuccess(NPCActor)
			PrecisionCheck(NPCActor, false)
			Return
		Elseif Time > DownedTime
			BackHugResistFailed(NPCActor)
			PrecisionCheck(NPCActor, false)
			Return
		Endif

		;if Time == 7.0
			;Parent.PlayKissSound();panting Sound will be added in future updates
		;endif
	StruggleBar.Alpha = 100.0
	RegisterForSingleUpdate(1.0)
	EndEvent

EndState

Function SimpleMotionStop(actor akactor)
	Restore()
	Parent.PrecisionCheck(NPCActor, false)
	Parent.RestoreControl(akactor)
EndFunction

Function KissResistSuccess(actor akactor)
	Restore()
	Parent.PrecisionCheck(NPCActor, false)
	Parent.KissAnimResist(akactor)
	SLApproachKissResist.setvalue(1)
	SLAppAfterKiss.forcestart()
EndFunction

Function KissResistFailed(actor akactor)
	Restore()
	Parent.PrecisionCheck(NPCActor, false)
	Parent.KissAnimStop(akactor)
	SLApproachKissResist.setvalue(2)
	SLAppAfterKiss.forcestart()
EndFunction

Function BackHugResistSuccess(actor akactor)
	SLAppBackHugMolest.stop()
	Self.Restore()
	Parent.PrecisionCheck(NPCActor, false)
	Parent.RestoreControl(akactor)
	SLApproachMolestAura.cast(PlayerRef, akactor)
	If SLApproachMain.enableBDFlag
		if (akactor.isinfaction(SLApproachMain.BaboViceGuardCaptainFaction))
			BaboDialogueSLAPPTrigger(akactor, false, 60)
		endif
	endif
	;Parent.ResistFailed(akactor);End motion not ready yet
EndFunction


Function BackHugResistFailed(actor akactor)
	SLAppBackHugMolest.stop()
	Self.Restore()
	Parent.PrecisionCheck(NPCActor, false)
	;Parent.RestoreControl(akactor)
	SLApproachMain.ResetHeelEffect(PlayerRef)
	;You allowed the rape
	SLApproachRapedTimes.setvalue(SLApproachRapedTimes.getvalue() + 1)
	
	If SLApproachMain.enableBDFlag
		if (akactor.isinfaction(SLApproachMain.BaboViceGuardCaptainFaction))
			Self.StartSexHook(PlayerRef, akactor, true, "BDA", "BaboDialogueAfter", 80, true)
			return
		endif
	endif

	If (SLApproachMain.enableSLHHFlag)
		SLHHActivate(akactor, None)
		if SLApproachMain.debugLogFlag
			Debug.notification(akactor + "SLHH Activated")
		endif
	Else
		self.StartSexMulti(PlayerRef, akactor, HelpRaperRef.GetReference() as Actor, true)
	EndIf
	;Parent.ResistFailed(akactor);End motion not ready yet
EndFunction


Event OnKeyDown(Int KeyCode)
	If ((KeyCode == StrafeL) && LeftRight)
		LeftRight = False
		FillDifficulty += FillThreshold
		StruggleBar.Percent = (FillDifficulty)
	Elseif ((KeyCode == StrafeR) && !LeftRight)
		LeftRight = True
		FillDifficulty += FillThreshold
		StruggleBar.Percent = (FillDifficulty)
	Endif
EndEvent


Function StruggleBarDisplay(Bool Display = True)
If Display == true
	StruggleBar.Alpha = 100.0
	If ((SLApproach_Config as SLApproachConfigScript).ResistType == "$Attack")
		StrafeL = Input.GetMappedKey("Left Attack/Block")
		StrafeR = Input.GetMappedKey("Right Attack/Block")
	Else
		StrafeL = Input.GetMappedKey("Strafe Left")
		StrafeR = Input.GetMappedKey("Strafe Right")
	Endif
	RegisterForKey(StrafeL)
	RegisterForKey(StrafeR)
Else
	StruggleBar.Alpha = 0.0
	StruggleBar.Percent = 0.0
	FillDifficulty = 0.0
	UnregisterForKey(StrafeL)
	UnregisterForKey(StrafeR)
EndIf

EndFunction

Event Onupdate()
	Time = 0
	StruggleBarDisplay(False)
EndEvent

Function Restore()
	Time = 0
	StruggleBarDisplay(False)
	GotoState("")
	RegisterForSingleUpdate(10.0);Just in case
EndFunction

Function ForceAllocation(actor akactor)
	talkingActor.clear()
	talkingActor.ForceRefTo(akactor)
EndFunction

GlobalVariable Property SLA_DDEquipType Auto

Function EquipDD()
	(SLApproach_ExternalMods as SLApproachExternalScript).DeviousEquip(talkingActor.getreference() as actor, SLA_DDEquipType.value as int)
EndFunction
;####################################################
;################ JSON Import #######################
;####################################################

Function ImportPlayerStatus()

if SLA_BaboDialogue.getvalue() == 1

	String File = "../BaboDialogue/BaboDialoguePlayerStatus.json"
	String FileB = "../BaboDialogue/BaboDialogueConfig.json"
	
	WhiterunOrcFuckToyTitleRank = JsonUtil.GetintValue(File, "WhiterunOrcFuckToyTitleRank")
	RieklingThirskFuckToyTitleRank = JsonUtil.GetintValue(File, "RieklingThirskFuckToyTitleRank")
	NightgateInnVictoryTitleRank = JsonUtil.GetintValue(File, "NightgateInnVictoryTitleRank")
	NightgateInnFuckedTitleRank = JsonUtil.GetintValue(File, "NightgateInnFuckedTitleRank")
	InvestigationMarkarthTitleRank = JsonUtil.GetintValue(File, "InvestigationMarkarthTitleRank")
	DeviousNobleSonFuckToyTitleRank = JsonUtil.GetintValue(File, "DeviousNobleSonFuckToyTitleRank")
	ChallengerFucktoyTitleRank = JsonUtil.GetintValue(File, "ChallengerFucktoyTitleRank")
	ArgonianDisplayedFuckToyTitleRank = JsonUtil.GetintValue(File, "ArgonianDisplayedFuckToyTitleRank")
	ArgonianDefeatedTitleRank = JsonUtil.GetintValue(File, "ArgonianDefeatedTitleRank")
	LoanSharkSlaveTitleRank = JsonUtil.GetintValue(File, "LoanSharkSlaveTitleRank")
	PitifulHeroineTitleRank = JsonUtil.GetintValue(File, "PitifulHeroineTitleRank")
	
	BaboReputationint = JsonUtil.GetintValue(File, "BaboReputation")
	BaboPubicHairStyle = JsonUtil.GetintValue(FileB, "BaboPubicHairCheck")

	SLA_WhiterunOrcFuckToyTitleRank.setvalue(WhiterunOrcFuckToyTitleRank)
	SLA_RieklingThirskFuckToyTitleRank.setvalue(RieklingThirskFuckToyTitleRank)
	SLA_NightgateInnVictoryTitleRank.setvalue(NightgateInnVictoryTitleRank)
	SLA_NightgateInnFuckedTitleRank.setvalue(NightgateInnFuckedTitleRank)
	SLA_InvestigationMarkarthTitleRank.setvalue(InvestigationMarkarthTitleRank)
	SLA_DeviousNobleSonFuckToyTitleRank.setvalue(DeviousNobleSonFuckToyTitleRank)
	SLA_ChallengerFucktoyTitleRank.setvalue(ChallengerFucktoyTitleRank)
	SLA_ArgonianDisplayedFuckToyTitleRank.setvalue(ArgonianDisplayedFuckToyTitleRank)
	SLA_ArgonianDefeatedTitleRank.setvalue(ArgonianDefeatedTitleRank)
	SLA_LoanSharkSlaveTitleRank.setvalue(LoanSharkSlaveTitleRank)
	SLA_PitifulHeroineTitleRank.setvalue(PitifulHeroineTitleRank)

	SLA_BaboReputation.setvalue(BaboReputationint)
	SLA_BaboPubicHairStyle.setvalue(BaboPubicHairStyle)
endif
EndFunction


int WhiterunOrcFuckToyTitleRank
int RieklingThirskFuckToyTitleRank
int NightgateInnVictoryTitleRank
int NightgateInnFuckedTitleRank
int InvestigationMarkarthTitleRank
int DeviousNobleSonFuckToyTitleRank
int ChallengerFucktoyTitleRank
int ArgonianDisplayedFuckToyTitleRank
int ArgonianDefeatedTitleRank
int LoanSharkSlaveTitleRank
int PitifulHeroineTitleRank

int BaboPubicHairStyle
int BaboReputationint


GlobalVariable Property SLA_WhiterunOrcFuckToyTitleRank Auto
GlobalVariable Property SLA_RieklingThirskFuckToyTitleRank Auto
GlobalVariable Property SLA_NightgateInnVictoryTitleRank Auto
GlobalVariable Property SLA_NightgateInnFuckedTitleRank Auto
GlobalVariable Property SLA_InvestigationMarkarthTitleRank Auto
GlobalVariable Property SLA_DeviousNobleSonFuckToyTitleRank Auto
GlobalVariable Property SLA_ChallengerFucktoyTitleRank Auto
GlobalVariable Property SLA_ArgonianDisplayedFuckToyTitleRank Auto
GlobalVariable Property SLA_ArgonianDefeatedTitleRank Auto
GlobalVariable Property SLA_LoanSharkSlaveTitleRank Auto
GlobalVariable Property SLA_PitifulHeroineTitleRank Auto

GlobalVariable Property SLA_BaboPubicHairStyle Auto


;----------------------------Properties----------------------------

Actor NPCtalkingActor
Actor VisitorRef
Scene selectedScene
bool property willRape Auto Hidden Conditional
bool property SLHHwillRape Auto Hidden Conditional
bool property PCApproachOngoing Auto Hidden Conditional
bool property PCVisitingBefore Auto Hidden Conditional
bool property PCVisitingOn Auto Hidden Conditional
bool property PCVisitingAfter Auto Hidden Conditional
bool Property HasDoorKey Auto Hidden conditional
bool Property DoorKeyexist Auto Hidden conditional
float Property ProstitutionAcceptChance = 0.0 Auto Hidden Conditional

Actor NPCActor

keyword property ClothingPoor Auto
keyword property ClothingRich Auto

Miscobject property gold001 Auto
WorldSpace AkWorld
WorldSpace Property Whiterunworld Auto
WorldSpace Property Solitudeworld Auto
Float Property fPlayerSpeechCraft Auto
GlobalVariable Property SlappSpeechAV Auto

SLApproachMainScript Property SLApproachPC auto
Quest property SLApproachScanningPlayerHouse auto
Quest property SLApproachScanningVisitor auto
Quest Property SLApproachAskForSexQuest auto

SLAppSexUtil Property SexUtil Auto

Formlist Property SLApproachDDIList Auto
Formlist Property SLApproachDDIYokeList Auto

Formlist Property SLApproachPlayerHouseCustom01 Auto
Formlist Property SLApproachPlayerHouseCustom02 Auto
Formlist Property SLApproachPlayerHouseCustom03 Auto
Formlist Property SLApproachPlayerHouseCustom04 Auto
Formlist Property SLApproachPlayerHouseCustom05 Auto
Formlist Property SLApproachPlayerHouseCustom06 Auto
Formlist Property SLApproachPlayerHouseCustom07 Auto
Formlist Property SLApproachPlayerHouseCustom08 Auto
Formlist Property SLApproachPlayerHouseCustom09 Auto
Formlist Property SLApproachPlayerHouseCustom10 Auto

GlobalVariable Property SLA_DDI Auto
GlobalVariable Property sla_slsurvival Auto

GlobalVariable Property SLAKnockCount Auto
GlobalVariable Property SLApproachRapeToggle Auto

GlobalVariable Property SLApproachStayingTime Auto
GlobalVariable Property SLApproachRapedTimes Auto
GlobalVariable Property SLApproachAskNameTimes Auto
GlobalVariable Property SLApproachAskSexTimes Auto
GlobalVariable Property SLApproachNormalSexTimes Auto
GlobalVariable Property SLApproachProstitutionTimes Auto
GlobalVariable Property SLApproachProstitutionTryTimes Auto
GlobalVariable Property SLApproachGiftTimes Auto

GlobalVariable Property SLApproachProstitutionMin Auto
GlobalVariable Property SLApproachProstitutionMax Auto
GlobalVariable Property SLApproachProstitutionValue Auto
GlobalVariable Property SLApproachProstitutionFraudChance Auto

GlobalVariable Property SLApproachCurrentPlayerHouse Auto
GlobalVariable Property SLApproachVisitorStaying Auto
GlobalVariable Property SLApproachSweetKissType Auto

GlobalVariable Property SLApproachSpankTimes Auto
GlobalVariable Property SLApproachMolestTimes Auto
GlobalVariable Property SLApproachBackHugTimes Auto
GlobalVariable Property SLApproachBackHugMolestTimes Auto
GlobalVariable Property SLApproachSweetKissTimes Auto
GlobalVariable Property SLApproachForcedKissTimes Auto

Faction Property sla_Arousal  Auto
Faction Property ArousalFaction  Auto
Faction Property slapp_VisitedRapistFaction  Auto
Faction Property slapp_VisitingRapistFaction  Auto
Faction Property slapp_NoVisitFaction  Auto
Faction Property slapp_ThugFaction  Auto
Faction Property slapp_SpoiledKid Auto


ReferenceAlias Property Alias_VisitorRef  Auto  ; SLApproachScanningPlayerHouse
ReferenceAlias Property TalkingActor  Auto
ReferenceAlias Property StayingActor  Auto  

ReferenceAlias Property FollowerRef  Auto  
ReferenceAlias Property ExternalFollowerRef  Auto  

ReferenceAlias Property PlayerHouseCenterMarker Auto
ReferenceAlias Property ExternalPlayerHouseCenterMarker Auto

ReferenceAlias Property PlayerHouseDoor Auto
ReferenceAlias Property ExternalPlayerHouseDoor Auto

ReferenceAlias Property PlayerHouseCOC Auto
ReferenceAlias Property ExternalPlayerHouseCOC Auto

Scene Property SLAppHousevisitScene  Auto  
Scene Property SLAppAggressiveBFPCScene  Auto  
Scene Property SLAppViceGuardCaptainScene  Auto  
Scene Property SLAppViceGuardCaptainSpankScene  Auto  
Scene Property SLAppAskingNameToPCScene  Auto  
Scene Property SLAppAskingKidScene  Auto  
Scene Property SLAppAskingKid02Scene  Auto  
Scene Property SLAppAskingMiscScene  Auto  
Scene Property SLAppBackHugMolest Auto
Scene Property SLApproachHouseStayScene  Auto  
Scene Property SLApproachAskForSexQuestScene  Auto  
Scene Property SLApproachAskForSexQuestFollowPlayerScene Auto
Scene Property SLAppAfterDrink Auto
Scene Property SLAppGuardPunishmentScene Auto
;Scene Property SLAppHugToPCScene  Auto
;Scene Property SLAppKissToPCScene  Auto  

Armor Property SLAppRingBeast  Auto  

Keyword Property ActorTypeNPC  Auto  
TalkingActivator Property SLAPP_MaleVisitorTalkingActivator  Auto  

Sound Property SLAPPMarker_DoorClose  Auto  
Sound Property SLAPPMarker_DoorKnob  Auto  
Sound Property SLAPPMarker_DoorKnock  Auto  

Message Property SLAPP_KnockingDoorMsg  Auto  


actorbase Property VisitorRefBase Auto
ObjectReference Property SLAPPTestZoneXmarker Auto
ObjectReference Property SLAPPTemporaryVisitorMarker Auto
ObjectReference Property SLAPPTemporaryVisitorBackMarker Auto
LocationRefType Property SLAppCustomHouseLocKeyword  Auto  
Globalvariable Property SLAMiscDialogueType Auto
Faction Property slapp_PunishingGuard Auto
