public override Job TryGiveJob(Pawn pawn) { // If the weather outside is frightful, only look for benches indoors bool allowedOutside = JoyUtility.EnjoyableOutsideNow(pawn, null); // If the pawn doesn't have the required needs for some reason, fail if ((pawn.needs == null || pawn.needs.joy == null || pawn.needs.mood == null || pawn.needs.mood.thoughts == null)) { return(null); } // Find a bench matching the correct criteria IEnumerable <Thing> bench = pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.BuildingArtificial).Where(delegate(Thing b) { return(b.def == ThingDef.Named("ZEN_ScenicBench") && b.Faction == Faction.OfPlayer && !b.IsForbidden(pawn) && (allowedOutside || b.Position.Roofed(b.Map)) && pawn.CanReserveAndReach(b, PathEndMode.Touch, Danger.None, 1, -1, null, false)); }); Thing t; if (!bench.TryRandomElementByWeight(delegate(Thing x) { float lengthHorizontal = (x.Position - pawn.Position).LengthHorizontal; return(Mathf.Max(150f - lengthHorizontal, 5f)); }, out t)) { return(null); } return(new Job(def.jobDef, t)); }
// Token: 0x06000299 RID: 665 RVA: 0x0001948C File Offset: 0x0001788C protected override IEnumerable <Toil> MakeNewToils() { this.FailOn(() => !JoyUtility.EnjoyableOutsideNow(this.pawn, null)); Toil goToil = Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.OnCell); goToil.tickAction = delegate() { if (Find.TickManager.TicksGame > this.startTick + this.job.def.joyDuration) { this.EndJobWith(JobCondition.Succeeded); return; } JoyUtility.JoyTickCheckEnd(this.pawn, JoyTickFullJoyAction.EndJob, 1f, null); }; yield return(goToil); yield return(new Toil { initAction = delegate() { if (this.job.targetQueueA.Count > 0) { LocalTargetInfo targetA = this.job.targetQueueA[0]; this.job.targetQueueA.RemoveAt(0); this.job.targetA = targetA; this.JumpToToil(goToil); return; } } }); yield break; }
protected override IEnumerable <Toil> MakeNewToils() { yield return(Toils_Goto.GotoCell(TargetIndex.B, PathEndMode.OnCell)); Toil throwing = Toils_General.Wait(2000, TargetIndex.A); throwing.socialMode = RandomSocialMode.Normal; throwing.FailOn(() => !JoyUtility.EnjoyableOutsideNow(this.pawn, null) || this.TargetB.Cell.IsForbidden(this.pawn)); throwing.handlingFacing = true; throwing.initAction = () => { pawn.rotationTracker.FaceCell(TargetLocA); }; throwing.tickAction = () => { if (this.pawn.IsHashIntervalTick(400)) { pawn.skills.Learn(SkillDefOf.Shooting, 5f); FleckMaker.ThrowStone(pawn, TargetLocA); } }; yield return(throwing); yield break; }
static void Postfix(ref bool __result, IntVec3 c, IntVec3 root, Pawn pawn) { if (!__result) { return; } // if (pawn.Faction == Faction.OfPlayer && (pawn.Position.Roofed(pawn.Map) || root.Roofed(pawn.Map)) && !c.Roofed(pawn.Map) && !JoyUtility.EnjoyableOutsideNow(pawn.Map)) { __result = false; return; } // if (!pawn.RaceProps.Humanlike) { return; } // RoomRoleDef def = c.GetRoom(pawn.Map)?.Role; if (def == RoomRoleDefOf.Bedroom && !pawn.GetRoom().Owners.Contains(pawn) || def == RoomRoleDefOf.Hospital || def == RoomRoleDefOf.PrisonCell || def == RoomRoleDefOf.PrisonBarracks) { __result = false; return; } }
protected override Job TryGiveJob(Pawn pawn) { if (!JoyUtility.EnjoyableOutsideNow(pawn, null)) { return(null); } bool nextMoveOrderIsWait = pawn.mindState.nextMoveOrderIsWait; pawn.mindState.nextMoveOrderIsWait = !pawn.mindState.nextMoveOrderIsWait; if (nextMoveOrderIsWait) { return(new Job(RimWorld.JobDefOf.Wait_Wander) { expiryInterval = this.ticksBetweenWandersRange.RandomInRange }); } IntVec3 c = this.getSwimmingCell(pawn); if (!c.IsValid) { pawn.mindState.nextMoveOrderIsWait = false; return(null); } Job job = new Job(JobDefOf.TKKN_GoSwimming, c); pawn.Map.pawnDestinationReservationManager.Reserve(pawn, job, c); job.locomotionUrgency = this.locomotionUrgency; return(job); }
protected override IEnumerable <Toil> MakeNewToils() { yield return(Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.OnCell)); Toil toil = new Toil { initAction = delegate { //pawn.jobs.posture = PawnPosture.LayingOnGroundFaceUp; pawn.rotationTracker.FaceCell(TargetB.Cell); //pawn.jobs. }, tickAction = delegate { float extraJoyGainFactor = thrownRockNum * .2f; JoyUtility.JoyTickCheckEnd(pawn, JoyTickFullJoyAction.EndJob, extraJoyGainFactor); TickAction(); }, defaultCompleteMode = ToilCompleteMode.Delay, defaultDuration = job.def.joyDuration }; toil.FailOn(() => pawn.Position.Roofed(pawn.Map)); toil.FailOn(() => !JoyUtility.EnjoyableOutsideNow(pawn)); yield return(toil); }
public override Job TryGiveJob(Pawn pawn) { if (!JoyUtility.EnjoyableOutsideNow(pawn.Map)) { return(null); } IntVec3 position = AIUtility.FindRandomSpotOutsideColony(pawn, def.searchDistance, canReach: false, canReserve: false); if (!position.IsValid) { return(null); } IntVec3 standPosition = IntVec3.Invalid; if (!AIUtility.FindAroundSpotFromTarget(pawn, position, 4.0f, 3.0f, canSee: true, canReach: true, canReserve: true).TryRandomElement(out standPosition)) { return(null); } return(new Job(IdleJobDefOf.IdleJob_ThrowingStone, position, standPosition) { locomotionUrgency = modSettings.wanderMovePolicy }); }
public override Job TryGiveJob(Pawn pawn) { if (!JoyUtility.EnjoyableOutsideNow(pawn.Map)) { return(null); } IntVec3 position = IntVec3.Invalid; RCellFinder.TryFindRandomSpotJustOutsideColony(pawn.Position, pawn.Map, pawn, out position, (IntVec3 x) => { TerrainDef terrainDef = x.GetTerrain(pawn.Map); if (terrainDef.fertility > 0 && pawn.CanReserveAndReach(x, PathEndMode.Touch, Danger.None)) { return(true); } return(false); }); if (position.IsValid) { return(new Job(IdleJobDefOf.IdleJob_Graffiti, position) { locomotionUrgency = LocomotionUrgency.Walk }); } return(null); }
protected override IEnumerable <Toil> MakeNewToils() { Pawn target = this.TargetA.Thing as Pawn; float xp = 5f * Mathf.Pow(5f, target.RaceProps.wildness); this.FailOnDestroyedNullOrForbidden(TargetIndex.A); yield return(DSFIToils_Moving.GotoNearTarget(TargetIndex.A, Danger.Some, moveDistance, lookDistance)); Toil observing = Toils_General.Wait(1500); observing.FailOnDestroyedOrNull(TargetIndex.A); observing.socialMode = RandomSocialMode.SuperActive; observing.handlingFacing = true; observing.FailOn(() => !JoyUtility.EnjoyableOutsideNow(this.pawn, null)); observing.tickAction = () => { if (pawn.IsHashIntervalTick(20)) { pawn.skills.Learn(SkillDefOf.Animals, 5f); pawn.rotationTracker.FaceTarget(target); if (!pawn.CanSee(target) || !pawn.Position.InHorDistOf(target.Position, lookDistance)) { this.ReadyForNextToil(); } } }; yield return(observing); yield break; }
public static bool PawnMayEnjoyPlayingOutside(Pawn pawn) { if (PawnOrAnimalIsGoneOrIncapable(pawn)) { return(false); } else if (pawn.MapHeld is null) { PetThemAll.Debug($"MapHeld is null: {pawn.ToStringSafe()}"); return(false); // impossible? //} else if (!pawn.IsColonist) { // PetThemAll.Debug($"not a colonist: {pawn.ToStringSafe()}"); // return false; // prisoners shouldn't be interacting with our pets } else if (!JoyUtility.EnjoyableOutsideNow(pawn)) { PetThemAll.Debug($"doesn't want to have fun outside: {pawn.ToStringSafe()}"); return(false); // world's on fire? } else if (PawnUtility.WillSoonHaveBasicNeed(pawn)) { PetThemAll.Debug($"will soon have basic need: {pawn.ToStringSafe()}"); return(false); // too sleepy or hungry } else { return(true); } }
public static bool ShouldHideFromWeather(this Pawn pawn) { if (!Settings.safe_wander || pawn.Faction != Faction.OfPlayer || !pawn.Map.IsPlayerHome || pawn.mindState?.duty != null) { return(false); } // bool cares = pawn.needs?.mood != null; if (cares) { if (JoyUtility.EnjoyableOutsideNow(pawn.Map)) { return(false); } } else if (!pawn.RaceProps.IsFlesh || pawn.Map.gameConditionManager.ActiveConditions.FirstOrDefault(x => x is GameCondition_ToxicFallout) == null) { return(false); } // //if (pawn.Position.Roofed(pawn.Map)) // return false; return(true); }
protected override Job TryGiveJob(Pawn pawn) { if (!JoyUtility.EnjoyableOutsideNow(pawn, null)) { return(null); } Predicate <Thing> validator = delegate(Thing t) { if (t.def.defName == "TKKN_HotSpring" && t.AmbientTemperature < 26 && t.AmbientTemperature > 15) { return(true); } if (t.def.defName == "TKKN_ColdSpring" && t.AmbientTemperature > 24) { return(true); } return(false); }; Thing hotSpring = GenClosest.ClosestThingReachable(pawn.GetLord().CurLordToil.FlagLoc, pawn.Map, ThingRequest.ForDef(TKKN_NPS.ThingDefOf.TKKN_HotSpring), PathEndMode.Touch, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), -1f, validator, null, 0, -1, false, RegionType.Set_Passable, false); if (hotSpring != null) { Thing spring = GenClosest.ClosestThingReachable(pawn.GetLord().CurLordToil.FlagLoc, pawn.Map, ThingRequest.ForDef(TKKN_NPS.ThingDefOf.TKKN_ColdSpring), PathEndMode.Touch, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), -1f, validator, null, 0, -1, false, RegionType.Set_Passable, false); if (spring != null) { return(new Job(RimWorld.JobDefOf.GotoSafeTemperature, this.getSpringCell(spring))); } } else { return(new Job(RimWorld.JobDefOf.GotoSafeTemperature, this.getSpringCell(hotSpring))); } return(null); }
public override Job TryGiveJob(Pawn pawn) { if (!JoyUtility.EnjoyableOutsideNow(pawn.Map)) { return(null); } pawns.Clear(); foreach (Thing thing in GenRadial.RadialDistinctThingsAround(pawn.Position, pawn.Map, this.def.searchDistance, true)) { Pawn targetPawn = thing as Pawn; if (targetPawn != null && targetPawn.RaceProps.Animal) { pawns.Add(targetPawn); } } if (pawns.Any()) { Pawn target = pawns.RandomElement(); return(new Job(IdleJobDefOf.IdleJob_ObservingAnimal, target) { locomotionUrgency = LocomotionUrgency.Walk }); } return(null); }
protected override Job TryGivePlayJob(Pawn pawn, Thing t) { if ((t as ThingWithComps).TryGetComp <CompMountable>().IsMounted&& !ToolsForHaulUtility.IsDriverOfThisVehicle(pawn, t)) { return(null); } if (!(t as ThingWithComps).TryGetComp <CompRefuelable>().HasFuel) { return(null); } if (t.IsForbidden(Faction.OfPlayer)) { return(null); } if (!JoyUtility.EnjoyableOutsideNow(pawn, null)) { return(null); } if (PawnUtility.WillSoonHaveBasicNeed(pawn)) { return(null); } Region reg; if (!CellFinder.TryFindClosestRegionWith(pawn.Position.GetRegion(), TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), (Region r) => r.Room.PsychologicallyOutdoors && !r.IsForbiddenEntirely(pawn), 100, out reg)) { return(null); } IntVec3 root; if (!reg.TryFindRandomCellInRegionUnforbidden(pawn, null, out root)) { return(null); } List <IntVec3> list; if (!WalkPathFinder.TryFindWalkPath(pawn, root, out list)) { return(null); } Job job = new Job(this.def.jobDef, list[0]) { targetQueueA = new List <TargetInfo>(), targetB = t, }; for (int i = 1; i < list.Count; i++) { job.targetQueueA.Add(list[i]); } job.locomotionUrgency = LocomotionUrgency.Jog; return(job); }
//RCellFinder public static void TryFindGatheringSpot_PostFix(Pawn organizer, ref IntVec3 result, ref bool __result) { var enjoyableOutside = JoyUtility.EnjoyableOutsideNow(organizer); var map = organizer.Map; if (!map.listerThings.ThingsOfDef(ThingDef.Named("LotRH_PlantPartyTree")) .Any(x => x is Plant { LifeStage: PlantLifeStage.Mature }))
// Token: 0x06000568 RID: 1384 RVA: 0x00035040 File Offset: 0x00033440 public override Job TryGiveJob(Pawn pawn) { float HowMuchSnowIsThere = 0; if (pawn.Map.weatherManager.curWeather.snowRate > 0.0f) { HowMuchSnowIsThere = pawn.Map.weatherManager.curWeather.snowRate; } if (HowMuchSnowIsThere < 0.1f) { return(null); } if (!JoyUtility.EnjoyableOutsideNow(pawn, null)) { return(null); } if (PawnUtility.WillSoonHaveBasicNeed(pawn)) { return(null); } Predicate <IntVec3> cellValidator = (IntVec3 x) => !PawnUtility.KnownDangerAt(x, pawn.Map, pawn) && !x.GetTerrain(pawn.Map).avoidWander&& x.Standable(pawn.Map) && !x.Roofed(pawn.Map); Predicate <Region> validator = delegate(Region x) { IntVec3 intVec; return(x.Room.PsychologicallyOutdoors && !x.IsForbiddenEntirely(pawn) && x.TryFindRandomCellInRegionUnforbidden(pawn, cellValidator, out intVec)); }; Region reg; if (!CellFinder.TryFindClosestRegionWith(pawn.GetRegion(RegionType.Set_Passable), TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), validator, 100, out reg, RegionType.Set_Passable)) { return(null); } IntVec3 root; if (!reg.TryFindRandomCellInRegionUnforbidden(pawn, cellValidator, out root)) { return(null); } List <IntVec3> list; if (!WalkPathFinder.TryFindWalkPath(pawn, root, out list)) { return(null); } Job job = new Job(this.def.jobDef, list[0]); job.targetQueueA = new List <LocalTargetInfo>(); for (int i = 1; i < list.Count; i++) { job.targetQueueA.Add(list[i]); } job.locomotionUrgency = LocomotionUrgency.Walk; return(job); }
public override Job TryGiveJob(Pawn pawn) { if (!JoyUtility.EnjoyableOutsideNow(pawn.Map)) { return(null); } IntVec3 position = IntVec3.Invalid; RCellFinder.TryFindRandomSpotJustOutsideColony(pawn.Position, pawn.Map, pawn, out position, (IntVec3 x) => { if (!x.InBounds(pawn.Map) || !x.Walkable(pawn.Map)) { return(false); } if (x.IsForbidden(pawn)) { return(false); } TerrainDef terrainDef = x.GetTerrain(pawn.Map); if (terrainDef.fertility <= 0) { return(false); } int distSq = x.DistanceToSquared(pawn.Position); if (distSq < 9 && distSq > 225) { return(false); } if (!pawn.CanReserveAndReach(x, PathEndMode.Touch, Danger.None)) { return(false); } return(true); }); if (position.IsValid) { return(new Job(IdleJobDefOf.IdleJob_Graffiti, position) { locomotionUrgency = modSettings.wanderMovePolicy }); } return(null); }
public override Job TryGiveJob(Pawn pawn) { if (!JoyUtility.EnjoyableOutsideNow(pawn, null)) { return(null); } IntVec3 c = JoyGiver_FindTreasure.TryFindTreasureCell(pawn); if (!c.IsValid) { return(null); } return(new Job(this.def.jobDef, c)); }
protected override IEnumerable <Toil> MakeNewToils() { this.FailOn(() => !JoyUtility.EnjoyableOutsideNow(pawn.Map, null)); this.FailOn(() => pawn.Map.mapTemperature.OutdoorTemp < ModSettings_WaterIsCold.swimTemp - 5f); yield return(Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.OnCell)); Action swimTick = delegate() { JoyUtility.JoyTickCheckEnd(this.pawn, JoyTickFullJoyAction.GoToNextToil, 1f, null); }; Toil treadWaterToil = Toils_General.Wait(job.def.joyDuration / 3, TargetIndex.C); treadWaterToil.tickAction = swimTick; //Swim to first spot Toil firstSwimToil = Toils_Goto.GotoCell(TargetIndex.B, PathEndMode.OnCell); firstSwimToil.tickAction = swimTick; firstSwimToil.FailOn(() => this.pawn.Position.GetTerrain(this.pawn.Map) == TerrainDef.Named("Marsh")); yield return(firstSwimToil); yield return(treadWaterToil); //Swim to second spot Toil secondSwimToil = Toils_Goto.GotoCell(TargetIndex.C, PathEndMode.OnCell); secondSwimToil.tickAction = swimTick; secondSwimToil.FailOn(() => this.pawn.Position.GetTerrain(this.pawn.Map) == TerrainDef.Named("Marsh")); yield return(secondSwimToil); yield return(treadWaterToil); //Swim back to first spot yield return(firstSwimToil); yield return(treadWaterToil); //Return to shore Toil shoreReturnToil = Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.OnCell); shoreReturnToil.tickAction = delegate() { JoyUtility.JoyTickCheckEnd(this.pawn, JoyTickFullJoyAction.None, 1f, null); }; yield return(shoreReturnToil); yield break; }
static void Postfix(JobDriver_Goto __instance, ref IEnumerable <Toil> __result) { if (__instance?.job == null) { return; } if (__instance.job.targetB == LocalTargetInfo.Invalid || __instance.pawn?.Faction != Faction.OfPlayer) { return; } List <Toil> l = __result.ToList(); l[0].AddPreTickAction(delegate { Pawn a = __instance.GetActor(); if (a.Faction != Faction.OfPlayer) { return; } IntVec3 val = a.jobs.curJob.GetTarget(TargetIndex.B).Cell; if (val == IntVec3.Invalid) { return; } val.y += 1; // if (a.pather.Moving && a.pather.Destination != a.pather.nextCell) { if (val.y >= val.x) { a.pather.StartPath(a.pather.nextCell, PathEndMode.OnCell); } else if (a.pather.curPath != null && val.z != a.pather.curPath.NodesLeftCount) { val.z = a.pather.curPath.NodesLeftCount; if (!JoyUtility.EnjoyableOutsideNow(a.Map) && a.Position.Roofed(a.Map) && !a.pather.nextCell.Roofed(a.Map)) { a.pather.StartPath(a.Position, PathEndMode.OnCell); } } } // a.jobs.curJob.SetTarget(TargetIndex.B, val); }); __result = l; }
//RCellFinder public static void TryFindGatheringSpot_PostFix(Pawn organizer, ref IntVec3 result, ref bool __result) { bool enjoyableOutside = JoyUtility.EnjoyableOutsideNow(organizer, null); Map map = organizer.Map; if (map.listerThings.ThingsOfDef(ThingDef.Named("LotRH_PlantPartyTree")).Any(x => x is Plant y && y.HarvestableNow)) { bool baseValidator(IntVec3 cell) { if (!cell.Standable(map)) { return(false); } if (cell.GetDangerFor(organizer, map) != Danger.None) { return(false); } if (!enjoyableOutside && !cell.Roofed(map)) { return(false); } if (cell.IsForbidden(organizer)) { return(false); } if (!organizer.CanReserveAndReach(cell, PathEndMode.OnCell, Danger.None, 1, -1, null, false)) { return(false); } Room room = cell.GetRoom(map, RegionType.Set_Passable); bool flag = room != null && room.isPrisonCell; return(organizer.IsPrisoner == flag && GatheringsUtility.EnoughPotentialGuestsToStartGathering(map, GatheringDefOf.Party, new IntVec3?(cell))); } if ((from x in map.listerThings.ThingsOfDef(ThingDef.Named("LotRH_PlantPartyTree")).Where(x => x is Plant y && y.HarvestableNow) where baseValidator(x.InteractionCell) select x.InteractionCell).TryRandomElement(out result)) { __result = true; } } }
public override Job TryGiveJob(Pawn pawn) { bool allowedOutside = JoyUtility.EnjoyableOutsideNow(pawn, null); Job result; try { JoyGiver_CuddlePlushie.candidates.AddRange(pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.Art).Where(delegate(Thing thing) { if (thing.Faction != Faction.OfPlayer || thing.IsForbidden(pawn) || (!allowedOutside && !thing.Position.Roofed(thing.Map)) || !pawn.CanReserveAndReach(thing, PathEndMode.Touch, Danger.None, 1, -1, null, false) || !thing.IsPoliticallyProper(pawn)) { return(false); } CompArt compArt = thing.TryGetComp <CompArt>(); if (compArt == null) { Log.Error("No CompArt on thing being considered for viewing: " + thing, false); return(false); } //if (thing.def.defName != "Plushie") if (thing.def.defName.StartsWith("Plushie") == false) { return(false); } Room room = thing.GetRoom(RegionType.Set_Passable); return(room != null && ((room.Role != RoomRoleDefOf.Bedroom && room.Role != RoomRoleDefOf.Barracks && room.Role != RoomRoleDefOf.PrisonCell && room.Role != RoomRoleDefOf.PrisonBarracks && room.Role != RoomRoleDefOf.Hospital) || (pawn.ownership != null && pawn.ownership.OwnedRoom != null && pawn.ownership.OwnedRoom == room))); })); Thing t; if (!JoyGiver_CuddlePlushie.candidates.TryRandomElementByWeight((Thing target) => Math.Max(target.GetStatValue(StatDefOf.Beauty, true), 0.5f), out t)) { result = null; } else { result = JobMaker.MakeJob(this.def.jobDef, t); } } finally { JoyGiver_CuddlePlushie.candidates.Clear(); } return(result); }
public override Job TryGiveJob(Pawn pawn) { Map mapHeld = pawn.MapHeld; if (mapHeld == null || !ModSettings_WaterIsCold.funWater || !JoyUtility.EnjoyableOutsideNow(mapHeld, null) || PawnUtility.WillSoonHaveBasicNeed(pawn)) { return(null); } //Log.Message(pawn.Name + "is looking for a swimming hole near " + pawn.Position.x + ", " + pawn.Position.z); IntVec3 swimSpot; IntVec3 shoreSpot; IntVec3 wadeSpot = FindRandomSwimmingHoleNear(pawn.Position, mapHeld, pawn, out swimSpot, out shoreSpot); if (shoreSpot == wadeSpot) { return(null); } return(JobMaker.MakeJob(this.def.jobDef, shoreSpot, wadeSpot, swimSpot)); }
public override Job TryGiveJob(Pawn pawn) { string debugStr = MyDebug ? pawn.LabelShort + " TryGiveJob - " : ""; Tools.Warn(debugStr + "entering ", MyDebug); if (!JoyUtility.EnjoyableOutsideNow(pawn) || pawn.Map.weatherManager.curWeather.rainRate > 0.1f) { Tools.Warn(debugStr + "EnjoyableOutsideNow/rain: ko", MyDebug); return(null); } if (!this.TryFindPawnAndTargetCells(pawn, out IntVec3 pawnCell, out IntVec3 targetCell)) { Tools.Warn(debugStr + "TryFindPawnAndTargetCells: ko", MyDebug); return(null); } Tools.Warn(debugStr + "Making Job", MyDebug); return(JobMaker.MakeJob(def.jobDef, pawnCell, targetCell)); }
// Token: 0x0600005E RID: 94 RVA: 0x00004464 File Offset: 0x00002664 public override Job TryGiveJob(Pawn pawn) { bool allowedOutside = JoyUtility.EnjoyableOutsideNow(pawn, null); var tankDefs = (from tankDef in DefDatabase <ThingDef> .AllDefsListForReading where tankDef.defName.StartsWith("AQFishTank") select tankDef.defName).ToList(); foreach (var tankDef in tankDefs) { try { ThingDef AQBowlDef = ThingDef.Named(tankDef); candidates.AddRange(pawn.Map.listerThings.ThingsOfDef(AQBowlDef).Where(delegate(Thing thing) { if (!AQUtility.HasFish(thing)) { return(false); } if (thing.Faction != Faction.OfPlayer || thing.IsForbidden(pawn) || (!allowedOutside && !thing.Position.Roofed(thing.Map)) || !pawn.CanReserveAndReach(thing, PathEndMode.Touch, Danger.None, 1, -1, null, false) || !thing.IsPoliticallyProper(pawn)) { return(false); } Room room = thing.GetRoom(RegionType.Set_Passable); return(room != null && AQUtility.IsValidAquaRoom(pawn, room)); })); } catch { } } Job result2; if (!candidates.TryRandomElementByWeight((Thing target) => Mathf.Max(target.GetStatValue(StatDefOf.Beauty, true), 0.5f), out Thing result)) { result2 = null; } else { result2 = JobMaker.MakeJob(def.jobDef, result); } candidates.Clear(); return(result2); }
static bool Prefix(Pawn pawn, ref Job __result, JobGiver_Wander __instance) { if (pawn.Faction != Faction.OfPlayer || JoyUtility.EnjoyableOutsideNow(pawn.Map) || pawn.Position.Roofed(pawn.Map)) { return(true); } Predicate <IntVec3> cellValidator = (IntVec3 x) => pawn.Map.areaManager.Home[x] && !PawnUtility.KnownDangerAt(x, pawn.Map, pawn) && !x.GetTerrain(pawn.Map).avoidWander&& x.Standable(pawn.Map) && x.Roofed(pawn.Map); Predicate <Region> validator = delegate(Region x) { IntVec3 intVec; return(x.OverlapWith(pawn.Map.areaManager.Home) > AreaOverlap.None && !x.IsForbiddenEntirely(pawn) && x.TryFindRandomCellInRegionUnforbidden(pawn, cellValidator, out intVec)); }; Region reg; if (!CellFinder.TryFindClosestRegionWith(pawn.GetRegion(RegionType.Set_Passable), TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), validator, 100, out reg, RegionType.Set_Passable)) { return(true); } // IntVec3 root; if (!reg.TryFindRandomCellInRegionUnforbidden(pawn, cellValidator, out root)) { return(true); } root = RCellFinder.RandomWanderDestFor(pawn, root, 7, ((Pawn p, IntVec3 v1, IntVec3 v2) => true), PawnUtility.ResolveMaxDanger(pawn, Danger.Deadly)); Job job = JobMaker.MakeJob(JobDefOf.GotoWander, root); job.locomotionUrgency = LocomotionUrgency.Jog; job.expiryInterval = -1; __result = job; return(false); }
protected override IEnumerable <Toil> MakeNewToils() { this.FailOnForbidden(TargetIndex.A); yield return(Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.Touch)); Toil doWork = new Toil(); doWork.defaultCompleteMode = ToilCompleteMode.Never; doWork.FailOn(() => !JoyUtility.EnjoyableOutsideNow(this.pawn, null)); doWork.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch); doWork.PlaySustainerOrSound(SoundDefOf.Interact_CleanFilth); doWork.initAction = () => { this.workLeft = 600f; }; doWork.tickAction = () => { if (pawn.IsHashIntervalTick(50)) { pawn.skills.Learn(SkillDefOf.Artistic, 0.5f); } this.workLeft -= doWork.actor.GetStatValue(StatDefOf.WorkSpeedGlobal, true); if (this.workLeft <= 0f) { Thing thing = ThingMaker.MakeThing(DSFIThingDefOf.DSFI_Scribbling, null); Thing spawnedThing = GenSpawn.Spawn(thing, this.TargetLocA, this.Map, WipeMode.Vanish); spawnedThing.Rotation = Rot4.Random; this.ReadyForNextToil(); return; } }; yield return(doWork); yield break; }
/// <summary> /// Makes the new toils. /// </summary> /// <returns></returns> protected override IEnumerable <Toil> MakeNewToils() { this.FailOn(() => !JoyUtility.EnjoyableOutsideNow(pawn)); Toil goToil = Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.OnCell); goToil.tickAction = GotToToil; var tComps = pawn.health.hediffSet.hediffs.Select(h => h.TryGetComp <Comp_TerrainProduction>()) .Where(c => c != null) .ToList(); yield return(goToil); void OnEndToil() { if (job.targetQueueA.Count > 0) { Log.Message("checking production now"); if (tComps.Count > 0 && Rand.Range(0, 1f) < 0.4f) { tComps.RandomElement().ProduceNow(); } LocalTargetInfo targetA = job.targetQueueA[0]; job.targetQueueA.RemoveAt(0); job.targetA = targetA; JumpToToil(goToil); } } yield return(new Toil() { initAction = OnEndToil }); //TODO trigger production }
protected override IEnumerable <Toil> MakeNewToils() { this.FailOnForbidden(TargetIndex.A); yield return(Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.Touch)); Toil doWork = new Toil(); doWork.defaultCompleteMode = ToilCompleteMode.Never; doWork.FailOn(() => !JoyUtility.EnjoyableOutsideNow(this.pawn, null)); doWork.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch); doWork.initAction = delegate() { this.workLeft = 1800f; }; doWork.tickAction = delegate() { if (pawn.IsHashIntervalTick(20)) { pawn.skills.Learn(SkillDefOf.Artistic, 5f); } this.workLeft -= doWork.actor.GetStatValue(StatDefOf.ConstructionSpeed, true); if (this.workLeft <= 0f) { Thing thing = ThingMaker.MakeThing(ThingDefOf.Snowman, null); thing.SetFaction(this.pawn.Faction, null); GenSpawn.Spawn(thing, this.TargetLocA, this.Map, WipeMode.Vanish); this.ReadyForNextToil(); return; } }; yield return(doWork); yield break; }
public override Job TryGiveJob(Pawn pawn) { if (!JoyUtility.EnjoyableOutsideNow(pawn.Map)) { return(null); } IntVec3 position = IntVec3.Invalid; RCellFinder.TryFindRandomSpotJustOutsideColony(pawn.Position, pawn.Map, pawn, out position, (IntVec3 x) => pawn.CanReserveAndReach(x, PathEndMode.Touch, Danger.None)); if (!position.IsValid) { return(null); } IntVec3 standPosition = IntVec3.Invalid; (from x in GenRadial.RadialCellsAround(position, 4.0f, true) where x.DistanceToSquared(position) > 9 && GenSight.LineOfSight(position, x, pawn.Map) select x).TryRandomElement(out standPosition); if (standPosition == null) { return(null); } if (position.IsValid) { return(new Job(IdleJobDefOf.IdleJob_ThrowingStone, position, standPosition) { locomotionUrgency = LocomotionUrgency.Walk }); } return(null); }