From 38c102c04f73e2e527a032dc3310b5acfe67c1fe Mon Sep 17 00:00:00 2001
From: lowercase-donkey <lowercasedonkey@gmail.com>
Date: Wed, 29 May 2019 16:29:41 -0400
Subject: [PATCH] .length used instead of for loop

---
 src/js/slaveCostJS.js                 | 22 +++++++++-------------
 src/uncategorized/bodyModification.tw | 17 +++++++++++++----
 2 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/src/js/slaveCostJS.js b/src/js/slaveCostJS.js
index 69db2b464ae..c438a6a11dd 100644
--- a/src/js/slaveCostJS.js
+++ b/src/js/slaveCostJS.js
@@ -188,13 +188,11 @@ window.Beauty = (function() {
 	 * @param {App.Entity.SlaveState} slave
 	 */
 	function calcCosmeticsBeauty(slave) {
-		for (let [key, value] of Object.entries(slave.brand)) {
-			if (V.rep > 10000) {
-				beauty += 1;
-			} else if (V.rep < 5000) {
-				beauty -= 1;
-			}
-		}
+		if (V.rep > 10000) {
+			beauty += Object.getOwnPropertyNames(slave.brand).length;
+		} else if (V.rep < 5000) {
+			beauty -= Object.getOwnPropertyNames(slave.brand).length;
+		}		
 		if (slave.minorInjury !== 0) {
 			beauty -= 2;
 		}
@@ -2232,12 +2230,10 @@ window.slaveCost = (function() {
 		if (slave.geneticQuirks.albinism === 2) {
 			multiplier += 0.2;
 		}
-		for (let [key, value] of Object.entries(slave.brand)) {
-			if (V.rep > 10000) {
-				multiplier += 0.1;
-			} else if (V.rep < 5000) {
-				multiplier -= 0.1;
-			}
+		if (V.rep > 10000) {
+			multiplier += 0.1(Object.getOwnPropertyNames(slave.brand).length);
+		} else if (V.rep < 5000) {
+			multiplier -= 0.1(Object.getOwnPropertyNames(slave.brand).length);
 		}
 		if (slave.amp === 1) {
 			multiplier -= 0.2;
diff --git a/src/uncategorized/bodyModification.tw b/src/uncategorized/bodyModification.tw
index 5421394574b..9289baeea77 100644
--- a/src/uncategorized/bodyModification.tw
+++ b/src/uncategorized/bodyModification.tw
@@ -885,14 +885,16 @@ Custom Tats:
 /* Branding */
 
 Branding:
+<<set _brandCount = 1>> /* avoid div by zero */
 <<for _brandName, _brand range $activeSlave.brand>>
 	<br>&nbsp;&nbsp;&nbsp;&nbsp; $His _brandName is marked with _brand:
+	<<set _brandCount++>>/* Hopefully not captured */
 	<<capture _brandName>>
 		<<link "Remove Brand">>
 			<<set $brandApplied = 0>>
 			<<run delete $activeSlave.brand[_brandName]>>
 			<<run cashX(forceNeg($surgeryCost), "slaveSurgery", $activeSlave)>>
-			<<set $degradation -= 10>>
+			<<set $degradation -= Math.trunc(10/_brandCount)>>
 			<<goto "Body Modification">>
 		<</link>>
 	<</capture>>
@@ -1056,7 +1058,7 @@ Or a custom site: <<textbox "$brandTarget.local" $brandTarget.local "Body Modifi
 		<<set $brandApplied = 1>>
 		<<set $activeSlave.brand[_leftTarget] = $brandDesign.local>>
 		<<run cashX(forceNeg($modCost), "slaveMod", $activeSlave)>>
-		<<set $degradation += 10>>
+		<<set $degradation += Math.trunc(10/_brandCount)>>
 		<<goto "Body Modification">>
 	<</link>>
 	$brandTarget.local, or the
@@ -1064,14 +1066,21 @@ Or a custom site: <<textbox "$brandTarget.local" $brandTarget.local "Body Modifi
 		<<set $brandApplied = 1>>
 		<<set $activeSlave.brand[_rightTarget] = $brandDesign.local>>
 		<<run cashX(forceNeg($modCost), "slaveMod", $activeSlave)>>
-		<<set $degradation += 10>>
+		<<set $degradation += Math.trunc(10/_brandCount)>>
 		<<goto "Body Modification">>
 	<</link>>? //Branding will slightly reduce $his beauty but may slowly increase your reputation.//
 <<else>>
 	<<if $activeSlave.brand[$brandTarget.local] === $brandDesign.local>>
 		$He already has $brandDesign.local on $his $brandTarget.local.
 	<<else>>
-		[[Brand|Body Modification][$brandApplied = 1,$activeSlave.brand[$brandTarget.local] = $brandDesign.local,cashX(forceNeg($surgeryCost), "slaveSurgery", $activeSlave),$degradation += 10]] with $brandDesign.local on the $brandTarget.local<<if $activeSlave.brand[$brandTarget.local]>>, covering the "<<print $activeSlave.brand[$brandTarget.local]>>" that is already there?<<else>>.<</if>> //Branding will slightly reduce $his beauty but may slowly increase your reputation.//
+		<<link "Brand">>
+			<<set $brandApplied = 1>>
+			<<set $activeSlave.brand[$brandTarget.local] = $brandDesign.local>>
+			<<run cashX(forceNeg($modCost), "slaveMod", $activeSlave)>>
+			<<set $degradation += Math.trunc(10/_brandCount)>>
+			<<goto "Body Modification">>
+		<</link>>
+		with $brandDesign.local on the $brandTarget.local<<if $activeSlave.brand[$brandTarget.local]>>, covering the "<<print $activeSlave.brand[$brandTarget.local]>>" that is already there?<<else>>.<</if>> //Branding will slightly reduce $his beauty but may slowly increase your reputation.//
 	<</if>>
 <</if>>
 
-- 
GitLab