public static bool Prefix(Pawn ingester, Thing __instance, ref JoyState __state)
        {
            ThingDef        ingestThingDef = __instance.def;
            JoyToleranceSet set            = ingester?.needs?.joy?.tolerances;

            if (ingestThingDef == null || set == null || !DessertDefs.AllDeserts.Contains(ingestThingDef))
            {
                __state = new JoyState(false, 0, null);
                return(true);
            }

            DefMap <JoyKindDef, float> tolerances = (DefMap <JoyKindDef, float>)_tolerances.GetValue(set);

            __state = new JoyState(true, tolerances[JoyKindDefOf.Gluttonous], tolerances);
            return(true);
        }
Ejemplo n.º 2
0
        private List <JoyGiverDef> PopulateChances(Pawn pawn)
        {
            // From Core
            List <JoyGiverDef> allDefsListForReading = DefDatabase <JoyGiverDef> .AllDefsListForReading;

            // ADDED
            if (allDefsListForReading == null)
            {
                Log.Message("AllDefsListForReading == null");
                return(new List <JoyGiverDef>());
            } // ^^^
            JoyToleranceSet tolerances = pawn.needs.joy.tolerances;

            foreach (JoyGiverDef joyGiverDef in allDefsListForReading)
            {
                this.joyGiverChances[joyGiverDef] = 0f;

                //if (this.JoyGiverAllowed(joyGiverDef)) REMOVED
                {
                    if (!pawn.needs.joy.tolerances.BoredOf(joyGiverDef.joyKind))
                    {
                        if (joyGiverDef.Worker.MissingRequiredCapacity(pawn) == null)
                        {
                            if (joyGiverDef.pctPawnsEverDo < 1f)
                            {
                                Rand.PushState(pawn.thingIDNumber ^ 63216713);
                                if (Rand.Value >= joyGiverDef.pctPawnsEverDo)
                                {
                                    Rand.PopState();
                                    goto IL_FB;
                                }
                                Rand.PopState();
                            }
                            float tolerance = tolerances[joyGiverDef.joyKind];
                            float factor    = Mathf.Pow(1f - tolerance, 5f);
                            factor = Mathf.Max(0.001f, factor);
                            this.joyGiverChances[joyGiverDef] = joyGiverDef.Worker.GetChance(pawn) * factor;
                        }
                    }
                }
IL_FB:
                ;
            }
            return(allDefsListForReading);
        }
        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);
        }
Ejemplo n.º 4
0
            //double pass on trying to give a joyjob. At first, we'll try to give a job, that located outside;
            static bool Prefix(ref Job __result, ref JobCrutch __instance, ref Pawn pawn)
            {
                if (!Settings.fulfill_outdoors || !__instance.CanDoDuringMedicalRestCrutch() && pawn.InBed() && HealthAIUtility.ShouldSeekMedicalRest(pawn) ||
                    pawn.needs.outdoors == null || pawn.needs.outdoors.CurLevel >= 0.4f)
                {
                    return(true);
                }

                List <JoyGiverDef>          allDefsListForReading = DefDatabase <JoyGiverDef> .AllDefsListForReading;
                JoyToleranceSet             tolerances            = pawn.needs.joy.tolerances;
                DefMap <JoyGiverDef, float> joyGiverChances       = new DefMap <JoyGiverDef, float>();

                for (int i = 0; i < allDefsListForReading.Count; i++)
                {
                    JoyGiverDef joyGiverDef = allDefsListForReading[i];
                    joyGiverChances[joyGiverDef] = 0f;
                    if (__instance.JoyGiverAllowedCrutch(joyGiverDef) && !pawn.needs.joy.tolerances.BoredOf(joyGiverDef.joyKind) && joyGiverDef.Worker.MissingRequiredCapacity(pawn) == null)
                    {
                        if (joyGiverDef.pctPawnsEverDo < 1f)
                        {
                            Rand.PushState(pawn.thingIDNumber ^ 0x3C49C49);
                            if (Rand.Value >= joyGiverDef.pctPawnsEverDo)
                            {
                                Rand.PopState();
                                continue;
                            }
                            Rand.PopState();
                        }
                        float num = tolerances[joyGiverDef.joyKind];
                        float b   = Mathf.Pow(1f - num, 5f);
                        b = Mathf.Max(0.001f, b);
                        joyGiverChances[joyGiverDef] = joyGiverDef.Worker.GetChance(pawn) * b;
                    }
                }
                for (int j = 0; j < joyGiverChances.Count; j++)
                {
                    if (!allDefsListForReading.TryRandomElementByWeight((JoyGiverDef d) => joyGiverChances[d], out JoyGiverDef result))
                    {
                        break;
                    }
                    Job job = __instance.TryGiveJobFromJoyGiverDefDirectCrutch(result, pawn);
                    if (job != null && job.targetA != null)
                    {
                        if (job.targetA.Thing != null)
                        {
                            if (job.targetA.Thing.GetRoom() != null && job.targetA.Thing.GetRoom().PsychologicallyOutdoors)
                            {
                                __result = job;
                                return(false);
                            }
                        }
                        else if (job.targetA.Cell != null)
                        {
                            IntVec3 vec3 = (IntVec3)job.targetA;
                            if (job.targetA.Cell.GetRoom(pawn.Map).PsychologicallyOutdoors)
                            {
                                __result = job;
                                return(false);
                            }
                        }
                    }
                    joyGiverChances[result] = 0f;
                }
                return(true);
            }