internal static void UnclaimDoors(this Pawn_Ownership self)
        {
            FieldInfo field = typeof(Pawn_Ownership).GetField("pawn", BindingFlags.Instance | BindingFlags.NonPublic);

            if (field != null)
            {
                Pawn pawn = (Pawn)field.GetValue(self);

                // At this point chances are Pawn.Destroy was invoked to call UnclaimAll -> UnclaimDoors anyway
                // Pawn.Destroy will invoke its parent Thing.Destroy which in turn sets the Thing.mapIndexOrState of the pawn to -2
                // As Pawn.Map is actually a property that retrieves the Map using Thing.mapIndexOrState, it is not possible to get
                // the pawn's map anymore. Thus we must loop through every map... unless someone has a better idea?
                foreach (Map map in Find.Maps)
                {
                    foreach (Building_LockableDoor building in map.listerBuildings.AllBuildingsColonistOfClass <Building_LockableDoor>())
                    {
                        building.TryUnassignPawn(pawn);
                    }
                }
            }
            else
            {
                Log.Error("[LockableDoors] Could not reflect private pawn member at UnclaimDoors.");
            }
        }
Exemplo n.º 2
0
        public static bool Vamp_BedsForTheUndead(Pawn_Ownership __instance, Building_Bed newBed)
        {
            Pawn pawn = (Pawn)AccessTools.Field(typeof(Pawn_Ownership), "pawn").GetValue(__instance);

            if (pawn != null && !pawn.IsVampire() && newBed.IsVampireBed())
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 3
0
        static bool Prefix(Building_Bed newBed, Pawn_Ownership __instance, ref Pawn ___pawn, ref Building_Bed ___intOwnedBed)
        {
            if (newBed == null ||
                newBed.Medical ||
                !Helpers.ShouldRunForPawn(___pawn) ||
                (newBed.OwnersForReading != null && newBed.OwnersForReading.Contains(___pawn) && ___pawn.ownership?.OwnedBed == newBed))
            {
                return(true);
            }

            // Remove other pawn to make room in bed
            var pawn = ___pawn;

            if (newBed.OwnersForReading?.Count == newBed.SleepingSlotsCount &&
                !newBed.OwnersForReading.Any(p => p == pawn) &&
                newBed.OwnersForReading.Count > 0)
            {
                var pawnToRemove = newBed.OwnersForReading.LastOrDefault();
                pawnToRemove?.ownership?.UnclaimBed();
            }

            // Unclaim bed if pawn already has one on the map of the new bed
            var pawnBeds = Helpers.PawnBedsOnMap(___pawn, newBed.Map);

            if (pawnBeds.Any())
            {
                Helpers.UnclaimBeds(___pawn, pawnBeds, ref ___intOwnedBed);
            }

            // Claim new bed
            newBed.CompAssignableToPawn.ForceAddPawn(___pawn);
            // ... but only assign it if the pawn is on the same map
            if (___pawn.Map == newBed.Map)
            {
                ___intOwnedBed = newBed;
                ThoughtUtility.RemovePositiveBedroomThoughts(___pawn);
            }

            return(false);
        }
 internal static void UnclaimAll(Pawn_Ownership __instance)
 {
     __instance.UnclaimDoors();
 }
Exemplo n.º 5
0
 public static void Prefix(Pawn_Ownership __instance)
 {
     __instance?.pawn?.Map?.reachability?.ClearCache();
     LockConfig.Notify_Dirty();
 }
Exemplo n.º 6
0
        // Token: 0x06000051 RID: 81 RVA: 0x00005676 File Offset: 0x00003876
        protected override IEnumerable <Toil> MakeNewToils()
        {
            Pawn pawn = base.GetActor();

            this.FailOnBurningImmobile(TargetIndex.A);
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.A));

            Toil toil = new Toil
            {
                tickAction = delegate()
                {
                }
            };
            Toil prepare = toil;

            prepare.WithProgressBarToilDelay(TargetIndex.A, false, -0.5f);
            prepare.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            prepare.defaultCompleteMode = ToilCompleteMode.Delay;
            prepare.defaultDuration     = 300;
            yield return(prepare);

            yield return(Toils_General.Do(delegate
            {
                JobCondition JC;
                if (this.TargetA.Thing != null && this.TargetA.Thing.Spawned)
                {
                    MSExoticUtility.DoMSCondom(pawn, this.TargetA.Thing.def);
                    int stack = this.TargetA.Thing.stackCount;
                    if (stack > 1)
                    {
                        stack--;
                        this.TargetA.Thing.stackCount = stack;
                    }
                    else
                    {
                        this.TargetA.Thing.Destroy(DestroyMode.Vanish);
                    }
                    JC = JobCondition.Succeeded;
                }
                else
                {
                    JC = JobCondition.Incompletable;
                }
                Thing thing;
                if (pawn == null)
                {
                    thing = null;
                }
                else
                {
                    Pawn_Ownership ownership = pawn.ownership;
                    thing = (ownership?.OwnedBed);
                }
                Thing LovinBed = thing;
                if (LovinBed != null)
                {
                    Pawn partnerInMyBed = JobDriver_MSWearCondom.GetCondomPartnerInMyBed(pawn, LovinBed as Building_Bed);
                    if (partnerInMyBed != null && partnerInMyBed.health.capacities.CanBeAwake)
                    {
                        Job newLovin = new Job(JobDefOf.Lovin, partnerInMyBed, LovinBed);
                        if (newLovin != null)
                        {
                            Pawn pawn2 = pawn;
                            if (pawn2 != null)
                            {
                                Pawn_JobTracker jobs = pawn2.jobs;
                                if (jobs != null)
                                {
                                    jobs.jobQueue.EnqueueFirst(newLovin, null);
                                }
                            }
                        }
                    }
                }
                this.EndJobWith(JC);
            }));

            yield break;
        }