protected override bool TryFindGoodExitDest(Pawn pawn, out IntVec3 spot)
 {
     using (List <Thing> .Enumerator enumerator = ToolsForHaulUtility.Cart().GetEnumerator())
     {
         while (enumerator.MoveNext())
         {
             Vehicle_Cart vehicle_Cart = (Vehicle_Cart)enumerator.Current;
             if (vehicle_Cart.mountableComp.IsMounted && !vehicle_Cart.mountableComp.Driver.RaceProps.Animal && vehicle_Cart.mountableComp.Driver.ThingID == pawn.ThingID)
             {
                 vehicle_Cart.despawnAtEdge = true;
             }
         }
     }
     return(ExitUtility.TryFindRandomExitSpot(pawn, ref spot, 1));
 }
Exemplo n.º 2
0
        public static Toil FreeSlave(TargetIndex PrisonerInd, TargetIndex CollarInd)
        {
            var toil = new Toil();

            toil.defaultCompleteMode = ToilCompleteMode.Delay;
            toil.defaultDuration     = 100;
            toil.AddFinishAction(new Action(() =>
            {
                try
                {
                    var slave     = toil.actor.CurJob.GetTarget(PrisonerInd).Thing as Pawn;
                    var collar    = toil.actor.CurJob.GetTarget(CollarInd).Thing as Apparel;
                    var compSlave = slave.TryGetComp <CompSlave>();
                    if (
                        (slave == null) ||
                        (collar == null) ||
                        (compSlave == null)
                        )
                    {
                        throw new Exception(
                            string.Format(
                                "slave = {0}\n\tcollar = {1}\n\tcompSlaver = {2}",
                                slave == null ? "null" : slave.ThingID,
                                collar == null ? "null" : collar.ThingID,
                                compSlave == null ? "null" : "valid"));
                    }
                    if (slave.outfits != null)
                    {
                        slave.outfits.forcedHandler.SetForced(collar, false);
                    }
                    slave.apparel.wornApparel().Remove(collar);
                    collar.wearer        = (Pawn)null;
                    Thing resultingThing = (Thing)null;
                    bool flag            = GenThing.TryDropAndSetForbidden((Thing)collar, slave.Position, ThingPlaceMode.Near, out resultingThing, false);
                    slave.Drawer.renderer.graphics.ResolveApparelGraphics();
                    if (slave.ownership != null)
                    {
                        slave.ownership.UnclaimAll();
                    }
                    var faction = compSlave.originalFaction;
                    if (
                        (faction == null) ||
                        (faction == Faction.OfColony)
                        )
                    {                       // Unknown faction or originally from the colony
                        // Pick outlander faction
                        faction = Find.FactionManager.FirstFactionOfDef(FactionDefOf.Outlander);
                        if (faction == null)
                        {                           // No outlander faction, pick a random non-colony faction
                            Find.FactionManager.TryGetRandomNonColonyHumanlikeFaction(out faction, false);
                        }
                    }
                    // Update control flags
                    compSlave.wasSlave          = true;
                    compSlave.freeSlave         = false;
                    slave.guest.released        = true;
                    slave.guest.interactionMode = PrisonerInteractionMode.NoInteraction;
                    // Remove enslaved trait
                    slave.RemoveTrait(Data.EnslavedTraitDef);
                    // Adjust thoughts
                    if (
                        (slave.needs != null) &&
                        (slave.needs.mood != null) &&
                        (slave.needs.mood.thoughts != null)
                        )
                    {
                        slave.needs.mood.thoughts.RemoveThoughtsOfDef(Data.EnslavedThoughtDef);
                        slave.needs.mood.thoughts.TryGainThought(Data.FreedThoughtDef);
                    }
                    // Restore faction
                    slave.SetFaction(faction, null);
                    // Restore PawnKindDef
                    slave.kindDef = compSlave.originalPawnKind;
                    // Find an exit spot
                    IntVec3 spot;
                    if (!ExitUtility.TryFindClosestExitSpot(slave, out spot, TraverseMode.ByPawn))
                    {
                        Log.Warning("Tried to make slave " + slave.Name + " leave but couldn't find an exit spot");
                        return;
                    }
                    // Stop any other jobs
                    slave.jobs.StopAll(true);
                    Job newJob = new Job(JobDefOf.Goto, spot);
                    newJob.exitMapOnArrival = true;
                    // Assign new exit job
                    slave.jobs.StartJob(newJob, JobCondition.None, (ThinkNode)null, false, true, (ThinkTreeDef)null);
                }
                catch (Exception e)
                {
                    Log.Error("ESM - Prison Improvements :: Could not free slave!\n\t" + e.Message);
                }
            }));
            return(toil);
        }