private Toil FindCarrier() { return(new Toil { initAction = delegate() { Pawn pawn = FindBestCarrierShips(); if (pawn is null) { bool flag = this.pawn.GetLord() == job.lord; if (flag && !MassUtility.IsOverEncumbered(this.pawn)) { pawn = this.pawn; } else { if (pawn is null) { if (flag) { pawn = this.pawn; } else { IEnumerable <Pawn> source = from x in job.lord.ownedPawns where x is VehiclePawn v && IsUsableCarrier(v, this.pawn) select x; if (!source.Any()) { EndJobWith(JobCondition.Incompletable); return; } pawn = source.RandomElement(); } } } } job.SetTarget(TargetIndex.B, pawn); } });
public static Pawn FindPawnToMoveInventoryTo(Thing item, List <Pawn> candidates, List <Pawn> ignoreCandidates, Pawn currentItemOwner = null) { if (item is Pawn) { Log.Error("Called FindPawnToMoveInventoryTo but the item is a pawn."); return(null); } if (candidates.Where((Pawn x) => CanMoveInventoryTo(x) && (ignoreCandidates == null || !ignoreCandidates.Contains(x)) && x != currentItemOwner && !MassUtility.IsOverEncumbered(x)).TryRandomElement(out Pawn result)) { return(result); } if (candidates.Where((Pawn x) => CanMoveInventoryTo(x) && (ignoreCandidates == null || !ignoreCandidates.Contains(x)) && x != currentItemOwner).TryRandomElement(out result)) { return(result); } if (candidates.Where((Pawn x) => (ignoreCandidates == null || !ignoreCandidates.Contains(x)) && x != currentItemOwner).TryRandomElement(out result)) { return(result); } return(null); }
protected override IEnumerable <Toil> MakeNewToils() { Building_ShellfishTrap crabPot = this.job.GetTarget(CrabPotIndex).Thing as Building_ShellfishTrap; Pawn actor = this.pawn; Toil unloadProcess = new Toil() { initAction = () => { storemode = crabPot.StoreMode; }, defaultDuration = BaseUnloadDuration, defaultCompleteMode = ToilCompleteMode.Delay, activeSkill = (() => SkillDefOf.Animals) } .FailOnDespawnedNullOrForbidden(CrabPotIndex) .FailOnBurningImmobile(CrabPotIndex) .FailOnThingHavingDesignation(CrabPotIndex, DesignationDefOf.Uninstall) .FailOnCannotTouch(CrabPotIndex, PathEndMode.Touch) .WithProgressBarToilDelay(CrabPotIndex); Toil unloadPot = new Toil() { initAction = () => { //Log.Message("unloadPot"); AddFinishAction(DropStuff); crabPot.LastOpenTick = Find.TickManager.TicksGame; var items = crabPot.GetDirectlyHeldThings(); //Log.Message("items"); //foreach(var item in items) //{ // Log.Message(item.def.defName + " " + item.stackCount); //} //Log.Message("unloading"); while (!MassUtility.IsOverEncumbered(pawn) && items.Count > 0) { int count = Math.Min(MassUtility.CountToPickUpUntilOverEncumbered(actor, items[0]), items[0].stackCount); //Log.Message(count + " " + items[0].stackCount + MassUtility.CountToPickUpUntilOverEncumbered(actor, items[0])); if (items.TryTransferToContainer(items[0], pawn.inventory.innerContainer, count, out Thing resultingItem, false) > 0) { if (!resultingItem.Destroyed && resultingItem.stackCount > 0) { LoadedFish.Add(resultingItem); } } } items.TryDropAll(pawn.Position, pawn.Map, ThingPlaceMode.Near); //actor.jobs.EndCurrentJob(JobCondition.Succeeded); }, defaultCompleteMode = ToilCompleteMode.Instant }; this.FailOnDespawnedNullOrForbidden(CrabPotIndex); this.FailOnBurningImmobile(CrabPotIndex); this.FailOnThingHavingDesignation(CrabPotIndex, DesignationDefOf.Uninstall); yield return(Toils_Goto.GotoThing(CrabPotIndex, PathEndMode.Touch) .FailOnDespawnedNullOrForbidden(CrabPotIndex) .FailOnBurningImmobile(CrabPotIndex) .FailOnThingHavingDesignation(CrabPotIndex, DesignationDefOf.Uninstall)); yield return(unloadProcess); yield return(unloadPot); //todo: repeatetive haul Toil finishAndStartHaul = FinishAndStartHaul(); yield return(finishAndStartHaul); yield return(Toils_Misc.TakeItemFromInventoryToCarrier(pawn, HaulableInd)); yield return(Toils_Reserve.Reserve(StoreCellInd)); Toil carryToCell = Toils_Haul.CarryHauledThingToCell(StoreCellInd); yield return(carryToCell); yield return(Toils_Haul.PlaceHauledThingInCell(StoreCellInd, carryToCell, storageMode: true, tryStoreInSameStorageIfSpotCantHoldWholeStack: true)); yield return(Toils_Jump.JumpIf(finishAndStartHaul, () => LoadedFish.Count > 0)); }
public void Notify_CaravanArrived(Caravan caravan) { if (caravan.PawnsListForReading.Where(p => !p.IsBoat()).Count() > TotalAvailableSeats) { Messages.Message("CaravanMustHaveEnoughSpaceOnShip".Translate(), this, MessageTypeDefOf.RejectInput, false); return; } caravan.pawns.TryAddRangeOrTransfer(dockedBoats); List <Pawn> boats = caravan.PawnsListForReading.Where(p => p.IsBoat()).ToList(); foreach (Pawn p in caravan.pawns) { if (!p.IsBoat()) { for (int i = p.inventory.innerContainer.Count - 1; i >= 0; i--) { Thing t = p.inventory.innerContainer[i]; p.inventory.innerContainer.TryTransferToContainer(t, boats.Find(x => !MassUtility.IsOverEncumbered(x)).inventory.innerContainer, true); } } } CaravanHelper.ToggleDocking(caravan, false); Find.WorldObjects.Remove(this); }
public static Pawn FindPawnToMoveInventoryTo(Thing item, List <Pawn> candidates, List <Pawn> ignoreCandidates, Pawn currentItemOwner = null) { if (item is Pawn) { Log.Error("Called FindPawnToMoveInventoryTo but the item is a pawn."); return(null); } Pawn result = default(Pawn); if ((from x in candidates where CaravanInventoryUtility.CanMoveInventoryTo(x) && (ignoreCandidates == null || !ignoreCandidates.Contains(x)) && x != currentItemOwner && !MassUtility.IsOverEncumbered(x) select x).TryRandomElement <Pawn>(out result)) { return(result); } if ((from x in candidates where CaravanInventoryUtility.CanMoveInventoryTo(x) && (ignoreCandidates == null || !ignoreCandidates.Contains(x)) && x != currentItemOwner select x).TryRandomElement <Pawn>(out result)) { return(result); } if ((from x in candidates where (ignoreCandidates == null || !ignoreCandidates.Contains(x)) && x != currentItemOwner select x).TryRandomElement <Pawn>(out result)) { return(result); } return(null); }
internal bool <> m__0(Pawn x) { return(CaravanInventoryUtility.CanMoveInventoryTo(x) && (this.ignoreCandidates == null || !this.ignoreCandidates.Contains(x)) && x != this.currentItemOwner && !MassUtility.IsOverEncumbered(x)); }