From 9b704206d13e38ca66f9b3c43335832243a38f72 Mon Sep 17 00:00:00 2001
From: lowercasedonkey <lowercasedonkey@gmail.com>
Date: Sat, 10 Jul 2021 15:25:26 -0400
Subject: [PATCH] betray

---
 .../nonRandom/daughters/pCoupBetrayal.js      | 107 ++++++++++--------
 src/events/timeGatedPlotEvent.js              |   2 +-
 2 files changed, 62 insertions(+), 47 deletions(-)

diff --git a/src/events/nonRandom/daughters/pCoupBetrayal.js b/src/events/nonRandom/daughters/pCoupBetrayal.js
index 34fb69e4988..afbae9ec880 100644
--- a/src/events/nonRandom/daughters/pCoupBetrayal.js
+++ b/src/events/nonRandom/daughters/pCoupBetrayal.js
@@ -1,24 +1,37 @@
-		:: P coup betrayal [nobr]
+App.Events.PCoupBetrayal = class PCoupBetrayal extends App.Events.BaseEvent {
+	eventPrerequisites() {
+		return [
+			() => V.collaboration === 1,
+			() => V.traitorType !== "trapper"
+		];
+	}
 
-		V.nextButton = "Continue", V.daughtersVictory = 1;
+	execute(node) {
+		let r = [];
+		const {He, he} = getPronouns(V.traitor ? V.traitor : {pronoun: App.Data.Pronouns.Kind.neutral});
 
-		_weeks = V.traitorWeeks-1, _pregWeeks = V.traitorWeeks-1, V.traitorWeeks = 0;
+		V.nextButton = "Continue";
+		V.daughtersVictory = 1;
 
-		WombProgress(V.traitor, _pregWeeks, _pregWeeks);
-			r.push(`/* In all cases should be done */`);
+		const _weeks = V.traitorWeeks-1;
+		const _pregWeeks = V.traitorWeeks-1;
+		V.traitorWeeks = 0;
+
+		if (V.traitor === 0) { // never happens, needed for typing
+			return node;
+		}
+
+		WombProgress(V.traitor, _pregWeeks, _pregWeeks); /* In all cases should be done */
 		WombUpdatePregVars(V.traitor);
-		if (WombBirthReady(V.traitor, V.traitor.pregData.normalBirth) > 0 ) {
-			r.push(`/* normal birth case, partial birthers not supported*/`);
-			V.traitor.preg = -1, V.traitor.counter.birthsTotal += WombBirthReady(V.traitor, V.traitor.pregData.normalBirth);
+		if (WombBirthReady(V.traitor, V.traitor.pregData.normalBirth) > 0 ) { /* normal birth case, partial birthers not supported*/
+			V.traitor.preg = -1;
+			V.traitor.counter.birthsTotal += WombBirthReady(V.traitor, V.traitor.pregData.normalBirth);
 			WombFlush(V.traitor);
-		} else {/* still pregnant slave */
-			V.traitor.preg = WombMaxPreg(V.traitor);
-			r.push(`/*most ready fetus is a base*/`);
-			V.traitor.pregWeek = WombMaxPreg(V.traitor);
-			r.push(`/*most ready fetus is a base*/`);
+		} else { /* still pregnant slave */
+			V.traitor.preg = WombMaxPreg(V.traitor); /* most ready fetus is a base*/
+			V.traitor.pregWeek = WombMaxPreg(V.traitor); /* most ready fetus is a base*/
 		}
-		SetBellySize(V.traitor);
-			r.push(`/*In any case it's useful to do.*/`);
+		SetBellySize(V.traitor); /* In any case it's useful to do.*/
 
 		if (V.traitor.bald !== 1) {
 			if (V.traitor.hLength < 150) {
@@ -27,23 +40,23 @@
 		}
 		ageSlaveWeeks(V.traitor, _weeks);
 
-		You are awakened in the middle of the night by a jolt that shakes the entire arcology, accompanied by a distant boom. It is followed by the wail of the arcology's alarm systems, and then finally by a faint crackle that grows to a constant chatter of gunfire. You rush to the video feeds to see what is going on. The Daughters of Liberty have not only succeeded in locking down your arcology with them outside of it, but have effectively cornered themselves against it. A PMC group has their retreat cut off and is steadily bleeding their numbers. It is a rather short, if not spectacular, battle.
+		r.push(`You are awakened in the middle of the night by a jolt that shakes the entire arcology, accompanied by a distant boom. It is followed by the wail of the arcology's alarm systems, and then finally by a faint crackle that grows to a constant chatter of gunfire. You rush to the video feeds to see what is going on. The Daughters of Liberty have not only succeeded in locking down your arcology with them outside of it, but have effectively cornered themselves against it. A PMC group has their retreat cut off and is steadily bleeding their numbers. It is a rather short, if not spectacular, battle.`);
 
-		<br><br>
+		App.Events.addParagraph(node, r);
+		r = [];
 
-		<span class="yellow">The Daughters of Liberty are utterly crushed.</span> V.arcologies[0].name has been slightly damaged in the crossfire, but even as the last pockets of resistance are cleaned up, your citizens begin repairs themselves. The effect on your reputation is <span class="green">immensely positive,</span> since you won without lifting a finger and the arcology's prosperity, if anything, was benefited. However, the PMCs took the lion's share of the loot.
+		r.push(`<span class="yellow">The Daughters of Liberty are utterly crushed.</span> ${V.arcologies[0].name} has been slightly damaged in the crossfire, but even as the last pockets of resistance are cleaned up, your citizens begin repairs themselves. The effect on your reputation is <span class="rep inc">immensely positive,</span> since you won without lifting a finger and the arcology's prosperity, if anything, was benefited. However, the PMCs took the lion's share of the loot.`);
 
 		cashX(-10000, "war");
 		V.arcologies[0].prosperity = Math.trunc(V.arcologies[0].prosperity*0.9);
 		repX(5000, "war");
 		V.daughtersVictory = 3;
-		V.desc = "a leftover banner bearing Daughters of Liberty insignia";
-		V.trinkets.push(V.desc);
+		V.trinkets.push("a leftover banner bearing Daughters of Liberty insignia");
 
-		<br><br>
+		App.Events.addParagraph(node, r);
+		r = [];
 
-		<<setLocalPronouns V.traitor>>
-		When V.traitor.slaveName finally manages to return to you, ${he} explains what happened. ${He} caught wind of the military contractors working in the area and succeeded in goading the Daughters of Liberty into attacking the supposed slaver troop. Once it became clear that the untrained ex-slaves and their saviors stood no chance against a coordinated force, they beat a hasty retreat for your arcology under the assumption that the codes you gave them would allow them a fortifiable position. But alas, they found nothing more than their demise.
+		r.push(`When ${V.traitor.slaveName} finally manages to return to you, ${he} explains what happened. ${He} caught wind of the military contractors working in the area and succeeded in goading the Daughters of Liberty into attacking the supposed slaver troop. Once it became clear that the untrained ex-slaves and their saviors stood no chance against a coordinated force, they beat a hasty retreat for your arcology under the assumption that the codes you gave them would allow them a fortifiable position. But alas, they found nothing more than their demise.`);
 
 		V.traitor.assignment = "rest";
 		if (V.traitorStats.PCpregSource > 0 && V.PC.preg > 0 && V.PC.pregSource === 0) {
@@ -55,48 +68,50 @@
 		if (V.traitorStats.PCfather > 0) {
 			V.PC.father = V.traitor.ID;
 		}
-		<<for _pca = 0; _pca < V.slaves.length; _pca++>>
-			if (V.traitorStats.traitorMother.includes(V.slaves[_pca].ID)) {
-				V.slaves[_pca].mother = V.traitor.ID;
+		for (const slave of V.slaves) {
+			if (V.traitorStats.traitorMother.includes(slave.ID)) {
+				slave.mother = V.traitor.ID;
 			}
-			if (V.traitorStats.traitorFather.includes(V.slaves[_pca].ID)) {
-				V.slaves[_pca].father = V.traitor.ID;
+			if (V.traitorStats.traitorFather.includes(slave.ID)) {
+				slave.father = V.traitor.ID;
 			}
-			if (V.traitorStats.traitorPregSources.includes(V.slaves[_pca].ID) && V.slaves[_pca].preg > 0 && V.slaves[_pca].pregSource === 0) {
-				V.slaves[_pca].pregSource = V.traitor.ID;
+			if (V.traitorStats.traitorPregSources.includes(slave.ID) && slave.preg > 0 && slave.pregSource === 0) {
+				slave.pregSource = V.traitor.ID;
 			}
-		<</for>>
+		}
 		if (V.incubator.capacity > 0) {
-			<<for _pca range V.incubator.tanks>>
+			for (const _pca of V.incubator.tanks) {
 				if (V.traitorStats.traitorMotherTank.includes(_pca.ID)) {
 					_pca.mother = V.traitor.ID;
 				}
 				if (V.traitorStats.traitorFatherTank.includes(_pca.ID)) {
 					_pca.father = V.traitor.ID;
 				}
-			<</for>>
+			}
 		}
 		if (V.nursery > 0) {
-			<<for _pca range V.cribs>>
+			for (const _pca of V.cribs) {
 				if (V.traitorStats.traitorMotherTank.includes(_pca.ID)) {
 					_pca.mother = V.traitor.ID;
 				}
 				if (V.traitorStats.traitorFatherTank.includes(_pca.ID)) {
 					_pca.father = V.traitor.ID;
 				}
-			<</for>>
+			}
 		}
 		if (V.traitorStats.boomerangBody > 0) {
-			_pca = V.slaveIndices[V.traitorStats.traitorBody];
-			if (def _pca) {
-				V.slaves[_pca].origBodyOwnerID = V.traitor.ID;
+			const _pca = getSlave(V.traitorStats.traitorBody);
+			if (_pca) {
+				_pca.origBodyOwnerID = V.traitor.ID;
 			}
 		}
-		<<for _pca = 0; _pca < V.slaves.length; _pca++>>
-			WombChangeID(V.slaves[_pca], V.traitor.missingParentTag, V.traitor.ID);
-			WombChangeGeneID(V.slaves[_pca], V.traitor.missingParentTag, V.traitor.ID);
-		<</for>>
-		newSlave(V.traitor);
-			r.push(`/* skip New Slave Intro */`);
-		V.traitor = 0, V.traitorStats = 0, V.traitorType = 0;
-
+		for (const slave of V.slaves) {
+			WombChangeID(slave, V.traitor.missingParentTag, V.traitor.ID);
+			WombChangeGeneID(slave, V.traitor.missingParentTag, V.traitor.ID);
+		}
+		newSlave(V.traitor); /* skip New Slave Intro */
+		V.traitor = 0;
+		V.traitorStats = 0;
+		V.traitorType = 0;
+	}
+};
diff --git a/src/events/timeGatedPlotEvent.js b/src/events/timeGatedPlotEvent.js
index a9a4503aee0..2fc48f934eb 100644
--- a/src/events/timeGatedPlotEvent.js
+++ b/src/events/timeGatedPlotEvent.js
@@ -40,7 +40,7 @@ App.Events.TimeGatedPlotEvent = class TimeGatedPlotEvent extends App.Events.Base
 		// week 71 plot event is one of three possibilities, depending on game state
 		const doubleAgent = (V.traitorType !== "agent" && V.traitorType !== "trapper") ? 0 : 1;
 		if (V.traitorType === "trapper") {
-			this.events[71] = new App.Events.TwineEvent().wrapPassage([], "P coup betrayal");
+			this.events[71] = new App.Events.PCoupBetrayal();
 		} else if (V.mercenaries + V.personalArms + V.hackerSupport + doubleAgent < 5) {
 			this.events[71] = new App.Events.PCoupLoss();
 		} else {
-- 
GitLab