예제 #1
0
        public override Job JobOnThing(Pawn pawn, Thing thing, bool forced = false)
        {
            IBillGiver billGiver = thing as IBillGiver;

            if (billGiver != null && ThingIsUsableBillGiver(thing) && billGiver.BillStack.AnyShouldDoNow && billGiver.UsableForBillsAfterFueling())
            {
                LocalTargetInfo target = thing;
                bool            ignoreOtherReservations = forced;
                if (pawn.CanReserve(target, 1, -1, null, ignoreOtherReservations) && !thing.IsBurning() && !thing.IsForbidden(pawn))
                {
                    CompRefuelable compRefuelable = thing.TryGetComp <CompRefuelable>();
                    if (compRefuelable != null && !compRefuelable.HasFuel)
                    {
                        if (!RefuelWorkGiverUtility.CanRefuel(pawn, thing, forced))
                        {
                            return(null);
                        }
                        return(RefuelWorkGiverUtility.RefuelJob(pawn, thing, forced));
                    }
                    billGiver.BillStack.RemoveIncompletableBills();
                    return(StartOrResumeBillJob(pawn, billGiver));
                }
            }
            return(null);
        }
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            List <ThingDefCountClass> products = t.TryGetComp <CompMachineChargingStation>().turretToInstall.costList;
            List <Thing> toGrab      = new List <Thing>();
            List <int>   toGrabCount = new List <int>();

            foreach (ThingDefCountClass thingNeeded in products)
            {
                List <Thing> thingsOfThisType = RefuelWorkGiverUtility.FindEnoughReservableThings(pawn, t.Position, new IntRange(thingNeeded.count, thingNeeded.count), (Thing thing) => thing.def == thingNeeded.thingDef);
                if (thingsOfThisType == null)
                {
                    return(null);
                }
                toGrab.AddRange(thingsOfThisType);
                int totalCountNeeded = thingNeeded.count;
                foreach (Thing thingGrabbed in thingsOfThisType)
                {
                    if (thingGrabbed.stackCount >= totalCountNeeded)
                    {
                        toGrabCount.Add(totalCountNeeded);
                        totalCountNeeded = 0;
                    }
                    else
                    {
                        toGrabCount.Add(thingGrabbed.stackCount);
                        totalCountNeeded -= thingGrabbed.stackCount;
                    }
                }
            }
            Job job = JobMaker.MakeJob(DefDatabase <JobDef> .GetNamed("VFE_Mechanoids_AttachTurret"), t);

            job.targetQueueB = toGrab.Select((Thing f) => new LocalTargetInfo(f)).ToList();
            job.countQueue   = toGrabCount.ToList();
            return(job);
        }
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            if (CompMachineChargingStation.cachedChargingStationsDict.TryGetValue(t, out CompMachineChargingStation comp))
            {
                if (!(comp != null && comp.wantsRespawn))
                {
                    return(false);
                }

                List <ThingDefCountClass> products = comp.Props.pawnToSpawn.race.butcherProducts.ListFullCopy();
                foreach (ThingDefCountClass thingNeeded in products)
                {
                    List <Thing> thingsOfThisType = RefuelWorkGiverUtility.FindEnoughReservableThings(pawn, t.Position, new IntRange(thingNeeded.count, thingNeeded.count),
                                                                                                      (Thing thing) => thing.def == thingNeeded.thingDef);
                    if (thingsOfThisType == null)
                    {
                        JobFailReason.Is("VFEMechNoResources".Translate());
                        return(false);
                    }
                }
                return(pawn.CanReserveAndReach(t, PathEndMode.OnCell, Danger.Deadly, ignoreOtherReservations: forced));
            }
            else
            {
                return(false);
            }
        }
        // Token: 0x06005677 RID: 22135 RVA: 0x001CE7CC File Offset: 0x001CC9CC
        public static List <Thing> FindEnoughAmmo(Pawn pawn, IntVec3 rootCell, CompReloadableDual comp, bool forceReload)
        {
            if (comp == null)
            {
                return(null);
            }
            IntRange desiredQuantity = new IntRange(comp.MinAmmoNeededSecondry(forceReload), comp.MaxAmmoNeededSecondry(forceReload));

            return(RefuelWorkGiverUtility.FindEnoughReservableThings(pawn, rootCell, desiredQuantity, (Thing t) => t.def == comp.AmmoDefSecondry));
        }
예제 #5
0
        public static List <Thing> FindAmmo(Pawn pawn, IntVec3 root, IReloadable comp)
        {
            if (comp == null)
            {
                return(null);
            }
            var desired = new IntRange(comp.ItemsPerShot,
                                       comp.ItemsPerShot * (comp.MaxShots - comp.ShotsRemaining));

            return(RefuelWorkGiverUtility.FindEnoughReservableThings(pawn, root, desired, comp.CanReloadFrom));
        }
예제 #6
0
        public override Job JobOnThing(Pawn pawn, Thing thing, bool forced = false)
        {
            IBillGiver billGiver = thing as IBillGiver;

            if (billGiver != null && ThingIsUsableBillGiver(thing) && billGiver.BillStack.AnyShouldDoNow && billGiver.UsableForBillsAfterFueling())
            {
                LocalTargetInfo target = thing;
                bool            ignoreOtherReservations = forced;
                if (pawn.CanReserve(target, 1, -1, null, ignoreOtherReservations) && !thing.IsBurning() && !thing.IsForbidden(pawn))
                {
                    CompRefuelable compRefuelable = thing.TryGetComp <CompRefuelable>();
                    if (compRefuelable != null && !compRefuelable.HasFuel)
                    {
                        if (!RefuelWorkGiverUtility.CanRefuel(pawn, thing, forced))
                        {
                            return(null);
                        }
                        return(RefuelWorkGiverUtility.RefuelJob(pawn, thing, forced));
                    }
                    CompAbilityUserMagic compMagic = pawn.TryGetComp <CompAbilityUserMagic>();
                    if (compMagic != null && compMagic.Mana != null)
                    {
                        if (thing is Building_TMMagicCircle)
                        {
                            Building_TMMagicCircle mc = thing as Building_TMMagicCircle;
                            if (mc.InteractionCellOccupied())
                            {
                                return(null);
                            }
                        }
                        else if (compMagic.Mana.CurLevel < .5f)
                        {
                            return(null);
                        }
                    }

                    billGiver.BillStack.RemoveIncompletableBills();
                    return(StartOrResumeBillJob(pawn, billGiver, thing));
                }
            }
            return(null);
        }
예제 #7
0
        public override Job JobOnThing(Pawn pawn, Thing thing, bool forced = false)
        {
            IBillGiver billGiver = thing as IBillGiver;

            if (billGiver == null || !ThingIsUsableBillGiver(thing) || !billGiver.BillStack.AnyShouldDoNow || !billGiver.UsableForBillsAfterFueling() || !pawn.CanReserve(thing, 1, -1, null, forced) || thing.IsBurning() || thing.IsForbidden(pawn))
            {
                return(null);
            }
            CompRefuelable compRefuelable = thing.TryGetComp <CompRefuelable>();

            if (compRefuelable != null && !compRefuelable.HasFuel)
            {
                if (!RefuelWorkGiverUtility.CanRefuel(pawn, thing, forced))
                {
                    return(null);
                }
                return(RefuelWorkGiverUtility.RefuelJob(pawn, thing, forced));
            }
            billGiver.BillStack.RemoveIncompletableBills();
            return(StartOrResumeBillJob(pawn, billGiver));
        }
예제 #8
0
        public override Job JobOnThing(Pawn pawn, Thing thing, bool forced = false)
        {
            Building_CokeFurnace furnace = thing as Building_CokeFurnace;

            if (furnace != null && !furnace.Started)
            {
                LocalTargetInfo target = thing;
                bool            ignoreOtherReservations = forced;
                if (pawn.CanReserve(target, 1, -1, null, ignoreOtherReservations) && !thing.IsBurning() && !thing.IsForbidden(pawn))
                {
                    if (furnace.Result != null)
                    {
                        return(new Job(JobDefOfLocal.TakeResultFromCokeFurnace, furnace));
                    }
                    if (furnace.Ready)
                    {
                        return(TryStartFurnace(pawn, furnace));
                    }

                    CompRefuelable compRefuelable = thing.TryGetComp <CompRefuelable>();
                    if (compRefuelable != null && !compRefuelable.HasFuel)
                    {
                        if (!RefuelWorkGiverUtility.CanRefuel(pawn, thing, forced))
                        {
                            return(null);
                        }
                        return(RefuelWorkGiverUtility.RefuelJob(pawn, thing, forced));
                    }
                    if (!furnace.IngredientsReady && (furnace.ProduceCount > 0 || furnace.Infinity))
                    {
                        return(TryStartJob(pawn, furnace));
                    }
                }
            }
            return(null);
        }
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            MicroWorkGiverDef mdef = def as MicroWorkGiverDef;

            if (mdef == null)
            {
                return(null);
            }

            LocalTargetInfo target = t;

            if (!pawn.CanReserve(target, 1, -1, null, forced) || t.IsBurning() || t.IsForbidden(pawn))
            {
                return(null);
            }

            List <Building> list = new List <Building>();

            foreach (var user in mdef.recipeDef.AllRecipeUsers)
            {
                List <Building> buildings = t.Map.listerBuildings.AllBuildingsColonistOfDef(user).Where(
                    x => !x.IsForbidden(pawn) && pawn.CanReserve(x, 1, -1, null, forced) &&
                    (x as IBillGiver) != null && (x as IBillGiver).CurrentlyUsableForBills() &&
                    pawn.CanReach(x, PathEndMode.InteractionCell, Danger.Deadly)).ToList();
                list.AddRange(buildings);
            }

            if (list.NullOrEmpty())
            {
                return(null);
            }
            //
            list.SortBy(x => x.TryGetComp <CompRefuelable>() == null || x.TryGetComp <CompRefuelable>().HasFuel ? 0f : 99999f + x.Position.DistanceTo(t.Position));

            Thing building = null;

            foreach (var l in list)
            {
                CompRefuelable compRefuelable = l.TryGetComp <CompRefuelable>();
                if (compRefuelable != null && !compRefuelable.HasFuel)
                {
                    if (RefuelWorkGiverUtility.CanRefuel(pawn, l, forced))
                    {
                        return(RefuelWorkGiverUtility.RefuelJob(pawn, l, forced, null, null));
                    }
                }
                else
                {
                    building = l;
                    break;
                }
            }

            Job job = WorkGiverUtility.HaulStuffOffBillGiverJob(pawn, building as IBillGiver, null);

            if (job != null)
            {
                return(job);
            }

            job = new Job(mdef.jobDef, building);
            job.targetQueueB = new List <LocalTargetInfo>(1);
            job.countQueue   = new List <int>(1);
            job.targetQueueB.Add(t);
            job.countQueue.Add(1);
            job.haulMode = HaulMode.ToCellNonStorage;
            Bill            bill = mdef.recipeDef.MakeNewBill();
            Bill_Production bp   = bill as Bill_Production;

            if (bp != null)
            {
                bp.repeatCount++;
                bp.SetStoreMode(BillStoreModeDefOf.DropOnFloor);
            }

            job.bill = bill;

            return(job);
        }