Merge branch 'brothelBedIsValid' into 'master'

Prevent automatc brothel bed claiming.

See merge request Ed86/rjw-whoring!5
This commit is contained in:
Ed86 2023-12-14 14:51:22 +00:00
commit 8023975389

View file

@ -10,7 +10,7 @@ using rjw;
/// <summary>
/// patches Building_Bed to add stuff for WhoreBeds
///
/// Also contains smaller patches for RoomRoleWorker_Barracks (don't count whore beds) (disabled) and Toils_LayDown.ApplyBedThoughts (slept in brothel thought)
/// Also contains smaller patches for RoomRoleWorker_Barracks (don't count whore beds) (disabled), Toils_LayDown.ApplyBedThoughts (slept in brothel thought) and RestUtility (don't automatically claim brothel beds)
/// </summary>
namespace rjwwhoring
@ -288,5 +288,29 @@ namespace rjwwhoring
}
}
}
}
/// <summary>
///Prevents automatic claiming of brothel beds (beds that allow anyone to use for whoring)
///Note, that intent is not verified here, and this works because bed usage for actual whoring does not rely on IsValidBedFor call.
///Should above change in future, this patch needs to be removed or adjusted
///If the bed is already claimed (for example - assigned manually to pawn), it will still be used.
///<returns>Modifies __result to false, if bed is set to allow anyone for whroing AND is not already claimed.</returns>
/// </summary>
[HarmonyPatch(typeof(RestUtility), nameof(RestUtility.IsValidBedFor))]
public class RestUtility_IsValidBedFor_Patch
{
[HarmonyPostfix]
public static void Postfix(Pawn sleeper, Thing bedThing, ref bool __result)
{
if (!__result) return;
Building_Bed building_Bed = bedThing as Building_Bed;
bool isOwner = sleeper.ownership != null && sleeper.ownership.OwnedBed == bedThing;
if (building_Bed.IsAllowedForWhoringAll() && !isOwner ) __result = false;
}
}
}
}