コード例 #1
0
 public static bool WillConsume(BloodType bl, BloodPreferabilty pref)
 {
     if ((int)bl < (int)pref)
     {
         return(false);
     }
     return(true);
 }
コード例 #2
0
        // RimWorld.FoodUtility
        public static Thing BestBloodSourceOnMap(Pawn getter, Pawn eater, bool desperate, BloodPreferabilty maxPref = BloodPreferabilty.Highblood, bool allowForbidden = false)
        {
            bool getterCanManipulate = getter.RaceProps.ToolUser && getter.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation);

            if (!getterCanManipulate && getter != eater)
            {
                Log.Error(string.Concat(new object[]
                {
                    getter,
                    " tried to find blood to bring to ",
                    eater,
                    " but ",
                    getter,
                    " is incapable of Manipulation."
                }));
                return(null);
            }

            BloodPreferabilty minPref = eater?.VampComp()?.Bloodline?.minBloodPref ?? BloodPreferabilty.Any;

            if (desperate)
            {
                minPref = eater?.VampComp()?.Bloodline?.desperateBloodPref ?? BloodPreferabilty.Any;
            }
            Predicate <Thing> foodValidator = delegate(Thing t)
            {
                if (t.TryGetComp <CompBloodItem>() is CompBloodItem bl)
                {
                    if (!allowForbidden && t.IsForbidden(getter))
                    {
                        return(false);
                    }
                    if ((int)bl.Props.bloodType < (int)minPref)
                    {
                        return(false);
                    }
                    if ((int)bl.Props.bloodType > (int)maxPref)
                    {
                        return(false);
                    }
                    if (t.IsBurning() || (!desperate && t.IsNotFresh()) || !getter.CanReserve(t, 1, -1, null, false))
                    {
                        return(false);
                    }
                    return(true);
                }
                return(false);
            };
            Thing             thing;
            Predicate <Thing> validator = foodValidator;

            thing = BloodUtility.SpawnedBloodItemScan(eater, getter.Position, getter.Map.listerThings.ThingsInGroup(ThingRequestGroup.FoodSourceNotPlantOrTree), PathEndMode.ClosestTouch, TraverseParms.For(getter, Danger.Deadly, TraverseMode.ByPawn, false), 9999f, validator);
            return(thing);
        }