diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2019-02-01 18:44:17 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2019-02-01 20:46:58 +0000 |
commit | 74d99351514c0415c5b79e149a16e4e9ed4bd697 (patch) | |
tree | 539ec74fa63ff13ba21eee3f6caa7df6c39bc405 | |
parent | Load the DOMME object (diff) | |
download | toy-74d99351514c0415c5b79e149a16e4e9ed4bd697.zip |
Whole new dynamic session play code
-rw-r--r-- | scripts/toy.groovy | 154 |
1 files changed, 110 insertions, 44 deletions
diff --git a/scripts/toy.groovy b/scripts/toy.groovy index 42b78f1..aa089b5 100644 --- a/scripts/toy.groovy +++ b/scripts/toy.groovy @@ -1072,62 +1072,128 @@ def sessionSummon = { imageSpec -> }; def sessionPlay = { if (is(CHASTE)) sessionToys[CHASTITY] = getTime(); - def ph = (float)1.0; - def pm = { val -> - if (val) { - ph *= val; - } - }; - def ap = { val -> - if (val) { - adjustPunish(-val * ph); - } - }; + def playScope = [ + 'randRange': randRange, + 'currentPunishment': getPunish, + 'sessionAborted': { return sessionAborted }, + 'can': can, + 'has': has, + 'is': is, + 'likes': likes, + 'punishMultiple': (float)1.0, + 'prop': load('toy') ?: [:] + ]; def apply = { activitity, use = null -> if (!activitity) return; - def val = (Float)activitity(); + def val = activitity(); playBackgroundSound(null); - if (use) { + if (use && val instanceof Number) { use(val); } }; - def interval = { - def activities = [null, intClamps, intSqueeze]; - apply(activities[getRandom(activities.size())], null); + def interval = { activities -> + if (activities) { + apply(activities[getRandom(activities.size())], null); + } }; - def playRepeat = { amount, activities, use = null -> - amount.times { - if (!sessionAborted) { - apply(activities[getRandom(activities.size())], use); + def funcMap = [ + 'use': [ + 'punishMultiply': { val -> + if (val) { + playScope.punishMultiple *= val; + } + }, + 'punishApply': { val -> + if (val) { + adjustPunish(-val * playScope.punishMultiple); + } } - }; - }; - def playTake = { amount, activities, use = null -> - Collections.shuffle(activities); - activities.take(amount).each { - if (!sessionAborted) { - apply(it, use); + ], + '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': [ + 'intSqueeze': intSqueeze, + 'intClamps': intClamps, + 'preRelease': preRelease, + 'preChastity': preChastity, + 'preEdge': preEdge, + 'preGag': preGag, + 'preStrip': preStrip, + 'preCollar': preCollar, + 'preClamps': preClamps, + 'playStrokes': playStrokes, + 'playEdges': playEdges, + 'playKneel': playKneel, + 'playCbt': playCbt, + 'playClamps': playClamps, + 'playNothing': playNothing, + 'playBondage': playBondage, + 'postCum': postCum, + 'postPermitCum': { + addEventIfMissing(CUM, getTime() + (DAY * 2) + getRandom(DAY * 2), PERMIT, CUM); // 2 - 4 days from now + }, + 'postChastity': postChastity + ] + ]; + final eval = { expr -> Eval.me('toy', playScope, expr.toString()) }; + if (is("DEBUG")) { + // Check everything in DOMME evaluates and resolves + final checkIsFunc = { group, name -> + if (!name) return; + show("checking $group:$name is a function"); + if (!(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); + } + (phase.intervals ?: []).forEach { i -> + checkIsFunc("activities", i); + } + checkIsFunc("use", phase.use); + }; }; - }; - def cp = getPunish(); - if (cp > 50) { - // Punish only: bad toy - preChastity(); - def pr = 1 + getRandom(2 + (int)(cp / 100)); - playRepeat(pr, [preGag, preClamps, preCollar, preStrip], pm); - playRepeat(pr, [playKneel, playCbt, playClamps, playNothing], ap); - playTake(pr, [playBondage, playCbt, playClamps]); } - else { - // Sub pleasure: good toy - playRepeat(1 + getRandom(3), [preRelease, preEdge, preGag, preClamps, preCollar, preStrip]); - playRepeat(1 + getRandom(3), [playStrokes, playEdges], interval); - playTake(getRandom(3), [postCum, postChastity]); - if (!sessionAborted && !can(CUM)) { - addEventIfMissing(CUM, getTime() + (DAY * 2) + getRandom(DAY * 2), PERMIT, CUM); // 2 - 4 days from now + final sessions = DOMME.sessions.findAll { s -> eval(s.require ?: true) }; + final probabilities = sessions.withIndex().collect { s, idx -> [idx] * s.probability }.sum(); + final sessionIdx = probabilities[getRandom(probabilities.size)]; + sessions[sessionIdx].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]); } - } + }; }; def sessionRelease = { goodToy -> if (goodToy) { |