static bool Prefix(Pawn_JobTracker_Crutch __instance, JobCondition condition, bool startNewJob)
            {
                if (__instance == null || __instance.curJob == null)
                {
                    return(true);
                }

                if (Settings.fun_police && __instance._pawn.needs.joy != null && __instance._pawn.needs.joy.CurLevel > 0.95f)
                {
                    CompJoyToppedOff c = __instance._pawn.TryGetComp <CompJoyToppedOff>();
                    if (c != null)
                    {
                        c.JoyToppedOff = true;
                    }
                }

                if (Settings.clean_after_tanding && condition == JobCondition.Succeeded &&
                    __instance.curJob.def == JobDefOf.TendPatient && __instance.jobQueue != null &&
                    __instance.jobQueue.Count == 0 && __instance.curJob.targetA != null && __instance.curJob.targetA.Thing != null &&
                    __instance.curJob.targetA.Thing != __instance._pawn)
                {
                    Job job = MakeCleaningJob(__instance._pawn, __instance.curJob.targetA, int.MaxValue);
                    if (job != null)
                    {
                        __instance.jobQueue.EnqueueFirst(job);
                    }
                }
                return(true);
            }
Ejemplo n.º 2
0
            static bool Prefix(Pawn_JobTracker_Crutch __instance, JobCondition condition)
            {
                if (__instance == null || __instance._pawn == null || !__instance._pawn.IsColonistPlayerControlled || __instance.curJob == null)
                {
                    return(true);
                }

                if (Settings.fun_police && __instance._pawn.needs.joy != null && __instance._pawn.needs.joy.CurLevel > 0.95f)
                {
                    CompJoyToppedOff c = __instance._pawn.TryGetComp <CompJoyToppedOff>();
                    if (c != null)
                    {
                        c.JoyToppedOff = true;
                    }
                }

                Job job = null;

                if (Settings.clean_before_work && condition == JobCondition.Succeeded && __instance.jobQueue != null &&
                    __instance.jobQueue.Count == 0 && __instance.curJob != null && ProperJob(__instance.curJob, __instance._pawn, JobDefOf.DeliverFood))
                {
                    job = MakeCleaningJob(__instance._pawn, __instance.curJob.targetA, Settings.op_clean_num);
                }

                if (Settings.clean_after_tending && condition == JobCondition.Succeeded && __instance.jobQueue != null &&
                    __instance.jobQueue.Count == 0 && ProperJob(__instance.curJob, __instance._pawn, JobDefOf.TendPatient))
                {
                    ThinkTreeDef thinkTree   = null;
                    MethodInfo   mi          = AccessTools.Method(typeof(Pawn_JobTracker), "DetermineNextJob");
                    ThinkResult  thinkResult = (ThinkResult)mi.Invoke(__instance, new object[] { thinkTree });
                    if (ProperJob(thinkResult.Job, __instance._pawn, JobDefOf.TendPatient))
                    {
                        Pawn pawn = (Pawn)thinkResult.Job.targetA.Thing;
                        if (pawn.GetRoom() == __instance.curJob.targetA.Thing.GetRoom() || ((float)HealthUtility.TicksUntilDeathDueToBloodLoss(pawn) / 2500f) < 6)
                        {
                            return(true);
                        }
                    }

                    job = MakeCleaningJob(__instance._pawn, __instance.curJob.targetA, Settings.doc_clean_num);
                }
                //
                if (job != null)
                {
                    __instance.jobQueue.EnqueueFirst(job);
                }
                //
                return(true);
            }
        static float JoyPolicePriority(Pawn pawn)
        {
            if (!Settings.fun_police)
            {
                return(0.8f);
            }

            CompJoyToppedOff c = pawn.TryGetComp <CompJoyToppedOff>();

            if (c == null || !c.JoyToppedOff)
            {
                return(0.95f);
            }
            else
            {
                return(0.8f);
            }
        }
            static bool Prefix(ref Pawn_JobTracker_Crutch __instance, Job newJob, JobCondition lastJobEndCondition, ThinkNode jobGiver, bool resumeCurJobAfterwards, bool cancelBusyStances, ThinkTreeDef thinkTree, JobTag?tag, bool fromQueue)
            {
                if (__instance == null || __instance._pawn == null || newJob == null || newJob.def == null)
                {
                    return(true);
                }

                if (Settings.fun_police && __instance._pawn.needs.joy != null && __instance._pawn.needs.joy.CurLevel < 0.8f)
                {
                    CompJoyToppedOff c = __instance._pawn.TryGetComp <CompJoyToppedOff>();
                    if (c != null)
                    {
                        c.JoyToppedOff = false;
                    }
                }

                if (!Settings.clean_before_work && !Settings.hauling_over_bills)
                {
                    return(true);
                }

                if (!newJob.def.allowOpportunisticPrefix)
                {
                    return(true);
                }

                Job job = null;

                if (newJob.def == JobDefOf.DoBill)
                {
                    if (Settings.hauling_over_bills)
                    {
                        job = Hauling_Opportunity(newJob, __instance._pawn);
                    }
                }
                else if (!newJob.playerForced && newJob.targetA != null && newJob.targetA.Cell != null)
                {
                    IntVec3 cell = newJob.targetA.Cell;

                    if (!cell.IsValid || cell.IsForbidden(__instance._pawn) || __instance._pawn.Downed)
                    {
                        return(true);
                    }

                    if (Settings.clean_before_work && (newJob.targetA.Thing != null && newJob.targetA.Thing.GetType().IsSubclassOf(typeof(Building)) || newJob.def.joyKind != null))
                    {
                        job = Cleaning_Opportunity(newJob, cell, __instance._pawn, 20);
                    }
                }

                if (job != null)
                {
                    if (Settings.add_to_que)
                    {
                        __instance.jobQueue.EnqueueFirst(newJob);
                    }
                    __instance.jobQueue.EnqueueFirst(job);
                    __instance.curJob    = null;
                    __instance.curDriver = null;
                    return(false);
                }
                return(true);
            }
Ejemplo n.º 5
0
            static bool Prefix(ref Pawn_JobTracker_Crutch __instance, Job newJob, bool fromQueue)
            {
                try
                {
                    if (__instance == null || __instance._pawn == null || !__instance._pawn.IsColonistPlayerControlled || newJob == null || newJob.def == null)
                    {
                        return(true);
                    }

                    if (Settings.fun_police && __instance._pawn.needs?.joy != null && __instance._pawn.needs.joy.CurLevel < 0.8f)
                    {
                        CompJoyToppedOff c = __instance._pawn.TryGetComp <CompJoyToppedOff>();
                        if (c != null)
                        {
                            c.JoyToppedOff = false;
                        }
                    }

                    if (!Settings.clean_before_work && !Settings.hauling_over_bills)
                    {
                        return(true);
                    }

                    if (!newJob.def.allowOpportunisticPrefix && newJob.def != JobDefOf.SpectateCeremony)
                    {
                        return(true);
                    }

                    Job job = null;

                    if (newJob.def == JobDefOf.DoBill)
                    {
                        if (Settings.hauling_over_bills)
                        {
                            job = Hauling_Opportunity(newJob, __instance._pawn);
                        }
                    }
                    else if (!fromQueue && !newJob.playerForced && newJob.targetA != null && newJob.targetA.Cell != null)
                    {
                        IntVec3 cell = newJob.targetA.Cell;

                        if (!cell.IsValid || cell.IsForbidden(__instance._pawn) || __instance._pawn.Downed)
                        {
                            return(true);
                        }
                        if (Settings.clean_before_work &&
                            (
                                newJob.def == JobDefOf.PrisonerAttemptRecruit ||
                                newJob.def == JobDefOf.PrisonerConvert ||
                                newJob.def == JobDefOf.PrisonerEnslave ||
                                newJob.def == JobDefOf.SpectateCeremony ||
                                newJob.targetA.Thing != null && newJob.targetA.Thing.GetType().IsSubclassOf(typeof(Building)) && newJob.def != JobDefOf.PlaceNoCostFrame && newJob.def != JobDefOf.FinishFrame ||
                                newJob.def.joyKind != null
                            ) &&
                            !HealthAIUtility.ShouldBeTendedNowByPlayer(__instance._pawn))
                        {
                            job = Cleaning_Opportunity(newJob, cell, __instance._pawn, Settings.op_clean_num);
                        }
                    }

                    if (job != null)
                    {
                        if (Settings.add_to_que)
                        {
                            __instance.jobQueue.EnqueueFirst(newJob);
                        }
                        __instance.jobQueue.EnqueueFirst(job);
                        return(false);
                    }
                }
                catch (Exception e)
                {
                    Log.Warning($"CommonSense: opportunistic task skipped due to error ({e.Message}) ({__instance._pawn}, {newJob})");
                }
                return(true);
            }
Ejemplo n.º 6
0
            static bool Prefix(ref Pawn_JobTracker_Crutch __instance, Job newJob, JobCondition lastJobEndCondition, ThinkNode jobGiver, bool resumeCurJobAfterwards, bool cancelBusyStances, ThinkTreeDef thinkTree, JobTag?tag, bool fromQueue)
            {
                try
                {
                    if (__instance == null || __instance._pawn == null || !__instance._pawn.IsColonistPlayerControlled || newJob == null || newJob.def == null)
                    {
                        return(true);
                    }

                    if (Settings.fun_police && __instance._pawn.needs.joy != null && __instance._pawn.needs.joy.CurLevel < 0.8f)
                    {
                        CompJoyToppedOff c = __instance._pawn.TryGetComp <CompJoyToppedOff>();
                        if (c != null)
                        {
                            c.JoyToppedOff = false;
                        }
                    }

                    if (!Settings.clean_before_work && !Settings.hauling_over_bills)
                    {
                        return(true);
                    }

                    if (!newJob.def.allowOpportunisticPrefix)
                    {
                        return(true);
                    }

                    Job job = null;

                    if (newJob.def == JobDefOf.DoBill)
                    {
                        if (Settings.hauling_over_bills)
                        {
                            job = Hauling_Opportunity(newJob, __instance._pawn);
                        }
                    }
                    else if (!newJob.playerForced && newJob.targetA != null && newJob.targetA.Cell != null)
                    {
                        IntVec3 cell = newJob.targetA.Cell;

                        if (!cell.IsValid || cell.IsForbidden(__instance._pawn) || __instance._pawn.Downed)
                        {
                            return(true);
                        }

                        if (Settings.clean_before_work && (newJob.targetA.Thing != null &&
                                                           newJob.targetA.Thing.GetType().IsSubclassOf(typeof(Building)) && newJob.def != JobDefOf.PlaceNoCostFrame && newJob.def != JobDefOf.FinishFrame ||
                                                           newJob.def.joyKind != null) &&
                            !HealthAIUtility.ShouldBeTendedNowByPlayer(__instance._pawn))
                        {
                            job = Cleaning_Opportunity(newJob, cell, __instance._pawn, Settings.op_clean_num);
                        }
                    }

                    //Log.Message($"pawn={__instance._pawn},job={newJob},enque={job}, limit = {Settings.op_clean_num}");
                    if (job != null)
                    {
                        if (Settings.add_to_que)
                        {
                            newJob.playerForced = true;
                            __instance.jobQueue.EnqueueFirst(newJob);
                        }
                        __instance.jobQueue.EnqueueFirst(job);
                        //__instance.curJob = null;
                        //__instance.curDriver = null;
                        return(false);
                    }
                }
                catch (Exception e)
                {
                    Log.Error($"CommonSense: opportunistic task skipped due to error ({e.Message})");
                }
                return(true);
            }