From 15eb8bd481bb764fbd3f5f261f34aefe69c968e0 Mon Sep 17 00:00:00 2001
From: Svornost <11434-svornost@users.noreply.gitgud.io>
Date: Mon, 24 May 2021 21:08:45 -0700
Subject: [PATCH] Busy Master Suite JS cleanup.

---
 src/events/RE/reBusyMasterSuite.js | 130 ++++++++++++++++-------------
 1 file changed, 72 insertions(+), 58 deletions(-)

diff --git a/src/events/RE/reBusyMasterSuite.js b/src/events/RE/reBusyMasterSuite.js
index d7bdfaf3b11..b8019a831df 100644
--- a/src/events/RE/reBusyMasterSuite.js
+++ b/src/events/RE/reBusyMasterSuite.js
@@ -38,7 +38,8 @@ App.Events.REBusyMasterSuite = class REBusyMasterSuite extends App.Events.BaseEv
 				}
 				return {slave: s, mode: options.pluck()};
 			});
-		const bottomSlave = msSlaves.find((s) => s.mode !== "none").slave;
+		const [participants, nonparticipants] = _.partition(msSlaves, s => s.mode !== "none");
+		const bottomSlave = participants.first().slave;
 		let r = [];
 
 		const {
@@ -65,61 +66,75 @@ App.Events.REBusyMasterSuite = class REBusyMasterSuite extends App.Events.BaseEv
 
 		App.Events.addParagraph(node, r);
 
+		/** helper function for train...identify the hole being penetrated by the next slave
+		 * @param {App.Entity.SlaveState} slave
+		 * @param {FC.SlaveActs} mode
+		 */
+		function hole(slave, mode) {
+			if (mode === "vaginal") {
+				if (slave.vagina > 2) {
+					return "loose pussy";
+				} else if (slave.vagina > 1) {
+					return "pussy";
+				} else {
+					return "tight pussy";
+				}
+			} else if (mode === "anal") {
+				if (slave.anus > 2) {
+					return "asspussy";
+				} else if (slave.anus > 1) {
+					return "asshole";
+				} else {
+					return "tight butt";
+				}
+			}
+		}
+
+		/** helper function for train...identify the tool being used by the next slave to penetrate this slave
+		 * @param {App.Entity.SlaveState} slave
+		 * @param {FC.SlaveActs} mode
+		 * @param {App.Entity.SlaveState} nextSlave
+		 */
+		function penetrator(slave, mode, nextSlave) {
+			let t = ``;
+			if (canPenetrate(nextSlave)) {
+				t += nextSlave.slaveName + "'s ";
+				if (nextSlave.dick > 3) {
+					t += "painfully big";
+				} else {
+					t = "hard";
+				}
+				t += " dick";
+			} else {
+				t += "a ";
+				const size = (mode === "vaginal" ? slave.vagina : slave.anus);
+				if (size > 2) {
+					t += "huge";
+				} else if (size > 1) {
+					t += "big";
+				} else {
+					t += "moderate";
+				}
+				t += " strap-on worn by " + nextSlave.slaveName;
+			}
+			return t;
+		}
+
 		App.Events.addParagraph(node, [
 			/* build the train from all participating slaves */
-			msSlaves.filter((s) => s.mode !== "none").reduce((acc, cur, i, arr) => {
+			participants.reduce((acc, cur, i, arr) => {
 				let r = ``;
 				const {mode, slave} = cur;
+				if (mode === "none") {
+					throw new Error("Non-participating slave is participating"); // impossible, but needed for typechecking
+				}
 				const nextSlave = (i + 1 >= arr.length) ? S.Concubine : arr[i + 1].slave;
-				let hole = () => {
-					if (mode === "vaginal") {
-						if (slave.vagina > 2) {
-							return "loose pussy";
-						} else if (slave.vagina > 1) {
-							return "pussy";
-						} else {
-							return "tight pussy";
-						}
-					} else if (mode === "anal") {
-						if (slave.anus > 2) {
-							return "asspussy";
-						} else if (slave.anus > 1) {
-							return "asshole";
-						} else {
-							return "tight butt";
-						}
-					}
-				};
-				let penetrator = () => {
-					let t = ``;
-					if (canPenetrate(nextSlave)) {
-						t += nextSlave.slaveName + "'s ";
-						if (nextSlave.dick > 3) {
-							t += "painfully big";
-						} else {
-							t = "hard";
-						}
-						t += " dick";
-					} else {
-						t += "a ";
-						const size = (mode === "vaginal" ? slave.vagina : slave.anus);
-						if (size > 2) {
-							t += "huge";
-						} else if (size > 1) {
-							t += "big";
-						} else {
-							t += "moderate";
-						}
-						t += " strap-on worn by " + nextSlave.slaveName;
-					}
-					return t;
-				};
 
 				if (i === 0) {
 					return r; /* bottom slave already accounted for */
 				} else if (i !== arr.length - 1) {
 					/* middle slaves */
-					r += `${slave.slaveName}'s ${hole()} is filled by ${penetrator()}, `;
+					r += `${slave.slaveName}'s ${hole(slave, mode)} is filled by ${penetrator(slave, mode, nextSlave)}, `;
 					if (nextSlave.belly >= 150000) {
 						r += `whose middle is so obscenely distended that ${slave.slaveName} is struggling to support it.`;
 					} else if (nextSlave.belly >= 10000 || nextSlave.weight >= 160) {
@@ -139,24 +154,23 @@ App.Events.REBusyMasterSuite = class REBusyMasterSuite extends App.Events.BaseEv
 					}
 				} else {
 					/* top slave */
-					r += `Finally, ${slave.slaveName}'s ${hole()} is filled by ${penetrator()}, who has paused ${his} thrusting to issue a preemptory order to the slaves to stay where they are, before turning to greet you cheerfully.`;
-				}
-				if (mode !== "none") {
-					seX(nextSlave, "penetrative", slave, mode, 1);
+					r += `Finally, ${slave.slaveName}'s ${hole(slave, mode)} is filled by ${penetrator(slave, mode, nextSlave)}, who has paused ${his} thrusting to issue a preemptory order to the slaves to stay where they are, before turning to greet you cheerfully.`;
 				}
+				seX(nextSlave, "penetrative", slave, mode, 1);
 				return acc + ` ` + r;
 			}, ``)
 		]);
 		/* and now describe what the non-participating slaves are doing */
-		const nonparticipants = msSlaves.filter((s) => s.mode === "none").map((s) => s.slave);
 		if (nonparticipants.length > 0) {
 			App.Events.addParagraph(node, [
-				`${toSentence(nonparticipants.map((s) => s.slaveName))} can't participate in the train, so ${S.Concubine.slaveName} has them busy lying under the slaves who are, offering what oral stimulation they can manage.`
+				`${toSentence(nonparticipants.map((s) => s.slave.slaveName))} can't participate in the train, so ${S.Concubine.slaveName} has them busy lying under the slaves who are, offering what oral stimulation they can manage.`
 			]);
-			nonparticipants.forEach((s) => actX(s, "oral"));
+			for (const s of nonparticipants) {
+				actX(s.slave, "oral");
+			}
 		}
 
-		let top = msSlaves.slice().reverse().find((s) => s.mode !== "none");
+		const top = participants.last();
 
 		/** @type {FC.SlaveActs|"none"} */
 		let concubineMode = "none";
@@ -239,12 +253,12 @@ App.Events.REBusyMasterSuite = class REBusyMasterSuite extends App.Events.BaseEv
 			if (concubineMode !== "none") {
 				seX(V.PC, "penetrative", S.Concubine, concubineMode);
 			}
-			msSlaves.forEach((s) => {
+			for (const s of msSlaves) {
 				s.slave.trust += 1;
 				if (s.mode !== "none") {
 					seX(V.PC, "penetrative", s.slave, s.mode);
 				}
-			});
+			}
 			if (canImpreg(bottomSlave, V.PC)) {
 				knockMeUp(bottomSlave, 10, 1, V.PC.ID);
 			}
@@ -306,10 +320,10 @@ App.Events.REBusyMasterSuite = class REBusyMasterSuite extends App.Events.BaseEv
 			r.push(`ass down near the foot of the bed. You climax, on occasion, but are enjoying yourself so immensely that you let the slaves continue the rotation until you're entirely spent, and they're entirely exhausted. You reach for a tablet to get some work done, in the center of a pile of sweaty, tired slaves, all of whom are resting with at least one body part in contact with their <span class="devotion inc">beloved</span> ${properMaster()}.`);
 			S.Concubine.devotion += 5;
 			seX(V.PC, "penetrative", S.Concubine, "oral");
-			msSlaves.forEach((s) => {
+			for (const s of msSlaves) {
 				s.slave.devotion += 1;
 				seX(V.PC, "penetrative", s.slave, "oral", 2);
-			});
+			}
 
 			App.Events.addParagraph(frag, r);
 			return frag;
-- 
GitLab