public static Toil FailOnDespawnedNullOrForbiddenPlacedThings(this Toil toil) { toil.AddFailCondition(delegate { bool result; if (toil.actor.jobs.curJob.placedThings == null) { result = false; } else { for (int i = 0; i < toil.actor.jobs.curJob.placedThings.Count; i++) { ThingCountClass thingCountClass = toil.actor.jobs.curJob.placedThings[i]; if (thingCountClass.thing == null || !thingCountClass.thing.Spawned || thingCountClass.thing.Map != toil.actor.Map || (!toil.actor.CurJob.ignoreForbidden && thingCountClass.thing.IsForbidden(toil.actor))) { return(true); } } result = false; } return(result); }); return(toil); }
public static Toil CarryHauledThingToContainer() { Toil gotoDest = new Toil(); gotoDest.initAction = delegate { gotoDest.actor.pather.StartPath(gotoDest.actor.jobs.curJob.targetB.Thing, PathEndMode.Touch); }; gotoDest.AddFailCondition(delegate { Thing thing = gotoDest.actor.jobs.curJob.targetB.Thing; if (!thing.Destroyed && !thing.IsForbidden(gotoDest.actor)) { ThingOwner thingOwner = thing.TryGetInnerInteractableThingOwner(); if (thingOwner != null && !thingOwner.CanAcceptAnyOf(gotoDest.actor.carryTracker.CarriedThing, true)) { return(true); } return(false); } return(true); }); gotoDest.defaultCompleteMode = ToilCompleteMode.PatherArrival; return(gotoDest); }
//====================================================================================== //================================ Toil-only conditions ================================ //====================================================================================== public static Toil FailOnDespawnedNullOrForbiddenPlacedThings(this Toil toil) { toil.AddFailCondition(() => { if (toil.actor.jobs.curJob.placedThings == null) { return(false); } for (int i = 0; i < toil.actor.jobs.curJob.placedThings.Count; i++) { var targ = toil.actor.jobs.curJob.placedThings[i]; if (targ.thing == null || !targ.thing.Spawned || targ.thing.Map != toil.actor.Map || // note: if the target is spawned in another map, then from the actor's perspective it's unspawned, so we end the job (!toil.actor.CurJob.ignoreForbidden && targ.thing.IsForbidden(toil.actor))) { return(true); } } return(false); } ); return(toil); }
public static Toil CarryHauledThingToCell(TargetIndex squareIndex) { Toil toil = new Toil(); toil.initAction = delegate { IntVec3 cell2 = toil.actor.jobs.curJob.GetTarget(squareIndex).Cell; toil.actor.pather.StartPath(cell2, PathEndMode.ClosestTouch); }; toil.defaultCompleteMode = ToilCompleteMode.PatherArrival; toil.AddFailCondition(delegate { Pawn actor = toil.actor; IntVec3 cell = actor.jobs.curJob.GetTarget(squareIndex).Cell; return((actor.jobs.curJob.haulMode == HaulMode.ToCellStorage && !cell.IsValidStorageFor(actor.Map, actor.carryTracker.CarriedThing)) ? true : false); }); return(toil); }
public static Toil FailOnDespawnedNullOrForbiddenPlacedThings(this Toil toil) { toil.AddFailCondition(delegate { if (toil.actor.jobs.curJob.placedThings == null) { return(false); } int num = 0; while (num < toil.actor.jobs.curJob.placedThings.Count) { ThingStackPartClass thingStackPartClass = toil.actor.jobs.curJob.placedThings[num]; if (thingStackPartClass.thing != null && thingStackPartClass.thing.Spawned && thingStackPartClass.thing.Map == toil.actor.Map && (toil.actor.CurJob.ignoreForbidden || !thingStackPartClass.thing.IsForbidden(toil.actor))) { num++; continue; } return(true); } return(false); }); return(toil); }
public override void DecorateWaitToil(Toil wait) { base.DecorateWaitToil(wait); wait.AddFailCondition(() => !this.pawn.Downed); }