protected override Job TryGiveJob(Pawn pawn) { var mentalState = pawn.MentalState as MentalState_PanicFreezing; if (mentalState == null) { return(null); } var cells = pawn.ownership.OwnedRoom.Cells; if (cells.Count() > 0) { if (!cells.Contains(pawn.Position)) { Job job = JobMaker.MakeJob(JobDefOf.Flee, cells.Where(x => x.Walkable(pawn.Map)).RandomElement()); job.locomotionUrgency = LocomotionUrgency.Sprint; return(job); } else { Job job = JobMaker.MakeJob(JobDefOf.GotoWander, cells.Where(x => x.Walkable(pawn.Map)).RandomElement()); return(job); } } else { var spot = WanderUtility.BestCloseWanderRoot(pawn.Position, pawn); Job job = JobMaker.MakeJob(JobDefOf.Flee, spot); job.locomotionUrgency = LocomotionUrgency.Sprint; } return(null); }
protected override IntVec3 GetExactWanderDest(Pawn pawn) { Area outpostArea = OG_Util.FindOutpostArea(); if ((outpostArea != null) && outpostArea.ActiveCells.Contains(pawn.Position)) { return(RCellFinder.RandomWanderDestFor(pawn, pawn.Position, this.wanderRadius, this.wanderDestValidator, PawnUtility.ResolveMaxDanger(pawn, this.maxDanger))); } else { Building_OutpostCommandConsole console = OG_Util.FindOutpostCommandConsole(OG_Util.FactionOfMiningCo); if (console != null) { IntVec3 cell1 = WanderUtility.BestCloseWanderRoot(console.Position, pawn); return(cell1); } else { for (int cellIndex = 0; cellIndex < 50; cellIndex++) { IntVec3 cell2 = outpostArea.ActiveCells.RandomElement(); if (pawn.CanReserveAndReach(cell2, PathEndMode.Touch, Danger.Some)) { return(cell2); } } IntVec3 cell3 = WanderUtility.BestCloseWanderRoot(pawn.Position, pawn); return(cell3); } } }
public static bool GetWanderRoot(JobGiver_WanderNearDutyLocation __instance, ref IntVec3 __result, Pawn pawn) { __result = IntVec3.Invalid; PawnDuty duty = pawn.mindState.duty; if (duty != null) { __result = WanderUtility.BestCloseWanderRoot(duty.focus.Cell, pawn); } return(false); }
protected override Job TryGiveJob(Pawn pawn) { if (pawn.interactions.InteractedTooRecentlyToInteract() || lastRomanceTick > Find.TickManager.TicksGame - 1000) { return(null); } Predicate <Thing> validator = delegate(Thing t) { Pawn pawn3 = (Pawn)t; return(pawn3 != pawn && pawn3.Spawned && !pawn3.Dead && !pawn3.Downed && pawn3.Awake() && pawn3.IsColonist); }; Pawn pawn2 = (Pawn)GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForGroup(ThingRequestGroup.Pawn), PathEndMode.OnCell, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 9999f, validator); if (pawn2 == null) { return(null); } if (Rand.Chance(0.005f) && new InteractionWorker_RomanceAttempt().SuccessChance(pawn2, pawn) > 0f) { return(new Job(JobDefOfPsychology.MakeAdvance, pawn2)); } else if (Rand.Value < 0.5f) { IntVec3 root = WanderUtility.BestCloseWanderRoot(pawn2.PositionHeld, pawn); Func <Pawn, IntVec3, IntVec3, bool> wanderDestValidator = delegate(Pawn p, IntVec3 c, IntVec3 wRoot) { Room room = root.GetRoom(p.Map, RegionType.Set_Passable); if (room != null && !WanderRoomUtility.IsValidWanderDest(p, c, root)) { return(false); } return(true); }; return(new Job(JobDefOf.Goto, RCellFinder.RandomWanderDestFor(pawn, root, 3f, wanderDestValidator, PawnUtility.ResolveMaxDanger(pawn, Danger.Deadly)))); } return(null); }
protected override IntVec3 GetWanderRoot(Pawn pawn) { return(WanderUtility.BestCloseWanderRoot(pawn.playerSettings.master.PositionHeld, pawn)); }
protected override IntVec3 GetWanderRoot(Pawn pawn) { return(WanderUtility.BestCloseWanderRoot(pawn.mindState.duty.focusSecond.Cell, pawn)); }
protected override IntVec3 GetWanderRoot(Pawn pawn) { return((ClosestCharacter(pawn) is Pawn otherPawn) ? WanderUtility.BestCloseWanderRoot(otherPawn.PositionHeld, pawn) : pawn.PositionHeld); }
protected override Job TryGiveJob(Pawn pawn) { LordToil_HangOut toil = pawn.GetLord().CurLordToil as LordToil_HangOut; Pawn friend = (pawn == toil.friends[0] ? toil.friends[1] : toil.friends[0]); if (pawn.needs.food.CurLevel < 0.33f) { return(null); } if (friend.needs.food.CurLevel < 0.33f) { return(null); } if (LovePartnerRelationUtility.LovePartnerRelationExists(pawn, friend) && pawn.jobs.curDriver != null && pawn.jobs.curDriver.layingDown == LayingDownState.NotLaying && (pawn.IsHashIntervalTick(GenDate.TicksPerHour) || friend.IsHashIntervalTick(GenDate.TicksPerHour))) { return(new Job(JobDefOf.LayDown, pawn.ownership.OwnedBed)); } if (toil.hangOut != null && toil.hangOut.GetTarget(TargetIndex.A) != null && !pawn.CanReserve(toil.hangOut.GetTarget(TargetIndex.A), toil.hangOut.def.joyMaxParticipants, 0, null)) { Log.Message("can't reserve the target of the hangout"); /* Try our best to figure out which JoyGiver was used for the unreservable job. */ int prefix = "JoyGiver".Count(); var def = ( from j in DefDatabase <JoyGiverDef> .AllDefs where j.jobDef == toil.hangOut.def || (j.jobDef == null && DefDatabase <JobDef> .GetNamedSilentFail(nameof(j.giverClass).Substring(prefix)) == toil.hangOut.def) select j ).FirstOrDefault(); if (def != null) { Log.Message("giving job of def " + def.defName); do { toil.hangOut = base.TryGiveJobFromJoyGiverDefDirect(def, pawn); } while (toil.hangOut.GetTarget(TargetIndex.A).Thing.GetRoom() != friend.GetRoom()); } else { toil.hangOut = null; } } if (toil.hangOut == null || toil.ticksToNextJoy < Find.TickManager.TicksGame) { toil.hangOut = base.TryGiveJob(pawn); toil.ticksToNextJoy = Find.TickManager.TicksGame + Rand.RangeInclusive(GenDate.TicksPerHour, GenDate.TicksPerHour * 3); } if (pawn.needs.joy.CurLevel < 0.8f) { return(toil.hangOut); } Log.Message("no joy hangout available"); IntVec3 root = WanderUtility.BestCloseWanderRoot(toil.hangOut.targetA.Cell, pawn); Func <Pawn, IntVec3, bool> validator = delegate(Pawn wanderer, IntVec3 loc) { IntVec3 wanderRoot = root; Room room = wanderRoot.GetRoom(pawn.Map); return(room == null || WanderUtility.InSameRoom(wanderRoot, loc, pawn.Map)); }; pawn.mindState.nextMoveOrderIsWait = !pawn.mindState.nextMoveOrderIsWait; IntVec3 wanderDest = RCellFinder.RandomWanderDestFor(pawn, root, 5f, validator, PawnUtility.ResolveMaxDanger(pawn, Danger.Some)); if (!wanderDest.IsValid || pawn.mindState.nextMoveOrderIsWait) { if ((pawn.Position - friend.Position).LengthHorizontalSquared >= 42f && friend.jobs.curJob.def != JobDefOf.Goto) { Log.Message("friend not nearby, going to friend"); IntVec3 friendDest = RCellFinder.RandomWanderDestFor(pawn, friend.Position, 5f, validator, PawnUtility.ResolveMaxDanger(pawn, Danger.Some)); pawn.Map.pawnDestinationManager.ReserveDestinationFor(pawn, friendDest); return(new Job(JobDefOf.Goto, friendDest)); } Log.Message("waiting"); return(null); } Log.Message("wandering"); pawn.Map.pawnDestinationManager.ReserveDestinationFor(pawn, wanderDest); return(new Job(JobDefOf.GotoWander, wanderDest)); }