From 2516ed1439b15d7f7ba5107ace0dedb49d4f4e0c Mon Sep 17 00:00:00 2001 From: lutepickle <28810-lutepickle@users.noreply.gitgud.io> Date: Tue, 14 May 2024 20:51:18 -0700 Subject: [PATCH] Refactor DamagePants --- .../HediffComps/MenstruationUtility.cs | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/1.5/source/RJW_Menstruation/RJW_Menstruation/HediffComps/MenstruationUtility.cs b/1.5/source/RJW_Menstruation/RJW_Menstruation/HediffComps/MenstruationUtility.cs index 7a42bae..5628f9d 100644 --- a/1.5/source/RJW_Menstruation/RJW_Menstruation/HediffComps/MenstruationUtility.cs +++ b/1.5/source/RJW_Menstruation/RJW_Menstruation/HediffComps/MenstruationUtility.cs @@ -441,21 +441,10 @@ namespace RJW_Menstruation public static float DamagePants(this Pawn pawn, float fluidAmount) { if (pawn.apparel == null) return 0; - Apparel pants = null; - foreach(Apparel apparel in pawn.apparel.WornApparel.Where(app => app.def.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Legs))) - { - if (apparel.def.apparel.LastLayer == ApparelLayerDefOf.OnSkin) - { - pants = apparel; - break; - } - else if (pants == null || apparel.def.apparel.LastLayer == ApparelLayerDefOf.Middle) - // Either grab whatever's available or reassign the pants from shell to a middle - pants = apparel; - // Pants are middle and this is a shell - else continue; - } - if (pants == null) return 0; + if (!pawn.apparel.WornApparel. + Where(apparel => apparel.def.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Legs)). + TryMinBy(apparel => apparel.def.apparel.LastLayer.drawOrder, out Apparel pants)) + return 0; const float HPPerMl = 0.5f;