summaryrefslogtreecommitdiff
path: root/scripts/toy/play.groovy
blob: f30f19cad987b10bc57e33ecf450bb437e97bc70 (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
{ toy ->
	toy.metaClass.sessionPlay {
		if (stateIs(CHASTE)) sessionToys[CHASTITY] = getTime();
		def playScope = [
			'randRange': { min, max -> randRange(min, max) },
			'currentPunishment': { getPunish() },
			'sessionAborted': { return sessionAborted },
			'can': { return can(it) },
			'has': { return has(it) },
			'is': { return stateIs(it) },
			'likes': { return likes(it) },
			'punishMultiple': (float)1.0,
			'prop': load('toy') ?: [:]
		];
		def apply = { activitity, use = null ->
			if (!activitity) return;
			def val = activitity.func();
			playBackgroundSound(null);
			if (use && val instanceof Number) {
				use(val);
			}
		};
		def interval = { activities ->
			if (activities) {
				apply(activities[getRandom(activities.size())], null);
			}
		};
		def funcMap = [
			'use': [
				'punishMultiply': { val ->
					if (val) {
						playScope.punishMultiple *= val;
					}
				},
				'punishApply': { val ->
					if (val) {
						adjustPunish(-val * playScope.punishMultiple);
					}
				}
			],
			'select': [
				'repeat': { amount, activities, intervals, use = null ->
					amount.times {
						if (!sessionAborted) {
							apply(activities[getRandom(activities.size())], use);
							interval(intervals);
						}
					};
				},
				'take': { amount, activities, intervals, use = null ->
					Collections.shuffle(activities);
					activities.take(amount).each {
						if (!sessionAborted) {
							apply(it, use);
							interval(intervals);
						}
					};
				}
			],
			'activities': activityList
		];
		// Expand wildcards
		final expandWildcards = { list ->
			list
				.findAll { a -> a && a.startsWith("*") }
				.collect { a -> list.remove(a); return a.substring(1).split(",") }
				.collectMany { tags -> activityList.values().findAll(matchTags(tags))*.name }
				.forEach { a -> list.add(a) };
		}
		DOMME.sessions*.phases*.activities*.forEach { expandWildcards(it); }
		DOMME.sessions*.phases*.intervals*.forEach { expandWildcards(it); }
		final eval = { expr -> Eval.me('toy', playScope, expr.toString()) };
		if (stateIs("DEBUG")) {
			// Check everything in DOMME evaluates and resolves
			final checkIsFunc = { group, name, s = { f -> f } ->
				if (!name) return;
				show("checking $group:$name is a function");
				if (!(s(funcMap[group][name]) instanceof Closure)) {
					showPopup("$group:$name is not a function");
				}
			}
			final checkEval = { expr ->
				show("checking $expr evaluates");
				eval(expr);
			};
			DOMME.sessions.forEach { session ->
				checkEval(session.require ?: true);
				checkEval(session.probability);
				session.phases.forEach { phase ->
					checkEval(phase.require ?: true);
					checkIsFunc("select", phase.select);
					checkEval(phase.number ?: 1);
					phase.activities.forEach { a ->
						checkIsFunc("activities", a, { f -> f.func });
					}
					(phase.intervals ?: []).forEach { i ->
						checkIsFunc("activities", i, { f -> f.func });
					}
					checkIsFunc("use", phase.use);
				};
			};
		}
		final sessions = DOMME.sessions.findAll { s -> eval(s.require ?: true) };
		final probabilities = sessions.withIndex().collect { s, idx -> [idx] * s.probability }.sum();
		final session = sessions[probabilities[getRandom(probabilities.size)]];
		// Change if required
		dress(session.phases
			.collect { phase -> phase.activities + phase.intervals }
			.flatten()
			.unique()
			.findAll { a -> a }
			.collectMany { a -> activityList[a].images }
			.unique(), {
				present(null, [
						[ "Wait there while I change..."]]);
				pause(5);
				showButtonG("Yes, ${dommeTitle()}", "ok");
				showImage(null);
				pause(randRange(40, 60));
			});
		session.phases.forEach { phase ->
			if (eval(phase.require ?: true)) {
				funcMap.select[phase.select ?: 'take'](eval(phase.number ?: 1),
						(phase.activities ?: []).collect { f -> funcMap.activities[f] },
						(phase.intervals ?: []).collect { f -> funcMap.activities[f] },
						funcMap.use[phase.use]);
			}
		};
	};

	toy.metaClass.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."]]);
			pause(getRandom(10) + 5);
			postChastity();
		}
		pause(getRandom(10) + 5);
		if (!goodToy && anyToys()) {
			present([DRESSED], [
					["I should leave you like that.", "I suppose you still want letting free?"],
					["Maybe.", "Let me ponder on it."]]);
			pause(getRandom(20) + 20);
		}
		removeAllToys([DRESSED], getPunish());
		if (stateIs(NAKED)) {
			if (goodToy && getRandom(1)) {
				present([DRESSED], [
						["Put some clothes back on.", "Cover yourself up!"]]);
				pause(getRandom(10) + 15);
				set(NAKED, false);
			}
			else {
				present([DRESSED], [
						["No clothes now for a while,", "Keep those clothes off,"],
						["you don't get clothes until I say.", "I like seeing you naked."]]);
				addEvent(REDRESS, getTime() + 600 + getRandom(1200), "redress");
				showButtonG("Yes, ${dommeTitle()}", "ok");
			}
		}
		if (goodToy) {
			present([DRESSED], [
					["Off you go.", "You may leave."]]);
		}
		else {
			present([DRESSED], [
					["Get out of my sight.", "Go!"]]);
			removeEvent(CUM);
			revokePermission(CUM);
		}
		pause(10);
		save("toy.lastPlay", getTime());
		showLounge();
		setSessionAbort();
		sessionToys.clear();
		if (goodToy) {
			adjustPunish(-20);
		}
		else {
			setProp(DISAPPOINT, getProp(DISAPPOINT, loadI, 0) + 1);
		}
		show(null);
	};

	toy.metaClass.playWait {
		present([DRESSED,nTEASE,nKNEEL,nSQUAT], [
				["Hello,", "Hi,", "Hey there,"],
				["toy.", "slut.", "slave."],
				["On your knees,", "On the floor,", "Down... at my feet,",],
				["wait there.", "wait patiently.", "don't move."],
				["I'll be with you shortly.", "I won't be a moment."]]);
		showButtonGT("Yes, ${dommeTitle()}", "ok", 10, 1);
		showLounge();
		show(null);
		pause(20 + getRandom(20));
	};

	toy.metaClass.playSchedule {
		if (getAway()) return;
		final lastPlay = loadInteger("toy.lastPlay") ?: 0;
		if (lastPlay < getTime() - (4 * HOUR)) {
			addEventIfMissing(PLAY, getTime() + 120 + getRandom(480), PLAY, true); // 2-10mins
		}
		else {
			addEventIfMissing(PLAY, getTime() + 1200 + getRandom(5400), PLAY, false); // 20-90mins
		}
	};

	toy.metaClass.playEvent { rt = true, first = true ->
		if (!rt || getAway()) {
			playSchedule();
			return;
		}
		dress([[DRESSED,nTEASE],[DRESSED,TEASE],[TITS],[STOOD]]);
		if (sessionSummon([DRESSED,nTEASE])) {
			if (first.asBoolean()) {
				playWait();
			}
			executeTrigger("playStarted");
			sessionPlay();
			sessionRelease(sessionAborted == null);
			executeTrigger("playEnded", sessionAborted);
		}
		else {
			adjustPunish(25);
		}
		playSchedule();
		showLounge();
	}

	toy.addNamedEvent(toy.PLAY, { name, arg, schedTime, rt -> toy.playEvent(rt, arg) });
	toy.playSchedule();
	return null;
}