public static void JobOnThingRefill(Pawn pawn, Thing thing, ref Job __result, WorkGiver_DoBill __instance, bool forced = false)
 {
     if (__result is null)
     {
         IBillGiver billGiver = thing as IBillGiver;
         if (!(billGiver is null) && __instance.ThingIsUsableBillGiver(thing) && billGiver.BillStack.AnyShouldDoNow && billGiver.UsableForBillsAfterFueling())
         {
             LocalTargetInfo target = thing;
             if (pawn.CanReserve(target, 1, -1, null, forced) && !thing.IsBurning() && !thing.IsForbidden(pawn))
             {
                 CompRefillable compRefillable = thing.TryGetComp <CompRefillable>();
                 if (compRefillable is null || compRefillable.IsFull())
                 {
                     billGiver.BillStack.RemoveIncompletableBills();
                     __result = (Job)AccessTools.Method(type: typeof(WorkGiver_DoBill), name: "StartOrResumeBillJob").Invoke(__instance, new object[] { pawn, billGiver });
                     return;
                 }
                 if (!RefillWorkGiverUtility.CanRefill(pawn, thing, forced))
                 {
                     __result = null;
                     return;
                 }
                 __result = RefillWorkGiverUtility.RefillJob(pawn, thing, forced);
             }
         }
         return;
     }
 }
Пример #2
0
        public static bool CanRefill(Pawn pawn, Thing t, bool forced = false)
        {
            CompRefillable compRefill = t.TryGetComp <CompRefillable>();

            if (compRefill is null || compRefill.IsFull())
            {
                return(false);
            }
            bool flag = !forced;

            if (flag && !compRefill.ShouldAutoRefill)
            {
                return(false);
            }
            if (!t.IsForbidden(pawn))
            {
                LocalTargetInfo target = t;
                if (pawn.CanReserve(target, 1, -1, null, forced))
                {
                    if (t.Faction != pawn.Faction)
                    {
                        return(false);
                    }
                    if (RefillWorkGiverUtility.FindNextFuelItem(pawn, t) is null)
                    {
                        JobFailReason.Is("No items available to refill", null);
                        return(false);
                    }
                    return(true);
                }
            }
            return(false);
        }