Ejemplo n.º 1
0
        public static bool TryActuallyStartNextToil(JobDriver __instance)
        {
            if (!__instance.pawn.Spawned || (__instance.pawn.stances.FullBodyBusy && !get_CanStartNextToilInBusyStance2(__instance)) || __instance.job == null || __instance.pawn.CurJob != __instance.job)
            {
                return(false);
            }

            /*
             * if (get_HaveCurToil2(__instance))
             * {
             *  get_CurToil2(__instance).Cleanup(curToilIndex(__instance), __instance);
             * }
             */
            if (curToilIndex(__instance) >= 0 && curToilIndex(__instance) < toils(__instance).Count&& __instance.job != null)
            {
                if (__instance.pawn.CurJob == __instance.job)
                {
                    Toil curToil2 = toils(__instance)[curToilIndex(__instance)];
                    if (curToil2 != null)
                    {
                        curToil2.Cleanup(curToilIndex(__instance), __instance);
                    }
                }
            }

            if (nextToilIndex(__instance) >= 0)
            {
                curToilIndex(__instance)  = nextToilIndex(__instance);
                nextToilIndex(__instance) = -1;
            }
            else
            {
                curToilIndex(__instance)++;
            }

            wantBeginNextToil(__instance) = false;

            if (!get_HaveCurToil2(__instance))
            {
                if (__instance.pawn.stances != null && __instance.pawn.stances.curStance.StanceBusy)
                {
                    Log.ErrorOnce(__instance.pawn.ToStringSafe() + " ended job " + __instance.job.ToStringSafe() + " due to running out of toils during a busy stance.", 6453432);
                }

                __instance.EndJobWith(JobCondition.Succeeded);
                return(false);
            }


            __instance.debugTicksSpentThisToil = 0;
            Toil curToil = get_CurToil2(__instance);

            if (curToil != null)
            {
                __instance.ticksLeftThisToil    = curToil.defaultDuration;
                curToilCompleteMode(__instance) = curToil.defaultCompleteMode;
            }
            if (CheckCurrentToilEndOrFail2(__instance))
            {
                return(false);
            }

            curToil = get_CurToil2(__instance);
            Toil gct = get_CurToil2(__instance);

            if (gct != null && gct.preInitActions != null)
            {
                List <Action> preInitActions = gct.preInitActions;
                for (int i = 0; i < preInitActions.Count; i++)
                {
                    try
                    {
                        gct = get_CurToil2(__instance);
                        if (gct != null)
                        {
                            preInitActions = gct.preInitActions;
                        }
                        else
                        {
                            break;
                        }
                        preInitActions[i]();
                    }
                    catch (Exception exception)
                    {
                        JobUtility.TryStartErrorRecoverJob(__instance.pawn, "JobDriver threw exception in preInitActions[" + i + "] for pawn " + __instance.pawn.ToStringSafe(), exception, __instance);
                        return(false);
                    }

                    if (get_CurToil2(__instance) != curToil)
                    {
                        break;
                    }
                    gct = get_CurToil2(__instance);
                    if (gct != null)
                    {
                        preInitActions = gct.preInitActions;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            Toil gct2 = get_CurToil2(__instance);

            if (gct2 == curToil)
            {
                if (gct2 != null)
                {
                    if (gct2.initAction != null)
                    {
                        try
                        {
                            gct2.initAction();
                        }
                        catch (Exception exception2)
                        {
                            JobUtility.TryStartErrorRecoverJob(__instance.pawn, "JobDriver threw exception in initAction for pawn " + __instance.pawn.ToStringSafe(), exception2, __instance);
                            return(false);
                        }
                    }

                    if (!__instance.ended && curToilCompleteMode(__instance) == ToilCompleteMode.Instant && get_CurToil2(__instance) == curToil)
                    {
                        __instance.ReadyForNextToil();
                    }
                }
            }
            return(false);
        }