summaryrefslogtreecommitdiff
path: root/scripts/toy.groovy
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2018-12-28 14:06:46 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2018-12-28 14:06:46 +0000
commit614c0ba1410b06aed3785659dd28385665e74b76 (patch)
tree7f503f63263eb383a8284207f287822900616106 /scripts/toy.groovy
parentFix image selector in preStrip (diff)
downloadtoy-614c0ba1410b06aed3785659dd28385665e74b76.zip
Finally replace all the special case stuff for plans and sleeping
Now uses the generic eventing system... muuuuch better and no polling.
Diffstat (limited to 'scripts/toy.groovy')
-rw-r--r--scripts/toy.groovy207
1 files changed, 114 insertions, 93 deletions
diff --git a/scripts/toy.groovy b/scripts/toy.groovy
index 17453fa..b500188 100644
--- a/scripts/toy.groovy
+++ b/scripts/toy.groovy
@@ -27,9 +27,9 @@ final CHASTE = "chaste", COLLARED = "collared", CUFFED = "cuffed", CLAMPED = "cl
final REDRESS = "redress";
final TOYTOYS = [CUFFED, COLLARED, CLAMPED, GAGGED];
final RELEASEFROM = "releaseFrom";
-// toy.plan.<name>.{start|end|friend} UTC times
-final LUNCH = "lunch", SHOPPING = "shopping", PARTY = "party";
-final START = "start", END = "end", FRIEND = "friend";
+final LUNCH = "lunch", SHOPPING = "shopping", PARTY = "party", SLEEPING = "sleeping";
+final BEDTIME = "bedtime", WAKEUP = "wakeup";
+final BEGINPLAN = "beginPlan", ENDPLAN = "endPlan";
final FRIENDS = [ "Tori", "Sophie", "Krystal" ];
// toy.position
final KNEELING = "kneeling", ALLFOURS = "allfours", STANDING = "standing";
@@ -1151,6 +1151,7 @@ def playWait = {
wait(20 + getRandom(20));
};
def playSchedule = { lastPlay ->
+ if (getAway()) return;
if (lastPlay < getTime() - (4 * HOUR)) {
addEventIfMissing(PLAY, getTime() + 120 + getRandom(480), PLAY, true); // 2-10mins
}
@@ -1175,9 +1176,13 @@ def playEvent = { rt = true, first = true ->
playSchedule(getTime());
showLounge();
}
-def bedtime = {
+def sleepSchedule = {
+ def t = (int)(getDay() + localTimeOffset() + (25.1 * HOUR) + getRandom((int)HOUR));
+ addEventIfMissing(SLEEPING, t, BEDTIME);
+};
+def bedtime = { rt, schedTime ->
dress([[LINGERIE,nTITS]]);
- if (sessionSummon([LINGERIE,nTITS])) {
+ if (rt && sessionSummon([LINGERIE,nTITS])) {
preStrip([LINGERIE,nTITS]);
def toys = TOYTOYS.findAll { t -> is(t) };
Collections.shuffle(toys);
@@ -1195,7 +1200,18 @@ def bedtime = {
removeEvent("$RELEASEFROM-$it");
set(it, false);
};
- exit();
+ setAway(SLEEPING);
+ def t = schedTime + (6 * (int)HOUR) + getRandom(2 * (int)HOUR);
+ addEvent(SLEEPING, t, WAKEUP);
+ removeEvent(PLAY);
+ if (rt) {
+ exit();
+ }
+};
+def wakeup = { rt ->
+ setAway(null);
+ playSchedule(loadInteger("toy.lastPlay") ?: 0);
+ sleepSchedule();
};
def redress = { rt ->
if (!rt || !sessionSummon([DRESSED])) {
@@ -1352,22 +1368,22 @@ def confess = {
// Setup
// Plans - cannot overlap
def setupPlan = { plan, float startmin, float startmax, float endmin, float endmax ->
- def timeWindow = { float min, float max -> (int)((min * HOUR) + getRandom((int)((max - min) * HOUR))) };
- // Unplanned or past
- if (getTime() > loadInteger("toy.plan.${plan}.${END}")) {
- def day = getDay() + ((getRandom(3) + 1) * DAY);
- save("toy.plan.${plan}.${FRIEND}", FRIENDS[getRandom(FRIENDS.size())]);
- save("toy.plan.${plan}.${START}", day + timeWindow(startmin, startmax));
- save("toy.plan.${plan}.${END}", day + timeWindow(endmin, endmax));
- }
+ def timeWindow = { float min, float max -> (int)((min * HOUR) + localTimeOffset() + getRandom((int)((max - min) * HOUR))) };
+ final friendName = FRIENDS[getRandom(FRIENDS.size())];
+ def day = getDay() + ((getRandom(3) + 1) * DAY);
+ addEventIfMissing(plan, day + timeWindow(startmin, startmax), BEGINPLAN,
+ [friendName: friendName, returnTime: day + timeWindow(endmin, endmax)]);
}
def setupPlans = {
+ save("toy.plan", null);
setupPlan(LUNCH, 11.5, 12.5, 13.0, 14.0)
setupPlan(SHOPPING, 14.5, 15.5, 16.0, 18.0)
setupPlan(PARTY, 19, 20, 22.0, 25.0)
};
def setupEvents = {
playSchedule(loadInteger("toy.lastPlay") ?: 0);
+ sleepSchedule();
+ setupPlans();
};
def setDefault = { prop, val ->
if (loadString(prop) == null) {
@@ -1384,10 +1400,10 @@ def readNote = {
def plannedCheck = { plan ->
return (getTime() > loadInteger("toy.plan.${plan}.${START}") && getTime() < loadInteger("toy.plan.${plan}.${END}"));
}
-def beginPlan = { plan ->
+def beginPlan = { rt, plan, args ->
+ addEvent(plan, args.returnTime, ENDPLAN, args.friendName);
dress([[DRESSED,nTEASE], [DRESSED,TEASE]]);
- save("toy.owner.outfitTime", loadInteger("toy.plan.${plan}.${END}"));
- if (sessionSummon([DRESSED,nTEASE])) {
+ if (rt && sessionSummon([DRESSED,nTEASE])) {
present([DRESSED,nTEASE], [
[ "I'm going out now, toy.", "$plan time!" ],
[ "Will you be good while I'm gone?", "You will behave as I expect?" ]]);
@@ -1399,16 +1415,34 @@ def beginPlan = { plan ->
present([DRESSED,TEASE], [
[ "Back later!", "See you soon, toy" ]]);
wait(5);
- exit();
}
- if (has(CHASTITY)) {
+ else if (has(CHASTITY)) {
leaveNote("I want you in chastity until I return!", CHASTE);
}
- adjustPunish(5);
- exit();
+ setAway(plan);
+ removeEvent(PLAY);
+ if (rt) {
+ exit();
+ }
+};
+def endPlan = { rt, plan ->
+ save("toy.owner.outfitTime", getTime());
+ setAway(null);
+ if (rt && sessionSummon([DRESSED])) {
+ present([DRESSED], [["Hello, toy!"], ["I'm back home now."]]);
+ wait(10);
+ showLounge();
+ }
+ readNote();
+ playSchedule(getTime());
+ setupPlans();
};
// Initial - basic checks and defaults
namedEvents = [
+ bedtime: { name, arg, schedTime, rt -> bedtime(rt, schedTime) },
+ wakeup: { name, arg, schedTime, rt -> wakeup(rt) },
+ beginPlan: { name, arg, schedTime, rt -> beginPlan(rt, name, arg) },
+ endPlan: { name, arg, schedTime, rt -> endPlan(rt, name) },
play: { name, arg, schedTime, rt -> playEvent(rt, arg) },
releaseFrom: { name, arg, schedTime, rt -> releaseFrom(rt, arg, name) },
redress: { name, arg, schedTime, rt -> redress(rt) },
@@ -1464,7 +1498,6 @@ def setupInitial = {
save("toy.version", VERSION);
setDefault("toy.strokeTeaseOffset", 0);
setDefault("toy.punishment", 0);
- setupPlans();
execEvents(false);
setupEvents();
};
@@ -1489,10 +1522,13 @@ def setupShowState = {
showButton("OK");
};
def setupShowCalendar = {
+ final events = loadEvents();
show(
[LUNCH, SHOPPING, PARTY].collect {
- def s = loadInteger("toy.plan.${it}.${START}");
- def f = loadString("toy.plan.${it}.${FRIEND}");
+ final event = events[it];
+ if (!event) return "";
+ def s = event.time;
+ def f = event.arg.friendName;
def timeStr = localTimeOf(s).format(soonFormatter);
return "$it with $f on $timeStr.\n".capitalize();
}.join());
@@ -1520,85 +1556,70 @@ def tidyAvail = {
}
save("toy.availability", p2);
};
-if (localTime() > 25.75 || localTime() < 7.5) { // 1:45am - 7:30am
- show("Mistress is sleeping...");
- wait(10);
- exit();
-}
-if (plannedCheck(LUNCH) || plannedCheck(SHOPPING) || plannedCheck(PARTY)) {
- showLounge();
- def note = loadString("toy.note");
- def noteInstr = loadString("toy.noteInstr");
- if (note) {
- show("Mistress is out... but you find a note:\n$note");
- showButton("OK");
- if (noteInstr) {
- set(noteInstr, true);
- }
- readNote();
- }
- else {
- show("Mistress is out...");
- wait(10);
- }
- while (plannedCheck(LUNCH) || plannedCheck(SHOPPING) || plannedCheck(PARTY)) {
- wait(5);
- }
- execEvents(false);
- if (sessionSummon([DRESSED])) {
- present([DRESSED], [["Hello, toy!"], ["I'm back home now."]]);
- wait(10);
- showLounge();
- }
-}
-else {
- leaveNote(null, null);
-}
setupInitial();
tidyAvail();
-final cycleTime = 6;
+final cycleTime = 60;
showLounge();
while (true) {
- show("Mistress will summon you when required.");
- if (showButton("Please, Miss?", cycleTime) < cycleTime) {
- def opts = [
- [ lbl: "Calendar", act: setupShowCalendar ],
- [ lbl: "Confess", act: confess ],
- ];
- if (is("DEBUG")) {
- opts.push([ lbl: "Status", act: setupShowState ]);
- opts.push([ lbl: "Play", act: playEvent, arg: true ]);
- opts.push([ lbl: "Begin plan", act: beginPlan, arg: LUNCH ]);
+ def away = getAway();
+ def e = nextEvent(loadEvents());
+ if (!e) return "toy"; // Force restart, should create some events
+
+ if (away) {
+ def note = loadString("toy.note");
+ def noteInstr = loadString("toy.noteInstr");
+ if (note) {
+ show("Mistress is away ($away)... but you find a note:\n$note");
+ showButton("OK");
+ if (noteInstr) {
+ set(noteInstr, true);
+ }
+ readNote();
}
- if (is(NAKED)) {
- opts.push([ lbl: "May I wear clothes", act: requestClothes ]);
+ else {
+ show("Mistress is away ($away)...");
+ }
+ if (e && e.event && e.event.time > getTime()) {
+ wait(e.event.time - getTime());
}
- TOYTOYS.findAll { is(it) }.each {
- opts.push([ lbl: "May I be un-$it".toString(), act: requestRelease, arg: it ]);
- };
- opts.push([ lbl: "Back", act: null ]);
- def opt = getSelectedValue("Yes, toy?", opts.collect { it.lbl });
- def act = opts[opt].act;
- if (act)
- act(opts[opt].arg);
- else
- return "toy";
- }
- else if (localTime() > 25.75) { // 1:45am
- bedtime();
- }
- else if (plannedCheck(LUNCH)) {
- beginPlan(LUNCH);
- }
- else if (plannedCheck(SHOPPING)) {
- beginPlan(SHOPPING);
}
- else if (plannedCheck(PARTY)) {
- beginPlan(PARTY);
+ else {
+ if (is("DEBUG")) {
+ def timeStr = localTimeOf(e.event.time).format(soonFormatter);
+ show("$e.name: $timeStr -> ${e.event.func}(${e.event.arg})");
+ }
+ else {
+ show("Mistress will summon you when required.");
+ }
+ final waitTime = Math.min(cycleTime, e.event.time - getTime());
+ final clickTime = showButton("Please, Miss?", waitTime);
+ if (clickTime < waitTime) {
+ def opts = [
+ [ lbl: "Calendar", act: setupShowCalendar ],
+ [ lbl: "Confess", act: confess ],
+ ];
+ if (is("DEBUG")) {
+ opts.push([ lbl: "Status", act: setupShowState ]);
+ opts.push([ lbl: "Play", act: playEvent, arg: true ]);
+ }
+ if (is(NAKED)) {
+ opts.push([ lbl: "May I wear clothes", act: requestClothes ]);
+ }
+ TOYTOYS.findAll { is(it) }.each {
+ opts.push([ lbl: "May I be un-$it".toString(), act: requestRelease, arg: it ]);
+ };
+ opts.push([ lbl: "Back", act: null ]);
+ def opt = getSelectedValue("Yes, toy?", opts.collect { it.lbl });
+ def act = opts[opt].act;
+ if (act)
+ act(opts[opt].arg);
+ else
+ return "toy";
+ }
+ addAvail(clickTime);
}
execEvents(true);
- addAvail(cycleTime);
}