예제 #1
0
        public static Thing FindSuitableFuelForPawn(Pawn pawn, EnergySource_Fueled fuelEnergySourceComp)
        {
            Thing closestConsumablePowerSource =
                GenClosest.ClosestThingReachable(
                    pawn.Position, pawn.Map, ThingRequest.ForGroup(ThingRequestGroup.HaulableEver), PathEndMode.OnCell, TraverseParms.For(pawn), 9999f,
                    thing => FuelUtility.ValidFuelSource(fuelEnergySourceComp, thing));

            return(closestConsumablePowerSource);
        }
예제 #2
0
        public override float GetPriority(Pawn pawn)
        {
            if (FuelUtility.FueledEnergySourceNeedRefilling(pawn) != null)
            {
                return(10f);
            }

            return(0f);
        }
예제 #3
0
        public override IEnumerable <Gizmo> CompGetGizmosExtra()
        {
            if (Find.Selector.NumSelected <= 1)
            {
                yield return(new Gizmo_EnergySourceFueled()
                {
                    apparel = parent as Apparel,
                    fueledEnergySource = this
                });
            }

            yield return(new Command_Toggle()
            {
                defaultLabel = "AndroidGizmoAutoRefuelLabel".Translate(),
                defaultDesc = "AndroidGizmoAutoRefuelDescription".Translate(),
                isActive = () => autoRefuel,
                order = -99,
                toggleAction = delegate()
                {
                    autoRefuel = !autoRefuel;
                },
                icon = ContentFinder <Texture2D> .Get("UI/Commands/SetTargetFuelLevel", true)
            });

            yield return(new Command_Action()
            {
                defaultLabel = "AndroidGizmoRefuelNowLabel".Translate(),
                defaultDesc = "AndroidGizmoRefuelNowDescription".Translate(),
                icon = RimWorld.ThingDefOf.Chemfuel.uiIcon,
                order = -99,
                action = delegate()
                {
                    Apparel apparel = parent as Apparel;
                    if (apparel != null)
                    {
                        Thing closestConsumablePowerSource = FuelUtility.FindSuitableFuelForPawn(apparel.Wearer, this);
                        if (closestConsumablePowerSource != null)
                        {
                            int refuelCount = CalculateFuelNeededToRefill(closestConsumablePowerSource);
                            if (refuelCount > 0)
                            {
                                Job refuelJob = new Job(EnergyProps.refillJob, parent, closestConsumablePowerSource);
                                refuelJob.count = refuelCount;

                                apparel.Wearer.jobs.TryTakeOrderedJob(refuelJob, JobTag.Misc);
                            }
                        }
                    }
                }
            });
        }
예제 #4
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            if (pawn.Downed)
            {
                return(null);
            }

            if (pawn.InBed())
            {
                return(null);
            }

            Thing fueledEnergySource = FuelUtility.FueledEnergySourceNeedRefilling(pawn);

            //Nothing to refill.
            if (fueledEnergySource == null)
            {
                return(null);
            }

            //Is there anything to refill it witH?
            EnergySource_Fueled fuelEnergySourceComp = fueledEnergySource.TryGetComp <EnergySource_Fueled>();

            if (!fuelEnergySourceComp.autoRefuel)
            {
                return(null);
            }

            Thing closestConsumablePowerSource = FuelUtility.FindSuitableFuelForPawn(pawn, fuelEnergySourceComp);

            //No compatible fuel source found.
            if (closestConsumablePowerSource == null)
            {
                return(null);
            }

            //Refill the fueled energy source with this.
            Job refuelJob   = new Job(refillJob, fueledEnergySource, closestConsumablePowerSource);
            int refuelCount = fuelEnergySourceComp.CalculateFuelNeededToRefill(closestConsumablePowerSource);

            refuelJob.count = refuelCount;
            return(refuelJob);
        }