// Token: 0x0600003C RID: 60 RVA: 0x00002F10 File Offset: 0x00001110
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            CompUniversalFermenter compUniversalFermenter = ThingCompUtility.TryGetComp <CompUniversalFermenter>(t);

            if (compUniversalFermenter == null || compUniversalFermenter.Fermented || compUniversalFermenter.SpaceLeftForIngredient <= 0)
            {
                return(false);
            }
            float ambientTemperature = compUniversalFermenter.parent.AmbientTemperature;

            if (ambientTemperature < compUniversalFermenter.Product.temperatureSafe.min + 2f || ambientTemperature > compUniversalFermenter.Product.temperatureSafe.max - 2f)
            {
                JobFailReason.Is(WorkGiver_FillUniversalFermenter.TemperatureTrans, null);
                return(false);
            }
            if (ForbidUtility.IsForbidden(t, pawn) || !ReservationUtility.CanReserveAndReach(pawn, t, (PathEndMode)2, DangerUtility.NormalMaxDanger(pawn), 1, -1, null, forced))
            {
                return(false);
            }
            if (pawn.Map.designationManager.DesignationOn(t, DesignationDefOf.Deconstruct) != null)
            {
                return(false);
            }
            if (this.FindIngredient(pawn, t) == null)
            {
                JobFailReason.Is(WorkGiver_FillUniversalFermenter.NoIngredientTrans, null);
                return(false);
            }
            return(!FireUtility.IsBurning(t));
        }
Example #2
0
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Job result;

            if (t.def.defName != "RD_HoloDisk")
            {
                result = null;
            }
            else if (!ReservationUtility.CanReserveAndReach(pawn, t, PathEndMode.Touch, Danger.Deadly, 1, 1, null, false))
            {
                result = null;
            }
            else
            {
                HoloEmitter holoEmitter = this.FindEmitter(pawn, t);
                if (holoEmitter == null)
                {
                    result = null;
                }
                else if (holoEmitter.GetComp <CompHoloEmitter>().SimPawn != null)
                {
                    result = null;
                }
                else
                {
                    result = new Job(JobDefOfReconAndDiscovery.RD_LoadIntoEmitter, t, holoEmitter)
                    {
                        count = 1
                    };
                }
            }
            return(result);
        }
        public override Job JobOnThing(Pawn pawn, Thing t)
        {
            Vehicle_Cart cart = t as Vehicle_Cart;

            if (cart == null)
            {
                return((Job)null);
            }
            if (cart.IsForbidden(pawn.Faction) || !ReservationUtility.CanReserveAndReach(pawn, cart, PathEndMode.ClosestTouch, DangerUtility.NormalMaxDanger(pawn)))
            {
                return((Job)null);
            }
            if (FireUtility.IsBurning(cart))
            {
                JobFailReason.Is(ToolsForHaulUtility.BurningLowerTrans);
                return((Job)null);
            }
            if (ListerHaulables.ThingsPotentiallyNeedingHauling().Count == 0 && cart.storage.Count == 0)
            {
                JobFailReason.Is(ToolsForHaulUtility.NoHaulable);
                return((Job)null);
            }
            if (Find.SlotGroupManager.AllGroupsListInPriorityOrder.Count == 0)
            {
                JobFailReason.Is(ToolsForHaulUtility.NoEmptyPlaceLowerTrans);
                return((Job)null);
            }
            if (ToolsForHaulUtility.AvailableAnimalCart(cart) || ToolsForHaulUtility.AvailableCart(cart, pawn))
            {
                return(ToolsForHaulUtility.HaulWithTools(pawn, cart));
            }
            JobFailReason.Is(ToolsForHaulUtility.NoAvailableCart);
            return((Job)null);
        }
        public override Job JobOnCell(Pawn pawn, IntVec3 c, bool forced = false)
        {
            var job = base.JobOnCell(pawn, c, forced);

            // plant has seeds, if there is a seed return a job, otherwise prevent it. Seeds with no category are forbidden.
            var seed = job?.plantDefToSow?.blueprintDef;

            if (seed != null && !seed.thingCategories.NullOrEmpty())
            {
                // Clear the area some...
                var zone = c.GetZone(pawn.Map);
                if (zone != null)
                {
                    foreach (var corner in GenAdj.AdjacentCells8WayRandomized())
                    {
                        var cell = c + corner;
                        if (zone.ContainsCell(cell))
                        {
                            foreach (var thing in pawn.Map.thingGrid.ThingsAt(cell))
                            {
                                if (thing.def != job.plantDefToSow && thing.def.BlocksPlanting(true) && pawn.CanReserve(thing) && !thing.IsForbidden(pawn))
                                {
                                    if (thing.def.category == ThingCategory.Plant)
                                    {
                                        return(new Job(JobDefOf.CutPlant, thing));
                                    }
                                    if (thing.def.EverHaulable)
                                    {
                                        return(HaulAIUtility.HaulAsideJobFor(pawn, thing));
                                    }
                                }
                            }
                        }
                    }
                }

                Predicate <Thing> predicate = (Thing tempThing) =>
                                              !ForbidUtility.IsForbidden(tempThing, pawn.Faction) &&
                                              ForbidUtility.InAllowedArea(tempThing.Position, pawn) &&
                                              PawnLocalAwareness.AnimalAwareOf(pawn, tempThing) &&
                                              ReservationUtility.CanReserve(pawn, tempThing, 1);

                Thing bestSeedThingForSowing = GenClosest.ClosestThingReachable(
                    c, pawn.Map, ThingRequest.ForDef(job.plantDefToSow.blueprintDef),
                    PathEndMode.ClosestTouch, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 9999,
                    predicate);

                if (bestSeedThingForSowing != null)
                {
                    return(new Job(ResourceBank.JobDefOf.SowWithSeeds, c, bestSeedThingForSowing)
                    {
                        plantDefToSow = job.plantDefToSow,
                        count = SEEDS_TO_CARRY
                    });
                }
                return(null);
            }

            return(job);
        }
        public void CanModify()
        {
            var rsv1 = DA.Current.Single <ReservationInfo>(835041).Model <ReservationItem>();

            var data = GetReservationData(
                resourceId: rsv1.ResourceID,
                clientId: rsv1.ClientID,
                accountId: rsv1.AccountID,
                activityId: rsv1.ActivityID,
                autoEnd: rsv1.AutoEnd,
                keepAlive: rsv1.KeepAlive,
                notes: rsv1.Notes,
                selectedDate: DateTime.Parse("2018-08-02"),
                startTimeHour: 10,
                startTimeMinute: 0,
                duration: 5);

            var rsv2 = ReservationUtility.Modify(rsv1, data);

            Assert.AreNotEqual(rsv1.ReservationID, rsv2.ReservationID);
            Assert.AreEqual(DateTime.Parse("2018-08-02 10:00:00"), rsv2.BeginDateTime);
            Assert.AreEqual(DateTime.Parse("2018-08-02 10:05:00"), rsv2.EndDateTime);

            int deleted = ServiceProvider.Current.Use <IReservationManager>().PurgeReservation(rsv2.ReservationID);

            Console.WriteLine("Deleted: {0}", deleted);
        }
        bool GetNearbyPlantingSite(IntVec3 originPos, Map map, out IntVec3 newSite)
        {
            Predicate <IntVec3> validator = (IntVec3 tempCell) => IsCellOpenForSowingPlantOfType(tempCell, map, job.plantDefToSow) &&
                                            ReservationUtility.CanReserveAndReach(GetActor(), tempCell, PathEndMode.Touch, DangerUtility.NormalMaxDanger(GetActor()), 1);

            return(CellFinder.TryFindRandomCellNear(originPos, map, 2, validator, out newSite));
        }
Example #7
0
        // Token: 0x0600014D RID: 333 RVA: 0x0000D51C File Offset: 0x0000B91C
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Job result;

            if (t.def.defName != "HoloDisk")
            {
                result = null;
            }
            else if (!ReservationUtility.CanReserveAndReach(pawn, t, (Verse.AI.PathEndMode) 2, (Verse.Danger) 3, 1, 1, null, false))
            {
                result = null;
            }
            else
            {
                HoloEmitter holoEmitter = this.FindEmitter(pawn, t);
                if (holoEmitter == null)
                {
                    result = null;
                }
                else if (holoEmitter.GetComp <CompHoloEmitter>().SimPawn != null)
                {
                    result = null;
                }
                else
                {
                    result = new Job(JobDefOfHoloEmitters.LoadIntoEmitter, t, holoEmitter)
                    {
                        count = 1
                    };
                }
            }
            return(result);
        }
        public async Task <Models.ReservationModel> Start(int reservationId, int clientId, string ip)
        {
            var rsv = DA.Scheduler.Reservation.Single(reservationId);

            var isInLab = KioskUtility.ClientInLab(rsv.Resource.ProcessTech.Lab.LabID, clientId, ip);

            ReservationState state = ReservationUtility.GetReservationState(rsv.ReservationID, clientId, isInLab);
            var startable          = ReservationUtility.IsStartable(state);

            if (!startable)
            {
                throw new InvalidOperationException(string.Format("ReservationID {0} cannot be started: {1}", reservationId, GetNotStartableMessage(state)));
            }

            if (rsv != null)
            {
                await ReservationUtility.StartReservation(rsv, clientId, isInLab);

                return(CreateReservationModel(rsv, clientId, ip));
            }
            else
            {
                throw new ArgumentException(string.Format("Cannot find record for ReservationID = {0}", reservationId), "reservationId");
            }
        }
Example #9
0
        public static void Postfix(Pawn pawn, Building_Turret tube, ref Thing __result)
        {
            if (__result != null)
            {
                return;
            }
            var               turret = tube as Building_ShipTurret;
            StorageSettings   allowedShellsSettings = ThingCompUtility.TryGetComp <CompChangeableProjectilePlural>(turret.gun).allowedShellsSettings;
            Predicate <Thing> pred = (Thing x) =>
            {
                if (ForbidUtility.IsForbidden(x, pawn) || !ReservationUtility.CanReserve(pawn, x, 1, -1, (ReservationLayerDef)null, false))
                {
                    return(false);
                }
                else
                {
                    return(allowedShellsSettings?.AllowedToAccept(x) ?? true);
                }
            };

            foreach (String defName in shellDefNames)
            {
                var val = ThingDef.Named(defName);
                __result = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(val), PathEndMode.ClosestTouch, TraverseParms.For(pawn), 9999f, pred);
                if (__result != null)
                {
                    return;
                }
            }
        }
Example #10
0
        public override Job JobOnCell(Pawn pawn, IntVec3 cell)
        {
            Job job = base.JobOnCell(pawn, cell);

            if (job != null && job.plantDefToSow != null && job.plantDefToSow.blueprintDef != null)
            {
                Predicate <Thing> predicate = (Thing tempThing) =>
                                              !ForbidUtility.IsForbidden(tempThing, pawn.Faction) &&
                                              PawnLocalAwareness.AnimalAwareOf(pawn, tempThing) &&
                                              ReservationUtility.CanReserve(pawn, tempThing, 1);

                Thing bestSeedThingForSowing = GenClosest.ClosestThingReachable(
                    cell, pawn.Map, ThingRequest.ForDef(job.plantDefToSow.blueprintDef),
                    PathEndMode.ClosestTouch, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 9999,
                    predicate, null, -1, false);

                if (bestSeedThingForSowing != null)
                {
                    return(new Job(LocalJobDefOf.SowWithSeeds, cell, bestSeedThingForSowing)
                    {
                        plantDefToSow = job.plantDefToSow,
                        count = 25
                    });
                }
                return(null);
            }

            return(job);
        }
Example #11
0
        public void CanInsertFacilityDownTime()
        {
            int resourceId = 80010; //Zygo NewView 5000
            int rid        = 0;
            int fdtid      = 0;

            using (ContextManager.StartRequest(1600))
            {
                // Create a reservation that starts at 10 am tomorrow.

                var data = new ReservationData()
                {
                    ClientID            = 1600,
                    ResourceID          = resourceId,
                    ActivityID          = 6,
                    AccountID           = 67,
                    Notes               = "Test Reservation",
                    AutoEnd             = true,
                    KeepAlive           = true,
                    ReservationDuration = new ReservationDuration(DateTime.Now.Date.AddDays(1).AddHours(10), TimeSpan.FromMinutes(5))
                };

                var rsv = ReservationUtility.Create(data);
                rid = rsv.ReservationID;
            }

            using (ContextManager.StartRequest(155))
            {
                int clientId = HttpContext.Current.CurrentUser().ClientID;

                DateTime sd = DateTime.Now.Date.AddDays(1).AddHours(9);
                DateTime ed = sd.AddHours(4);

                ReservationGroup group = FacilityDownTimeUtility.CreateFacilityDownTimeGroup(clientId, sd, ed);

                var result = FacilityDownTimeUtility.InsertFacilityDownTime(
                    resourceId: 80010,
                    groupId: group.GroupID,
                    clientId: clientId,
                    beginDateTime: sd,
                    endDateTime: ed,
                    notes: "EECS building fire drill"
                    );

                Assert.AreEqual(1, result.Existing.Count());
                Assert.AreEqual(rid, result.Existing.ElementAt(0).ReservationID);

                fdtid = result.ReservationID;

                var rsv = DA.Current.Single <Reservation>(fdtid);
                Assert.IsTrue(rsv.Activity.IsFacilityDownTime);
            }

            using (ContextManager.StartRequest(1301))
            {
                // clean up
                PurgeReservations(new[] { rid, fdtid });
            }
        }
Example #12
0
        public override bool TryMakePreToilReservations(bool errorOnFailed)
        {
            Pawn            pawn   = this.pawn;
            LocalTargetInfo target = this.job.GetTarget(TargetIndex.A);
            Job             job    = this.job;

            return(ReservationUtility.Reserve(pawn, target, job, 1, -1, null, errorOnFailed));
        }
        public static Building_BaseRobotRechargeStation FindRechargeStationFor(ArcBaseRobot sleeper, ArcBaseRobot traveler, bool sleeperWillBePrisoner, bool checkSocialProperness, bool medicalBedNeeded = false)
        {
            Predicate <Thing> predicate = delegate(Thing t) {
                bool flag3 = !ReservationUtility.CanReserveAndReach(traveler, t, PathEndMode.OnCell, Danger.Some, 1, -1, null, false);
                bool result2;
                if (flag3)
                {
                    result2 = false;
                }
                else
                {
                    Building_BaseRobotRechargeStation rechargeStation = t as Building_BaseRobotRechargeStation;
                    bool flag4 = rechargeStation == null;
                    if (flag4)
                    {
                        result2 = false;
                    }
                    else
                    {
                        bool flag5 = rechargeStation.robot != null && rechargeStation.robot != sleeper;
                        if (flag5)
                        {
                            result2 = false;
                        }
                        else
                        {
                            bool flag6 = ForbidUtility.IsForbidden(rechargeStation, traveler);
                            if (flag6)
                            {
                                result2 = false;
                            }
                            else
                            {
                                bool flag7 = FireUtility.IsBurning(rechargeStation);
                                result2 = !flag7;
                            }
                        }
                    }
                }
                return(result2);
            };
            bool flag = sleeper.rechargeStation != null && predicate(sleeper.rechargeStation);
            Building_BaseRobotRechargeStation result;

            if (flag)
            {
                Building_BaseRobotRechargeStation rechargeStation = sleeper.rechargeStation;
                bool flag2 = rechargeStation != null;
                if (flag2)
                {
                    result = rechargeStation;
                    return(result);
                }
            }
            result = null;
            return(result);
        }
Example #14
0
 internal static bool _HasJobOnThing(this WorkGiver_Researcher obj, Pawn pawn, Thing t)
 {
     return
         ((
              (t.def.thingClass == typeof(Building_ResearchBench)) ||
              (t.def.thingClass.IsSubclassOf(typeof(Building_ResearchBench)))
              ) &&
          (ReservationUtility.CanReserve(pawn, (TargetInfo)t, 1)));
 }
Example #15
0
        public static void JumpToCarryToNextContainerIfPossible_Prefix(ref Toil __result, Toil carryToContainerToil, TargetIndex primaryTargetInd)
        {
            Toil toil = new Toil();

            toil.initAction = delegate()
            {
                Pawn actor  = toil.actor;
                Job  curJob = actor.jobs.curJob;
                if (actor.carryTracker.CarriedThing != null)
                {
                    LocalTargetInfo target;
                    if (curJob.targetQueueB != null && curJob.targetQueueB.Count > 0 && actor.RaceProps.Animal)
                    {
                        target = curJob.GetTarget(primaryTargetInd);
                        Thing             primaryTarget2 = target.Thing;
                        bool              hasSpareItems2 = actor.carryTracker.CarriedThing.stackCount > GenConstruct.AmountNeededByOf((IConstructible)(object)(IConstructible)primaryTarget2, actor.carryTracker.CarriedThing.def);
                        Predicate <Thing> predicate      = (Thing th) => ReservationUtility.CanReserve(actor, primaryTarget2, 1, -1, (ReservationLayerDef)null, false) && GenCollection.Any <ThingDefCountClass>(((IConstructible)th).MaterialsNeeded(), (Predicate <ThingDefCountClass>)((ThingDefCountClass need) => need.thingDef == actor.carryTracker.CarriedThing.def)) && ((th == primaryTarget2) | hasSpareItems2);
                        Thing             nextTarget2    = GenClosest.ClosestThing_Global_Reachable(actor.Position, actor.Map, curJob.targetQueueB.Select(delegate(LocalTargetInfo targ)
                        {
                            //IL_0000: Unknown result type (might be due to invalid IL or missing references)
                            //IL_0001: Unknown result type (might be due to invalid IL or missing references)
                            LocalTargetInfo val2 = targ;
                            return(val2.Thing);
                        }), (PathEndMode)2, TraverseParms.For(actor, (Danger)3, (TraverseMode)0, false), 99999f, predicate, (Func <Thing, float>)null);
                        if (nextTarget2 != null)
                        {
                            curJob.targetQueueB.RemoveAll((LocalTargetInfo targ) => targ.Thing == nextTarget2);
                            curJob.targetB = nextTarget2;
                            actor.jobs.curDriver.JumpToToil(carryToContainerToil);
                        }
                    }
                    if (curJob.targetQueueB != null && curJob.targetQueueB.Count > 0 && !actor.RaceProps.Animal)
                    {
                        target = curJob.GetTarget(primaryTargetInd);
                        Thing             primaryTarget = target.Thing;
                        bool              hasSpareItems = actor.carryTracker.CarriedThing.stackCount > GenConstruct.AmountNeededByOf((IConstructible)(object)(IConstructible)primaryTarget, actor.carryTracker.CarriedThing.def);
                        Predicate <Thing> predicate2    = (Thing th) => GenConstruct.CanConstruct(th, actor, false, false) && GenCollection.Any <ThingDefCountClass>(((IConstructible)th).MaterialsNeeded(), (Predicate <ThingDefCountClass>)((ThingDefCountClass need) => need.thingDef == actor.carryTracker.CarriedThing.def)) && ((th == primaryTarget) | hasSpareItems);
                        Thing             nextTarget    = GenClosest.ClosestThing_Global_Reachable(actor.Position, actor.Map, curJob.targetQueueB.Select(delegate(LocalTargetInfo targ)
                        {
                            //IL_0000: Unknown result type (might be due to invalid IL or missing references)
                            //IL_0001: Unknown result type (might be due to invalid IL or missing references)
                            LocalTargetInfo val = targ;
                            return(val.Thing);
                        }), (PathEndMode)2, TraverseParms.For(actor, (Danger)3, (TraverseMode)0, false), 99999f, predicate2, (Func <Thing, float>)null);
                        if (nextTarget != null)
                        {
                            curJob.targetQueueB.RemoveAll((LocalTargetInfo targ) => targ.Thing == nextTarget);
                            curJob.targetB = nextTarget;
                            actor.jobs.curDriver.JumpToToil(carryToContainerToil);
                        }
                    }
                }
            };
            __result = toil;
        }
Example #16
0
        static void Postfix(Pawn pawn, ref Job __result)
        {
            IEnumerable <Building_Dresser> dressers = pawn.Map.listerBuildings.AllBuildingsColonistOfClass <Building_Dresser>();

            if (!DoesDressersHaveApparel(dressers))
            {
                return;
            }

            Thing thing = null;

            if (__result != null)
            {
                thing = __result.targetA.Thing;
            }

            Building_Dresser containingDresser = null;
            Outfit           currentOutfit     = pawn.outfits.CurrentOutfit;
            float            baseApparelScore  = 0f;

            foreach (Building_Dresser dresser in dressers)
            {
                foreach (Apparel apparel in dresser.StoredApparel)
                {
                    if (currentOutfit.filter.Allows(apparel))
                    {
                        if (!apparel.IsForbidden(pawn))
                        {
                            float newApparelScore = JobGiver_OptimizeApparel.ApparelScoreGain(pawn, apparel);
                            if (newApparelScore >= 0.05f && newApparelScore >= baseApparelScore)
                            {
                                if (ApparelUtility.HasPartsToWear(pawn, apparel.def))
                                {
                                    if (ReservationUtility.CanReserveAndReach(pawn, dresser, PathEndMode.OnCell, pawn.NormalMaxDanger(), 1))
                                    {
                                        containingDresser = dresser;
                                        thing             = apparel;
                                        baseApparelScore  = newApparelScore;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (thing != null && containingDresser != null)
            {
                __result = new Job(containingDresser.wearApparelFromStorageJobDef, containingDresser, thing);
            }
        }
        public Models.ReservationModel CreateReservationModel(Reservation rsv, int clientId, string ip)
        {
            var item = new Models.ReservationModel();

            item.ReservationID        = rsv.ReservationID;
            item.ResourceID           = rsv.Resource.ResourceID;
            item.ResourceName         = rsv.Resource.ResourceName;
            item.AccountID            = rsv.Account.AccountID;
            item.AccountName          = rsv.Account.Name;
            item.ShortCode            = rsv.Account.ShortCode;
            item.ReservedByClientID   = rsv.Client.ClientID;
            item.ReservedByClientName = string.Format("{0} {1}", rsv.Client.FName, rsv.Client.LName);

            Client c;

            if (rsv.ClientIDBegin.HasValue)
            {
                if (rsv.ClientIDBegin.Value > 0)
                {
                    c = DA.Current.Single <Client>(rsv.ClientIDBegin.Value);
                    item.StartedByClientID   = c.ClientID;
                    item.StartedByClientName = string.Format("{0} {1}", c.FName, c.LName);
                }
                else
                {
                    item.StartedByClientID   = 0;
                    item.StartedByClientName = string.Empty;
                }
            }
            else
            {
                c = DA.Current.Single <Client>(clientId);
                item.StartedByClientID   = clientId;
                item.StartedByClientName = string.Format("{0} {1}", c.FName, c.LName);
            }

            var isInLab            = KioskUtility.ClientInLab(rsv.Resource.ProcessTech.Lab.LabID, clientId, ip);
            ReservationState state = ReservationUtility.GetReservationState(rsv.ReservationID, clientId, isInLab);

            item.Startable           = ReservationUtility.IsStartable(state);
            item.NotStartableMessage = GetNotStartableMessage(state);

            var inst = ActionInstanceUtility.Find(ActionType.Interlock, rsv.Resource.ResourceID);

            item.HasInterlock = inst != null;

            item.ReturnUrl = GetResourceUrl(rsv.Resource.ResourceID);

            return(item);
        }
Example #18
0
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Building building_PsionicEmanator = t as Building;
            Job      result;

            if (ReservationUtility.CanReserveAndReach(pawn, building_PsionicEmanator, PathEndMode.ClosestTouch, Danger.Some, 1, -1, null, false))
            {
                var victim = (Thing)pawn.Map.designationManager.SpawnedDesignationsOfDef(DesignationDefOf.Slaughter).RandomElement().target;
                result = new Job(JobDefOfReconAndDiscovery.RD_SacrificeAtAltar, victim, building_PsionicEmanator);
            }
            else
            {
                result = null;
            }
            return(result);
        }
Example #19
0
 public override bool HasJobOnThing(Pawn pawn, Thing t)
 {
     if (pawn.Faction != Faction.OfColony)
     {
         return(false);
     }
     RimWorld.Filth filth = t as RimWorld.Filth;
     if (filth == null)
     {
         return(false);
     }
     if (!Find.AreaCleaning[filth.Position] || !ReservationUtility.CanReserveAndReach(pawn, t, PathEndMode.ClosestTouch, DangerUtility.NormalMaxDanger(pawn), 1))
     {
         return(false);
     }
     return(filth.TicksSinceThickened >= minTicksSinceThickened);
 }
Example #20
0
        // Token: 0x0600001B RID: 27 RVA: 0x000030DC File Offset: 0x000012DC
        public static Building FindBreakDownTargetFor(Pawn p)
        {
            Predicate <Thing> breakdownValidator = delegate(Thing t)
            {
                Building building2 = (Building)t;
                return(ReservationUtility.CanReserveAndReach(p, t, (PathEndMode)1, (Danger)2, 1, -1, null, false) && !building2.GetComp <CompBreakdownable>().BrokenDown&& !FireUtility.IsBurning(building2));
            };
            ThingDef thingDef = GenCollection.RandomElement <ThingDef>((from t in DefDatabase <ThingDef> .AllDefsListForReading
                                                                        where t.GetCompProperties <CompProperties_Breakdownable>() != null
                                                                        select t).ToList <ThingDef>());
            Predicate <Thing> predicate = (Thing b) => breakdownValidator(b);
            Building          building  = (Building)GenClosest.ClosestThingReachable(p.Position, p.Map, ThingRequest.ForDef(thingDef), (PathEndMode)1, TraverseParms.For(p, (Danger)3, 0, false), 9999f, predicate, null, 0, -1, false, (RegionType)6, false);

            if (building != null)
            {
                return(building);
            }
            return(null);
        }
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            bool result;

            if (!(t is Building))
            {
                result = false;
            }
            else if (!pawn.story.traits.HasTrait(TraitDef.Named("PsychicSensitivity")))
            {
                JobFailReason.Is("RD_OnlyPsychicCanBroadcast".Translate());                 //"Only psychic pawns can broadcast a battle prayer"
                result = false;
            }
            else
            {
                result = ReservationUtility.CanReserveAndReach(pawn, t, PathEndMode.Touch, Danger.Some, 1, -1, null, forced);
            }
            return(result);
        }
 public static void AddHumanlikeOrdersPostfix(Vector3 clickPos, Pawn pawn, ref List <FloatMenuOption> opts)
 {
     foreach (LocalTargetInfo localTargetInfo in GenUI.TargetsAt(clickPos, TargetingParameters.ForRescue(pawn), true))
     {
         Pawn target = (Pawn)localTargetInfo.Thing;
         if (target.Faction == PurpleIvyData.AlienFaction && target.Downed &&
             ReservationUtility.CanReserveAndReach(pawn, target, PathEndMode.OnCell,
                                                   Danger.Deadly, 1, -1, null, true))
         {
             var containers = target.Map.listerBuildings.AllBuildingsColonistOfClass
                              <Building_СontainmentBreach>().Where(x => x.maxNumAliens > x.innerContainer.Count);
             var containmentBreach = (Building_СontainmentBreach)GenClosest.ClosestThing_Global
                                         (target.Position, containers, 9999f);
             if (containmentBreach != null)
             {
                 JobDef jobDef = PurpleIvyDefOf.PI_TakeAlienToContainmentBreach;
                 Action action = delegate()
                 {
                     Job job = JobMaker.MakeJob(jobDef, target, containmentBreach);
                     job.count = 1;
                     pawn.jobs.TryTakeOrderedJob(job, 0);
                 };
                 string          text = TranslatorFormattedStringExtensions.Translate("TakeAlienToContainmentBreach", target.LabelCap, target);
                 FloatMenuOption opt  = new FloatMenuOption
                                            (text, action, MenuOptionPriority.RescueOrCapture, null, target, 0f, null, null);
                 if (opts.Where(x => x.Label == text).Count() == 0)
                 {
                     opts.Add(opt);
                 }
             }
             else
             {
                 string text = "NoContainersToTake".Translate();
                 if (opts.Where(x => x.Label == text).Count() == 0)
                 {
                     opts.Add(new FloatMenuOption(text, null, MenuOptionPriority.Default, null, null,
                                                  0f, null, null));
                 }
             }
         }
     }
 }
Example #23
0
        public override bool HasJobOnThing(Pawn pawn, Thing thing, bool forced = false)
        {
            Pawn pawn2 = thing as Pawn;

            if (pawn2 == null || !pawn2.RaceProps.Humanlike)
            {
                return(false);
            }
            CompHasGatherableBodyResource comp = GetComp(pawn2);

            if (comp != null && comp.ActiveAndFull && PawnUtility.CanCasuallyInteractNow(pawn2, false) && pawn2 != pawn)
            {
                LocalTargetInfo localTargetInfo = pawn2;
                if (ReservationUtility.CanReserve(pawn, localTargetInfo, 1, -1, null, forced))
                {
                    return(true);
                }
            }
            return(false);
        }
Example #24
0
        public Job TryGiveJob(Pawn pawn, Thing targetThing, bool NoJoyCheck = false)
        {
            Verb verb = null;

            if (pawn != null)
            {
                verb = pawn.meleeVerbs.TryGetMeleeVerb(targetThing);
            }
            Job result;

            if (pawn.WorkTagIsDisabled(WorkTags.Violent) || verb == null || verb.verbProps == null)
            {
                result = null;
            }
            else
            {
                List <Thing>      list      = pawn.Map.listerThings.ThingsOfDef(this.def.thingDefs[0]);
                Predicate <Thing> predicate = delegate(Thing t)
                {
                    return(!ForbidUtility.IsForbidden(t, pawn) &&
                           ReservationUtility.CanReserve(pawn, t, this.def.jobDef.joyMaxParticipants, -1, null, false) &&
                           SocialProperness.IsSociallyProper(t, pawn));
                };
                Thing thing = null;
                if (targetThing != null && ReachabilityUtility.CanReach(pawn, targetThing.Position, PathEndMode.InteractionCell, Danger.Deadly, false, 0) && predicate(targetThing))
                {
                    thing = targetThing;
                }
                else if (targetThing == null)
                {
                    thing = GenClosest.ClosestThing_Global_Reachable(pawn.Position, pawn.Map, list, PathEndMode.InteractionCell, TraverseParms.For(pawn, Danger.Deadly, 0, false), 9999f, predicate, null);
                }
                if (thing != null)
                {
                    Job job = JobMaker.MakeJob(this.def.jobDef, thing);
                    return(job);
                }
                result = null;
            }
            return(result);
        }
Example #25
0
        public override IEnumerable <FloatMenuOption> GetFloatMenuOptions(Pawn myPawn)
        {
            List <FloatMenuOption> floatMenuOptionList = new List <FloatMenuOption>();

            if (!ReservationUtility.CanReserve(myPawn, (LocalTargetInfo)((Thing)this), 1))
            {
                return (IEnumerable <FloatMenuOption>) new List <FloatMenuOption>()
                       {
                           new FloatMenuOption("CannotUseReserved", (Action)null, MenuOptionPriority.VeryLow, (Action)null, (Thing)null)
                       }
            }
            ;
            if (!myPawn.CanReach((LocalTargetInfo)((Thing)this), PathEndMode.Touch, Danger.None, false, TraverseMode.ByPawn))
            {
                return (IEnumerable <FloatMenuOption>) new List <FloatMenuOption>()
                       {
                           new FloatMenuOption("CannotUseNoPath", (Action)null, MenuOptionPriority.VeryLow, (Action)null, (Thing)null)
                       }
            }
            ;
            if (!this.MyAllowList.Contains(myPawn))
            {
                return (IEnumerable <FloatMenuOption>) new List <FloatMenuOption>()
                       {
                           new FloatMenuOption("Not on training list", (Action)null, MenuOptionPriority.VeryLow, (Action)null, (Thing)null)
                       }
            }
            ;

            Action action = (Action)(() =>
            {
                Busy = true;
                myPawn.jobs.StopAll();
                myPawn.jobs.TryTakeOrderedJob(MyCustomJob, JobTag.MiscWork);
                this.PawnSelected = myPawn;
                //myPawn.Reserve((LocalTargetInfo) ((Thing) this),this.MyCustomJob,1,-1,null);
            });

            floatMenuOptionList.Add(new FloatMenuOption("Go train medicine", action, MenuOptionPriority.VeryLow, (Action)null, (Thing)null));
            return((IEnumerable <FloatMenuOption>)floatMenuOptionList);
        }
Example #26
0
        // Token: 0x0600000B RID: 11 RVA: 0x000029EC File Offset: 0x00000BEC
        private Toil StartCollectCorpseToil()
        {
            var toil = new Toil();

            toil.initAction = delegate()
            {
                if (Victim == null)
                {
                    toil.actor.jobs.EndCurrentJob(JobCondition.Incompletable, true);
                }
                else
                {
                    TaleRecorder.RecordTale(TaleDefOf.Hunted, new object[]
                    {
                        pawn,
                        Victim
                    });
                    Corpse corpse = Victim.Corpse;
                    if (corpse == null || !pawn.CanReserveAndReach(corpse, PathEndMode.ClosestTouch, Danger.Deadly, 1, -1, null, false))
                    {
                        pawn.jobs.EndCurrentJob(JobCondition.Incompletable, true);
                    }
                    else
                    {
                        corpse.SetForbidden(false, true);
                        if (corpse.InnerPawn.RaceProps.deathActionWorkerClass != null && !Hunting_Loader.settings.shouldCollectExplodables)
                        {
                            pawn.jobs.EndCurrentJob(JobCondition.Incompletable, true);
                        }
                        else
                        {
                            if (StoreUtility.TryFindBestBetterStoreCellFor(corpse, pawn, Map, StoragePriority.Unstored, pawn.Faction, out IntVec3 c, true))
                            {
                                ReservationUtility.Reserve(pawn, corpse, job, 1, -1, null);
                                ReservationUtility.Reserve(pawn, c, job, 1, -1, null);
                                job.SetTarget(TargetIndex.B, c);
                                job.SetTarget(TargetIndex.A, corpse);
                                job.count    = 1;
                                job.haulMode = HaulMode.ToCellStorage;
                            }
Example #27
0
        // Token: 0x06000009 RID: 9 RVA: 0x0000211C File Offset: 0x0000031C
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            if (pawn.Map.designationManager.DesignationOn(t, TrapsDefOf.TR_RearmTrap) == null)
            {
                return(false);
            }
            LocalTargetInfo localTargetInfo = t;

            if (!ReservationUtility.CanReserve(pawn, localTargetInfo, 1, -1, null, forced))
            {
                return(false);
            }
            List <Thing> thingList = GridsUtility.GetThingList(t.Position, t.Map);

            for (int i = 0; i < thingList.Count; i++)
            {
                if (thingList[i] != t && thingList[i].def.category == ThingCategory.Item && (ForbidUtility.IsForbidden(thingList[i], pawn) || StoreUtility.IsInValidStorage(thingList[i]) || !HaulAIUtility.CanHaulAside(pawn, thingList[i], out IntVec3 intVec)))
                {
                    return(false);
                }
            }
            return(true);
        }
Example #28
0
 // Token: 0x0600004F RID: 79 RVA: 0x00005498 File Offset: 0x00003698
 private static bool DrugValidator(Pawn pawn, Thing drug)
 {
     if (!drug.def.IsDrug)
     {
         return(false);
     }
     if (!pawn.IsPrisoner && drug.Spawned)
     {
         if (ForbidUtility.IsForbidden(drug, pawn))
         {
             return(false);
         }
         if (!ReservationUtility.CanReserve(pawn, drug, 1, -1, null, false))
         {
             return(false);
         }
         if (!SocialProperness.IsSociallyProper(drug, pawn))
         {
             return(false);
         }
     }
     return(true);
 }
 protected override Job TryGiveJob(Pawn pawn)
 {
     if (pawn.mindState.meleeThreat != null && pawn.mindState.meleeThreat.RaceProps.Humanlike &&
         pawn.mindState.meleeThreat.Downed && pawn.mindState.meleeThreat.HostileTo(pawn))
     {
         if (ReservationUtility.CanReserve(pawn, pawn.mindState.meleeThreat))
         {
             if (!RCellFinder.TryFindBestExitSpot(pawn, out IntVec3 spot))
             {
                 return(null);
             }
             //Log.Message(pawn + " - meleeThreat: " + pawn.mindState.meleeThreat);
             Job job = JobMaker.MakeJob(JobDefOf.Kidnap);
             job.targetA = pawn.mindState.meleeThreat;
             job.targetB = spot;
             job.count   = 1;
             return(job);
         }
     }
     else if (pawn.mindState.enemyTarget != null && pawn.mindState.enemyTarget is Pawn pawn2 &&
              pawn2.RaceProps.Humanlike && pawn2.Downed && pawn2.HostileTo(pawn))
     {
         if (ReservationUtility.CanReserve(pawn, pawn.mindState.enemyTarget))
         {
             if (!RCellFinder.TryFindBestExitSpot(pawn, out IntVec3 spot))
             {
                 return(null);
             }
             //Log.Message(pawn + " - enemyTarget: " + pawn2);
             Job job = JobMaker.MakeJob(JobDefOf.Kidnap);
             job.targetA = pawn.mindState.enemyTarget;
             job.targetB = spot;
             job.count   = 1;
             return(job);
         }
     }
Example #30
0
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Building building_PsionicEmanator = t as Building;
            bool     result;

            if (building_PsionicEmanator == null)
            {
                result = false;
            }
            else if (pawn.Map.designationManager.SpawnedDesignationsOfDef(DesignationDefOf.Slaughter).Count() == 0)
            {
                result = false;
            }
            else if (pawn.story != null && pawn.WorkTagIsDisabled(WorkTags.Social))
            {
                JobFailReason.Is("IsIncapableOfViolenceShort".Translate());
                result = false;
            }
            else
            {
                result = ReservationUtility.CanReserve(pawn, building_PsionicEmanator, 1, -1, null, forced);
            }
            return(result);
        }