public override IEnumerable <Thing> PotentialWorkThingsGlobal(Pawn pawn) { List <Thing> potentialWorkThingsGlobal = new List <Thing>(); foreach (Thing thing in Find.ListerThings.AllThings) { float statfloat = 0; if (!thing.def.IsWeapon) { continue; } if (!pawn.CanReserveAndReach(thing, PathEndMode.ClosestTouch, Danger.Some)) { continue; } foreach (KeyValuePair <StatDef, float> stat in pawn.GetWeightedWorkStats()) { statfloat += RightTools.GetMaxStat(thing as ThingWithComps, stat.Key); if (statfloat > 0) { potentialWorkThingsGlobal.Add(thing); } } } return(potentialWorkThingsGlobal); }
public override bool ShouldSkip(Pawn pawn) { Trace.DebugWriteHaulingPawn(pawn); if (RightTools.GetRightVehicle(pawn, WorkTypeDefOf.Hauling) == null) { return(true); } if (pawn.RaceProps.Animal || !pawn.RaceProps.Humanlike || !pawn.RaceProps.hasGenders) { return(true); } return(false); }
public override IEnumerable <Thing> PotentialWorkThingsGlobal(Pawn pawn) { List <Thing> potentialWorkThingsGlobal = new List <Thing>(); foreach (Thing thing in pawn.Map.listerThings.AllThings) { float statfloat = 0; if (!thing.def.IsWeapon) { continue; } if (!HaulAIUtility.PawnCanAutomaticallyHaul(pawn, thing, true)) { continue; } bool grabNewTool = false; foreach (KeyValuePair <StatDef, float> stat in pawn.GetWeightedWorkStats()) { statfloat = RightTools.GetMaxStat(thing as ThingWithComps, stat.Key); if (statfloat > 0) { grabNewTool = true; // Should skip if already better tool in inventory foreach (var entry in GameComponent_ToolsForHaul.CachedToolEntries.Where(x => x.pawn != null && x.pawn == pawn)) { if (entry.stat == stat.Key) { if (entry.workStat > statfloat) { grabNewTool = false; } } } } } if (grabNewTool) { potentialWorkThingsGlobal.Add(thing); } } return(potentialWorkThingsGlobal); }
public override Job JobOnThing(Pawn pawn, Thing t) { Vehicle_Cart cart = null; if (!HaulAIUtility.PawnCanAutomaticallyHaulFast(pawn, t)) { return(null); } // Vehicle selection if (ToolsForHaulUtility.IsDriver(pawn)) { cart = ToolsForHaulUtility.GetCartByDriver(pawn); if (cart == null) { // JobFailReason.Is("Can't haul with military vehicle"); return(ToolsForHaulUtility.DismountInBase(pawn, MapComponent_ToolsForHaul.currentVehicle[pawn])); } } if (cart == null) { cart = RightTools.GetRightVehicle(pawn, WorkTypeDefOf.Hauling, t) as Vehicle_Cart; if (cart == null) { return(null); } } if (cart.IsBurning()) { JobFailReason.Is(ToolsForHaulUtility.BurningLowerTrans); return(null); } if (!cart.allowances.Allows(t)) { JobFailReason.Is("Cart does not allow that thing"); return(null); } if (ListerHaulables.ThingsPotentiallyNeedingHauling().Count == 0 && cart.storage.Count == 0) { JobFailReason.Is("NoHaulable".Translate()); return(null); } if (Find.SlotGroupManager.AllGroupsListInPriorityOrder.Count == 0) { JobFailReason.Is(ToolsForHaulUtility.NoEmptyPlaceLowerTrans); return(null); } if (ToolsForHaulUtility.AvailableAnimalCart(cart) || ToolsForHaulUtility.AvailableVehicle(pawn, cart)) { return(ToolsForHaulUtility.HaulWithTools(pawn, cart, t)); } JobFailReason.Is(ToolsForHaulUtility.NoAvailableCart); return(null); }
protected override IEnumerable <Toil> MakeNewToils() { Apparel_Toolbelt toolbelt = this.CurJob.GetTarget(SlotterInd).Thing as Apparel_Toolbelt; // no free slots this.FailOn(() => toolbelt.slotsComp.slots.Count >= toolbelt.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 (!toolbelt.slotsComp.slots.TryAdd(this.CurJob.targetA.Thing)) { this.EndJobWith(JobCondition.Incompletable); } else { float statfloat = 0; Thing thing = this.TargetThingA; // add stats to pawn inventory foreach (KeyValuePair <StatDef, float> stat in pawn.GetWeightedWorkStats()) { statfloat = RightTools.GetMaxStat(thing as ThingWithComps, stat.Key); if (statfloat > 0) { MapComponent_ToolsForHaul.CachedToolEntries.Add(new MapComponent_ToolsForHaul.Entry(pawn, thing, stat.Key, statfloat)); } for (int i = toolbelt.slotsComp.slots.Count - 1; i >= 0; i--) { var tool = toolbelt.slotsComp.slots[i]; var checkstat = RightTools.GetMaxStat(tool as ThingWithComps, stat.Key); if (checkstat > 0 && checkstat < statfloat) { Thing dropTool; toolbelt.slotsComp.slots.TryDrop(tool, pawn.Position, pawn.Map, ThingPlaceMode.Near, out dropTool, null); for (int j = MapComponent_ToolsForHaul.CachedToolEntries.Count - 1; j >= 0; j--) { var entry = MapComponent_ToolsForHaul.CachedToolEntries[j]; if (entry.tool == tool) { MapComponent_ToolsForHaul.CachedToolEntries.RemoveAt(j); } } } } } } } }; yield return(pickUpThingIntoSlot); yield return(Toils_Jump.JumpIfHaveTargetInQueue(HaulableInd, toilExtractNextTarget)); }
public override ThinkResult TryIssueJobPackage(Pawn pawn) { Job job = this.TryGiveJob(pawn); bool jobNull = job == null; ThinkResult result; Apparel_Toolbelt toolbelt = ToolsForHaulUtility.TryGetToolbelt(pawn); if (toolbelt != null) { if (PreviousPawnWeapon.ContainsKey(pawn) && PreviousPawnWeapon[pawn] != null) { Pawn wearer = toolbelt.Wearer; ThingWithComps previousWeapon = PreviousPawnWeapon[pawn]; if (previousWeapon != null && toolbelt.slotsComp.slots.Contains(previousWeapon)) { for (int i = toolbelt.slotsComp.slots.Count - 1; i >= 0; i--) { var thing = toolbelt.slotsComp.slots[i]; ThingWithComps item = (ThingWithComps)thing; if (item == previousWeapon) { if (wearer.equipment.Primary != null) { toolbelt.slotsComp.SwapEquipment(item); } else { wearer.equipment.AddEquipment(item); toolbelt.slotsComp.slots.Remove(item); } break; } } } } PreviousPawnWeapon[pawn] = null; } if (jobNull) { result = ThinkResult.NoJob; } else { if (pawn.Faction == Faction.OfPlayer && pawn.RaceProps.Humanlike && pawn.RaceProps.IsFlesh) { if (job.def == JobDefOf.DoBill) { RightTools.EquipRigthTool(pawn, job.RecipeDef.workSpeedStat); } if (job.def == JobDefOf.FinishFrame || job.def == JobDefOf.Deconstruct || job.def == JobDefOf.Repair || job.def == JobDefOf.BuildRoof || job.def == JobDefOf.RemoveRoof || job.def == JobDefOf.RemoveFloor) { RightTools.EquipRigthTool(pawn, StatDefOf.ConstructionSpeed); } if (job.def == JobDefOf.SmoothFloor) { RightTools.EquipRigthTool(pawn, StatDefOf.SmoothingSpeed); } if (job.def == JobDefOf.Harvest) { RightTools.EquipRigthTool(pawn, StatDefOf.PlantHarvestYield); } if (job.def == JobDefOf.CutPlant || job.def == JobDefOf.Sow) { RightTools.EquipRigthTool(pawn, StatDefOf.PlantWorkSpeed); } if (job.def == JobDefOf.Mine) { RightTools.EquipRigthTool(pawn, StatDefOf.MiningSpeed); } } result = new ThinkResult(job, this); } return(result); }