Stephan Fuchs před 11 měsíci
rodič
revize
b37a5ad722

+ 4 - 0
glife.code-workspace

@@ -42,6 +42,10 @@
 			{
 				"filePath": "sugarcube\\src\\playerCharacter\\mood\\moodlets.js",
 				"group": "Default"
+			},
+			{
+				"filePath": "sugarcube\\src\\macros\\0macros.twee-config.json",
+				"group": "Default"
 			}
 		]
 	}

+ 130 - 140
sugarcube/src/activities/sleep/sleep.tw

@@ -1,69 +1,4 @@
 /*:: sleep_simple
-<<if $location_var[$here][0] == 'simple'>>
-	<!-- !! to avoid sleeping the whole day I decide to calculate the duration of the sleep in advance-->
-	<!-- !! the quality of the sleep depends on many factors, so the time of sleep can be modify later, especially the part when the time of sleep is shortened-->
-	<<setinit $varsleep['time_to_full'] = (100 - $pc.pcs_sleep) * 6>>
-	<!-- !! fully exhausted Sveta can recover in 420 minutes = 7 hours of sleep-->
-	<!-- !! healthy Sveta can hardly sleep more then 10 hours = 600 minutes-->
-	<!-- !! so we can add about 3 hours to time to full as a limit-->
-	<<setinit $varsleep['time_to_full'] += 150 + rand(0,60)>>
-	<<setinit $varsleep['time_now'] = $time.daystart * 1440 + $time.hour * 60 + $time.minutes>>
-	<<setinit $varsleep['alarm_time_end'] = $time.daystart * 1440 + $timerEnd * 60 + $timerEndM>>
-	<<if $varsleep['time_now'] >= $varsleep['alarm_time_end']>>
-		<<setinit $varsleep['alarm_time_end'] += 1440>>
-
-	<</if>>
-	<<setinit $varsleep['alarm_time'] = $time.daystart * 1440 + $timer * 60 + $timerM>>
-	<<if $varsleep['time_now'] >= $varsleep['alarm_time']>>
-		<<setinit $varsleep['alarm_time'] += 1440>>
-
-	<</if>>
-	<<if getvar("$budilnikOn") == 1>>
-		<<setinit $varsleep['minutes to wakeup'] = Math.min(varsleep['time_to_full'], varsleep['alarm_time'] - varsleep['time_now'])>>
-		<<setinit $varsleep['minutes to wakeup end'] = Math.min(varsleep['time_to_full'], varsleep['alarm_time_end'] - varsleep['time_now'])>>
-	<<else>>
-		<<setinit $varsleep['minutes to wakeup'] = $varsleep['time_to_full']>>
-		<<setinit $varsleep['minutes to wakeup end'] = $varsleep['time_to_full']>>
-	<</if>>
-	<<set $pc.isSleeping= 1>>
-	<<warn 'JUMP MARKER ENCOUNTERED: :loopson_sleep'>>
-	<<set $time.minutes += 1>>
-	<<set $stime += 1>>
-	<<if getvar("$recuperation") == 0>>
-		<<setn $pc.pcs_health += 5>>
-
-	<</if>>
-	<<if getvar("$stime") >= 60>>
-		<<set $stime = 0>>
-		<<set $pc.pcs_sleep += 15>>
-	<</if>>
-	<<setinit $varsleep['minutes to wakeup'] -= 1>>
-	<<setinit $varsleep['minutes to wakeup end'] -= 1>>
-	<<if getvar("$alarm_holiday") == 1 and $time.isSchoolHoliday == 1>>
-		<!-- !! use weekend time alarm-->
-		<<setinit $varsleep['alarm_time'] = $time.daystart * 1440 + $timerEnd * 60 + $timerEndM>>
-		<<if $varsleep['minutes to wakeup end'] > 0>>
-			<<warn 'JUMP COMMAND ENCOUNTERED: jump loopson_sleep'>>
-
-		<</if>>
-	<<elseif $time.weekday > 5>>
-		<!-- !! use weeken time alarm-->
-		<<setinit $varsleep['alarm_time'] = $time.daystart * 1440 + $timerEnd * 60 + $timerEndM>>
-		<<if $varsleep['minutes to wakeup end'] > 0>>
-			<<warn 'JUMP COMMAND ENCOUNTERED: jump loopson_sleep'>>
-
-		<</if>>
-	<<else>>
-		<<setinit $varsleep['alarm_time'] = $time.daystart * 1440 + $timer * 60 + $timerM>>
-		<<if $varsleep['minutes to wakeup'] > 0>>
-			<<warn 'JUMP COMMAND ENCOUNTERED: jump loopson_sleep'>>
-
-		<</if>>
-	<</if>>
-	<<setinit $varsleep['time_now'] = $time.daystart * 1440 + $time.hour * 60 + $time.minutes>>
-	<<set $pc.isSleeping= 0>>
-<</if>>
-
 	<<if getvar("$succubusQW") == 2>>
 		<<actCLA '$sleep_txt'>>
 			<<if getvar("$clo_flag['bed']") == 0>>
@@ -107,33 +42,141 @@
 		<<set $sleep_txt to null>>
 	<</if>>
 <</if>>
-<<if $location_var[$here][0] == 'nap_bed'>>
-	<<actCLA 'Take a nap (1:00)'>>
-		<<if $pc.pcs_sleep >= 10 and $pc.pcs_sleep <= 90>>
-			<<set $InSleep = 1>>
-			<<set $pc.pcs_sleep += 10>>
-			<<set $pc.pcs_health += 5>>
-			<<set $time.minutes += 60>>
-			You sleep about an hour.
-			<<actCLA 'Get up'>>
-				<<set $InSleep = 0>> <<gt $location>>
-			<</actCLA>>
-		<<elseif $pc.pcs_sleep < 10>>
-			<<gt 'sleep' 'sleep'>>
-		<<else>>
-			<<set $time.minutes += 5>>
-			You are not tired enough to sleep, even for a short nap.
-			<<actCLA 'Get up'>>
-				<<gt $location>>
-			<</actCLA>>
-		<</if>>
-	<</actCLA>>
-<</if>> */
+ */
+:: sleep_scripts[script]
+setup.moodletGroups ??= {};
+setup.moodletGroups.sleep = {
+	accumulationMode: 2
+}
+setup.moodlets ??= {};
+setup.moodlets.sleep_1 = {
+	title: "Well rested",
+	group: 'sleep',
+	description: '',
+	effect: 10,
+	timeMode: 1,
+	duration: 240
+};
+
+setup.moodlets.sleep_m1 = {
+	title: "Sleepy",
+	group: 'sleep',
+	description: '',
+	effect: -5,
+	timeMode: 1,
+	duration: 240
+};
+
+setup.moodlets.sleep_m2 = {
+	title: "Too little sleep",
+	group: 'sleep',
+	description: '',
+	effect: -10,
+	timeMode: 1,
+	duration: 240
+};
+
+setup.moodlets.sleep_m3 = {
+	title: "Way too little sleep",
+	group: 'sleep',
+	description: '',
+	effect: -20,
+	timeMode: 1,
+	duration: 240
+};
+
 :: sleep[event]
 	<!--<<if $loc == 'nichBedroomServant'>>
 		<<gs 'nichBedroomServant' 'sleepEvents'>>
 	<</if>>-->
 	<<set $pc.isSleeping= 1>>
+	<<eventExecute 'dream'>>
+	<hr/>
+	<<eventExecute 'wakeup'>>
+
+	<<if _eventTime.used >= 60>>
+		<<gs 'sleep_apply_wake_moodlet'>>
+	<</if>>
+
+	<<gs 'wake'>>
+
+:: wakeup_events[wakeup_events]
+
+	<<set _desiredSleepLength = _eventTime.requested || 720>>
+	<<set _desiredWakeupTime = $time.nowWithMinutesOffset(_desiredSleepLength)>>
+
+	<<event `10000-_desiredSleepLength`>>
+		<!-- This is the default event that fires if you had the requested amount of sleep -->
+		<<set _eventTime.used = _desiredSleepLength>>
+		<<addtime _eventTime.used>>
+		<<set $pc.isSleeping= 0>>
+		<p>You had more than enough sleep and wake up by yourself.</p>
+		<<eventFired>>
+	<</event>>
+
+	<<if getvar("$budilnikOn") == 1>>
+		<<set _nextAlarmClockAlarm = setup.alarmClockNextAlarm()>>
+		<<set _minutesTilAlarmClock = (_nextAlarmClockAlarm.getTime() - $time.now.getTime()) / 60000>>
+		<<if _nextAlarmClockAlarm.getTime() < _desiredWakeupTime.getTime()>>
+			<<event `10000-_minutesTilAlarmClock`>>
+				<!-- This is the alarm clock event -->
+				<<set _eventTime.used = _minutesTilAlarmClock>>
+				<<addtime _eventTime.used>>
+				<<set $pc.isSleeping= 0>>
+				<p>Your alarm clock wakes you up as scheduled.</p>
+				<<eventFired>>
+			<</event>>
+			<<log 'Sleep: Alarm Clock activated and event queued'>>
+		<<else>>
+			<<log 'Sleep: Alarm Clock activated but not within sleep duration'>>
+		<</if>>
+	<<else>>
+		<<log 'Sleep: Alarm Clock not activated'>>
+	<</if>>
+	
+	<<set _minutesTilHungerZero = $pc.minutesTilStat('hunger',0)>>
+	<<if _desiredSleepLength > _minutesTilHungerZero>>
+		<<event `10000-_minutesTilHungerZero`>>
+			<!-- This is the hunger event -->
+			<<set _eventTime.used = _minutesTilHungerZero>>
+			<<addtime _eventTime.used>>
+			<<set $pc.isSleeping= 0>>
+			<p>The painful emptiness of your stomach wakes you up. You really need to eat something.</p>
+			<<eventFired>>
+		<</event>>
+		<<log 'Sleep: Hunger activated and event queued'>>
+	<<else>>
+		<<log 'Sleep: Hunger to zero not within sleep duration'>>
+	<</if>>
+	
+	<<set _minutesTilThirstZero = $pc.minutesTilStat('thirst',0)>>
+	<<if _desiredSleepLength > _minutesTilThirstZero>>
+		<<event `10000-_minutesTilThirstZero`>>
+			<!-- This is the thirst event -->
+			<<set _eventTime.used = _minutesTilThirstZero>>
+			<<addtime _eventTime.used>>
+			<<set $pc.isSleeping= 0>>
+			<p>The uncomfortable dryness of your mouth wakey you up. You really need to drink something.</p>
+			<<eventFired>>
+		<</event>>
+		<<log 'Sleep: Thirst activated and event queued'>>
+	<<else>>
+		<<log 'Sleep: Thirst to zero not within sleep duration'>>
+	<</if>>
+	
+:: sleep_apply_wake_moodlet[include]
+	<<if $pc.pcs_sleep == 100>>
+		<<mood 'sleep_1'>>
+	<<elseif $pc.pcs_sleep >= 90>>
+		<<mood 'sleep_m1'>>
+	<<elseif $pc.pcs_sleep >= 70>>
+		<<mood 'sleep_m2'>>
+	<<else>>
+		<<mood 'sleep_m3'>>
+	<</if>>
+	
+
+:: sleep_deprecated[deprecated]
 	<<gs 'dreams' 'start'>>
 
 	<<set _wake_up = undefined>>
@@ -161,44 +204,7 @@
 
 	<<set _iterationsLeft = 100>>
 	<<for ;!_wake_up && _iterationsLeft > 0;>>
-		<<set _iterationsLeft -= 1>>
-
-		<<set _minutesToSleep = rand(14,29)>>
-		<<if _alarm_time > 0>>
-			<<set _minutesToSleep = Math.min(_minutesToSleep, _alarm_time - _time_now)>>
-		<</if>>
-		/*<<debug>>
-			minutesToSleep: _minutesToSleep<br/>
-			timeNow: _time_now<br/>
-			alarmTime: _alarm_time<br/>
-			pcSleep: $pc.pcs_sleep
-		<</debug>>*/
-		<<set $time.minutes += _minutesToSleep>>
-		<<set _minutesSlept += _minutesToSleep>>
-		<<if _minutesSlept >= 60>>
-			<<set _minutesSlept -= 60>>
-			<<if $pc.pcs_sleep >= 100>>
-				<<setinit $pcs_condition['lack_of_sleep'] = 0>>
-			<<elseif getvar("$pcs_condition['lack_of_sleep']") > 0>>
-				<<setinit $pcs_condition['lack_of_sleep'] -= 1>>
-			<</if>>
-		<</if>>
 
-		<<if getvar("$recuperation") == 0>>
-			<<setn $pc.pcs_health += 5>>
-		<</if>>
-
-		<<set _time_now = $time.daystart * 1440 + $time.hour * 60 + $time.minutes>>
-		/*<<debug>>Update timeNow: _time_now<</debug>>*/
-
-		<<if _alarm_time >= 0 and _time_now >= _alarm_time>>
-			<<set _wake_up = 'alarm'>>
-		<<elseif $pc.pcs_sleep >= 100>>
-			<<set _extraSleep -= _minutesToSleep>>
-			<<if _extraSleep <= 0>>
-				<<set _wake_up = 'enough'>>
-			<</if>>
-		<</if>>
 		<!--
 			<<if $pc.vibratorin == 1>>
 				<<set $vtime += 1>>
@@ -241,22 +247,6 @@
 		<<set $pc.skinDailyPenalty -= 1>>
 	<</if>>
 
-	<<switch _wake_up>>
-		<<case 'alarm'>>
-			<<if $pc.pcs_sleep == 100>>
-				You wake up at <b><<time_current>></b>, just before your alarm goes off. You've had plenty of sleep.
-			<<elseif $pc.pcs_sleep >= 90>>
-				<<set $pc.mood -= 5>>
-				Your alarm goes off at <b><<time_current>></b>, and you've had plenty of sleep.
-			<<elseif $pc.pcs_sleep >= 70>>
-				<<set $pc.mood -= 10>>
-				Your alarm goes off at <b><<time_current>></b>, but you could do with some extra sleep.
-			<<else>>
-				<<set $pc.mood -= 20>>
-				Your alarm goes off at <b><<time_current>></b>, but you still feel way too tired.
-			<</if>>
-	<</switch>>
-
 
 	/*<<if getvar("$slept_in") == 1>>
 		You wake up at <b><<time_current>></b>, after sleeping-in a little longer than planned, but at least you've had plenty of sleep.

+ 7 - 4
sugarcube/src/autogenerated/unsorted/dreams.tw

@@ -1,7 +1,10 @@
-:: dreams
-<<set $here = 'dreams'>>
-<<set $ARGS = $location_var[$here]>>
-<<set $menu_off = 1>>
+:: dream_event[dream_events]
+<<event>>
+	<!-- Fire the standard-dream-event -->
+	<<gs 'dreams' 'start'>>
+<</event>>
+
+:: dreams[include]
 <<if $location_var[$here][0] == 'start'>>
 	<<if getvar("$stepdadqw") == 3>>
 		<<image "characters/pavlovsk/resident/vladimir/sex/bath_voyer_1.jpg">>