summaryrefslogtreecommitdiff
path: root/scripts/toy.groovy
blob: f2f4f13a3421947d4d89a8c0c4fe79bd99bdd26a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
// Toy main

setInfos(9, "Toy", "Your frustration is my amusement.", "rascalDan", "WIP", 0xFFFFFF, "en", ["", "", ""]);
final VERSION = 1;
final DAY = 86400;
final HOUR = 3600.0;
final soonFormatter = java.time.format.DateTimeFormatter.ofPattern("EEEE 'at' h:mma");
// Notes
// toys.<name> ankle_cuffs, ballgag, blindfold, chastity_belt, clothespins, cockring, dog_collar, handcuffs, hood, nipple_clamps, ring_gag
final BALLGAG = "ballgag", COLLAR = "dog_collar", CLAMPS = "nipple_clamps", CHASTITY = "chastity_belt";
// fetish.<name>
final BONDAGE = "bondage", CBT = "cbt", CHORES = "chores", PAIN = "pain";
// toy.permission.<name>
final CUM = "cum", EDGE = "edge"
// toy.state.<name>
final CHASTE = "chaste", COLLARED = "collared", CUFFED = "cuffed", CLAMPED = "clamped", GAGGED = "gagged", NAKED = "naked";
// toy.plan.<name>.{start|end|friend} UTC times
final LUNCH = "lunch", SHOPPING = "shopping", PARTY = "party";
final START = "start", END = "end", FRIEND = "friend";
final FRIENDS = [ "Tori", "Sophie", "Krystal" ];
// toy.position
final KNEELING = "kneeling", ALLFOURS = "allfours", STANDING = "standing";
final OWNER = "ancilla";
final SITTER = "sarah-james";

// Imagery
final DRESSED = "dressed", TITS = "tits", PUSSY = "pussy", LINGERIE = "lingerie", TEASE = "tease", SIT = "sit", BOOTS = "boots", KNEEL = "kneel", STOOD = "stood", MEAN = "mean", CROP = "crop", ASS = "ass", SQUAT = "squat", SSSH = "sssh";
final nDRESSED = "!$DRESSED", nTITS = "!$TITS", nTEASE = "!$TEASE";
def IMAGEDATA = { [
	[ domme: "ancilla", sets: [
		[ set: "corset", images: [
			[ image: 1, tags: [DRESSED, STOOD] ],
			[ image: 2, tags: [DRESSED, STOOD] ],
			[ image: 3, tags: [DRESSED, STOOD] ],
			[ image: 4, tags: [DRESSED, STOOD] ],
			[ image: 5, tags: [DRESSED, STOOD] ],
			[ image: 6, tags: [DRESSED, STOOD] ],
			[ image: 7, tags: [DRESSED, STOOD, TEASE] ],
			[ image: 8, tags: [DRESSED, STOOD, ASS] ],
			[ image: 9, tags: [DRESSED, STOOD, TEASE] ],
			[ image: 10, tags: [DRESSED, STOOD, TEASE] ],
			[ image: 11, tags: [KNEEL, TITS] ],
			[ image: 12, tags: [KNEEL, TITS, ASS] ],
			[ image: 13, tags: [KNEEL, TITS, LINGERIE] ],
			[ image: 14, tags: [KNEEL, TITS, LINGERIE] ],
			[ image: 15, tags: [SIT, TITS, LINGERIE] ],
			[ image: 16, tags: [STOOD, TITS, LINGERIE] ],
		] ],
		[ set: "crop", images: [
			[ image: 1, tags: [TITS, KNEEL, SSSH] ],
			[ image: 2, tags: [TITS, KNEEL, MEAN, CROP] ],
			[ image: 3, tags: [TITS, KNEEL, CROP] ],
			[ image: 4, tags: [TEASE, KNEEL] ],
			[ image: 5, tags: [STOOD, TITS] ],
			[ image: 6, tags: [KNEEL, TITS] ],
			[ image: 7, tags: [KNEEL, TITS] ],
			[ image: 8, tags: [DRESSED, STOOD, CROP] ],
			[ image: 9, tags: [DRESSED, STOOD, CROP] ],
			[ image: 10, tags: [DRESSED, STOOD, CROP, TEASE] ],
			[ image: 11, tags: [DRESSED, STOOD, CROP, TEASE] ],
			[ image: 12, tags: [DRESSED, STOOD, CROP] ],
			[ image: 13, tags: [DRESSED, STOOD, CROP] ],
			[ image: 14, tags: [DRESSED, SIT, CROP, TEASE] ],
			[ image: 15, tags: [TITS, SIT] ],
			[ image: 16, tags: [TITS, STOOD] ],
		] ],
		[ set: "dress", images: [
			[ image: 1, tags: [TITS, STOOD] ],
			[ image: 2, tags: [TITS, STOOD] ],
			[ image: 3, tags: [TITS, SIT] ],
			[ image: 4, tags: [TITS, SIT] ],
			[ image: 5, tags: [TITS, STOOD] ],
			[ image: 6, tags: [TITS, STOOD, ASS] ],
			[ image: 7, tags: [DRESSED, STOOD] ],
			[ image: 8, tags: [DRESSED, STOOD] ],
			[ image: 9, tags: [DRESSED, STOOD, ASS] ],
			[ image: 10, tags: [DRESSED, STOOD, ASS] ],
			[ image: 11, tags: [DRESSED, SQUAT] ],
			[ image: 12, tags: [DRESSED, STOOD, TEASE] ],
			[ image: 13, tags: [DRESSED, STOOD, TEASE] ],
			[ image: 14, tags: [TITS, STOOD] ],
			[ image: 15, tags: [TITS, STOOD] ],
		] ],
		[ set: "pink", images: [
			[ image: 1, tags: [TITS, KNEEL, LINGERIE] ],
			[ image: 2, tags: [TITS, KNEEL, LINGERIE] ],
			[ image: 3, tags: [TITS, KNEEL, LINGERIE] ],
			[ image: 4, tags: [TITS, KNEEL, LINGERIE] ],
			[ image: 5, tags: [TITS, KNEEL, LINGERIE] ],
			[ image: 6, tags: [TITS, KNEEL] ],
			[ image: 7, tags: [DRESSED, KNEEL] ],
			[ image: 8, tags: [DRESSED, STOOD] ],
			[ image: 9, tags: [DRESSED, STOOD] ],
			[ image: 10, tags: [DRESSED, STOOD, TEASE] ],
			[ image: 11, tags: [DRESSED, STOOD, TEASE] ],
			[ image: 12, tags: [KNEEL, LINGERIE] ],
			[ image: 13, tags: [TITS, KNEEL, LINGERIE] ],
			[ image: 14, tags: [TITS, KNEEL, LINGERIE] ],
			[ image: 15, tags: [TITS, KNEEL, LINGERIE] ],
		] ],
	]
	]
] };
def selectImage = { domme, set, spec ->
	def meets = { i ->
		return spec.every({ s ->
			return (s[0] == "!") ? i.tags.indexOf(s.drop(1)) == -1 : i.tags.indexOf(s) != -1;
		});
	};
	def matches = IMAGEDATA()
		.find({ d -> d.domme == domme })
		.sets.find({ s -> s.set == set })
		.images.findAll({ i -> meets(i) });
	return matches[getRandom(matches.size())];
};
def showImage = { spec ->
	def outfit = loadString("toy.owner.outfit");
	def image = selectImage(OWNER, outfit, spec);
	setImage("toy/$OWNER/$outfit/${image.image}.jpg");
	return image.tags;
};
def selectImageSet = { domme, specs ->
	def matches = IMAGEDATA()
		.find({ d -> d.domme == domme })
		.sets.findAll({ s -> specs.every({ spec -> selectImage(domme, s.set, spec)})});
	return matches[getRandom(matches.size())];
};
def dress = { specs ->
	def outfit = loadString("toy.owner.outfit");
	def outfitTime = loadInteger("toy.owner.outfitTime");
	if (outfitTime > getTime() - 7200) { // Recent, check
		def prev = IMAGEDATA()
			.find({ d -> d.domme == OWNER })
			.sets.find({ s -> s.set == outfit });
		if (specs.every({ spec -> selectImage(OWNER, prev.set, spec)})) {
			return outfit;
		}
	}
	outfit = selectImageSet(OWNER, specs);
	if (!outfit) {
		showPopup("No outfit for $OWNER : $specs");
	}
	save("toy.owner.outfit", outfit.set);
	save("toy.owner.outfitTime", getTime());
};
// Utils
def localTimeOffset = {
	return java.time.ZoneId.systemDefault()
		.getRules()
		.getOffset(java.time.Instant.now())
		.getTotalSeconds();
};
def localTimeOf = { s ->
	java.time.LocalDateTime.ofInstant(
			java.time.Instant.ofEpochSecond(s), java.time.ZoneId.systemDefault())
}
def localTime = {
	// A float between 4.0 (4am) and 28.0 (4am)
	def wallclock = ((getTime() + localTimeOffset()) % DAY) / HOUR;
	if (wallclock < 4) {
		wallclock += 24;
	}
	return wallclock;
};
def getDay = { (int)(getTime() / DAY) * DAY };
def has = {i -> loadBoolean("toys.$i") == true};
def likes = {i -> loadBoolean("fetish.$i") == true};
def can = {i -> loadBoolean("toy.permission.$i") == true};
def is = {i -> loadBoolean("toy.state.$i") == true};
def set = {i, s -> save("toy.state.$i", s)};
def positioned = { i -> loadString("toy.position") == i };
def getPunish = { loadInteger("toy.punishment"); };
def adjustPunish = { p -> save("toy.punishment", Math.max(getPunish() + (int)p, 0)); };
def sessionAborted = null;
def gagText = { t, p ->
	if (!is(GAGGED)) return t;
	return t.split(/\s+/)
		.collect {
			'm' * getRandom((int)Math.max(1.0, it.length() * 1.0)) +
			'p' * getRandom((int)Math.max(1.0, it.length() * 0.4)) +
			'h' * getRandom((int)Math.max(1.0, it.length() * 0.8))
		}
	.join(" ")
		.capitalize() + " ($p)";
};
def showButtonG = { s, p, t = null ->
	return t != null ? showButton(gagText(s, p), t) : showButton(gagText(s, p));
};
def present = { imageSpec, texts ->
	if (texts) {
		show(texts.collect {
			t -> t[getRandom(t.size())]
		}.join(" ").capitalize());
	}
	if (imageSpec) {
		return showImage(imageSpec);
	}
	return null;
};
def showButtonGT = { s, p, t, pc ->
	def tt = showButton(gagText(s, p), t);
	if (tt == t) {
		present(null, [
				["Don't keep me waiting!", "Hurry up!", "Quicker, toy!"]]);
		def pt = showButton(gagText(s, p));
		adjustPunish(pt * pc);
		return pt + tt;
	}
	return tt;
};

def harden = { imageSpec ->
	present([DRESSED], [
			["Take that cock...", "Hand on penis..."],
			["stroke it, slowly...", "slow strokes..."],
			["don't edge...", "no edging..."],
			["and do NOT cum.", "and definitely no cumming."]]);
	if (showButtonG("Hard, mistress", "hard", 60) == 60) {
		present(null, [
				["What's taking so long!?", "Come on!", "Don't disappoint me."],
				["Slap it about a bit!.", "Get it hard, now!", "Pinch your nipples."]]);
		showButtonGT("Hard, mistress", "hard", 60, 0.5);
	}
};
def expose = { imageSpec ->
	if (!is(NAKED)) {
		present(imageSpec, [
				["Get that cock out, toy;", "Let's see that cock of mine."],
				["I want to torment it.", "It's playtime!"]]);
		wait(10);
	}
};
def mightCum = { time ->
	if (showButtonG("Sorry, mistress, I'm cumming without permission", "cumming", time) < time) {
		playBackgroundSound(null);
		sessionAborted = CUM;
		present(null, [
				["Bah!", "Pfft. I'm very disappointed in you."],
				["Ruin it.", "Don't touch it."]]);
		adjustPunish(100);
		wait(10);
		present([DRESSED], [["Clean up your mess!"]]);
		showButtonG("Yes, mistress", "ok");
		wait(10);
		showButtonG("Cleaned up, mistress, back", "back");
		return true;
	}
	return false;
};
def edge = { amount, imageSpec ->
	def allowedTime = 128;
	(getRandom(amount) + 2).times {
		if (sessionAborted) return;
		present(imageSpec, [
				["Stroke to edge now, toy...", "Edge!"],
				["Don't cum.", "No cumming.", "No accidents though."]]);
		showButtonGT("Edging, mistress", "edging", allowedTime + 20, 1);
		if (getRandom(2) == 1) {
			present(imageSpec, [
					["Hold it...", "And hold...", "Keeping going..."]]);
			if (mightCum(getRandom(20) + 5)) return;
		}
		present(imageSpec, [
				["Hands off!", "Stop!"]]);
		if (mightCum(getRandom(5) + 5)) return;
		allowedTime /= 2;
	};
};
def strokes = { amount, imageSpec ->
	present(imageSpec, [
			["Stroke to the beat, toy.", "Follow the beat.", "Beat it!"],
			["No cumming unless I say so...", "Don't cum without my say so,"],
			["Tell me if you get too close.", "so tell me if you're edging.", "I don't want any messes."]]);
	final BEATS = [
		// bpm:30, len:60 ],
		[ bpm:90, len:45 ],
		[ bpm:165, len:30 ],
		[ bpm:180, len:30 ],
		[ bpm:240, len:20 ],
		];
	def sto = loadInteger("toy.strokeTeaseOffset");
	def edges = 0;
	(getRandom(amount) + 5).times {
		if (sessionAborted) return;
		def beatNo = getRandom(BEATS.size());
		def beat = BEATS[beatNo];
		playBackgroundSound("toy/${beat.bpm}bpm.mp3", 10); // Lots, to cover offset
		def len = getRandom(java.lang.Math.max(1, beat.len + (sto * beatNo)));
		if (showButtonG("Edging, mistress", "edging", len) < len) {
			sto -= 1;
			edges += 1;
			playBackgroundSound(null);
			switch (getRandom(3)) {
				case 0:
					present(imageSpec, [
							["Stop!", "Let go!", "Hands off!"]]);
					if (mightCum(getRandom(8) + 10)) return;
					break;
				case 1:
					present(imageSpec, [
							["Careful now...", "No accidents..."],
							["slow it down...", "slowly now..."]]);
					playBackgroundSound("toy/30bpm.mp3");
					if (mightCum(getRandom(20) + 5)) return;
				case 2:
					switch(getSelectedValue("Would you like to cum, toy?", [
								gagText("Please, mistress, may I cum!?", "yes"),
								gagText("No, mistress, please torment me more!", "no")
					])) {
						case 0:
							if (can(CUM)) {
								present(imageSpec, [
										["Maybe...", "Perhaps.", "We'll see."]]);
							}
							else {
								present(imageSpec, [
										["No you may not!", "Nope.", "Not a chance."]]);
								adjustPunish(5);
							}
							break;
						case 1:
							present(imageSpec, [
									["Good boy.", "Very well.", "OK then!"]]);
							adjustPunish(-5);
							break;
					}
					if (mightCum(getRandom(8) + 5)) return;
			}
			present(imageSpec, [
					["Back to stroking, toy...", "Get to it again...."],
					["follow the beat..."],
					["no accidents.", "and concentrate."]]);
		}
		else {
			playBackgroundSound(null);
		}
	}
	if (edges == 0) {
		sto += 1;
	}
	save("toy.strokeTeaseOffset", sto);
}

// Pre-tease
def preRelease = {
	if (!is(CHASTE)) return;
	present([DRESSED], [
			["I'm feeling generous, toy...", "Well, that's not good to me..."],
			["let's get that chastity device off.", "take your chastity device off."]]);
	showButtonG("Yes, mistress", "ok");
	wait(15);
	set(CHASTE, false);
	showButtonGT("Thank you, mistress", "ok", 80, 1);
};
def preEdge = {
	if (is(CHASTE)) return;
	expose([DRESSED]);
	harden([DRESSED]);
	edge(4, [DRESSED]);
	present([DRESSED], [
			["And relax...", "Hands off..."],
			["cool down a little.", "but keep it hard for me!", "for now!"]]);
	wait(getRandom(5) + 5);
};
def preGag = {
	if (is(GAGGED)) return;
	if (!has(BALLGAG)) return;
	present([DRESSED], [
			["Go fetch your gag, toy...", "Bring me your gag, toy..."],
			["Quickly!", "Hurry back!"]]);
	showButton("Yes, mistress");
	show(null);
	wait(10);
	showButtonGT("Back, mistress", "back", 50, 2);
	present([DRESSED], [
			["Good boy.", "Very good."],
			["Put it on..."],
			["Nice and tight.", "Tight!"],
			["I don't want to a hear a word from you.", "A quiet toy is a good toy."]]);
	set(GAGGED, true);
	showButtonGT("Gagged, mistress", "gagged", 20, 2);
	return 1.2;
};
def preClamps = {
	if (is(CLAMPED)) return;
	present([DRESSED],
			likes(PAIN) ? [
			["We both like to see you suffer.", "Pain is fun."],
			["Isn't that right, toy?", "Don't you agree?"]]
			: [
			["I'm sorry, toy,"],
			["but seeing you suffer is too much fun.", "but I need to find my amusement somewhere."]]);
	wait(10);
	present([DRESSED],[
			["Go put your nipple clamps on...", "I want those nipples clamped..."],
			["but on your way back...", "no walking though..."],
			["crawl, down on all fours.", "on your knees."]]);
	showButtonG("Yes, mistress", "ok");
	show(null);
	wait(10);
	set(CLAMPED, true);
	showButtonGT("Back, mistress", "back", 60, 1);
	present([DRESSED], [
			["On your knees,", "Kneel before me"],
			["let me see.", "hands behind your back."]]);
	wait(getRandom(10) + 5);
	getRandom(4).times {
		present([DRESSED], [
				["Pull them tight.", "Pull them!"]]);
		wait(getRandom(10) + 5);
		if (getRandom(5) == 0) {
			present(null, [
					["Tighter!", "Harder!"]]);
			wait(getRandom(10) + 2);
			present(null, [
					["Haha!", "Ooo, they must hurt.", "Do they hurt?"]]);
			wait(3);
		}
		present(null, [
				["And release.", "Let go."]]);
		wait(getRandom(5) + 3);
	};
	return 1.8;
};
def preCollar = {
	if (is(COLLARED)) return;
	if (!has(COLLAR)) return;
	present([DRESSED], [
			["You look underdressed, toy.", "A toy without a collar doesn't look right."],
			["Go put your collar on", "I want a collar around your neck"],
			["and crawl back like the slutty puppy dog you are.", "and kneel before me."]]);
	showButtonG("Yes, mistress", "ok");
	show(null);
	wait(10);
	set(COLLARED, true);
	showButtonGT("Back, mistress", "back", 60, 1);
	return 1.1;
};
def preStrip = { imageSpec = [DRESSED] ->
	if (is(NAKED)) return;
	present(imageSpec, [
			["Clothes off!", "Get naked, slut!"]]);
	wait(10);
	present([DRESSED], [
			["All of them off!", "And the rest!", "Keep going."]]);
	set(NAKED, true);
	showButtonGT("Naked, mistress", "naked", 60, 5);
	(getRandom(2) + 1).times {
		switch (getRandom(2)) {
			case 0:
				present(null, [
						["Stand up straight,", "On your feet,"],
						["hands behind your head,", "arms up,", "hands high up,"],
						["let me see you properly.", "let's see what we have.", "I want a good view."]]);
				break;
			case 1:
				present(null, [
						["Turn around,", "Spin"],
						["slowly", "nice and slow."]]);
				break;
			case 2:
				present(null, [
						["Very good. Now...", "I see..."],
						["on your knees before me,", "kneel,"],
						["don't move those hands.", "hands still."]]);
				break;
		}
		wait(10);
	};
	return 1.1;
};

// Post
def postEdge = {
	if (is(CHASTE)) return;
	if (!can(EDGE)) return;
	edge(6, [TEASE]);
};
def postCum = {
	if (is(CHASTE)) return;
	present([TEASE], [
			["How about I let you cum?", "Maybe I should let you cum."],
			["Would you like that?", "Let some of that frustration out?"]]);
	wait(getRandom(5) + 5);
	if (!can(CUM)) {
		present([TEASE], [
				["Or not.", "No, not right now.", "Maybe later.", "Not yet."]]);
		wait(getRandom(5) + 5);
		return;
	}
};
def chastity = { pre ->
	if (is(CHASTE)) return;
	if (!has(CHASTITY)) return;
	if (pre) {
		present([DRESSED,TEASE], [
				["Fun time is over for you.", "You'd have enough pleasure lately, my turn."]]);
	}
	else {
		present([TEASE], [
				["I can't keep an eye on you all time.", "It's not that I don't trust you."],
				["But...", "I just like to be sure."]]);
	}
	wait(getRandom(5) + 10);
	present([DRESSED,TEASE], [
			["Go to your room,", "Run along now,"],
			["get your chastity device and"],
			["lock it on.", "get that cock secured away."],
			["Bring back the key.", "I want the key of course."]]);
	wait(10);
	show(null);
	showButtonGT("Locked, mistress. Here's the key.", "locked", 180, 1);
	set(CHASTE, true);
	present([DRESSED,TEASE], [
			["Good boy.", "Thank you, toy."]]);
	wait(5);
}
def preChastity = {
	chastity(true);
}
def postChastity = {
	chastity(false);
};

// Play
def playStrokes = {
	preRelease();
	harden([TITS]);
	strokes(15, [TITS]);
};
def playEdges = {
	preRelease();
	harden([TITS]);
	edge(6, [TITS]);
};
def playNothing = {
	(getRandom(5) + 4).times {
		def tags = showImage([TITS]).intersect(
				[ASS, CROP, BOOTS, PUSSY, SSSH]);
		Collections.shuffle(tags);
		if (tags.isEmpty()) {
			show(null);
		}
		else {
			switch (tags[0]) {
				case ASS:
					if (!is(GAGGED))
						present(null, [
								["Come closer,", "Don't be shy,"],
								["kiss it!", "two kisses on each cheek."]]);
					break;
				case CROP:
					present(null, [
							["You know what this is for?", "Good boys get rewards, bad ones getting a beating.", "Would you like your ass a darker shade?"]]);
					break;
				case BOOTS:
					if (is(GAGGED))
						present(null, [
								["I know you'd like to worship them.", "Too bad that tongue can't be put to good use."]]);
					else
						break;
				case PUSSY:
					if (is(GAGGED))
						present(null, [
								["I know you'd like to pleasure me.", "Too bad that tongue can't be put to good use."]]);
					else
						present(null, [
								["How about you start licking it?", "How much would like your tongue in there?"]]);
					break;
				case SSSH:
					present(null, [
							["Quiet now.", "Sssssh.", "Patience."]]);
					break;
				default:
					show(null);
			}
		}
		wait(getRandom(10) + 10);
	};
};

// Session
def sessionSummon = { imageSpec ->
	final limit = 5;
	final timeMax = 10;

	for (def n = 1; n <= limit; n++) {
		switch (n) {
			case limit:
				present(imageSpec, [
						["TOY!", "SLAVE!", "SLUT!"],
						["Last chance!", "Final warning!"]]);
				adjustPunish(5);
				break;
			case limit - 1:
			case limit - 2:
				present(imageSpec, [
						["Toy!", "Slave!", "Slut!"],
						["Where are you!?", "Get yourself here, now!"]]);
				break;
			default:
				present(imageSpec, [
						["Toy!", "Slave!", "Slut!"]]);
				break;
		}
		playBackgroundSound(n == limit ? "shortwhip.wav" : "bell.wav");
		if (showButton("Yes, Miss?", timeMax) < timeMax) {
			return true;
		};
	}
	setImage(null);
	show(null);
	adjustPunish(5);
	return false;
};
def sessionPlay = {
	def play = { amount, activities ->
		(getRandom(amount) + 1).times {
			if (!sessionAborted) {
				activities[getRandom(activities.size())]();
			}
		};
	};
	play(3, [preRelease, preEdge, preGag, preClamps, preCollar, preStrip]);
	play(3, [playStrokes, playEdges, playNothing]);
	play(2, [postEdge, postCum, postChastity]);
};
def sessionRelease = { goodToy ->
	if (goodToy) {
		present([DRESSED], [
				["Ahhh,", "OK,"],
				["I'm done with you for now.", "That was fun... for me at least."]]);
	}
	else {
		present([DRESSED], [
				["I don't ask much of you, toy."]]);
	}
	wait(getRandom(10) + 5);
	if (is(CUFFED) || is(COLLARED) || is(CLAMPED) || is(GAGGED)) {
		if (!goodToy) {
			present([DRESSED], [
					["I should leave you like that.", "I suppose you still want letting free?"],
					["Maybe.", "Let me ponder on it."]]);
			wait(getRandom(20) + 20);
		}
		present([DRESSED], [
				["You may release yourself", "Free yourself"]]);
		wait(getRandom(5) + 5);
		set(CUFFED, false);
		set(COLLARED, false);
		set(CLAMPED, false);
		set(GAGGED, false);
	}
	if (is(NAKED)) {
		present([DRESSED], [
				["Put some clothes back on.", "Cover yourself up!"]]);
		wait(getRandom(10) + 15);
		set(NAKED, false);
	}
	if (goodToy) {
		present([DRESSED], [
				["Off you go.", "You may leave."]]);
	}
	else {
		present([DRESSED], [
				["Get out of my sight.", "Go!"]]);
	}
	wait(10);
	setImage(null);
	sessionAborted = null;
	if (goodToy) {
		adjustPunish(-20);
	}
	show(null);
};
def playtime = {
	dress([[DRESSED,nTEASE],[DRESSED,TEASE],[TITS]]);
	if (sessionSummon([DRESSED,nTEASE])) {
		sessionPlay();
		sessionRelease(sessionAborted == null);
	}
	else {
		adjustPunish(25);
	}
}
def bedtime = {
	dress([[LINGERIE,nTITS]]);
	if (sessionSummon([LINGERIE,nTITS])) {
		preStrip([LINGERIE,nTITS]);
		present([LINGERIE,nTITS], [
				["Very good, toy.", "OK"],
				["Bedtime!", "Off to bed with you!", "Bed! Now!"]]);
		showButtonG("Good night, mistress", "night");
	}
	exit();
};

// 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(7) + 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 setupPlans = {
	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 setDefault = { prop, val ->
	if (loadString(prop) == null) {
		save(prop, val);
	}
};
def leaveNote = { msg, instr ->
	save("toy.note", msg);
	save("toy.noteInstr", instr);
};
def readNote = {
	leaveNote(null, null);
};
def plannedCheck = { plan ->
	return (getTime() > loadInteger("toy.plan.${plan}.${START}") && getTime() < loadInteger("toy.plan.${plan}.${END}"));
}
def beginPlan = { plan ->
	dress([[DRESSED,nTEASE], [DRESSED,TEASE]]);
	save("toy.owner.outfitTime", loadInteger("toy.plan.${plan}.${END}"));
	if (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?" ]]);
		wait(10);
		if (has(CHASTITY) && !is(CHASTE)) {
			postChastity();
		}
		present([DRESSED,TEASE], [
				[ "Back later!", "See you soon, toy" ]]);
		wait(5);
		return;
	}
	else if (has(CHASTITY)) {
		leaveNote("I want you in chastity until I return!", CHASTE);
	}
	adjustPunish(5);
};
// Initial - basic checks and defaults
def setupInitial = {
	if (loadInteger("toy.version") == null) {
		// Welcome
	}
	save("toy.version", VERSION);
	setDefault("toy.strokeTeaseOffset", 0);
	setDefault("toy.punishment", 0);
	setupPlans();
};
def setupShowState = {
	show(
			[CHASTE, COLLARED, CUFFED, CLAMPED, GAGGED, NAKED].collect {
				def v = is(it);
				return "$it: $v\n".capitalize()
			}.join());
	showButton("OK");
	show(
			[BALLGAG, COLLAR, CLAMPS, CHASTITY].collect {
				def v = has(it);
				return "$it: $v\n".capitalize()
			}.join());
	showButton("OK");
	show(
			[BONDAGE, CBT, CHORES, PAIN].collect {
				def v = likes(it);
				return "$it: $v\n".capitalize()
			}.join());
	showButton("OK");
};
def setupShowCalendar = {
	show(
			[LUNCH, SHOPPING, PARTY].collect {
				def s = loadInteger("toy.plan.${it}.${START}");
				def f = loadString("toy.plan.${it}.${FRIEND}");
				def timeStr = localTimeOf(s).format(soonFormatter);
				return "$it with $f on $timeStr.\n".capitalize();
			}.join());
	showButton("OK");
};

// GO!
setupInitial();
def getDayNum = { Math.floorDiv(getTime() + localTimeOffset() - 14400, 86400) };
def getAvail = { dayNum -> loadInteger("toy.availability.$dayNum") ?: 0 };
def addAvail = { amount ->
	def dayNum = getDayNum();
	save("toy.availability.$dayNum", getAvail(dayNum) + amount);
};
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)) {
	setImage(null);
	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);
	}
	if (sessionSummon([DRESSED])) {
		present([DRESSED], [["Hello, toy!"], ["I'm back home now."]]);
		wait(10);
		setImage(null);
	}
}
else {
	leaveNote(null, null);
}

final cycleTime = 6;
while (true) {
	if (showButton("Please, Miss?", cycleTime) < cycleTime) {
		switch (getSelectedValue("Yes, toy?", [
					"Status",
					"Calendar",
					"Play",
					"Plan begin",
					"Back"
		])) {
			case 0: setupShowState(); break;
			case 1: setupShowCalendar(); break;
			case 2: playtime(); break;
			case 3: beginPlan(LUNCH); exit();
			case 4: return "toy";
		}
	}
	else if (localTime() > 25.75) { // 1:45am
		bedtime();
	}
	else if (plannedCheck(LUNCH)) {
		beginPlan(LUNCH);
		exit();
	}
	else if (plannedCheck(SHOPPING)) {
		beginPlan(SHOPPING);
		exit();
	}
	else if (plannedCheck(PARTY)) {
		beginPlan(PARTY);
		exit();
	}
	else if (getRandom(1000) == 0) {
		playtime();
	}
	addAvail(cycleTime);
}