Title:chastity_end_test
Sex: Female T Male T Trans T
Require:
Limits:
use:chastity
use:gen
;Task to guide slave through unlocking. To be run when slave is allowed to unlock
;
; Variable table -
; TEMP1 == Working variable
; TEMP2 == Working variable
; TEMP3 == Working variable
; TEMP4 == Working variable
;
; Persistent variables -
; chastityLock               == Type of locking mechanism. Values 1 through 5
; chastityStartTime          == Time in seconds when chastity was started
; chastityStartTimeP         == as above but persistent over month
; chastityDuration           == Seconds the slave has been in chastity in the current month
; chastityAllTimeMax         == Longest hours locked in chastity to date (for other tasks)
; chastityAllTimeMonthlyMax  == Longest monthly hours locked in chastity to date (for other tasks)
; unlock_pending             == JIC server Flag that user message board is blocked until this task has been called
; pending-unlock-time        == Time stamp when unlock_pending flag was set. Used to calculate chastity duration
; chastityMustCumFast        == True if slave has to cum quickly to be allowed to stay unlocked
;
; Local variables -
; $lockType                  == Type of locking mechanism chosen by slave. Values 1 through 5
;
; ********** check if task is run at wrong time ***************************************************
loadtemp1:chastityStartTimeP
loadtemp2:unlock_pending
if:(('TEMP1' == '')||('TEMP1' == 'undefined')||('TEMP2' != 'true'))
  show: This task should not be run now. chastityStartTime or unlock_pending not set
  log:This task should not be run now. chastityStartTime or unlock_pending not set
  peerreview:false
  ;  call: clearMemory
  button: ok
  goto:exitTask
fi:
;
; ********** set up various variables *************************************************************
loadtemp1:chastityStartTimeP
if:(('TEMP1' == '') || ('TEMP1' == 'undefined'))
  loadtemp1:chastityStartTime
  if:(('TEMP1' == '') || ('TEMP1' == 'undefined'))
    settemp1:STIME
  fi:
fi:
assign:chastityStartTimeP:TEMP1
loadtemp1:chastityMustCumFast
if:(('TEMP1' == '') || ('TEMP1' == 'undefined'))
  settemp1:false
fi:
assign:chastityMustCumFast:TEMP1
call:initializeChastityClub
;
; ********** Allow slave to add chastity time instead of getting unlocked *************************
call:chastityImage2
call:allowToAddChastityTime
;
; ********** Check if chastity duration is less than minimum defined in settings ******************
call:checkChastityDurationLessThanSettings
;
; ********** enforce fast cumming if needed ********************************************************
call:informSlaveIfFastCumAfterUnlock
;
; ********** Chastity members have a 10% chance that time gets extended ****************************
call:chastityClubExtendTime
;
; ********** check if slave is at the correct gps location *****************************************
call:checkSlavesGPSLocation
;
; ********** start controlled cumming task if needed ***********************************************
call:checkAndStartControlledCumming
;
; ********** Chastity members have a 5% chance that they need to provide a blackmail video *********
call:chastityClubBlackmailVideo
;
; ********** Main Task Body ************************************************************************
call:initializeUnlockAndControlNumber
call:createValidationPictures
call:unlockNow
call:finishUnlockAndSaveVideoAndStats
;
; ********** Finish task ****************************************************************************
label:exitTask
; update to-do list with task run and validate if there are overdue tasks
assign:taskName:'chastity_end'
call:validateToDoTasks
call:saveToDoTasks
;
;--------------- FUNCTIONS ---------------------------------------------------------------------------
;
function:allowToAddChastityTime
  if:(('L_CH_MIN' != '') && (((STIME - $chastityStartTimeP)/3600)+1) < L_CH_MIN)
    show: Slave, your chastity term has ended. You now have the choice to unlock, or to stay in chastity a little longer.<br><br>WARNING. The duration of your chastity is less than the set minimum number of hours (in your settings). There will be a punishment if you unlock yourself that early.
  else:
    show: Slave, your chastity term has ended. You now have the choice to unlock, or to stay in chastity a little longer.
  fi:
  choice: unlock, extend chastity
  if:(LASTASK==2)
    show:Slave, you have to stay locked<br><br>I have added one hour of chastity and will now put you back to your message board, where you can add more time yourself.
    log:Slave has chosen to stay in chastity. Pending unlock cleared
    peerreview:false
    addchastity:1
    button:YES DTITLE
    goto:exitTask
  fi:
end:
;----------------------------------------------------
function:checkChastityDurationLessThanSettings
  if:(('L_CH_MIN' != '') && (((STIME-$chastityStartTimeP)/3600)+1) < L_CH_MIN)
    image2:taskimg/Punishment.PNG
    show: Slave, the duration of your chastity is less than the set minimum number of hours. You should have added more chastity time. There will be a punishment
    button:YES DTITLE
    if:(MOOD > 30)
      show: Slave, chastity is taken very serious here. Your mood has dropped to 20 percent. You will now follow my instructions how to unlock yourself. Read carefully what you need to do to avoid further punishment and exposure
      log:Chastity time was less than defined minimum hours in settings. Dropping mood to 20 percent
      button:Yes DTITLE
      setmood:20
    else:
      show: Slave, chastity is taken very serious here. Your mood has dropped by 10  points. You will now follow my instructions how to unlock yourself. Read carefully what you need to do to avoid further punishment and exposure
      log:Chastity time was less than defined minimum hours in settings. Dropping mood by 10 points
      button:Yes DTITLE
      setmood:(MOOD - 10)
    fi:
    call:chastityImage2
  else:
    if:('L_CH_FEE' != '')
      if:(L_CH_FEE != 0)
        setmood:(MOOD - L_CH_FEE)
        log: Reducing mood by nominal fee for getting unlocked
        show: Slave I guess you are looking forward to being unlocked.<br><br>In order to earn that privilege, I have reduced your mood as indicated in your settings
        button: YES DTITLE
      fi:
    fi:
  fi:
end:
;----------------------------------------------------
function:checkAndStartControlledCumming
  loadtemp3:controlledCummingDays
  if:(('TEMP3' == '') || ('TEMP3' == 'undefined'))
    settemp3:0
  fi:
  if:((TEMP3 < 1) && ('$chastityClubLevel' == 'platinum'))
    settemp3:1
  fi:
  savetemp3:controlledCummingDays
  if:('TEMP3' > 0)
    if:(('SNAME' == 'Thomas3' || 'SNAME' == 'Swen'))
      settemp1:TEMP3 * 24
      settemp2:TEMP3 * 120
      show:I see that you have TEMP3 controlled cummings scheduled. You have to work these off before I allow you to truly unlock
      button: Yes DTITLE
      show:But I give you a choice. Instead of the TEMP3 controlled cummings, you can unlock now, but at the cost of TEMP1 hours added to your monthly minimum, or TEMP2 days added to your chastity time next time you lock up (on top of your monthly minimum). Which will it be
      choice:controlled cummings, monthly minimum, add time to next lockup
      if:(LASTASK == 1)
        addchastity: 8 hours
        show:Ok, when you run the cumming task, you are allowed to unlock then, but you have to re-lock again immediately after cumming. I have added 8 hours of chastity time, during which you should run the controlled cumming task. See you back here in a while
        button:Yes DTITLE
        show:Oh, and to make one thing clear. You MUST lock up after you have done the controlled cumming, even if you think its only for an hour. Yes it might waste a tag, but also there might always be a surprise waiting for you. So you are NOT allowed to just stay unlocked because it was your last controlled cum, or you think it was
        button:I will lock up again DTITLE
        log:Slave has been assigned controlled cumming tasks. He is not allowed to unlock. After running the controlled cumming task, he MUST lock up again, no matter what. Please also check for that.
        settemp1:1
        savetemp1:controlledCummingUnlock
        assign:taskName:'controlled_cumming'
        assign:taskDelay:0
        assign:taskGrace:24
        call:scheduleToDoTask
        goto:exitTask
      fi:
      if:(LASTASK == 2)
        addchmin:TEMP1
        log:added TEMP1 hours monthly minimum chastity time
        show:I have added TEMP1 hours to your monthly minimum
        button:ok
        settemp1:0
        savetemp1:controlledCummingUnlock
        settemp3:0
        savetemp3:controlledCummingDays
      fi:
      if:(LASTASK == 3)
        loadtemp1:scheduledChastityDuration
        if:(('TEMP1' == '') || ('TEMP1' == 'undefined'))
          settemp1:0
        fi:
        show:You have previously added TEMP1 hours to your next lock up, and I will now increase this by TEMP2 hours.
        log:Added TEMP2 hours of postponed chastity time to previously postponed TEMP1 hours (effective at next lock up)
        button:ok
        settemp1:TEMP1 + TEMP2
        savetemp1:scheduledChastityDuration
        settemp1:0
        savetemp1:controlledCummingUnlock
        settemp3:0
        savetemp3:controlledCummingDays
      fi:
    else:
      assign:taskName:'controlled_cumming'
      assign:taskDelay:0
      assign:taskGrace:24
      call:scheduleToDoTask
      show:Congratulations for getting unlocked. You however have been marked that I will determine how you can cum. Watch out for a delayed task that will guide you through your next orgasms
      button:I will watch for it
    fi:
  fi:
end:
;----------------------------------------------------
function:chastityClubExtendTime
  if:(($lChastityClub == true) && ((Math.random() * 100) >= 90))
    image2:taskimg/chastity/cage stays on.jpg
    show:I am having second thoughts about letting you out, I tell you what you can stay locked for another 24 hours or I will let you out and increase you min avg limits by 0.1
    choice:stay locked up, increase avg limit
    if:(LASTASK== 1)
      peerreview:false
      addchastity: 24 hours
      log:slave was challenged and has chosen to stay 24 more hours locked up. Unlock aborted and pending unlock cleared.
      show:Good choice, I have added 24 hours of chastity. You are not allowed to unlock
      button:Yes DTITLE
      goto:exitTask
    else:
      addavglmt:0.1
      log:slave was challenged and has chosen to continue unlocking at expense of 0.1 average limit increase
      show:I hope you know what you are doing. I have increased your average limit by 0.1. Dont forget to check your limits once you are done unlocking. Enjoy your freedom
      button:Yes DTITLE
    fi:
  fi:
end:
;----------------------------------------------------
function:checkSlavesGPSLocation
  loadtemp3:chastityGPSlat
  loadtemp4:chastityGPSlon
  if:(('TEMP3' == '') || ('TEMP3' == 'undefined'))
    settemp3:0
  fi:
  if:(('TEMP4' == '') || ('TEMP4' == 'undefined'))
    settemp4:0
  fi:
  if:((TEMP3 != 0) && (TEMP4 != 0))
    show:I will now check if you are in the right location. Hang on ...
    getgps:
    wait:10
    settemp1:(gps_lat)
    settemp2:(gps_lon)
    settemp1:Math.abs(TEMP1 - TEMP3)
    settemp2:Math.abs(TEMP2 - TEMP4)
    if:((TEMP1 <= 0.001) && (TEMP2 <= 0.001))
      show:You are in the correct location and can proceed with unlocking
      button:Yes DTITLE
    else:
      show:Nah Nah you are in the wrong place.
      log:GPS coordinates of locking and unlocking do not match
      button:Sorry DTITLE
      show:This could be because you ARE in the wrong place, or if you are not using a smartphone and your GPS tracking does not work properly. Do you want to unlock anyhow, or end this task and get to the correct place?
      choice:Unlock anyhow, End task
      if:(LASTASK == 1)
        show:As a punishment for being stupid when asking for GPS tracking I will reduce your mood a bit
        button:Sorry DTITLE
        setmood:(MOOD - 5)
        log:reducing mood by 5 as slave is not able to confirm GPS coordinates
      else:
        log:slave chose to abandon task so that he can get to right GPS location before starting it again
        goto:exitTask
      fi:
    fi:
  fi:
end:
;----------------------------------------------------
function:chastityClubBlackmailVideo
  if:(($lChastityClub == true) && ((Math.random() * 100) >= 98) && ($chastityMustCumFast == false) && ('SNAME' != 'JohnF'))
    peerreview:false
    show:Haha slave, today I am in a playfull mind
    button:Is that good DTITLE
    show:Good for me, not so good for you
    wait:3
    show:I want some new and really good blackmail video from you
    button:Gulp
    show:So when you are told to unlock, you may, but while the video is still running, you have to edge 10 times (make them good, I want to be able to see them properly), and loudly and convincingly speak some words after each edge. I will tell you what to say, and I will be listening
    button:Sounds exciting DTITLE
    show:Oh and make sure you have everything to lock up again in case that is needed
    button:Got everything to lock up again
    call:initializeUnlockAndControlNumber
    call:createValidationPictures
    call:unlockNow
    show:Great, now that you are unlocked, you can soon start edging. But first of all, I want to see your face on the video. Adjust the camera so that I can watch you edging (your cock must be visible as well as your body) AND YOUR FULL AND UNOBSCURED FACE
    button:My face is visible now
    show:Good, smile for me
    wait:5
    button:Similing
    log:Slave needs to show cock and face during the entire video. In particular edging needs to be visible with face
    show:Keep your face visible on the video all the time. You will be punished if not
    button:Will show face at all times
    show:Now we are getting close to the edging. When you start, you need to read the lines I show you loudly so that I can clearly hear you. You need to sound enthusiastic and believable. Repeat the lines as often as needed until you have visibly edged. Is that understood
    button:I will speak with enthusiastic voice
    show:Great, 10 seconds till you may start edging. Get ready
    wait:10
    loop:10
      settemp1:(Math.random() * 100)
      if:(TEMP1 < 20)
        show:Edge and say PLEASE MISTRESS LET ME CUM
        log:slave needs to say PLEASE MISTRESS LET ME CUM while edging
      fi:
      if:((TEMP1 >= 20) && (TEMP1 < 40))
        show:Edge and say MY SMALL COCK DOES NOT DESERVE TO CUM MISTRESS
        log:slave needs to say MY SMALL COCK DOES NOT DESERVE TO CUM MISTRESS while edging
      fi:
      if:((TEMP1 >= 40) && (TEMP1 < 60))
        show:Edge and say I LOVE BEING IN CHASTITY MISTRESS
        log:slave needs to say I LOVE BEING IN CHASTITY MISTRESS while edging
      fi:
      if:((TEMP1 >= 60) && (TEMP1 < 80))
        show:Edge and say PLEASE LET ME NEVER CUM MISTRESS
        log:slave needs to say PLEASE LET ME NEVER CUM MISTRESS while edging
      fi:
      if:(TEMP1 >= 80)
        show:Edge and say I AM YOUR LOYAL SLAVE MISTRESS
        log:slave needs to say I AM YOUR LOYAL SLAVE while edging
      fi:
      button:Edge number LOOPVAR done
    endloop:
    show:Well done, this should be a very valuable video for me to keep. Now let me think what to do with you
    wait:5
    if:((Math.random() * 100) < 50)
      show:Ok, I like to see a ruined orgasm. RUINED, so hands off before any cum comes out, and I want to see it dribbling, not spurting
      log:slave needs to produce a ruined orgasm (hand off before any cum comes out,no spurting just dribbling)
      button:Done with ruined orgasm DTITLE
      call:logChastityStats
      call:clearMemory
    else:
      show:Nah, I want you to lock up again since you asked so nicely.
      button:Thank you DTITLE
      addchastity: 24 hours
      call:chastityAskLockInfo
      show:Now attach your chastity device, and lock it
      log:slave needs to lock up in chastity again
      button:Locked DTITLE
    fi:
    show:I will show some mercy and you do not have to upload the video to the CC review queue. But I want to see it, and your other Mistresses will as well
    button:Yes DTITLE
    asktext:What is the link (URL) of the video file<br><br>There is still a bug in the system. <b>Please enter the URL without the https and colon</b>
    log:Slave SNAME has uploaded validation video to <b>LASTASK</b>
    msg:Natasha:Slave SNAME had to create a new blackmail video when unlocking. Check it out at LASTASK
    msg:Jennifer:Slave SNAME had to create a new blackmail video when unlocking. Check it out at LASTASK
    if: ('SNAME' == 'Thomas3')
      msg:lisa:Slave SNAME had to create a new blackmail video when unlocking. Check it out at LASTASK
    fi:
    show:Well, that was fun. And now I have this nice video with you edging and begging. Imaging what that would look like on X
    button:Please not DTITLE
    goto:exitTask
  fi:
end:
;----------------------------------------------------
function:initializeUnlockAndControlNumber
  call:chastityAssignControlNumber
  log:IMPORTANT Slave is getting out of chastity. As a reviewer you are asked to help validating that the slave was still properly locked up, with no chance to cheat.
  if:('CHASTITY_DESC' != '')
    wait:1
    log: Slave has provided the following information to validate that it's is not cheating. CHASTITY_DESC
  fi:
end:
;----------------------------------------------------
function:informSlaveIfFastCumAfterUnlock
  if:($chastityMustCumFast == true)
    show:<b>NOTICE:</b> You have been marked for having to immediately cum once you are unlocked. You are NOT allowed to unlock right now. I will add an hour of chastity time, and you need to run the fast cum task. It will be scheduled, look for it in your to-do list.
    button:Yes DTITLE
    addchastity: 1 hours
    settemp1:1
    savetemp1:controlledCummingUnlock
    assign:taskName:'Fast_Cum_or_Punishment'
    assign:taskDelay:0
    assign:taskGrace:48
    call:scheduleToDoTask
    show:All set up. Once you are done with the fast cum, and when you are allowed to unlock again, come back here. I wish you good luck as you will only be allowed to unlock if you can cum really fast.
    button:Ok
    settemp1:''
    savetemp1:chastityMustCumFast
    goto:exitTask
  fi:
end:
;----------------------------------------------------
function:createValidationPictures
  show:Before I allow you to open your chastity device, I want you to provide me one or more proof pictures, that you are still wearing it, and that you have not tampered with the lock
  button:Yes DTITLE
  call:chastityLoadLockInfo
  if:($lChastityClub == true)
    call:chastityClubRequestVideo
    call:chastityValidateClubMember
    call:chastityImage2
  else:
    if:($lockType != 2)
      call:chastityValidateAllLockTypes
    else:
      show:Since you have locked with a timer device, and your time has run out, there is no need to create any validation pictures
      button:Thank you DTITLE
      peerreview:false
    fi:
    call:chastityImage2
  fi:
end:
;----------------------------------------------------
function:unlockNow
  if:($lockType == 3)
    show:You shall now remove the chastity device. The number you need to unlock your device should be $combNum
  else:
    show:You shall now remove the chastity device.
  fi:
  button:I have removed the chastity device DTITLE
end:
;----------------------------------------------------
function:finishUnlockAndSaveVideoAndStats
  if:($lChastityClub == true)
    call:chastityClubSaveVideo
  fi:
  show:That's it. It you were allowed to unlock enjoy your freedom but don't forget. You may only cum if you ask permission or if a task orders you to cum!
  button:I'll do DTITLE
  call:logChastityStats
  call:clearMemory
end:
;----------------------------------------------------
function:clearMemory
  settemp1:''
  savetemp1:chastityTagNumber
  savetemp1:chastityLock
  savetemp1:chastityStartTime
  savetemp1:chastityStartTimeP
  savetemp1:unlock_pending
  savetemp1:pending-unlock-time
  savetemp1:chastityLockPic
  savetemp1:chastityLastValidation
  savetemp1:chastityMustCumFast
end:
;----------------------------------------------------
function:logChastityStats
  loadtemp4:pending-unlock-time
  if:(('TEMP4' == '') || ('TEMP4' == 'undefined'))
    settemp4:STIME
  fi:
  if:((TEMP4 > $chastityStartTimeP) && (TEMP4 < STIME))
    assign:chastityEndTime:TEMP4
  else:
    assign:chastityEndTime:STIME
  fi:
  loadtemp3:chastityDuration
  if:('TEMP3'=='')
    settemp3:0
  fi:
  settemp1: $chastityEndTime - $chastityStartTimeP
  ;chastity duration is over the entire term of the lockup. Now make sure that it is not longer than THIS month ...
  ; ... so that monthly minimum still has an effect
  assign:dayOfMonth:new Date(STIME).getDate()
  if:TEMP1 > ($dayOfMonth * 60 * 60 *24)
    settemp1:$dayOfMonth * 60 * 60 * 24
  fi:
  settemp1:TEMP1 + TEMP3
  savetemp1:chastityDuration
  settemp1:(Math.floor(TEMP1/360))/10
  settemp2:(Math.floor(($chastityEndTime - $chastityStartTimeP)/360))/10
  show:Slave, you have stayed TEMP2 hours in chastity (until allowed to unlock), and this month in total TEMP1 hours.
  button: Thank you DTITLE
  ; save all time max chastity times. This is for other tasks to push slave into longer chastity
  loadtemp3:chastityAllTimeMax
  if:(('TEMP3' == '') || ('TEMP3' == 'undefined'))
    settemp3:0
  fi:
  if:(TEMP2 > TEMP3)
    savetemp2:chastityAllTimeMax
  fi:
  loadtemp3:chastityAllTimeMonthlyMax
  if:(('TEMP3' == '') || ('TEMP3' == 'undefined'))
    settemp3:0
  fi:
  if:(TEMP1 > TEMP3)
    savetemp1:chastityAllTimeMonthlyMax
  fi:
end: