private Toil Manage(TargetIndex targetIndex) { var station = CurJob.GetTarget(targetIndex).Thing as Building_ManagerStation; if (station == null) { Log.Error("Target of manager job was not a manager station. This should never happen."); return(null); } var comp = station.GetComp <Comp_ManagerStation>(); if (comp == null) { Log.Error("Target of manager job does not have manager station comp. This should never happen."); return(null); } var toil = new Toil(); toil.defaultDuration = (int)(comp.Props.Speed * (1 - pawn.GetStatValue(StatDef.Named("ManagingSpeed")) + .5)); #if DEBUG_WORKGIVER Log.Message("Pawn stat: " + pawn.GetStatValue(StatDef.Named("ManagingSpeed")) + " (+0.5) Station speed: " + comp.Props.Speed + "Total time: " + toil.defaultDuration); #endif toil.defaultCompleteMode = ToilCompleteMode.Delay; toil.tickAction = delegate { toil.actor.skills.GetSkill(DefDatabase <SkillDef> .GetNamed("Managing")).Learn(0.11f); }; var finishers = new List <Action>(); finishers.Add(delegate { Manager.For(pawn.Map).TryDoWork(); }); toil.finishActions = finishers; return(toil); }
protected override IEnumerable <Toil> MakeNewToils() { this.EndOnDespawnedOrNull(MountableInd); if (TargetThingB.IsForbidden(pawn.Faction)) { this.FailOnForbidden(MountableInd); } yield return(Toils_Reserve.Reserve(MountableInd, CurJob.def.joyMaxParticipants)); Toil toil = Toils_Goto.GotoCell(DrivePathInd, PathEndMode.OnCell); toil.tickAction = delegate { if (Find.TickManager.TicksGame > startTick + CurJob.def.joyDuration) { EndJobWith(JobCondition.Succeeded); return; } JoyUtility.JoyTickCheckEnd(pawn, JoyTickFullJoyAction.EndJob, 1f); }; ThingWithComps cart = CurJob.GetTarget(MountableInd).Thing as ThingWithComps; //JumpIf already mounted yield return(Toils_Jump.JumpIf(toil, () => { if (cart.TryGetComp <CompMountable>().Driver == pawn) { return true; } return false; })); //Mount on Target yield return(Toils_Goto.GotoThing(MountableInd, PathEndMode.ClosestTouch) .FailOnDestroyedOrNull(MountableInd)); yield return(Toils_Cart.MountOn(MountableInd)); yield return(toil); yield return(new Toil { initAction = delegate { if (CurJob.targetQueueA.Count > 0) { TargetInfo targetA = CurJob.targetQueueA[0]; CurJob.targetQueueA.RemoveAt(0); CurJob.targetA = targetA; JumpToToil(toil); return; } } }); yield break; }
protected override IEnumerable <Toil> MakeNewToils() { Apparel_Backpack backpack = CurJob.GetTarget(BackpackInd).Thing as Apparel_Backpack; // no free slots this.FailOn(() => backpack.slotsComp.slots.Count >= backpack.MaxItem); // reserve resources yield return(Toils_Reserve.ReserveQueue(HaulableInd)); // extract next target thing from targetQueue Toil toilExtractNextTarget = Toils_JobTransforms.ExtractNextTargetFromQueue(HaulableInd); yield return(toilExtractNextTarget); Toil toilGoToThing = Toils_Goto.GotoThing(HaulableInd, PathEndMode.ClosestTouch) .FailOnDespawnedOrNull(HaulableInd); yield return(toilGoToThing); Toil pickUpThingIntoSlot = new Toil { initAction = () => { if (!backpack.slotsComp.slots.TryAdd(CurJob.targetA.Thing)) { EndJobWith(JobCondition.Incompletable); } } }; yield return(pickUpThingIntoSlot); yield return(Toils_Jump.JumpIfHaveTargetInQueue(HaulableInd, toilExtractNextTarget)); }
protected override IEnumerable <Toil> MakeNewToils() { /// //Set fail conditions /// this.FailOnDestroyed(HaulableInd); this.FailOnDestroyed(CarrierInd); //Note we only fail on forbidden if the target doesn't start that way //This helps haul-aside jobs on forbidden items if (!TargetThingA.IsForbidden(pawn.Faction)) { this.FailOnForbidden(HaulableInd); } /// //Define Toil /// Toil toilGoto = null; toilGoto = Toils_Goto.GotoThing(HaulableInd, PathMode.ClosestTouch) .FailOn(() => { Vehicle_Cargo vc = CurJob.GetTarget(CarrierInd).Thing as Vehicle_Cargo; if (!vc.storage.CanAcceptAnyOf(CurJob.GetTarget(HaulableInd).Thing)) { return(true); } return(false); }); /// //Toils Start /// //Reserve thing to be stored and storage cell yield return(Toils_Reserve.Reserve(HaulableInd)); //Collect Target yield return(toilGoto); yield return(ToolsForHaul.Toils_Collect.CollectThing(HaulableInd, CarrierInd)); }
public override string GetReport() { Thing hauledThing = TargetThingB; string repString; if (hauledThing != null) { repString = "ReportPutInInventory".Translate(hauledThing.LabelCap, CurJob.GetTarget(BackpackInd).Thing.LabelCap); } else { repString = "ReportPutSomethingInInventory".Translate(CurJob.GetTarget(BackpackInd).Thing.LabelCap); } return(repString); }
protected override IEnumerable <Toil> MakeNewToils() { //yield return Toils_Reserve.Reserve(TargetIndex.A); yield return(Toils_Goto.GotoCell(TargetIndex.B, PathEndMode.Touch)); yield return(new Toil { tickAction = delegate { pawn.Drawer.rotator.FaceCell(CurJob.GetTarget(TargetIndex.B).Cell); pawn.GainComfortFromCellIfPossible(); if (pawn.IsHashIntervalTick(100)) { pawn.jobs.CheckForJobOverride(); } }, defaultCompleteMode = ToilCompleteMode.Never }); }
protected override IEnumerable <Toil> MakeNewToils() { Apparel_Backpack backpack = CurJob.GetTarget(BackpackInd).Thing as Apparel_Backpack; /// //Set fail conditions /// //Backpack is full. this.FailOn(() => { return((pawn.inventory.container.Count < backpack.MaxItem) ? false : true); }); /// //Define Toil /// Toil extractB = new Toil(); extractB.initAction = () => { if (!CurJob.targetQueueB.NullOrEmpty()) { CurJob.targetB = CurJob.targetQueueB.First(); CurJob.targetQueueB.RemoveAt(0); this.FailOnDestroyedOrNull(HaulableInd); } else { this.EndJobWith(JobCondition.Succeeded); } }; Toil toilGoToThing = Toils_Goto.GotoThing(HaulableInd, PathEndMode.ClosestTouch) .FailOnDestroyedOrNull(HaulableInd); /// //Toils Start /// //Reserve thing to be stored and storage cell yield return(Toils_Reserve.Reserve(BackpackInd)); yield return(Toils_Reserve.Reserve(HaulableInd)); yield return(Toils_Reserve.ReserveQueue(HaulableInd)); yield return(Toils_Jump.JumpIf(toilGoToThing, () => { return (CurJob.targetB.HasThing) ? true : false; })); //Collect TargetQueue { //Extract an haulable into TargetA yield return(extractB); yield return(toilGoToThing); //CollectIntoCarrier Toil toilPutInInventory = new Toil(); toilPutInInventory.initAction = () => { if (pawn.inventory.container.Count < backpack.MaxItem && backpack.wearer.inventory.container.TotalStackCount < backpack.MaxStack) { if (CurJob.targetB.Thing.TryGetComp <CompForbiddable>() != null && CurJob.targetB.Thing.TryGetComp <CompForbiddable>().Forbidden == true) { CurJob.targetB.Thing.TryGetComp <CompForbiddable>().Forbidden = false; } if (pawn.inventory.container.TryAdd(CurJob.targetB.Thing, CurJob.maxNumToCarry)) { CurJob.targetB.Thing.holder = pawn.inventory.GetContainer(); CurJob.targetB.Thing.holder.owner = pawn.inventory; backpack.numOfSavedItems++; } } else { this.EndJobWith(JobCondition.Incompletable); } }; yield return(toilPutInInventory); yield return(Toils_Jump.JumpIfHaveTargetInQueue(HaulableInd, extractB)); } }
protected override IEnumerable <Toil> MakeNewToils() { Apparel_Backpack backpack = CurJob.GetTarget(BackpackInd).Thing as Apparel_Backpack; Thing lastItem = ToolsForHaulUtility.TryGetBackpackLastItem(pawn); /// //Set fail conditions /// /// //Define Toil /// Toil endOfJob = new Toil(); endOfJob.initAction = () => { EndJobWith(JobCondition.Succeeded); }; Toil checkStoreCellEmpty = Toils_Jump.JumpIf(endOfJob, () => CurJob.GetTargetQueue(StoreCellInd).NullOrEmpty()); Toil checkHaulableEmpty = Toils_Jump.JumpIf(checkStoreCellEmpty, () => CurJob.GetTargetQueue(HaulableInd).NullOrEmpty()); /// //Toils Start /// //Reserve thing to be stored and storage cell yield return(Toils_Reserve.ReserveQueue(HaulableInd)); yield return(Toils_Reserve.ReserveQueue(StoreCellInd)); //JumpIf checkStoreCellEmpty yield return(checkHaulableEmpty); //Collect TargetQueue { Toil extractA = Toils_Collect.Extract(HaulableInd); yield return(extractA); Toil gotoThing = Toils_Goto.GotoThing(HaulableInd, PathEndMode.ClosestTouch) .FailOnDestroyed(HaulableInd); yield return(gotoThing); yield return(ToolsForHaul.Toils_Collect.CollectInInventory(HaulableInd)); yield return(Toils_Collect.CheckDuplicates(gotoThing, BackpackInd, HaulableInd)); yield return(Toils_Jump.JumpIfHaveTargetInQueue(HaulableInd, extractA)); } //JumpIf toilEnd yield return(checkStoreCellEmpty); //Drop TargetQueue { Toil extractB = Toils_Collect.Extract(StoreCellInd); yield return(extractB); yield return(Toils_Goto.GotoCell(StoreCellInd, PathEndMode.ClosestTouch) .FailOnBurningImmobile(StoreCellInd)); yield return(ToolsForHaul.Toils_Collect.DropTheCarriedInCell(StoreCellInd, ThingPlaceMode.Direct, lastItem)); yield return(Toils_Jump.JumpIfHaveTargetInQueue(StoreCellInd, extractB)); } yield return(endOfJob); }
protected override IEnumerable <Toil> MakeNewToils() { Vehicle_Cart cart = CurJob.GetTarget(CartInd).Thing as Vehicle_Cart; /// //Set fail conditions /// this.FailOnDestroyedOrNull(CartInd); //Note we only fail on forbidden if the target doesn't start that way //This helps haul-aside jobs on forbidden items if (!TargetThingA.IsForbidden(pawn.Faction)) { this.FailOnForbidden(CartInd); } /// //Define Toil /// Toil findStoreCellForCart = Toils_Cart.FindStoreCellForCart(CartInd); Toil checkCartEmpty = Toils_Jump.JumpIf(findStoreCellForCart, () => cart.storage.Count <= 0); Toil checkStoreCellEmpty = Toils_Jump.JumpIf(findStoreCellForCart, () => CurJob.GetTargetQueue(StoreCellInd).NullOrEmpty()); Toil checkHaulableEmpty = Toils_Jump.JumpIf(checkStoreCellEmpty, () => CurJob.GetTargetQueue(HaulableInd).NullOrEmpty()); /// //Toils Start /// //Reserve thing to be stored and storage cell yield return(Toils_Reserve.Reserve(CartInd)); yield return(Toils_Reserve.ReserveQueue(HaulableInd)); yield return(Toils_Reserve.ReserveQueue(StoreCellInd)); //JumpIf already mounted yield return(Toils_Jump.JumpIf(checkHaulableEmpty, () => { return (cart.GetComp <CompMountable>().Driver == pawn) ? true : false; })); //Mount on Target yield return(Toils_Goto.GotoThing(CartInd, PathEndMode.ClosestTouch) .FailOnDestroyedOrNull(CartInd)); yield return(Toils_Cart.MountOn(CartInd)); //JumpIf checkStoreCellEmpty yield return(checkHaulableEmpty); //Collect TargetQueue { Toil extractA = Toils_Collect.Extract(HaulableInd); yield return(extractA); Toil gotoThing = Toils_Goto.GotoThing(HaulableInd, PathEndMode.ClosestTouch) .FailOnDestroyedOrNull(HaulableInd); yield return(gotoThing); yield return(Toils_Collect.CollectInCarrier(CartInd, HaulableInd)); yield return(Toils_Collect.CheckDuplicates(gotoThing, CartInd, HaulableInd)); yield return(Toils_Jump.JumpIfHaveTargetInQueue(HaulableInd, extractA)); } //JumpIf findStoreCellForCart yield return(checkStoreCellEmpty); //Drop TargetQueue { yield return(checkCartEmpty); Toil extractB = Toils_Collect.Extract(StoreCellInd); yield return(extractB); Toil gotoCell = Toils_Goto.GotoCell(StoreCellInd, PathEndMode.ClosestTouch); yield return(gotoCell); yield return(Toils_Collect.DropTheCarriedInCell(StoreCellInd, ThingPlaceMode.Direct, CartInd)); yield return(Toils_Jump.JumpIfHaveTargetInQueue(StoreCellInd, checkCartEmpty)); yield return(Toils_Collect.CheckNeedStorageCell(gotoCell, CartInd, StoreCellInd)); } yield return(findStoreCellForCart); yield return(Toils_Goto.GotoCell(StoreCellInd, PathEndMode.OnCell)); yield return(Toils_Cart.DismountAt(CartInd, StoreCellInd)); }
protected override IEnumerable <Toil> MakeNewToils() { /// //Set fail conditions /// this.FailOnDestroyedOrNull(MountableInd); this.FailOnDowned(DriverInd); //Note we only fail on forbidden if the target doesn't start that way //This helps haul-aside jobs on forbidden items if (!TargetThingA.IsForbidden(pawn.Faction)) { this.FailOnForbidden(MountableInd); } /// //Define Toil /// Toil toilMakeStandby = new Toil(); toilMakeStandby.initAction = () => { Pawn driver = CurJob.GetTarget(DriverInd).Thing as Pawn; driver.jobs.StartJob(new Job(HaulJobDefOf.StandBy, driver.Position, 2400 + (int)((pawn.Position - driver.Position).LengthHorizontal * 120)), JobCondition.InterruptForced); }; Toil toilGoto = null; toilGoto = Toils_Goto.GotoThing(MountableInd, PathEndMode.ClosestTouch) .FailOn(() => { //Note we don't fail on losing hauling designation //Because that's a special case anyway //While hauling to cell storage, ensure storage dest is still valid Pawn actor = toilGoto.actor; Job curJob = actor.jobs.curJob; if (curJob.haulMode == HaulMode.ToCellStorage) { Thing haulThing = curJob.GetTarget(MountableInd).Thing; IntVec3 destLoc = actor.jobs.curJob.GetTarget(TargetIndex.B).Cell; if (!destLoc.IsValidStorageFor(haulThing)) { return(true); } } return(false); }); Toil toilMountOn = new Toil(); toilMountOn.initAction = () => { Pawn driver = TargetB.Thing as Pawn; if (driver != null && TargetThingA.TryGetComp <CompMountable>() != null) { TargetThingA.TryGetComp <CompMountable>().MountOn(driver); } else { Log.Error(GetActor().LabelCap + ": Try make mount without target B Driver"); EndJobWith(JobCondition.Errored); } }; Toil toilEnd = new Toil(); toilEnd.initAction = () => { Vehicle_Cart cart = CurJob.GetTarget(MountableInd).Thing as Vehicle_Cart; //Vehicle_Saddle saddle = CurJob.GetTarget(MountableInd).Thing as Vehicle_Saddle; if (cart == null)// && saddle == null) { Log.Error(GetActor().LabelCap + ": MakeMount get TargetA not cart or saddle."); EndJobWith(JobCondition.Errored); return; } if (cart != null && cart.mountableComp.IsMounted && cart.mountableComp.Driver.CurJob.def == HaulJobDefOf.StandBy) { cart.mountableComp.Driver.jobs.curDriver.EndJobWith(JobCondition.Succeeded); } EndJobWith(JobCondition.Succeeded); }; /// //Toils Start /// //Reserve thing to be stored and storage cell yield return(Toils_Reserve.Reserve(MountableInd)); yield return(Toils_Reserve.Reserve(DriverInd)); yield return(toilMakeStandby); yield return(toilGoto); yield return(Toils_Haul.StartCarryThing(MountableInd)); yield return(Toils_Haul.CarryHauledThingToCell(DriverInd)); yield return(toilMountOn); yield return(toilEnd); }
protected override IEnumerable <Toil> MakeNewToils() { Vehicle_Cart cart = CurJob.GetTarget(CartInd).Thing as Vehicle_Cart; Job jobNew = new Job(); /// //Set fail conditions /// this.FailOnDestroyed(CartInd); this.FailOn(() => !cart.mountableComp.IsMounted); //Note we only fail on forbidden if the target doesn't start that way //This helps haul-aside jobs on forbidden items if (!TargetThingA.IsForbidden(pawn.Faction)) { this.FailOnForbidden(CartInd); } /// //Define Toil /// Toil releaseAnimalCart = Toils_Cart.ReleaseAnimalCart(CartInd); Toil checkCartEmpty = Toils_Jump.JumpIf(releaseAnimalCart, () => cart.storage.Count <= 0); Toil checkStoreCellEmpty = Toils_Jump.JumpIf(releaseAnimalCart, () => CurJob.GetTargetQueue(StoreCellInd).NullOrEmpty()); Toil checkHaulableEmpty = Toils_Jump.JumpIf(checkStoreCellEmpty, () => CurJob.GetTargetQueue(HaulableInd).NullOrEmpty()); /// //Toils Start /// //Reserve thing to be stored and storage cell yield return(Toils_Reserve.Reserve(CartInd)); yield return(Toils_Reserve.ReserveQueue(HaulableInd)); yield return(Toils_Reserve.ReserveQueue(StoreCellInd)); yield return(Toils_Goto.GotoThing(CartInd, PathEndMode.Touch) .FailOn(() => cart.Destroyed || !cart.TryGetComp <CompMountable>().IsMounted)); //JumpIf toilCheckStoreCellEmpty yield return(checkHaulableEmpty); //Collect TargetQueue { Toil extractA = Toils_Collect.Extract(HaulableInd); yield return(extractA); Toil callAnimalCartForCollect = Toils_Cart.CallAnimalCart(CartInd, HaulableInd) .FailOnDestroyed(HaulableInd); yield return(callAnimalCartForCollect); yield return(Toils_Goto.GotoThing(HaulableInd, PathEndMode.ClosestTouch) .FailOnDestroyed(HaulableInd)); yield return(Toils_Cart.WaitAnimalCart(CartInd, HaulableInd)); yield return(Toils_Collect.CollectInCarrier(CartInd, HaulableInd)); yield return(Toils_Collect.CheckDuplicates(callAnimalCartForCollect, CartInd, HaulableInd)); yield return(Toils_Jump.JumpIfHaveTargetInQueue(HaulableInd, extractA)); } //JumpIf releaseAnimalCart yield return(checkStoreCellEmpty); //Drop TargetQueue { yield return(checkCartEmpty); Toil extractB = Toils_Collect.Extract(StoreCellInd); yield return(extractB); Toil callAnimalCartForDrop = Toils_Cart.CallAnimalCart(CartInd, StoreCellInd); yield return(callAnimalCartForDrop); yield return(Toils_Goto.GotoCell(StoreCellInd, PathEndMode.ClosestTouch) .FailOnBurningImmobile(StoreCellInd)); yield return(Toils_Cart.WaitAnimalCart(CartInd, HaulableInd)); yield return(Toils_Collect.DropTheCarriedInCell(StoreCellInd, ThingPlaceMode.Direct, CartInd)); yield return(Toils_Jump.JumpIfHaveTargetInQueue(StoreCellInd, checkCartEmpty)); yield return(Toils_Collect.CheckNeedStorageCell(callAnimalCartForDrop, CartInd, StoreCellInd)); } yield return(releaseAnimalCart); }
protected override IEnumerable <Toil> MakeNewToils() { Apparel_Backpack backpack = CurJob.GetTarget(BackpackInd).Thing as Apparel_Backpack; /// //Set fail conditions /// // no free slots this.FailOn(() => backpack.slotsComp.slots.Count >= backpack.MaxItem); //// hauling stuff not allowed //foreach (ThingCategoryDef category in CurJob.targetA.Thing.def.thingCategories) //{ // this.FailOn(() => !backpack.slotsComp.Properties.allowedThingCategoryDefs.Contains(category)); // this.FailOn(() => backpack.slotsComp.Properties.forbiddenSubThingCategoryDefs.Contains(category)); //} /// //Define Toil /// Toil endOfJob = new Toil(); endOfJob.initAction = () => { EndJobWith(JobCondition.Succeeded); }; Toil checkStoreCellEmpty = Toils_Jump.JumpIf(endOfJob, () => CurJob.GetTargetQueue(StoreCellInd).NullOrEmpty()); Toil checkHaulableEmpty = Toils_Jump.JumpIf(checkStoreCellEmpty, () => CurJob.GetTargetQueue(HaulableInd).NullOrEmpty()); Toil checkBackpackEmpty = Toils_Jump.JumpIf(endOfJob, () => backpack.slotsComp.slots.Count <= 0); /// //Toils Start /// //Reserve thing to be stored and storage cell yield return(Toils_Reserve.ReserveQueue(HaulableInd)); yield return(Toils_Reserve.ReserveQueue(StoreCellInd)); //JumpIf checkStoreCellEmpty yield return(checkHaulableEmpty); //Collect TargetQueue { Toil extractA = Toils_Collect.Extract(HaulableInd); yield return(extractA); Toil gotoThing = Toils_Goto.GotoThing(HaulableInd, PathEndMode.ClosestTouch) .FailOnDestroyedOrNull(HaulableInd); yield return(gotoThing); // yield return Toils_Collect.CollectInBackpack(HaulableInd, backpack); Toil pickUpThingIntoSlot = new Toil { initAction = () => { if (!backpack.slotsComp.slots.TryAdd(CurJob.targetA.Thing)) { EndJobWith(JobCondition.Incompletable); } } }; yield return(pickUpThingIntoSlot); yield return(Toils_Collect.CheckDuplicates(gotoThing, BackpackInd, HaulableInd)); yield return(Toils_Jump.JumpIfHaveTargetInQueue(HaulableInd, extractA)); } //JumpIf toilEnd yield return(checkStoreCellEmpty); //Drop TargetQueue { yield return(checkBackpackEmpty); Toil extractB = Toils_Collect.Extract(StoreCellInd); yield return(extractB); Toil gotoCell = Toils_Goto.GotoCell(StoreCellInd, PathEndMode.ClosestTouch); yield return(gotoCell); yield return(Toils_Collect.DropTheCarriedFromBackpackInCell(StoreCellInd, ThingPlaceMode.Direct, backpack)); yield return(Toils_Jump.JumpIfHaveTargetInQueue(StoreCellInd, checkBackpackEmpty)); yield return(Toils_Collect.CheckNeedStorageCell(gotoCell, BackpackInd, StoreCellInd)); } yield return(endOfJob); }