Exemple #1
0
        public static bool CanUseConsideringQueuedJobs(Pawn pawn, ThingWithComps gear, bool showMessage = true)
        {
            CompReloadable compReloadable = gear.TryGetComp <CompReloadable>();

            if (compReloadable == null)
            {
                return(true);
            }
            string text = null;

            if (!Event.current.shift)
            {
                if (!compReloadable.CanBeUsed)
                {
                    text = compReloadable.DisabledReason(compReloadable.MinAmmoNeeded(allowForcedReload: false), compReloadable.MaxAmmoNeeded(allowForcedReload: false));
                }
            }
            else if (TotalChargesFromQueuedJobs(pawn, gear) + 1 > compReloadable.RemainingCharges)
            {
                text = compReloadable.DisabledReason(compReloadable.MaxAmmoAmount(), compReloadable.MaxAmmoAmount());
            }
            if (text != null)
            {
                if (showMessage)
                {
                    Messages.Message(text, pawn, MessageTypeDefOf.RejectInput, historical: false);
                }
                return(false);
            }
            return(true);
        }
Exemple #2
0
        public static List <Thing> FindEnoughAmmo(Pawn pawn, IntVec3 rootCell, CompReloadable comp, bool forceReload)
        {
            if (comp == null)
            {
                return(null);
            }
            IntRange desiredQuantity = new IntRange(comp.MinAmmoNeeded(forceReload), comp.MaxAmmoNeeded(forceReload));

            return(RefuelWorkGiverUtility.FindEnoughReservableThings(pawn, rootCell, desiredQuantity, (Thing t) => t.def == comp.AmmoDef));
        }
Exemple #3
0
        private IEnumerable <Toil> ReloadAsMuchAsPossible(CompReloadable comp)
        {
            Toil done = Toils_General.Label();

            yield return(Toils_Jump.JumpIf(done, () => pawn.carryTracker.CarriedThing == null || pawn.carryTracker.CarriedThing.stackCount < comp.MinAmmoNeeded(allowForcedReload: true)));

            yield return(Toils_General.Wait(comp.Props.baseReloadTicks).WithProgressBarToilDelay(TargetIndex.A));

            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Thing carriedThing = pawn.carryTracker.CarriedThing;
                comp.ReloadFrom(carriedThing);
            };
            toil.defaultCompleteMode = ToilCompleteMode.Instant;
            yield return(toil);

            yield return(done);
        }