internal static bool Prefix(Pawn getter, Pawn eater, ref bool __result, ref Thing foodSource, ref ThingDef foodDef, ref bool desperate)
            {
                if (desperate)
                {
                    return(true);           // Run original code
                }
                if (getter != eater)
                {
                    return(true);                 // Run original code
                }
                // Only if time assignment allows
                if (!eater.GetTimeAssignment().allowJoy)
                {
                    return(true);
                }

                if (!getter.IsAbleToDine())
                {
                    return(true);
                }

                var diningSpot = DiningUtility.FindDiningSpotFor(eater, false);

                var bestType = diningSpot?.GetRestaurant().Stock.GetBestMealTypeFor(eater, false);

                if (bestType == null)
                {
                    return(true);                  // Run original code
                }
                foodDef    = bestType;
                foodSource = diningSpot;
                //Log.Message($"{getter.NameShortColored} found diningSpot at {diningSpot.Position} with {foodDef?.label}.");
                __result = true;
                return(false); // Don't run original code
            }
            internal static bool Prefix(Pawn pawn, Predicate <Thing> extraValidator, ref Job __result)
            {
                var restaurant = pawn.GetRestaurant();

                if (restaurant?.IsOpenedRightNow == false)
                {
                    return(true);                                       // Run regular code
                }
                //Log.Message($"{pawn.NameShortColored} is looking for restaurant (as joy job).");

                bool allowDrug  = !pawn.IsTeetotaler();
                var  diningSpot = DiningUtility.FindDiningSpotFor(pawn, allowDrug, extraValidator);

                if (diningSpot == null)
                {
                    return(true);                     // Run regular code
                }
                // There is something edible, but is it good enough or like... a corpse?
                var bestFood = restaurant.Stock.GetBestMealTypeFor(pawn, allowDrug, false);

                if (bestFood == null)
                {
                    return(true);                  // Run regular code
                }
                //Log.Message($"{pawn.NameShortColored} wants to eat at restaurant ({diningSpot.Position}).");

                Job job = JobMaker.MakeJob(DiningUtility.dineDef, diningSpot);

                __result = job;
                return(false);
            }
Beispiel #3
0
 public override void Initialize(CompProperties props)
 {
     base.Initialize(props);
     DiningUtility.RegisterDiningSpotHolder(parent);
 }