From da876c052cd6d5140d38a2d2248b60efab8b70e3 Mon Sep 17 00:00:00 2001
From: Svornost <11434-svornost@users.noreply.gitgud.io>
Date: Thu, 28 Sep 2023 15:16:32 -0400
Subject: [PATCH] Don't compare clitSetting to fetish directly, since they
 don't match exactly; add `smartPiercingReinforcesFetish` function to properly
 check these cases.  Fixes a few cases where the SP "no sex" setting broke
 fetish changes, and where buttslut/cumslut fetishes could change even though
 they were supposed to be locked in with the SP.

---
 src/events/RESS/review/hormoneDysfunction.js |  4 ++--
 src/js/DefaultRules.js                       |  1 +
 src/js/slaveSummaryHelpers.js                |  4 +---
 src/js/utilsSlave.js                         | 21 +++++++++++++++++++-
 src/npc/interaction/fAbuse.js                |  2 +-
 5 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/src/events/RESS/review/hormoneDysfunction.js b/src/events/RESS/review/hormoneDysfunction.js
index e7564e4f031..529401c8415 100644
--- a/src/events/RESS/review/hormoneDysfunction.js
+++ b/src/events/RESS/review/hormoneDysfunction.js
@@ -79,7 +79,7 @@ App.Events.RESSHormoneDysfunction = class RESSHormoneDysfunction extends App.Eve
 			}
 			r.push(`and the same limp dick as before. <span class="devotion dec">It's frustrating for ${him}.</span>`);
 			eventSlave.devotion -= 2;
-			if (eventSlave.clitSetting !== eventSlave.fetish) {
+			if (!smartPiercingReinforcesFetish(eventSlave)) {
 				r.push(`But, ${he} slowly <span class="fetish gain">accepts ${his} new role as a submissive little sex toy.</span>`);
 				eventSlave.fetishStrength = 65;
 				eventSlave.fetishKnown = 1;
@@ -107,7 +107,7 @@ App.Events.RESSHormoneDysfunction = class RESSHormoneDysfunction extends App.Eve
 			r.push(`${He} doesn't climax to anal then, or the next time you assfuck ${him}, or the time after that; but some time later a long buttsex session ends when ${he} gives a little shake and a whimper and dribbles a pathetic squirt of cum from ${his} still-limp dick. By the end of the week <span class="mediumaquamarine">${he}'s smiling trustingly</span> and offering you ${his} butt every chance ${he} gets.`);
 			r.push(VCheck.Anal(eventSlave, 10));
 			eventSlave.trust += 4;
-			if (eventSlave.clitSetting !== eventSlave.fetish) {
+			if (!smartPiercingReinforcesFetish(eventSlave)) {
 				r.push(`<span class="fetish gain">${He}'s become a confirmed anal addict.</span>`);
 				eventSlave.fetishStrength = 65;
 				eventSlave.fetishKnown = 1;
diff --git a/src/js/DefaultRules.js b/src/js/DefaultRules.js
index 1c800a4173a..71768aea972 100644
--- a/src/js/DefaultRules.js
+++ b/src/js/DefaultRules.js
@@ -2772,6 +2772,7 @@ globalThis.DefaultRules = function(slave) {
 					fetish = either("vanilla", "oral", "anal", "boobs", "submissive", "dom", "humiliation", "pregnancy", "masochist", "sadist");
 				}
 				// check if already full fetish
+				// FIXME - this is wrong for some cases; see smartPiercingReinforcesFetish
 				if (slave.fetish !== fetish || slave.fetishStrength < 100) {
 					// Set the smart thingy to the correct fetish
 					if (slave.clitSetting !== fetish) {
diff --git a/src/js/slaveSummaryHelpers.js b/src/js/slaveSummaryHelpers.js
index aa2cdc3d0e5..ff6decf3ba4 100644
--- a/src/js/slaveSummaryHelpers.js
+++ b/src/js/slaveSummaryHelpers.js
@@ -437,9 +437,7 @@ App.UI.SlaveSummaryImpl = function() {
 					return value + spData.setting.all;
 				} else if ((slave.energy > 5) && (slave.clitSetting === "none")) {
 					return value + spData.setting.none;
-				} else if (((slave.fetish !== Fetish.NONE) && (slave.clitSetting === "vanilla"))) {
-					return value + spData.setting.vanilla;
-				} else if (slave.fetishStrength <= 95 || slave.fetish !== slave.clitSetting) {
+				} else if (slave.fetishStrength <= 95 || !smartPiercingReinforcesFetish(slave)) {
 					const s = value + spData.setting[slave.clitSetting];
 					if (s) {
 						return s;
diff --git a/src/js/utilsSlave.js b/src/js/utilsSlave.js
index 279c3d5d888..f7daea8b672 100644
--- a/src/js/utilsSlave.js
+++ b/src/js/utilsSlave.js
@@ -1583,7 +1583,7 @@ globalThis.fetishChangeChance = function(slave) {
 	let fetish = (slave.fetishStrength / 4);
 	let sex = 0;
 
-	if (slave.clitSetting !== slave.fetish && !('fetishChanged' in slave && slave.fetishChanged === 1)) {
+	if (!smartPiercingReinforcesFetish(slave) && !('fetishChanged' in slave && slave.fetishChanged === 1)) {
 		// fetish should be more uncertain leading towards puberty and then steadily become more set in stone afterwards
 		if (slave.balls) {
 			if (V.potencyAge >= slave.actualAge) {
@@ -3414,3 +3414,22 @@ globalThis.ChattelReligionistClothingPass = function(outfit) {
 		return fsLovesClothes;
 	}
 };
+
+/** Checks whether a slave's smart piercing is reinforcing a particular fetish
+ * You must use this function rather than comparing directly because some of the enumerated values don't match (i.e. "anal" reinforces "buttslut")
+ * @param {App.Entity.SlaveState} slave
+ * @param {FC.Fetish} [fetish] if unspecified, uses the slave's current fetish
+ */
+globalThis.smartPiercingReinforcesFetish = function(slave, fetish = slave.fetish) {
+	switch (slave.clitSetting) {
+		case SmartPiercingSetting.VANILLA:
+			return fetish === Fetish.NONE;
+		case SmartPiercingSetting.ANAL:
+			return fetish === Fetish.BUTTSLUT;
+		case SmartPiercingSetting.ORAL:
+			return fetish === Fetish.CUMSLUT;
+		case SmartPiercingSetting.NONE:
+			return false; // SP "none" is "no sex", not fetish "none", which is SP "vanilla"
+	}
+	return slave.clitSetting === fetish; // all the other ones are supposed to match
+};
diff --git a/src/npc/interaction/fAbuse.js b/src/npc/interaction/fAbuse.js
index 1996fea984a..291d8edb193 100644
--- a/src/npc/interaction/fAbuse.js
+++ b/src/npc/interaction/fAbuse.js
@@ -754,7 +754,7 @@ App.Interact.fAbuse = function(slave) {
 		}
 	}
 	if (random(1, 100) > (50+slave.devotion+slave.trust) && slave.assignment !== Job.BODYGUARD) {
-		if (slave.fetish !== Fetish.MINDBROKEN && slave.fetishKnown === 0 && slave.clitSetting !== slave.fetish) {
+		if (slave.fetish !== Fetish.MINDBROKEN && slave.fetishKnown === 0 && !smartPiercingReinforcesFetish(slave)) {
 			r.push(`${His} acceptance of your abuse has twisted ${his}`);
 			if (random(1, 2) === 1 && slave.fetish !== "submissive") {
 				r.push(`<span class="lightcoral">sexuality towards submissiveness.</span>`);
-- 
GitLab