static bool Prefix(Pawn pawn, ref Job __result)
        {
            if (pawn == null || pawn.Faction == null || !pawn.Faction.IsPlayer)
            {
                return(true);
            }
            Comp_PawnMenu comp = pawn.GetComp <Comp_PawnMenu>();

            if (comp == null && !comp.activated())
            {
                return(true);
            }
            if (pawn.inventory == null)
            {
                return(false);
            }
            ThingOwner <Thing> innerContainer = pawn.inventory.innerContainer;

            for (int i = 0; i < innerContainer.Count; i++)
            {
                Thing thing = innerContainer[i];
                if (thing.def.ingestible != null && thing.def.ingestible.nutrition > 0.3f && thing.def.ingestible.preferability >= FoodPreferability.MealAwful && pawn.RaceProps.CanEverEat(thing))
                {
                    return(false);
                }
            }
            if (pawn.Map.resourceCounter.TotalHumanEdibleNutrition < (float)pawn.Map.mapPawns.ColonistsSpawnedCount * 1.5f)
            {
                return(false);
            }
            Thing thing2 = GenClosest.ClosestThing_Regionwise_ReachablePrioritized(pawn.Position, pawn.Map, ThingRequest.ForGroup(ThingRequestGroup.FoodSourceNotPlantOrTree), PathEndMode.ClosestTouch, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 20f, delegate(Thing t) {
                if (!comp.contains(t.def))
                {
                    return(false);
                }
                if (t.def.category != ThingCategory.Item || t.def.ingestible == null || t.def.ingestible.nutrition < 0.3f || t.IsForbidden(pawn) || t is Corpse || !pawn.CanReserve(t, 1, -1, null, false) || !t.IsSociallyProper(pawn) || !pawn.RaceProps.CanEverEat(t))
                {
                    return(false);
                }
                List <ThoughtDef> list = FoodUtility.ThoughtsFromIngesting(pawn, t, FoodUtility.GetFinalIngestibleDef(t, false));
                for (int j = 0; j < list.Count; j++)
                {
                    if (list[j].stages[0].baseMoodEffect < 0f)
                    {
                        return(false);
                    }
                }
                return(true);
            }, (Thing x) => FoodUtility.FoodOptimality(pawn, x, FoodUtility.GetFinalIngestibleDef(x, false), 0f, false), 24, 30);

            if (thing2 == null)
            {
                return(false);
            }
            __result = new Job(JobDefOf.TakeInventory, thing2)
            {
                count = 1
            };
            return(false);
        }
        public static bool TryFindBestItemToSteal(IntVec3 root, Map map, float maxDist, out Thing item, Pawn thief, List <Thing> disallowed = null)
        {
            if (thief != null && !thief.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))
            {
                item = null;
                return(false);
            }
            if ((thief != null && !map.reachability.CanReachMapEdge(thief.Position, TraverseParms.For(thief, Danger.Some, TraverseMode.ByPawn, false))) || (thief == null && !map.reachability.CanReachMapEdge(root, TraverseParms.For(TraverseMode.PassDoors, Danger.Some, false))))
            {
                item = null;
                return(false);
            }
            Predicate <Thing> predicate      = (Thing t) => (thief == null || thief.CanReserve(t, 1, -1, null, false)) && (disallowed == null || !disallowed.Contains(t)) && t.def.stealable && !t.IsBurning();
            ThingRequest      thingReq       = ThingRequest.ForGroup(ThingRequestGroup.HaulableEverOrMinifiable);
            PathEndMode       peMode         = PathEndMode.ClosestTouch;
            TraverseParms     traverseParams = TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Some, false);
            Predicate <Thing> validator      = predicate;

            if (StealAIUtility.< > f__mg$cache0 == null)
            {
                StealAIUtility.< > f__mg$cache0 = new Func <Thing, float>(StealAIUtility.GetValue);
            }
            item = GenClosest.ClosestThing_Regionwise_ReachablePrioritized(root, map, thingReq, peMode, traverseParams, maxDist, validator, StealAIUtility.< > f__mg$cache0, 15, 15);
            if (item != null && StealAIUtility.GetValue(item) < 320f)
            {
                item = null;
            }
            return(item != null);
        }
示例#3
0
        public static bool TryFindBestItemToSteal(IntVec3 root, Map map, float maxDist, out Thing item, Pawn thief, List <Thing> disallowed = null)
        {
            bool result;

            if (thief != null && !thief.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))
            {
                item   = null;
                result = false;
            }
            else if ((thief != null && !map.reachability.CanReachMapEdge(thief.Position, TraverseParms.For(thief, Danger.Some, TraverseMode.ByPawn, false))) || (thief == null && !map.reachability.CanReachMapEdge(root, TraverseParms.For(TraverseMode.PassDoors, Danger.Some, false))))
            {
                item   = null;
                result = false;
            }
            else
            {
                Predicate <Thing> validator = (Thing t) => (thief == null || thief.CanReserve(t, 1, -1, null, false)) && (disallowed == null || !disallowed.Contains(t)) && t.def.stealable && !t.IsBurning();
                item = GenClosest.ClosestThing_Regionwise_ReachablePrioritized(root, map, ThingRequest.ForGroup(ThingRequestGroup.HaulableEverOrMinifiable), PathEndMode.ClosestTouch, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Some, false), maxDist, validator, (Thing x) => StealAIUtility.GetValue(x), 15, 15);
                if (item != null && StealAIUtility.GetValue(item) < 320f)
                {
                    item = null;
                }
                result = (item != null);
            }
            return(result);
        }
示例#4
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            if (pawn.inventory == null)
            {
                return(null);
            }
            float invNutrition = GetInventoryPackableFoodNutrition(pawn);

            if (invNutrition > 0.4f)
            {
                return(null);
            }
            if (pawn.Map.resourceCounter.TotalHumanEdibleNutrition < (float)pawn.Map.mapPawns.ColonistsSpawnedCount * 1.5f)
            {
                return(null);
            }
            Thing thing = GenClosest.ClosestThing_Regionwise_ReachablePrioritized(pawn.Position, pawn.Map, ThingRequest.ForGroup(ThingRequestGroup.FoodSourceNotPlantOrTree), PathEndMode.ClosestTouch, TraverseParms.For(pawn), 20f, delegate(Thing t)
            {
                if (!IsGoodPackableFoodFor(t, pawn) || t.IsForbidden(pawn) || !pawn.CanReserve(t) || !t.IsSociallyProper(pawn))
                {
                    return(false);
                }
                float num2 = invNutrition + t.GetStatValue(StatDefOf.Nutrition) * (float)t.stackCount;
                if (num2 < 0.8f)
                {
                    return(false);
                }
                List <ThoughtDef> list = FoodUtility.ThoughtsFromIngesting(pawn, t, FoodUtility.GetFinalIngestibleDef(t));
                for (int i = 0; i < list.Count; i++)
                {
                    if (list[i].stages[0].baseMoodEffect < 0f)
                    {
                        return(false);
                    }
                }
                return(true);
            }, (Thing x) => FoodUtility.FoodOptimality(pawn, x, FoodUtility.GetFinalIngestibleDef(x), 0f));

            if (thing == null)
            {
                return(null);
            }
            float num = pawn.needs.food.MaxLevel - invNutrition;
            int   a   = Mathf.FloorToInt(num / thing.GetStatValue(StatDefOf.Nutrition));

            a = Mathf.Min(a, thing.stackCount);
            a = Mathf.Max(a, 1);
            Job job = new Job(JobDefOf.TakeInventory, thing);

            job.count = a;
            return(job);
        }
        public static bool TryFindBestItemToSteal(IntVec3 root, Map map, float maxDist, out Thing item, Pawn thief, List <Thing> disallowed = null)
        {
            if (thief != null && !thief.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))
            {
                item = null;
                return(false);
            }
            if (thief != null && !map.reachability.CanReachMapEdge(thief.Position, TraverseParms.For(thief, Danger.Some, TraverseMode.ByPawn, false)))
            {
                goto IL_009d;
            }
            if (thief == null && !map.reachability.CanReachMapEdge(root, TraverseParms.For(TraverseMode.PassDoors, Danger.Some, false)))
            {
                goto IL_009d;
            }
            Predicate <Thing> validator = delegate(Thing t)
            {
                if (thief != null && !thief.CanReserve(t, 1, -1, null, false))
                {
                    return(false);
                }
                if (disallowed != null && disallowed.Contains(t))
                {
                    return(false);
                }
                if (!t.def.stealable)
                {
                    return(false);
                }
                if (t.IsBurning())
                {
                    return(false);
                }
                return(true);
            };

            item = GenClosest.ClosestThing_Regionwise_ReachablePrioritized(root, map, ThingRequest.ForGroup(ThingRequestGroup.HaulableEverOrMinifiable), PathEndMode.ClosestTouch, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Some, false), maxDist, validator, StealAIUtility.GetValue, 15, 15);
            if (item != null && StealAIUtility.GetValue(item) < 320.0)
            {
                item = null;
            }
            return(item != null);

IL_009d:
            item = null;
            return(false);
        }
        protected override Job TryGiveJob(Pawn pawn)
        {
            if (pawn.inventory == null)
            {
                return(null);
            }
            ThingOwner <Thing> innerContainer = pawn.inventory.innerContainer;

            for (int i = 0; i < innerContainer.Count; i++)
            {
                Thing thing = innerContainer[i];
                if (thing.def.ingestible != null && thing.def.ingestible.nutrition > 0.30000001192092896 && (int)thing.def.ingestible.preferability >= 6 && pawn.RaceProps.CanEverEat(thing))
                {
                    return(null);
                }
            }
            if (pawn.Map.resourceCounter.TotalHumanEdibleNutrition < (float)pawn.Map.mapPawns.ColonistsSpawnedCount * 1.5)
            {
                return(null);
            }
            Thing thing2 = GenClosest.ClosestThing_Regionwise_ReachablePrioritized(pawn.Position, pawn.Map, ThingRequest.ForGroup(ThingRequestGroup.FoodSourceNotPlantOrTree), PathEndMode.ClosestTouch, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 20f, delegate(Thing t)
            {
                if (t.def.category == ThingCategory.Item && t.def.ingestible != null && !(t.def.ingestible.nutrition < 0.30000001192092896) && !t.IsForbidden(pawn) && !(t is Corpse) && pawn.CanReserve(t, 1, -1, null, false) && t.IsSociallyProper(pawn) && pawn.RaceProps.CanEverEat(t))
                {
                    List <ThoughtDef> list = FoodUtility.ThoughtsFromIngesting(pawn, t, FoodUtility.GetFinalIngestibleDef(t, false));
                    for (int j = 0; j < list.Count; j++)
                    {
                        if (list[j].stages[0].baseMoodEffect < 0.0)
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
                return(false);
            }, (Thing x) => FoodUtility.FoodOptimality(pawn, x, FoodUtility.GetFinalIngestibleDef(x, false), 0f, false), 24, 30);

            if (thing2 == null)
            {
                return(null);
            }
            Job job = new Job(JobDefOf.TakeInventory, thing2);

            job.count = 1;
            return(job);
        }
示例#7
0
        public static Thing FindPlaceToHeatFood(Thing food, Pawn pawn, float searchRadius = -1f, Thing searchNear = null)
        {
            if (searchNear == null)
            {
                searchNear = food;
            }

            if (searchRadius < 1f)
            {
                searchRadius = HotMealsSettings.searchRadius;
            }

            Predicate <Thing> valid = delegate(Thing m)
            {
                if (m.def.building == null || !m.def.building.isMealSource)
                {
                    return(false);
                }
                if (!HotMealsSettings.useCookingAppliances && !allowedHeaters.Contains(m.def))
                {
                    return(false);
                }
                CompRefuelable compRefuelable = m.TryGetComp <CompRefuelable>();
                if (compRefuelable != null && !compRefuelable.HasFuel)
                {
                    return(false);
                }
                CompPowerTrader compPowerTrader = m.TryGetComp <CompPowerTrader>();
                if (compPowerTrader != null && !compPowerTrader.PowerOn)
                {
                    return(false);
                }
                return(!m.IsForbidden(pawn) && (HotMealsSettings.multipleHeat || pawn.CanReserve(m, 1, 1, null, false)));
            };

            Thing result = GenClosest.ClosestThing_Regionwise_ReachablePrioritized(searchNear.PositionHeld, searchNear.MapHeld, ThingRequest.ForGroup(ThingRequestGroup.BuildingArtificial),
                                                                                   PathEndMode.Touch, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), searchRadius, valid, (thing) => thing.GetStatValue(StatDefOf.WorkTableWorkSpeedFactor));

            return(result);
        }
        protected override Job TryGiveJob(Pawn pawn)
        {
            Job result;

            if (pawn.inventory == null)
            {
                result = null;
            }
            else
            {
                float invNutrition = this.GetInventoryPackableFoodNutrition(pawn);
                if (invNutrition > 0.4f)
                {
                    result = null;
                }
                else if (pawn.Map.resourceCounter.TotalHumanEdibleNutrition < (float)pawn.Map.mapPawns.ColonistsSpawnedCount * 1.5f)
                {
                    result = null;
                }
                else
                {
                    Thing thing = GenClosest.ClosestThing_Regionwise_ReachablePrioritized(pawn.Position, pawn.Map, ThingRequest.ForGroup(ThingRequestGroup.FoodSourceNotPlantOrTree), PathEndMode.ClosestTouch, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 20f, delegate(Thing t)
                    {
                        bool result2;
                        if (!this.IsGoodPackableFoodFor(t, pawn) || t.IsForbidden(pawn) || !pawn.CanReserve(t, 1, -1, null, false) || !t.IsSociallyProper(pawn))
                        {
                            result2 = false;
                        }
                        else
                        {
                            float num3 = invNutrition + t.GetStatValue(StatDefOf.Nutrition, true) * (float)t.stackCount;
                            if (num3 < 0.8f)
                            {
                                result2 = false;
                            }
                            else
                            {
                                List <ThoughtDef> list = FoodUtility.ThoughtsFromIngesting(pawn, t, FoodUtility.GetFinalIngestibleDef(t, false));
                                for (int i = 0; i < list.Count; i++)
                                {
                                    if (list[i].stages[0].baseMoodEffect < 0f)
                                    {
                                        return(false);
                                    }
                                }
                                result2 = true;
                            }
                        }
                        return(result2);
                    }, (Thing x) => FoodUtility.FoodOptimality(pawn, x, FoodUtility.GetFinalIngestibleDef(x, false), 0f, false), 24, 30);
                    if (thing == null)
                    {
                        result = null;
                    }
                    else
                    {
                        float num  = pawn.needs.food.MaxLevel - invNutrition;
                        int   num2 = Mathf.FloorToInt(num / thing.GetStatValue(StatDefOf.Nutrition, true));
                        num2   = Mathf.Min(num2, thing.stackCount);
                        num2   = Mathf.Max(num2, 1);
                        result = new Job(JobDefOf.TakeInventory, thing)
                        {
                            count = num2
                        };
                    }
                }
            }
            return(result);
        }
示例#9
0
        public static bool TryFindBestItemToSteal(IntVec3 root, Map map, float maxDist, out Thing item, Pawn thief, List <Thing> disallowed = null, Danger danger = Danger.Some)
        {
            if (map == null)
            {
                //Log.Message(" - TryFindBestItemToSteal - item = null; - 2", true);
                item = null;
                //Log.Message(" - TryFindBestItemToSteal - return false; - 3", true);
                return(false);
            }
            if (thief != null && !thief.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))
            {
                //Log.Message(" - TryFindBestItemToSteal - item = null; - 5", true);
                item = null;
                //Log.Message(" - TryFindBestItemToSteal - return false; - 6", true);
                return(false);
            }
            if ((thief != null && !map.reachability.CanReachMapEdge(thief.Position, TraverseParms.For(thief, Danger.Some))) ||
                (thief == null && !map.reachability.CanReachMapEdge(root, TraverseParms.For(TraverseMode.PassDoors, Danger.Some))))
            {
                //Log.Message(" - TryFindBestItemToSteal - item = null; - 8", true);
                item = null;
                //Log.Message(" - TryFindBestItemToSteal - return false; - 9", true);
                return(false);
            }
            Predicate <Thing> validator = delegate(Thing t)
            {
                if (!t.def.defName.ToLower().Contains("chunk"))
                {
                    //Log.Message("Item candidate: " + t, true);
                }
                if (t.def.IsCorpse)
                {
                    return(false);
                }
                if (thief != null && !thief.CanReserve(t))
                {
                    //Log.Message(" - TryFindBestItemToSteal - return false; - 11", true);
                    return(false);
                }
                if (disallowed != null && disallowed.Contains(t))
                {
                    //Log.Message(" - TryFindBestItemToSteal - return false; - 13", true);
                    return(false);
                }
                if (!t.def.stealable)
                {
                    //Log.Message(" - TryFindBestItemToSteal - return false; - 15", true);
                    return(false);
                }
                if (t.Faction == thief.Faction)
                {
                    return(false);
                }
                if (t.def.IsWeapon)
                {
                    return(false);
                }
                if (GetValue(t) < 10f)
                {
                    return(false);
                }
                return((!t.IsBurning()) ? true : false);
                //Log.Message(" - TryFindBestItemToSteal - }; - 17", true);
            };

            item = GenClosest.ClosestThing_Regionwise_ReachablePrioritized(root, map, ThingRequest.ForGroup(ThingRequestGroup.HaulableEverOrMinifiable),
                                                                           PathEndMode.ClosestTouch, TraverseParms.For(TraverseMode.PassDoors, danger), maxDist, validator, (Thing x) => GetValue(x), 15, 15);
            if (item == null)
            {
                //Log.Message("Item is null", true);
            }
            else
            {
                //Log.Message(item + " - " + GetValue(item), true);
            }
            return(item != null);
        }
示例#10
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            // 所持品インスタンスがない
            if (pawn.inventory == null)
            {
                return(null);
            }

            // 水分要求がない
            var need_water = pawn.needs.Water();

            if (need_water == null)
            {
                return(null);
            }

            bool validator(Thing t)
            {
                // 食べられるものは携帯飲料としては選ばれない
                if (t.def.IsIngestible)
                {
                    return(false);
                }

                var comp = t.TryGetComp <CompWaterSource>();

                if (comp == null)
                {
                    return(false); // 水源でないもの×
                }

                if (!comp.IsWaterSource)
                {
                    return(false); // 水源でないもの×
                }

                if (comp.SourceType != CompProperties_WaterSource.SourceType.Item)
                {
                    return(false); // 水アイテムではないもの×
                }

                if (comp.WaterAmount * comp.MaxNumToGetAtOnce < Need_Water.MinWaterAmountPerOneDrink)
                {
                    return(false); // 最低水分量を満たしていないもの×
                }

                if (MizuDef.Dic_WaterTypeDef[comp.WaterType].waterPreferability < MinWaterPreferability)
                {
                    return(false); // 最低の水質を満たしていないもの×
                }

                return(true);
            }

            // 既に条件を満たしたアイテムを持っているか?
            foreach (var thing in pawn.inventory.innerContainer)
            {
                if (!validator(thing))
                {
                    continue;
                }

                return(null);
            }

            // マップ中の水アイテムの合計水分量が、最低限必要とされる水の量(×入植者の人数)以下しかなければ、
            // 個人の所持品には入れない
            if (pawn.Map.resourceCounter.TotalWater() < pawn.Map.mapPawns.ColonistsSpawnedCount * MinWaterPerColonistToDo)
            {
                return(null);
            }

            var waterThing = GenClosest.ClosestThing_Regionwise_ReachablePrioritized(
                pawn.Position,
                pawn.Map,
                ThingRequest.ForGroup(ThingRequestGroup.HaulableEver),
                PathEndMode.ClosestTouch,
                TraverseParms.For(pawn),
                20f,
                t =>
            {
                if (!validator(t))
                {
                    return(false);        // 所持品チェック時と同じ条件を満たしていない×
                }

                if (t.IsForbidden(pawn))
                {
                    return(false);        // 禁止されている×
                }

                if (!pawn.CanReserve(t))
                {
                    return(false);        // 予約不可能×
                }

                if (!t.IsSociallyProper(pawn))
                {
                    return(false);        // 囚人部屋の物×
                }

                return(true);
            },         // スコアの高いものが優先?
                x => MizuUtility.GetWaterItemScore(pawn, x, 0f, true));

            if (waterThing == null)
            {
                return(null);
            }

            return(new Job(JobDefOf.TakeInventory, waterThing)
            {
                count = Mathf.Min(MizuUtility.StackCountForWater(waterThing, NeedTotalWaterAmount), waterThing.stackCount)
            });
        }