private static void TransformAndExplain(StatRequest req, ref float val, StringBuilder explanation) { CompReloadable compReloadable = req.Thing?.TryGetComp <CompReloadable>(); if (compReloadable != null && compReloadable.RemainingCharges != compReloadable.MaxCharges) { if (compReloadable.AmmoDef != null) { int num = compReloadable.MaxAmmoNeeded(allowForcedReload: true); float num2 = (0f - compReloadable.AmmoDef.BaseMarketValue) * (float)num; val += num2; explanation?.AppendLine("StatsReport_ReloadMarketValue".Translate(NamedArgumentUtility.Named(compReloadable.AmmoDef, "AMMO"), num.Named("COUNT")) + ": " + num2.ToStringMoneyOffset()); } else if (compReloadable.Props.destroyOnEmpty) { float num3 = (float)compReloadable.RemainingCharges / (float)compReloadable.MaxCharges; explanation?.AppendLine("StatsReport_ReloadRemainingChargesMultipler".Translate(compReloadable.Props.ChargeNounArgument, compReloadable.LabelRemaining) + ": x" + num3.ToStringPercent()); val *= num3; } if (val < 0f) { val = 0f; } } }
public static Job MakeReloadJob(CompReloadable comp, List <Thing> chosenAmmo) { Job job = JobMaker.MakeJob(JobDefOf.Reload, comp.parent); job.targetQueueB = chosenAmmo.Select((Thing t) => new LocalTargetInfo(t)).ToList(); job.count = chosenAmmo.Sum((Thing t) => t.stackCount); job.count = Math.Min(job.count, comp.MaxAmmoNeeded(allowForcedReload: true)); return(job); }
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)); }
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); }