public static void TakeFive(List <Pawn> pawns)
 {
     foreach (var pawn in pawns)
     {
         if (!pawn.mindState.IsIdle)
         {
             ThinkResult result = ThinkResult.NoJob;
             try
             {
                 var joyGiver = new JobGiver_GetJoy();
                 joyGiver.ResolveReferences();
                 result = joyGiver.TryIssueJobPackage(pawn, default(JobIssueParams));
             }
             catch (Exception exception)
             {
                 JobUtility.TryStartErrorRecoverJob(pawn, pawn.ToStringSafe() + " threw exception while determining job (main)", exception);
             }
             if (result.Job != null && result.Job.def != JobDefOf.GotoWander)
             {
                 pawn.jobs.TryTakeOrderedJob(result.Job);
             }
         }
     }
 }
        private static bool Prefix(JobGiver_GetJoy __instance, ref Job __result, Pawn pawn)
        {
            var timeAssignmentDef =
                pawn.timetable == null ? TimeAssignmentDefOf.Anything : pawn.timetable.CurrentAssignment;
            bool result;

            if (timeAssignmentDef != TimeAssignmentDefDinner.DinnerDef)
            {
                result = true;
            }
            else
            {
                if (pawn.InBed() && HealthAIUtility.ShouldSeekMedicalRest(pawn))
                {
                    __result = null;
                    result   = false;
                }
                else
                {
                    var allDefsListForReading = DefDatabase <JoyGiverDef> .AllDefsListForReading;
                    var tolerances            = pawn.needs.joy.tolerances;
                    foreach (var joyGiverDef in allDefsListForReading)
                    {
                        joyGiverChances[joyGiverDef] = 0f;
                        if (joyGiverDef.joyKind != JoyKindDefOf.Gluttonous &&
                            joyGiverDef.defName != "SocialRelax")
                        {
                            continue;
                        }

                        if (!pawn.needs.joy.tolerances.BoredOf(joyGiverDef.joyKind) &&
                            joyGiverDef.Worker.CanBeGivenTo(pawn))
                        {
                            if (joyGiverDef.pctPawnsEverDo < 1f)
                            {
                                Rand.PushState(pawn.thingIDNumber ^ 63216713);
                                if (Rand.Value >= joyGiverDef.pctPawnsEverDo)
                                {
                                    Rand.PopState();
                                    goto IL_196;
                                }

                                Rand.PopState();
                            }

                            var num  = tolerances[joyGiverDef.joyKind];
                            var num2 = Mathf.Pow(1f - num, 5f);
                            num2 = Mathf.Max(0.001f, num2);
                            joyGiverChances[joyGiverDef] = joyGiverDef.Worker.GetChance(pawn) * num2;
                        }

                        IL_196 :;
                    }

                    var num3 = 0;
                    Job job;
                    for (;;)
                    {
                        var  joyGiverDef2 = new JoyGiverDef();
                        bool hasJoyGiver;
                        if (num3 < joyGiverChances.Count)
                        {
                            hasJoyGiver = allDefsListForReading.TryRandomElementByWeight(d => joyGiverChances[d],
                                                                                         out joyGiverDef2);
                        }
                        else
                        {
                            hasJoyGiver = false;
                        }

                        if (!hasJoyGiver)
                        {
                            goto Block_17;
                        }

                        if (pawn.needs.joy.CurLevel < 0.95f || joyGiverDef2.joyKind != JoyKindDefOf.Gluttonous)
                        {
                            job = TryGiveJobFromJoyGiverDefDirect(joyGiverDef2, pawn);
                            if (job != null)
                            {
                                break;
                            }
                        }

                        joyGiverChances[joyGiverDef2] = 0f;
                        num3++;
                    }

                    __result = job;
                    return(false);

Block_17:
                    __result = null;
                    result   = false;
                }
            }

            return(result);
        }
        static bool Prefix(JobGiver_GetJoy __instance, ref Job __result, Pawn pawn)
        {
            TimeAssignmentDef timeAssignmentDef = ((pawn.timetable == null) ? TimeAssignmentDefOf.Anything : pawn.timetable.CurrentAssignment);

            if (timeAssignmentDef != TimeAssignmentDefDinner.DinnerDef)
            {
                return(true);
            }

            if (pawn.InBed() && HealthAIUtility.ShouldSeekMedicalRest(pawn))
            {
                __result = null;
                return(false);
            }
            List <JoyGiverDef> allDefsListForReading = DefDatabase <JoyGiverDef> .AllDefsListForReading;
            JoyToleranceSet    tolerances            = pawn.needs.joy.tolerances;

            for (int i = 0; i < allDefsListForReading.Count; i++)
            {
                JoyGiverDef joyGiverDef = allDefsListForReading[i];
                joyGiverChances[joyGiverDef] = 0f;
                if (joyGiverDef.joyKind != JoyKindDefOf.Gluttonous && joyGiverDef.defName != "SocialRelax")
                {
                    continue;                                                                                       //选择暴食和社交休闲娱乐
                }
                //Log.Message("{0} getchance baoshi".Translate(pawn.Label));
                if (!pawn.needs.joy.tolerances.BoredOf(joyGiverDef.joyKind) && joyGiverDef.Worker.CanBeGivenTo(pawn))
                {
                    if (joyGiverDef.pctPawnsEverDo < 1f)
                    {
                        Rand.PushState(pawn.thingIDNumber ^ 63216713);
                        if (Rand.Value >= joyGiverDef.pctPawnsEverDo)
                        {
                            Rand.PopState();
                            goto IL_11A;
                        }
                        Rand.PopState();
                    }
                    float num  = tolerances[joyGiverDef.joyKind];
                    float num2 = Mathf.Pow(1f - num, 5f);
                    num2 = Mathf.Max(0.001f, num2);
                    joyGiverChances[joyGiverDef] = joyGiverDef.Worker.GetChance(pawn) * num2;
                }
                IL_11A :;
            }
            int         num3 = 0;
            JoyGiverDef def;

            while (num3 < joyGiverChances.Count && allDefsListForReading.TryRandomElementByWeight((JoyGiverDef d) => joyGiverChances[d], out def))
            {
                //if(pawn.needs.joy.CurLevel>0.3f && def.joyKind == JoyKindDefOf.Gluttonous && pawn.timetable.GetAssignment((GenLocalDate.HourOfDay(pawn) + 1) % 24) == TimeAssignmentDefDinner.DinnerDef)
                if (pawn.needs.joy.CurLevel < 0.95f || def.joyKind != JoyKindDefOf.Gluttonous)
                {
                    Job job = TryGiveJobFromJoyGiverDefDirect(def, pawn);
                    if (job != null)
                    {
                        __result = job;
                        return(false);
                    }
                }
                //Log.Message("{0} trygivejoy".Translate(pawn.Label));
                joyGiverChances[def] = 0f;
                num3++;
            }
            __result = null;
            return(false);
        }