public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Job result;

            if (!base.ShouldTakeCareOfPrisoner(pawn, t))
            {
                result = null;
            }
            else
            {
                Pawn     pawn2 = (Pawn)t;
                Thing    thing;
                ThingDef thingDef;
                if (!pawn2.guest.CanBeBroughtFood)
                {
                    result = null;
                }
                else if (!pawn2.Position.IsInPrisonCell(pawn2.Map))
                {
                    result = null;
                }
                else if (pawn2.needs.food.CurLevelPercentage >= pawn2.needs.food.PercentageThreshHungry + 0.02f)
                {
                    result = null;
                }
                else if (WardenFeedUtility.ShouldBeFed(pawn2))
                {
                    result = null;
                }
                else if (!FoodUtility.TryFindBestFoodSourceFor(pawn, pawn2, pawn2.needs.food.CurCategory == HungerCategory.Starving, out thing, out thingDef, false, true, false, false, false, false, false))
                {
                    result = null;
                }
                else if (thing.GetRoom(RegionType.Set_Passable) == pawn2.GetRoom(RegionType.Set_Passable))
                {
                    result = null;
                }
                else if (WorkGiver_Warden_DeliverFood.FoodAvailableInRoomTo(pawn2))
                {
                    result = null;
                }
                else
                {
                    float nutrition = FoodUtility.GetNutrition(thing, thingDef);
                    result = new Job(JobDefOf.DeliverFood, thing, pawn2)
                    {
                        count   = FoodUtility.WillIngestStackCountOf(pawn2, thingDef, nutrition),
                        targetC = RCellFinder.SpotToChewStandingNear(pawn2, thing)
                    };
                }
            }
            return(result);
        }
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            if (!base.ShouldTakeCareOfPrisoner(pawn, t))
            {
                return(null);
            }
            Pawn pawn2 = (Pawn)t;

            if (!pawn2.guest.CanBeBroughtFood)
            {
                return(null);
            }
            if (!pawn2.Position.IsInPrisonCell(pawn2.Map))
            {
                return(null);
            }
            if (pawn2.needs.food.CurLevelPercentage >= pawn2.needs.food.PercentageThreshHungry + 0.019999999552965164)
            {
                return(null);
            }
            if (WardenFeedUtility.ShouldBeFed(pawn2))
            {
                return(null);
            }
            Thing    thing = default(Thing);
            ThingDef def   = default(ThingDef);

            if (!FoodUtility.TryFindBestFoodSourceFor(pawn, pawn2, pawn2.needs.food.CurCategory == HungerCategory.Starving, out thing, out def, false, true, false, false, false, false))
            {
                return(null);
            }
            if (thing.GetRoom(RegionType.Set_Passable) == pawn2.GetRoom(RegionType.Set_Passable))
            {
                return(null);
            }
            if (WorkGiver_Warden_DeliverFood.FoodAvailableInRoomTo(pawn2))
            {
                return(null);
            }
            Job job = new Job(JobDefOf.DeliverFood, thing, pawn2);

            job.count   = FoodUtility.WillIngestStackCountOf(pawn2, def);
            job.targetC = RCellFinder.SpotToChewStandingNear(pawn2, thing);
            return(job);
        }
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            if (!ShouldTakeCareOfPrisoner(pawn, t))
            {
                return(null);
            }
            Pawn pawn2 = (Pawn)t;

            if (!pawn2.guest.CanBeBroughtFood)
            {
                return(null);
            }
            if (!pawn2.Position.IsInPrisonCell(pawn2.Map))
            {
                return(null);
            }
            if (pawn2.needs.food.CurLevelPercentage >= pawn2.needs.food.PercentageThreshHungry + 0.02f)
            {
                return(null);
            }
            if (WardenFeedUtility.ShouldBeFed(pawn2))
            {
                return(null);
            }
            if (!FoodUtility.TryFindBestFoodSourceFor(pawn, pawn2, pawn2.needs.food.CurCategory == HungerCategory.Starving, out Thing foodSource, out ThingDef foodDef, canRefillDispenser: false, canUseInventory: true, allowForbidden: false, allowCorpse: false))
            {
                return(null);
            }
            if (foodSource.GetRoom() == pawn2.GetRoom())
            {
                return(null);
            }
            if (FoodAvailableInRoomTo(pawn2))
            {
                return(null);
            }
            float nutrition = FoodUtility.GetNutrition(foodSource, foodDef);
            Job   job       = new Job(JobDefOf.DeliverFood, foodSource, pawn2);

            job.count   = FoodUtility.WillIngestStackCountOf(pawn2, foodDef, nutrition);
            job.targetC = RCellFinder.SpotToChewStandingNear(pawn2, foodSource);
            return(job);
        }
예제 #4
0
        public static Toil CarryIngestibleToChewSpot(Pawn pawn, TargetIndex ingestibleInd)
        {
            Toil toil = new Toil();

            toil.initAction = delegate()
            {
                Pawn              actor              = toil.actor;
                IntVec3           intVec             = IntVec3.Invalid;
                Thing             thing              = null;
                Thing             thing2             = actor.CurJob.GetTarget(ingestibleInd).Thing;
                Predicate <Thing> baseChairValidator = delegate(Thing t)
                {
                    bool result;
                    if (t.def.building == null || !t.def.building.isSittable)
                    {
                        result = false;
                    }
                    else if (t.IsForbidden(pawn))
                    {
                        result = false;
                    }
                    else if (!actor.CanReserve(t, 1, -1, null, false))
                    {
                        result = false;
                    }
                    else if (!t.IsSociallyProper(actor))
                    {
                        result = false;
                    }
                    else if (t.IsBurning())
                    {
                        result = false;
                    }
                    else if (t.HostileTo(pawn))
                    {
                        result = false;
                    }
                    else
                    {
                        bool flag = false;
                        for (int i = 0; i < 4; i++)
                        {
                            IntVec3  c       = t.Position + GenAdj.CardinalDirections[i];
                            Building edifice = c.GetEdifice(t.Map);
                            if (edifice != null && edifice.def.surfaceType == SurfaceType.Eat)
                            {
                                flag = true;
                                break;
                            }
                        }
                        result = flag;
                    }
                    return(result);
                };
                if (thing2.def.ingestible.chairSearchRadius > 0f)
                {
                    thing = GenClosest.ClosestThingReachable(actor.Position, actor.Map, ThingRequest.ForGroup(ThingRequestGroup.BuildingArtificial), PathEndMode.OnCell, TraverseParms.For(actor, Danger.Deadly, TraverseMode.ByPawn, false), thing2.def.ingestible.chairSearchRadius, (Thing t) => baseChairValidator(t) && t.Position.GetDangerFor(pawn, t.Map) == Danger.None, null, 0, -1, false, RegionType.Set_Passable, false);
                }
                if (thing == null)
                {
                    intVec = RCellFinder.SpotToChewStandingNear(actor, actor.CurJob.GetTarget(ingestibleInd).Thing);
                    Danger chewSpotDanger = intVec.GetDangerFor(pawn, actor.Map);
                    if (chewSpotDanger != Danger.None)
                    {
                        thing = GenClosest.ClosestThingReachable(actor.Position, actor.Map, ThingRequest.ForGroup(ThingRequestGroup.BuildingArtificial), PathEndMode.OnCell, TraverseParms.For(actor, Danger.Deadly, TraverseMode.ByPawn, false), thing2.def.ingestible.chairSearchRadius, (Thing t) => baseChairValidator(t) && t.Position.GetDangerFor(pawn, t.Map) <= chewSpotDanger, null, 0, -1, false, RegionType.Set_Passable, false);
                    }
                }
                if (thing != null)
                {
                    intVec = thing.Position;
                    actor.Reserve(thing, actor.CurJob, 1, -1, null);
                }
                actor.Map.pawnDestinationReservationManager.Reserve(actor, actor.CurJob, intVec);
                actor.pather.StartPath(intVec, PathEndMode.OnCell);
            };
            toil.defaultCompleteMode = ToilCompleteMode.PatherArrival;
            return(toil);
        }