From d6d0690fd61f623ee6657b6aa44ddcb6002e1552 Mon Sep 17 00:00:00 2001
From: DCoded <dcoded@live.com>
Date: Sun, 13 Sep 2020 23:13:54 -0400
Subject: [PATCH] DOMified killSlave

---
 js/003-data/gameVariableData.js               |   2 -
 src/arcologyBuilding/markets.js               |   5 +-
 .../backwardsCompatibility.js                 |   9 +
 src/facilities/pit/killSlave.js               | 316 ++++++++++++++++++
 src/facilities/pit/pit.css                    |   3 +
 src/facilities/pit/pit.js                     |   2 +-
 src/js/removeSlave.js                         |   4 +-
 src/pregmod/killSlave.tw                      |   4 +
 src/uncategorized/repBudget.tw                |   2 +-
 src/uncategorized/scheduledEvent.tw           |   2 +-
 src/uncategorized/slaveInteract.tw            |   2 +-
 11 files changed, 342 insertions(+), 9 deletions(-)
 create mode 100644 src/facilities/pit/killSlave.js

diff --git a/js/003-data/gameVariableData.js b/js/003-data/gameVariableData.js
index 82c45310136..093a984185e 100644
--- a/js/003-data/gameVariableData.js
+++ b/js/003-data/gameVariableData.js
@@ -88,7 +88,6 @@ App.Data.defaultGameStateVariables = {
 	headGirlTrainsSkills: 1,
 	imageChoice: 1,
 	inbreeding: 1,
-	killChoice: -1,
 	lineSeparations: 1,
 	limitFamilies: 0,
 	makeDicks: 0,
@@ -472,7 +471,6 @@ App.Data.resetOnNGPlus = {
 	farmyardShows: 0,
 	DJignoresFlaws: 0,
 	DJnoSex: 0,
-	slaveFightingBG: 0,
 	HGSlaveSuccess: 0,
 	unMadam: 0,
 	madamCashBonus: 0,
diff --git a/src/arcologyBuilding/markets.js b/src/arcologyBuilding/markets.js
index 80db25abc4c..c043189430e 100644
--- a/src/arcologyBuilding/markets.js
+++ b/src/arcologyBuilding/markets.js
@@ -109,13 +109,14 @@ App.Arcology.Cell.Market = class extends App.Arcology.Cell.BaseCell {
 					V.pit = {
 						name: "the Pit",
 
-						bodyguardFights: false,
 						animal: false,
 						animalType: null,
 						audience: "none",
+						bodyguardFights: false,
+						fought: 0,
 						lethal: false,
+						slaveFightingBodyguard: null,
 						virginities: "neither",
-						fought: 0,
 					};
 				}, cost
 			));
diff --git a/src/data/backwardsCompatibility/backwardsCompatibility.js b/src/data/backwardsCompatibility/backwardsCompatibility.js
index 90660a1af5d..552d2eeb9fd 100644
--- a/src/data/backwardsCompatibility/backwardsCompatibility.js
+++ b/src/data/backwardsCompatibility/backwardsCompatibility.js
@@ -328,6 +328,15 @@ App.Update.globalVariables = function(node) {
 		V.pit.fought = V.pit.fought || V.pitFought || false;
 	}
 
+	if (V.slaveFightingBG) {
+		V.pit.slaveFightingBodyguard = V.slaveFightingBG;
+		delete V.slaveFightingBG;
+	}
+
+	if (V.killChoice) {
+		delete V.killChoice;
+	}
+
 	// Incubator
 	if (V.incubatorImprintSetting === 0) { V.incubatorImprintSetting = "trust"; }
 
diff --git a/src/facilities/pit/killSlave.js b/src/facilities/pit/killSlave.js
new file mode 100644
index 00000000000..d360b5b3418
--- /dev/null
+++ b/src/facilities/pit/killSlave.js
@@ -0,0 +1,316 @@
+// putting this here because it's somewhat related to the Pit and because I don't know where else to put it
+// the current filing system is an absolute mess
+
+/**
+ *
+ * @param {App.Entity.SlaveState} slave
+ */
+App.Facilities.Pit.killSlave = function(slave) {
+	// MARK: Declarations
+
+	const
+		frag = new DocumentFragment,
+		{He, His, he, him, his, daughter, himself} = getPronouns(slave);
+
+	let
+		weapon = "handgun",
+		qualifiedFS = false;
+
+	if (V.arcologies[0].FSRomanRevivalist !== "unset") {
+		qualifiedFS = true;
+		weapon = "gladius";
+	} else if (V.arcologies[0].FSNeoImperialist !== "unset") {
+		qualifiedFS = true;
+		weapon = "estoc";
+	} else if (V.arcologies[0].FSAztecRevivalist !== "unset") {
+		qualifiedFS = true;
+		weapon = "Tecpatl";
+	} else if (V.arcologies[0].FSEgyptianRevivalist !== "unset") {
+		qualifiedFS = true;
+		weapon = "kopesh";
+	} else if (V.arcologies[0].FSEdoRevivalist !== "unset") {
+		qualifiedFS = true;
+		weapon = "katana";
+	} else if (V.arcologies[0].FSArabianRevivalist !== "unset") {
+		qualifiedFS = true;
+		weapon = "scimitar";
+	} else if (V.arcologies[0].FSChineseRevivalist !== "unset") {
+		qualifiedFS = true;
+		weapon = "jian";
+	}
+
+	frag.appendChild(intro());
+
+	if (V.pit.slaveFightingBodyguard) {
+		frag.appendChild(plannedFight());
+	} else {
+		frag.appendChild(links());
+	}
+
+	return frag;
+
+
+
+	// MARK: Text Functions
+
+	function intro() {
+		const mainDiv = document.createElement("div");
+
+		mainDiv.append(`You ${canWalk(slave) ?
+			`call ${slave.slaveName}` :
+			`have ${slave.slaveName} brought`} into your office. `);
+
+		if (slave.fuckdoll) {
+			mainDiv.append(`It's hard to tell the expression on the Fuckdoll's face, but your guess is it's `);
+
+			if (slave.fetish !== "mindbroken") {
+				mainDiv.append(`one of `);
+
+				if (slave.devotion > 50) {
+					mainDiv.append(`adoration. `);
+				} else if (slave.devotion > 20) {
+					mainDiv.append(`calm. `);
+				} else if (slave.devotion > -20) {
+					mainDiv.append(`apprehension. `);
+				} else {
+					mainDiv.append(`hatred. `);
+				}
+			} else {
+				mainDiv.append(`blank. `);
+			}
+		} else {
+			mainDiv.append(`${He} looks at you `);
+
+			if (slave.devotion > 50) {
+				mainDiv.append(`with adoration`);
+			} else if (slave.devotion > 20) {
+				mainDiv.append(`calmly`);
+			} else if (slave.devotion > -20) {
+				mainDiv.append(`with apprehension`);
+			} else {
+				mainDiv.append(`with hatred`);
+			}
+
+			mainDiv.append(` and waits for you to continue. `);
+		}
+
+		mainDiv.append(`You tell ${him} that you've gotten tired of having ${him} around and that you decided it is time to get rid of ${him}. `);
+
+		if (slave.fuckdoll) {
+			mainDiv.append(`${He} simply nods, not being able to see `);	// can fuckdolls nod their heads?
+		} else {
+			if (slave.fetish !== "mindbroken") {
+				mainDiv.append(`${His} expression changes to one of `);
+
+				if (slave.devotion > 50) {
+					mainDiv.append(`pure sorrow`);
+				} else if (slave.devotion > 20) {
+					mainDiv.append(`sadness`);
+				} else {
+					mainDiv.append(`relief`);
+				}
+
+				mainDiv.append(` until `);
+			} else {
+				mainDiv.append(`${He} just nods dumbly and continues to watch you with a vacant expression, even as `);
+			}
+		}
+
+		mainDiv.append(`you ${canHear(slave) ? `quietly ` : ``}reach behind your desk and pull out your trusty ${weapon}`);
+
+		if (!slave.fuckdoll && canSee(slave)) {
+			if (slave.fetish !== "mindbroken") {
+				mainDiv.append(`, at which point abject fear fills ${his} face. ${He} immediately ${hasBothLegs(slave) ? `drops to ${his} knees and ` : ``}begins openly begging for you to show mercy.`);
+			} else {
+				mainDiv.append(`, to which ${he} still doesn't respond. `);
+			}
+		} else {
+			mainDiv.append(`. `);
+		}
+
+		return mainDiv;
+	}
+
+	function links() {
+		const
+			mainDiv = App.UI.DOM.makeElement("div", '', "kill-slave-options"),
+
+			links = [],
+			disableReasons = [],
+
+			combatLinkText = `Let ${him} win ${his} life in combat`;
+
+		mainDiv.id = "kill-scene";
+
+		links.push(
+			App.UI.DOM.link(`Kill ${him}`, () => {
+				refresh(mainDiv, kill);
+			}),
+			App.UI.DOM.link(`Have mercy on ${him}`, () => {
+				refresh(mainDiv, mercy);
+			}),
+		);
+
+		if (slave.fuckdoll) {
+			disableReasons.push(`Fuckdolls cannot properly fight`);
+		}
+
+		if (slave.fetish === "mindbroken") {
+			disableReasons.push(`Mindbroken slaves cannot properly fight`);
+		}
+
+		if (!S.Bodyguard) {
+			disableReasons.push(`You must have a bodyguard for ${slave.slaveName} to fight`);
+		}
+
+		if (!V.pit) {
+			disableReasons.push(`You must first build a pit for combat`);
+		} else {
+			if (!V.pit.lethal) {
+				disableReasons.push(`You must allow lethal fights in ${V.pit.name}`);
+			}
+		}
+
+		if (V.pit &&
+			V.pit.lethal &&
+			S.Bodyguard &&
+			slave.assignment !== Job.BODYGUARD &&
+			!slave.fuckdoll &&
+			slave.fetish !== "mindbroken") {
+			links.push(App.UI.DOM.link(combatLinkText, () => {
+				refresh(mainDiv, combat);
+			}));
+		} else {
+			links.push(App.UI.DOM.disabledLink(combatLinkText, disableReasons));
+		}
+
+		mainDiv.appendChild(App.UI.DOM.generateLinksStrip(links));
+
+		return mainDiv;
+	}
+
+	function kill() {
+		const mainDiv = document.createElement("div");
+
+		if (!slave.fuckdoll && slave.fetish !== "mindbroken") {
+			mainDiv.append(`You simply smile at ${him} and tell ${him} not to worry `);
+		} else {
+			mainDiv.append(`You say nothing `);
+		}
+
+		mainDiv.append(`as you continue ${qualifiedFS ?
+			`sharpening your ${weapon}.` :
+			`threading on a suppressor.`} ${slave.slaveName} ${!slave.fuckdoll && slave.fetish !== "mindbroken" ?
+			`gives an audible sigh of relief and begins to thank you profusely, though ${his} thanks are cut short as the sound of` :
+			`continues to stand there ${slave.fetish === "mindbroken" ? `dumbly` : ``} until the sound of`} ${qualifiedFS ?
+			`a sharp edge slicing through flesh` :
+			`a suppressed gunshot`} rings through the room. You have another servant clean up the mess as you continue with what you were previously doing.`);
+
+		mainDiv.appendChild(relations());
+
+		removeSlave(slave);
+
+		return mainDiv;
+	}
+
+	function mercy() {
+		const
+			mainDiv = document.createElement("div"),
+			devotionSpan = App.UI.DOM.makeElement("span", `thanking you again`, ["devotion", "inc"]),
+			trustSpan = App.UI.DOM.makeElement("span", `sobbing`, ["trust", "dec"]);
+
+		if (!slave.fuckdoll && slave.fetish !== "mindbroken") {
+			mainDiv.append(`You make a show of considering sparing ${his} life, then, with a heavy sigh, unbuckle your pants and sit down at your desk. You beckon to ${him}, and ${he} just about trips over ${himself} as ${he} hastily makes ${his} way over to you. ${His} blowjob isn't the best you've ever had, ${him} `, trustSpan, ` as much as ${he} is; but ${his} enthusiasm more than makes up for it. After you finish deep in ${his} throat, ${he} sits back and wipes away ${his} tears, sniffling and `, devotionSpan, ` for giving ${him} another chance.`);
+		} else {
+			mainDiv.append(`You change your mind, and with a wave of your hand, send ${slave.slaveName} back to $his duties. Maybe some other time.`);
+		}
+
+		slave.devotion = slave.devotion < 30 ? 30 : slave.devotion += 30;
+		slave.trust -= 100;
+
+		return mainDiv;
+	}
+
+	function combat() {
+		const mainDiv = document.createElement("div");
+
+		mainDiv.append(`You tell ${him} you'll let your bodyguard decide ${his} fate — if ${he} wants to live, ${he}'ll have to beat ${S.Bodyguard.slaveName} in hand-to-hand combat in ${V.pit.name}.`);
+
+		if (slave.skill.combat) {
+			mainDiv.append(`${He} nods ${his} head and straightens up, as though mentally preparing ${himself} for the fight for ${his} life.`);
+		} else {
+			mainDiv.append(`The fear on ${his} face is palpable, though ${he} nods slowly and agrees, not seeing another choice.`);
+		}
+
+		V.pit.slaveFightingBodyguard = slave.ID;
+		V.pit.animalFights = false;
+
+		return mainDiv;
+	}
+
+	function relations() {
+		const
+			mainDiv = App.UI.DOM.makeElement("div", '', "kill-slave-relations"),
+
+			sisters = [],
+			daughters = [];
+
+		let
+			mother = null,
+			father = null;
+
+		for (const target of V.slaves) {
+			if (slave.mother === target.ID) {
+				mother = target.ID;
+				break;
+			}
+
+			if (slave.father === target.ID) {
+				father = target.ID;
+				break;
+			}
+		}
+
+		if (mother) {
+			const devotionSpan = App.UI.DOM.makeElement("span", 'grief-stricken', ["devotion", "dec"]);
+
+			mother = getSlave(mother);
+
+			mainDiv.append(`${His} mother ${mother.slaveName} is `, devotionSpan, ` that you would take ${his} ${daughter} from ${getPronouns(mother).him}.`);
+
+			mother.devotion -= 30;
+		}
+
+		if (father) {
+			const devotionSpan = App.UI.DOM.makeElement("span", 'grief-stricken', ["devotion", "dec"]);
+
+			father = getSlave(father);
+
+			mainDiv.append(`${His} father ${father.slaveName} is `, devotionSpan, ` that you would take ${his} ${daughter} from ${getPronouns(father).him}.`);
+
+			father.devotion -= 30;
+		}
+
+		return mainDiv;
+	}
+
+	function plannedFight() {
+		const mainDiv = document.createElement("div");
+
+		mainDiv.append(`${!slave.fuckdoll && slave.fetish !== "mindbroken" ? `You abruptly cut ${his} begging short once you` : `You change your mind as you suddenly`} realize ${getSlave(V.pit.slaveFightingBodyguard).slaveName} is already fighting your bodyguard ${S.Bodyguard.slaveName} for ${his} life this week.`);
+
+		App.UI.DOM.appendNewElement("div", mainDiv, App.UI.DOM.passageLink(`Cancel the fight`, V.returnTo, () => {
+			V.pit.slaveFightingBodyguard = null;
+		}), ["kill-slave-cancel"]);
+
+		return mainDiv;
+	}
+
+
+
+	// MARK: Helper Functions
+
+	function refresh(el, handler) {
+		$(el).empty().append(handler());
+	}
+};
diff --git a/src/facilities/pit/pit.css b/src/facilities/pit/pit.css
index 4458c224ec8..7e6e7269394 100644
--- a/src/facilities/pit/pit.css
+++ b/src/facilities/pit/pit.css
@@ -2,6 +2,9 @@
 	margin-bottom: 1em;
 }
 
+.kill-slave-options,
+.kill-slave-relations,
+.kill-slave-cancel,
 .pit-assign,
 .pit-rename {
 	margin-top: 1em;
diff --git a/src/facilities/pit/pit.js b/src/facilities/pit/pit.js
index a8d69cc6169..82123468ddf 100644
--- a/src/facilities/pit/pit.js
+++ b/src/facilities/pit/pit.js
@@ -33,7 +33,7 @@ App.Facilities.Pit.pit = function() {
 	App.UI.DOM.appendNewElement("div", frag, intro(), "pit-intro");
 	App.UI.DOM.appendNewElement("div", frag, audience());
 
-	if (V.killChoice !== 2) {
+	if (!V.pit.slaveFightingBodyguard) {
 		App.UI.DOM.appendNewElement("div", frag, fighters());
 		App.UI.DOM.appendNewElement("div", frag, lethality());
 
diff --git a/src/js/removeSlave.js b/src/js/removeSlave.js
index 4a1ebfe82c9..d99856d2fe1 100644
--- a/src/js/removeSlave.js
+++ b/src/js/removeSlave.js
@@ -107,7 +107,9 @@ globalThis.removeSlave = function(slave) {
 		});
 
 		/* remove from Pit fighters list, if needed */
-		V.fighterIDs.delete(AS_ID);
+		if (V.pit.fighterIDs) {
+			V.pit.fighterIDs.delete(AS_ID);
+		}
 
 		/* remove from Coursing Association, if needed */
 		if (V.LurcherID === AS_ID) {
diff --git a/src/pregmod/killSlave.tw b/src/pregmod/killSlave.tw
index c90b2b9862a..cd9bd1a0a49 100644
--- a/src/pregmod/killSlave.tw
+++ b/src/pregmod/killSlave.tw
@@ -1,5 +1,8 @@
 :: KillSlave [nobr]
 
+<<includeDOM App.Facilities.Pit.killSlave($activeSlave)>>
+
+/*
 <<set _qualifiedFS = []>>
 <<if $arcologies[0].FSRomanRevivalist != "unset">>
 	<<set _qualifiedFS.push("roman revivalist"), _weapon = 'gladius'>>
@@ -254,3 +257,4 @@ you <<if canHear($activeSlave)>>quietly <</if>>reach behind your desk and pull o
 	<</if>>
 	realize $slaveFightingBG.slaveName is already fighting your bodyguard _S.Bodyguard.slaveName for $his life this week. [[Cancel the fight|KillSlave][$killChoice = -1]]
 <</if>>
+*/
diff --git a/src/uncategorized/repBudget.tw b/src/uncategorized/repBudget.tw
index e82a2f4c5ab..cda30a1c977 100644
--- a/src/uncategorized/repBudget.tw
+++ b/src/uncategorized/repBudget.tw
@@ -82,7 +82,7 @@
 		<br>
 	<</if>>
 
-	<<print budgetLine("pit", "<<if $pit>>[[capFirstChar($pitName)|Pit][$nextButton = \"Back to Budget\", $nextLink = \"Rep Budget\"]]<<else>><<= capFirstChar($pitName)>><</if>> ($fighterIDs.length slaves)")>>
+	<<print budgetLine("pit", "<<if $pit>>[[capFirstChar($pitName)|Pit][$nextButton = \"Back to Budget\", $nextLink = \"Rep Budget\"]]<<else>><<= capFirstChar($pitName)>><</if>> ($pit.fighterIDs.length slaves)")>>
 
 	<<print budgetLine("servantsQuarters", "<<if $servantsQuarters>>[[Servants' Quarters][$nextButton = \"Back to Budget\", $nextLink = \"Rep Budget\"]]<<else>>Servants' Quarters<</if>> (_L.servantsQuarters slaves)")>>
 
diff --git a/src/uncategorized/scheduledEvent.tw b/src/uncategorized/scheduledEvent.tw
index aa01cb8c37d..038ae36cefc 100644
--- a/src/uncategorized/scheduledEvent.tw
+++ b/src/uncategorized/scheduledEvent.tw
@@ -148,7 +148,7 @@
 	<<goto "SE coursing">>
 <<elseif $policies.raidingMercenaries == 1 && ($week > ($raided + 6))>>
 	<<goto "SE raiding">>
-<<elseif ($pit.fighterIDs.length > 1 && !$pit.bodyguardFights) || ($pit.fighterIDs.length > 0 && ($BodyguardID !== 0 && $pit.bodyguardFights || $pit.animalFights)) || $killChoice === 2 || !$pit.fought>>
+<<elseif ($pit.fighterIDs.length > 1 && !$pit.bodyguardFights) || ($pit.fighterIDs.length > 0 && ($BodyguardID !== 0 && $pit.bodyguardFights || $pit.animalFights)) || $pit.slaveFightingBodyguard || !$pit.fought>>
 	<<if $pit.lethal == true>><<goto "SE lethal pit">><<else>><<goto "SE nonlethal pit">><</if>>
 <<elseif ($bioreactorPerfectedID != 0) && ($bioreactorsAnnounced != 1)>>
 	<<goto "P bioreactor perfected">>
diff --git a/src/uncategorized/slaveInteract.tw b/src/uncategorized/slaveInteract.tw
index 90d552b63c2..834cb53fa9b 100644
--- a/src/uncategorized/slaveInteract.tw
+++ b/src/uncategorized/slaveInteract.tw
@@ -345,7 +345,7 @@
 					<</if>>
 				<</if>>
 				<<link "Discard $him" "Discard Confirm">><</link>>
-				<<if $seeExtreme == 1 && $arcologies[0].FSPaternalist == "unset" && $cheatMode>>
+				<<if $seeExtreme == 1 && $arcologies[0].FSPaternalist == "unset">>
 					| <<link "Threaten $his life" "KillSlave">><</link>>
 				<</if>>
 			<<else>>
-- 
GitLab