Scriptname dcur_slaveBeltScript extends zadEquipScript  

dcur_mcmconfig Property dcumenu  Auto  

; Frameworks
SexLabFramework property SexLab auto

; Keywords
Keyword Property zad_DeviousPlug Auto 

; Animations
Idle Property ZazAPCAO104 Auto

Function DeviceMenu(Int msgChoice = 0)
    msgChoice = zad_DeviceMsg.Show() ; display menu
	if msgChoice == 0 ; Equip Device voluntarily
		DeviceMenuEquip()
	elseif msgChoice == 1	; Remove device, with key
		if libs.playerref.getItemCount(dcumenu.dcur_slavebeltkey1) > 0 && libs.playerref.getItemCount(dcumenu.dcur_slavebeltkey2) > 0 && libs.playerref.getItemCount(dcumenu.dcur_slavebeltkey3) > 0 && libs.playerref.getItemCount(dcumenu.dcur_slavebeltkey4) > 0 && libs.playerref.getItemCount(dcumenu.dcur_slavebeltkey5) > 0 
			DeviceMenuRemoveWithKey()
		else
			;libs.Notify("To make escape highly difficult, this chastity belt is fitted with five different locks - three on the belt and two more on the shield. You cannot unlock this device unless you are in possession of all five keys!", messageBox=true)			
			libs.Notify("脱出を非常に難しくするため、この貞操帯には五つの異なるロック、- 三つはベルトに、二つはシールドに - が付いています。あなたは五つの鍵を持たない限り、開錠することができません!", messageBox=true)			
		endif		
	elseif msgChoice == 2 ; Remove device, without key
		DeviceMenuRemoveWithoutKey()
	endif
	DeviceMenuExt(msgChoice)	
	SyncInventory()
EndFunction

Function DeviceMenuRemoveWithoutKey()
    int deviceRemoveOption = zad_DeviceRemoveMsg.show()
    if deviceRemoveOption == 0 ; Lockpicking
	;	DeviceMenuPickLock()
		;libs.Notify("The " + deviceInventory.GetName() + " has a high security lock. You cannot attempt to pick it.", messageBox=true)		
		libs.Notify("その " + deviceInventory.GetName() + "  は高度にロックされているため、あなたは開錠しようにもできません。", messageBox=true)		
	elseif deviceRemoveOption == 1 ; Magicking
	;	DeviceMenuMagic()
		if libs.PlayerRef.GetAv("Magicka")<50
			;libs.Notify("Your mental reserves are far too drained to attempt this task.", true)
			libs.Notify("あなたはこのタスクを試そうにも、精神が衰弱しすぎていてできません。", true)
		else
			libs.PlayerRef.DamageAV("Magicka", 50)
			;libs.Notify("You flood the "+deviceInventory.GetName()+" with arcane energies, but everything you cast gets absorbed by the " + deviceName + ".", messageBox=true)
			libs.Notify("あなたはその "+deviceInventory.GetName()+"をアルケインの力で溢れさせましたが、あなたが詠唱はすべて" + deviceName + "に吸収されました。", messageBox=true)
		endif
	elseif deviceRemoveOption == 2 ; Brute force
		;libs.Notify("The " + deviceInventory.GetName() + " is made of super-hardened metal. There is no way for you to break it open.", messageBox=true)
		libs.Notify("その " + deviceInventory.GetName() + " はとてつもなく固い金属でできています。それをこじ開ける方法はありません。", messageBox=true)
		;DeviceMenuBruteForce()		
	elseif deviceRemoveOption == 3
        DeviceMenuCarryOn()
    endif
EndFunction

Function DeviceMenuExt(Int msgChoice)
; Masturbate
	if msgChoice == 3
		BeltMenuMasturbate()	
; probe locks	
	elseif msgChoice == 4
		;libs.Notify("You probe the five high security locks keeping the tight-sitting chastity belt locked shut on you. Your fingers run across the smooth metal of the shield. Your wet pussy is burning with desire under the belt's merciless embrace, but the steel shield keeps your fingers from reaching it and giving it what it so desperately craves. Frustrated, you forcefully tuck at the belt - of course to no avail. Your efforts had no effect except making you even more horny then you already were.", messageBox=true)	
		libs.Notify("あなたは高度なロックが施され、きつく巻き付いている貞操帯を調べます。滑らかな金属でできた前のシールドにあなたは指を走らせます。あなたの濡れたヴァギナは貞操帯の無慈悲な抱擁の中燃えていますが、指がそこに届き、あなたがその切望を叶えるのを前のシールドは邪魔します。あなたは苛立ち強くその帯をまくり上げようとします - もちろん、その甲斐はありません。あなたの努力は以前よりさらに欲情することを除けば、何も結果を残しませんでした。", messageBox=true)	
		Aroused.UpdateActorExposure(libs.PlayerRef, 20)
	endif
EndFunction

function DeviceMenuRemoveWithKey()
    if RemoveDeviceWithKey()    
		if Aroused.GetActorExposure(libs.PlayerRef) < libs.ArousalThreshold("Horny")
			;libs.Notify("You insert the five keys into their respective locks and turn them, one after the other. When you turn the last key, the chastity belt clicks open and loosens its tight grip around your waist and crotch.", messageBox=true)	
			libs.Notify("あなたは五つの鍵を順にそれぞれの鍵穴に差し込み、回します。あなたが最後の鍵を回すと、貞操帯は音を立てて開き、あなたの股、腰にきつく巻かれたものが緩みます。", messageBox=true)	
	     else
		    ;libs.Notify("With trembling fingers you insert the five keys into their respective locks and somehow manage to turn them, one after the other. When you turn the last key, the chastity belt clicks open and loosens its tight grip around your waist and crotch. You let the chastity belt fall to the ground while your hand reaches for your wet and finally free pussy, caressing it gently while your aroused mind is already planning your first sexual encounter in a while...", messageBox=true)	
		    libs.Notify("あなたは震える指で鍵を鍵穴に差し込み、何とか回します。貞操帯の鍵は開き、あなたの股、腰にきつく巻き付いた帯は緩くなります。あなたはその手を濡れているところ、やっと自由になったヴァギナに這わせながら、貞操帯を地面に落としました。そして優しく愛撫します。興奮した心で、次の性的な出会いをどうするか、思いを巡らせながら...", messageBox=true)	
	    endif
		libs.playerref.RemoveItem(dcumenu.dcur_slavebeltkey1, libs.playerref.GetItemCount(dcumenu.dcur_slavebeltkey1), true) 
		libs.playerref.RemoveItem(dcumenu.dcur_slavebeltkey2, libs.playerref.GetItemCount(dcumenu.dcur_slavebeltkey2), true) 
		libs.playerref.RemoveItem(dcumenu.dcur_slavebeltkey3, libs.playerref.GetItemCount(dcumenu.dcur_slavebeltkey3), true) 
		libs.playerref.RemoveItem(dcumenu.dcur_slavebeltkey4, libs.playerref.GetItemCount(dcumenu.dcur_slavebeltkey4), true) 
		libs.playerref.RemoveItem(dcumenu.dcur_slavebeltkey5, libs.playerref.GetItemCount(dcumenu.dcur_slavebeltkey5), true) 
		libs.playerref.RemoveItem(dcumenu.dcur_slavebelt, 1, true) 
    Endif
EndFunction


string Function DeviceMenuPickLockFail()
	libs.PlayerRef.RemoveItem(Lockpick)
	Aroused.UpdateActorExposure(libs.PlayerRef,1)
	;return "In addition, your struggles with the lock have left you aroused. "
	return "そのうえ、縛りにもがいたことで、あなたは欲情してしまいました。"
EndFunction

string function ReturnMagicAroused()
	Aroused.UpdateActorExposure(libs.PlayerRef,1)
	;return "Furthermore, the tingling magical energies so near your groin leave you feeling aroused. "
	return "しかも、ヴァギナ近くのチクチクした魔法の痛みは、あなたに興奮を与えます。"
EndFunction

string Function DeviceMenuDestructionModerate()
	return ReturnMagicAroused()
EndFunction

string Function DeviceMenuAlterationSuccess()
	return ReturnMagicAroused()
EndFunction

string Function DeviceMenuAlterationFail()
	return ReturnMagicAroused()
EndFunction

string Function DeviceMenuRestorationFail()
	return ReturnMagicAroused()
EndFunction
string Function DeviceMenuIllusionFail()
	return ReturnMagicAroused()
EndFunction

string Function DeviceMenuBruteForceFail()
	Aroused.UpdateActorExposure(libs.PlayerRef,2, "Brute force fail")
	;return "Your efforts leave you both exhausted, and aroused."
	return "あなたの努力は疲れと欲情をもたらすだけです。"
EndFunction


function BeltMenuMasturbate()
	;libs.NotifyPlayer("You attempt to seek relief from the burning desire that fills you...")
	libs.NotifyPlayer("あなたはその体を満たそうとする熱い欲求からの救済を求めます...")
	sslBaseAnimation[] anims = SexLab.GetAnimationsByTag(1, "Solo", "F", "DeviousDevice", requireAll=true)
	actor[] tmp = new actor[1]
	tmp[0] = libs.PlayerRef
        Aroused.UpdateActorExposure(libs.PlayerRef,3)
	SexLab.StartSex(tmp, anims)
EndFunction



function SetupQuest()
        deviceQuest.SetObjectiveCompleted(00)
	if libs.PlayerRef.WornHasKeyword(zad_DeviousPlug)
		deviceQuest.setStage(20)
		deviceQuest.SetObjectivedisplayed(20)
	else
		deviceQuest.setStage(10)
		deviceQuest.SetObjectivedisplayed(10)
	Endif
EndFunction


Function ResetQuest()
      deviceQuest.SetObjectiveDisplayed(10,false)
      deviceQuest.SetObjectiveCompleted(10,false)
      deviceQuest.SetObjectiveDisplayed(20,false)
      deviceQuest.SetObjectiveCompleted(20,false)
      deviceQuest.SetObjectiveDisplayed(30,false)
      deviceQuest.SetObjectiveCompleted(30,false)
      deviceQuest.SetObjectiveDisplayed(80,false)
      deviceQuest.SetObjectiveCompleted(80,false)
      deviceQuest.SetObjectiveDisplayed(100,false)
      deviceQuest.SetObjectiveCompleted(100,false)
      deviceQuest.Reset()
EndFunction

Function OnEquippedPre(actor akActor, bool silent=false)	
	libs.StoreExposureRate(akActor)
	string msg = ""
	if akActor == libs.PlayerRef						
		;msg = "Reluctantly you wrap the metal bands around your body. You wonder if its just bad luck or cruel magic at work, but the belt is sitting so extremely tight on your hips that you have to use considerable force to press the lock shut. A shiver runs through your body as you finally hear the mechanism click inside the belt. You probe the belt by trying to slide a finger underneath it and reach your already wet pussy, but soon you sigh in frustration at the utter futility of the task. You won't be able to satisfy your desires anytime soon."
		msg = "しぶしぶあなたはその金属製のベルトを体に巻きます。あなたは単に運が悪いのか、それとも狂った魔法が働いているか疑問に思いますが、そのベルトは極めてきつくあなたの腰に巻き付いているため、閉じているロックに抗うためにはあなたはかなりの力を使わなければなりません。ベルトの中で機構が音を立てるのを聞いて、あなたに戦慄が走ります。あなたはベルトの下に指走らせてそれを調べると、やがて指は既に濡れているヴァギナまで達しますが、すぐにあなたはその行為は無意味であることがわかり、不満で溜息をつきます。あなたはまだ欲求を満たすことができません"		
	Else
		;msg = akActor.GetLeveledActorBase().GetName() + " blushes as you lock the belt around her hips."
		msg = akActor.GetLeveledActorBase().GetName() + " はあなたが腰の周りでベルトをロックしている最中、赤面します。"
	EndIf
	if !silent
		libs.NotifyActor(msg, akActor, true)
	EndIf
EndFunction


Function OnEquippedPost(actor akActor)
	float modRate = libs.GetModifiedRate(akActor)
    libs.Log("original exposure rate was " + libs.GetOriginalRate(akActor) + ". Setting to " + modRate + ".")
    Aroused.SetActorExposureRate(akActor, modRate)
	libs.CorsetMagic(akActor)
EndFunction
 
int Function OnContainerChangedFilter(ObjectReference akNewContainer, ObjectReference akOldContainer)
	return 0
EndFunction


Function OnContainerChangedPre(ObjectReference akNewContainer, ObjectReference akOldContainer)
	;libs.NotifyPlayer("The belt remains firmly locked around your hips.")
	libs.NotifyPlayer("そのベルトはあなたの腰を固くロックしたままです。")
EndFunction

Function OnRemoveDevice(actor akActor)
	if akActor == libs.PlayerRef
		if deviceQuest.GetStage()>=80
			libs.Log("OnRemoveDevice() called when stage >=80")
		Else
			;        deviceQuest.SetObjectiveCompleted(100)
			;        deviceQuest.SetObjectivedisplayed(100)
			if Aroused.GetActorExposure(libs.PlayerRef) >= libs.ArousalThreshold("Desperate") && libs.Config.MasturbateOnBeltRemoval
				deviceQuest.SetObjectiveCompleted(10)
				deviceQuest.SetObjectiveFailed(20)
				deviceQuest.setStage(80)
			else
				deviceQuest.SetObjectiveCompleted(10)
				deviceQuest.SetObjectiveCompleted(20)
				deviceQuest.setStage(100)
			EndIf	
		Endif
	EndIf
	RestoreSettings(akActor)
	libs.CorsetMagic(akActor)
EndFunction


Function RestoreSettings(actor akActor)
	float originalExposureRate = libs.GetOriginalRate(akActor)
        libs.Log("Restoring original exposure rate to " + originalExposureRate)
        Aroused.SetActorExposureRate(akActor, originalExposureRate)
	StorageUtil.UnSetFloatValue(akActor, "zad.StoredExposureRate")
EndFunction


