Prevent automatc brothel bed claiming.

Pawns will now not automatically claim beds that use allow anyone to
whore option. If the pawn is already assigned to bed - for example
manually - it will still use the bed.
This commit is contained in:
Crow 2023-12-04 21:31:53 +01:00
parent 0daf0231a3
commit a7ba8bed80
1 changed files with 26 additions and 2 deletions

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;
}
}
}
}