Advertisement
Guest User

Set Owner for Prisoner Beds Source Code

a guest
Nov 8th, 2021
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.50 KB | None | 0 0
  1. using HarmonyLib;
  2. using RimWorld;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using UnityEngine;
  9. using Verse;
  10. using Verse.AI;
  11.  
  12. namespace PrisonerBedSetOwner.Patch
  13. {
  14.     [HarmonyPatch(typeof(Building_Bed), "GetGizmos")]
  15.     class PatchBuilding_BedGetGizmos
  16.     {
  17.         static IEnumerable<Gizmo> Postfix(IEnumerable<Gizmo> list, Building_Bed __instance)
  18.         {
  19.             foreach (Gizmo gizmo in list)
  20.             {
  21.                 yield return gizmo;
  22.             }
  23.  
  24.             if (__instance.def.building.bed_humanlike && __instance.Faction == Faction.OfPlayer && __instance.ForPrisoners)
  25.             {
  26.                 yield return new Command_Action
  27.                 {
  28.                     defaultLabel = "CommandThingSetOwnerLabel".Translate(),
  29.                     icon = ContentFinder<Texture2D>.Get("UI/Commands/AssignOwner", true),
  30.                     defaultDesc = "CommandBedSetOwnerDesc".Translate(),
  31.                     action = delegate ()
  32.                     {
  33.                         Find.WindowStack.Add(new Dialog_AssignBuildingOwner(__instance.CompAssignableToPawn));
  34.                     },
  35.                     hotKey = KeyBindingDefOf.Misc3
  36.                 };
  37.             }
  38.  
  39.             yield break;
  40.         }
  41.     }
  42.  
  43.     [HarmonyPatch(typeof(CompAssignableToPawn_Bed), "AssigningCandidates", MethodType.Getter)]
  44.     class PatchCompAssignableToPawn
  45.     {
  46.         static bool Prefix(ref IEnumerable<Pawn> __result, CompAssignableToPawn __instance)
  47.         {
  48.             Building_Bed bed = __instance.parent as Building_Bed;
  49.             if (bed == null || !bed.Spawned || !bed.ForPrisoners) return true;
  50.  
  51.             __result = bed.Map.mapPawns.PrisonersOfColony;
  52.             return false;
  53.         }
  54.     }
  55.  
  56.     [HarmonyPatch(typeof(WorkGiver_Warden_TakeToBed), "TakeToPreferredBedJob")]
  57.     class PatchWorkGiver_Warden_TakeToBedTakeToPreferredBedJob
  58.     {
  59.         static bool Prefix(ref Job __result, Pawn prisoner)
  60.         {
  61.             Building_Bed bed = prisoner.ownership?.OwnedBed;
  62.             Room bedroom = bed?.GetRoom();
  63.             Room room = prisoner.GetRoom(RegionType.Set_Passable);
  64.  
  65.             if (room != null && bedroom != null && room != bedroom)
  66.             {
  67.                 __result = JobMaker.MakeJob(JobDefOf.EscortPrisonerToBed, prisoner, bed);
  68.                 __result.count = 1;
  69.                 return false;
  70.             }
  71.  
  72.             return true;
  73.         }
  74.     }
  75.  
  76.  
  77. }
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement