public override Job JobOnThing(Pawn pawn, Thing thing, bool forced = false) { IBillGiver billGiver = thing as IBillGiver; if (billGiver != null && ThingIsUsableBillGiver(thing) && billGiver.BillStack.AnyShouldDoNow && billGiver.UsableForBillsAfterFueling()) { LocalTargetInfo target = thing; if (pawn.CanReserve(target, 1, -1, null, forced) && !thing.IsBurning() && !thing.IsForbidden(pawn)) { billGiver.BillStack.RemoveIncompletableBills(); foreach (Bill bill in RelevantBills(thing, pawn)) { if (bill.ShouldDoNow() && bill.PawnAllowedToStartAnew(pawn)) { //Log.Message("probing bill: pawn allowed is " + bill.PawnAllowedToStartAnew(pawn) + " for " + pawn); return(new Job(DefDatabase <JobDef> .GetNamed(bill.recipe.defName), target) { bill = bill }); } } } } return(null); }
private Job TryStartNewDoBillJob(Pawn pawn, Bill bill, IBillGiver giver) { Job job = WorkGiverUtility.HaulStuffOffBillGiverJob(pawn, giver, null); if (job != null) { return(job); } Job job2 = new Job(JobDefOf.DoBill, (Thing)giver); if (bill.recipe is MagicRecipeDef) { job2 = new Job(TorannMagicDefOf.JobDriver_DoMagicBill, (Thing)giver); } job2.targetQueueB = new List <LocalTargetInfo>(chosenIngThings.Count); job2.countQueue = new List <int>(chosenIngThings.Count); for (int i = 0; i < chosenIngThings.Count; i++) { job2.targetQueueB.Add(chosenIngThings[i].Thing); job2.countQueue.Add(chosenIngThings[i].Count); } job2.haulMode = HaulMode.ToCellNonStorage; job2.bill = bill; return(job2); }
private Job TryStartNewDoBillJob(Pawn pawn, Bill bill, IBillGiver giver) { // 材料の運搬先に物があった場合(邪魔なものがある場合)、それをどかす処理 var job = WorkGiverUtility.HaulStuffOffBillGiverJob(pawn, giver, null); if (job != null) { return(job); } // レシピ実行(本命) var job2 = CreateNewJob(bill.recipe.GetModExtension <DefExtension_WaterRecipe>()); if (job2 == null) { return(null); } job2.targetA = giver as Thing; job2.targetQueueB = new List <LocalTargetInfo>(this.chosenIngThings.Count); job2.countQueue = new List <int>(this.chosenIngThings.Count); for (int i = 0; i < this.chosenIngThings.Count; i++) { job2.targetQueueB.Add(this.chosenIngThings[i].thing); job2.countQueue.Add(this.chosenIngThings[i].count); } job2.targetC = GetBillGiverRootCell(giver as Thing, pawn); job2.haulMode = HaulMode.ToCellNonStorage; job2.bill = bill; return(job2); }
/// <summary> /// Creates a new instance of the repair job. /// </summary> /// <param name="bill">the work bill for the job.</param> /// <param name="workbench">The building that gave the job.</param> /// <param name="itemDamaged">Damaged item to be repaired.</param> /// <param name="ingredients">Resources to consume for repair.</param> /// <returns></returns> private static Job StartNewRepairJob(Bill bill, IBillGiver workbench, Thing itemDamaged, IList <ThingCount> ingredients) { // create the new job var job = new Job(DefDatabase <JobDef> .GetNamed(Settings.JOBDEF_REPAIR), (Thing)workbench) { haulMode = HaulMode.ToCellNonStorage, bill = bill, targetQueueB = new List <LocalTargetInfo>(ingredients.Count), countQueue = new List <int>(ingredients.Count) }; // add item to be repaired job.targetQueueB.Add(itemDamaged); job.countQueue.Add(1); // add ingredients for (var index = 0; index < ingredients.Count; ++index) { // don't add items with zero count if (ingredients[index].Count <= 0) { continue; } job.targetQueueB.Add(ingredients[index].Thing); job.countQueue.Add(ingredients[index].Count); } return(job); }
protected virtual bool ValidateChosenWeapons(Bill bill, Pawn pawn, IBillGiver giver) { if ((bool)BestIngredientsInfo.Invoke(this, new object[] { bill, pawn, giver, chosenIngThings })) { var studyWeapons = StudyWeapons(bill, pawn); chosenIngThings.RemoveAll(x => !studyWeapons.Contains(x.Thing.def)); if (chosenIngThings.Any()) { if (!JobFailReason.HaveReason) { JobFailReason.Is("NoWeaponToLearn".Translate(pawn), null); } return(studyWeapons.Any()); } } if (!JobFailReason.HaveReason) { JobFailReason.Is("NoWeaponsFoundToLearn".Translate(pawn), null); } if (FloatMenuMakerMap.makingFor != pawn) { bill.lastIngredientSearchFailTicks = Find.TickManager.TicksGame; } return(false); }
protected bool IsNotFullWater(IBillGiver giver, DefExtension_WaterRecipe ext, List <ThingAmount> chosen) { if (ext == null) { return(true); } if (giver == null) { return(false); } var thing = giver as Thing; if (thing == null) { return(false); } switch (ext.recipeType) { case DefExtension_WaterRecipe.RecipeType.DrawFromTerrain: return(true); case DefExtension_WaterRecipe.RecipeType.DrawFromWaterPool: return(true); case DefExtension_WaterRecipe.RecipeType.DrawFromWaterNet: return(true); case DefExtension_WaterRecipe.RecipeType.PourWater: { var building = thing as Building_WaterNetWorkTable; if (building == null) { return(false); } var totalWaterVolume = 0f; foreach (var ta in chosen) { var sourceComp = ta.thing.TryGetComp <CompWaterSource>(); if (sourceComp != null) { totalWaterVolume += sourceComp.WaterVolume * ta.count; } } if (GetTotalAmountCanAccept(building) < totalWaterVolume) { return(false); } return(true); } default: Log.Error("recipeType is Undefined"); return(false); } }
private static IEnumerable <IntVec3> IngredientPlaceCellsInOrder(IBillGiver billGiver) { Toils_JobTransforms.yieldedIngPlaceCells.Clear(); IntVec3 interactCell = ((Thing)billGiver).InteractionCell; foreach (IntVec3 c3 in from c in billGiver.IngredientStackCells orderby(c - interactCell).LengthHorizontalSquared select c) { Toils_JobTransforms.yieldedIngPlaceCells.Add(c3); yield return(c3); } for (int i = 0; i < 200; i++) { IntVec3 c2 = interactCell + GenRadial.RadialPattern[i]; if (!Toils_JobTransforms.yieldedIngPlaceCells.Contains(c2)) { Building ed = c2.GetEdifice(billGiver.Map); if (ed == null || ed.def.passability != Traversability.Impassable || ed.def.surfaceType != SurfaceType.None) { yield return(c2); } } } }
private Job StartOrResumeBillJob(Pawn pawn, IBillGiver giver) { for (int i = 0; i < giver.BillStack.Count; i++) { Bill bill = giver.BillStack [i]; if (Find.TickManager.TicksGame >= bill.lastIngredientSearchFailTicks + ReCheckFailedBillTicksRange.RandomInRange || FloatMenuMakerMap.making) { if (bill.ShouldDoNow()) { if (bill.PawnAllowedToStartAnew(pawn)) { if (!bill.recipe.PawnSatisfiesSkillRequirements(pawn)) { JobFailReason.Is(MissingSkillTranslated); } else { Thing chosen; if (TryFindBestBillIngredients(bill, pawn, (Thing)giver, ignoreHitPoints, out chosen)) { return(TryStartNewDoBillJob(pawn, bill, giver, chosen)); } } } } } } return(null); }
private Job TryStartNewDoBillJob(Pawn pawn, Bill bill, IBillGiver giver) { Job job = WorkGiverUtility.HaulStuffOffBillGiverJob(pawn, giver, null); Job result; if (job != null) { result = job; } else { Job job2 = new Job(JobDefOf.DoBill, (Thing)giver); job2.targetQueueB = new List <LocalTargetInfo>(this.chosenIngThings.Count); job2.countQueue = new List <int>(this.chosenIngThings.Count); for (int i = 0; i < this.chosenIngThings.Count; i++) { job2.targetQueueB.Add(this.chosenIngThings[i].Thing); job2.countQueue.Add(this.chosenIngThings[i].Count); } job2.haulMode = HaulMode.ToCellNonStorage; job2.bill = bill; result = job2; } return(result); }
private static IEnumerable <IntVec3> IngredientPlaceCellsInOrder(Thing destination) { yieldedIngPlaceCells.Clear(); try { IntVec3 interactCell = destination.Position; IBillGiver billGiver = destination as IBillGiver; if (billGiver != null) { interactCell = ((Thing)billGiver).InteractionCell; foreach (IntVec3 item in billGiver.IngredientStackCells.OrderBy((IntVec3 c) => (c - interactCell).LengthHorizontalSquared)) { yieldedIngPlaceCells.Add(item); yield return(item); } } for (int i = 0; i < 200; i++) { IntVec3 intVec = interactCell + GenRadial.RadialPattern[i]; if (!yieldedIngPlaceCells.Contains(intVec)) { Building edifice = intVec.GetEdifice(destination.Map); if (edifice == null || edifice.def.passability != Traversability.Impassable || edifice.def.surfaceType != 0) { yield return(intVec); } } } } finally { yieldedIngPlaceCells.Clear(); } }
private bool ValidateChosenWeapons(Bill bill, Pawn pawn, IBillGiver giver) { if ((bool)BestIngredientsInfo.Invoke(this, new object[] { bill, pawn, giver, chosenIngThings })) { var studyWeapons = StudyWeapons(bill, pawn); chosenIngThings.RemoveAll(x => !studyWeapons.Contains(x.Thing.def)); if (chosenIngThings.Any()) { if (!JobFailReason.HaveReason) { JobFailReason.Is("NoWeaponToLearn".Translate(pawn), null); } return(studyWeapons.Any()); } var traumas = pawn.TryGetComp <CompKnowledge>().fearedWeapons; if (!traumas.NullOrEmpty() && chosenIngThings.All(x => traumas.Contains(x.Thing.def))) { JobFailReason.Is("FearedWeapon".Translate(pawn)); } } if (!JobFailReason.HaveReason) { JobFailReason.Is("NoWeaponsFoundToLearn".Translate(pawn), null); } if (FloatMenuMakerMap.makingFor != pawn) { bill.lastIngredientSearchFailTicks = Find.TickManager.TicksGame; } return(false); }
private Job TryStartNewDoBillJob(Pawn pawn, Bill bill, IBillGiver giver) { Job job = WorkGiverUtility.HaulStuffOffBillGiverJob(pawn, giver, null); if (job != null) { return(job); } Job job2 = new Job(JobDefOf.DoBill, (Thing)giver); job2.targetQueueB = new List <LocalTargetInfo>(this.chosenIngThings.Count); job2.countQueue = new List <int>(this.chosenIngThings.Count); for (int i = 0; i < this.chosenIngThings.Count; i++) { List <LocalTargetInfo> targetQueueB = job2.targetQueueB; ThingAmount thingAmount = this.chosenIngThings[i]; targetQueueB.Add(thingAmount.thing); List <int> countQueue = job2.countQueue; ThingAmount thingAmount2 = this.chosenIngThings[i]; countQueue.Add(thingAmount2.count); } job2.haulMode = HaulMode.ToCellNonStorage; job2.bill = bill; return(job2); }
public override Job JobOnThing(Pawn pawn, Thing thing, bool forced = false) { int tick = Find.TickManager.TicksGame; if (actualJob == null || lastVerifiedJobTick != tick || Find.TickManager.Paused) { actualJob = null; IBillGiver billGiver = thing as IBillGiver; if (billGiver != null && ThingIsUsableBillGiver(thing) && billGiver.BillStack.AnyShouldDoNow && billGiver.UsableForBillsAfterFueling()) { LocalTargetInfo target = thing; if (pawn.CanReserve(target, 1, -1, null, forced) && !thing.IsBurning() && !thing.IsForbidden(pawn)) //basic desk availabilty { if (IsRangeClear(thing)) //check is shooting area is clear if it exists. { billGiver.BillStack.RemoveIncompletableBills(); foreach (Bill bill in RelevantBills(thing, pawn)) { if (ValidateChosenWeapons(bill, pawn, billGiver)) //check bill filter { actualJob = StartBillJob(pawn, billGiver, bill); lastVerifiedJobTick = tick; break; } } } } } } return(actualJob); }
public static Job TryStartNewDoBillJob(Pawn pawn, Bill bill, IBillGiver giver, List <ThingCount> chosenIngThings, out Job haulOffJob, bool dontCreateJobIfHaulOffRequired = true) { Job job = null; haulOffJob = WorkGiverUtility.HaulStuffOffBillGiverJob(pawn, giver, null); if (haulOffJob != null && dontCreateJobIfHaulOffRequired) { return(haulOffJob); } if (bill.recipe != PurpleIvyDefOf.PI_AlienStudyRecipe) { job = JobMaker.MakeJob(JobDefOf.DoBill, (Thing)giver); } else { job = JobMaker.MakeJob(PurpleIvyDefOf.PI_ConductResearchOnAliens, (Thing)giver); } job.targetQueueB = new List <LocalTargetInfo>(chosenIngThings.Count); job.countQueue = new List <int>(chosenIngThings.Count); for (int i = 0; i < chosenIngThings.Count; i++) { job.targetQueueB.Add(chosenIngThings[i].Thing); job.countQueue.Add(chosenIngThings[i].Count); } job.haulMode = HaulMode.ToCellNonStorage; job.bill = bill; return(job); }
public override Job JobOnThing(Pawn pawn, Thing thing, bool forced = false) { IBillGiver billGiver = thing as IBillGiver; if (billGiver != null && ThingIsUsableBillGiver(thing) && billGiver.BillStack.AnyShouldDoNow && billGiver.UsableForBillsAfterFueling()) { LocalTargetInfo target = thing; bool ignoreOtherReservations = forced; if (pawn.CanReserve(target, 1, -1, null, ignoreOtherReservations) && !thing.IsBurning() && !thing.IsForbidden(pawn)) { CompRefuelable compRefuelable = thing.TryGetComp <CompRefuelable>(); if (compRefuelable != null && !compRefuelable.HasFuel) { if (!RefuelWorkGiverUtility.CanRefuel(pawn, thing, forced)) { return(null); } return(RefuelWorkGiverUtility.RefuelJob(pawn, thing, forced)); } billGiver.BillStack.RemoveIncompletableBills(); return(StartOrResumeBillJob(pawn, billGiver)); } } return(null); }
public static WorkGiverDef GetWorkgiver(this IBillGiver billGiver) { Thing thing = billGiver as Thing; if (thing == null) { Log.ErrorOnce(string.Format("Attempting to get the workgiver for a non-Thing IBillGiver {0}", billGiver.ToString()), 96810282, false); return(null); } List <WorkGiverDef> allDefsListForReading = DefDatabase <WorkGiverDef> .AllDefsListForReading; for (int i = 0; i < allDefsListForReading.Count; i++) { WorkGiverDef workGiverDef = allDefsListForReading[i]; WorkGiver_DoBill workGiver_DoBill = workGiverDef.Worker as WorkGiver_DoBill; if (workGiver_DoBill != null) { if (workGiver_DoBill.ThingIsUsableBillGiver(thing)) { return(workGiverDef); } } } Log.ErrorOnce(string.Format("Can't find a WorkGiver for a BillGiver {0}", thing.ToString()), 57348705, false); return(null); }
public static void JobOnThingRefill(Pawn pawn, Thing thing, ref Job __result, WorkGiver_DoBill __instance, bool forced = false) { if (__result is null) { IBillGiver billGiver = thing as IBillGiver; if (!(billGiver is null) && __instance.ThingIsUsableBillGiver(thing) && billGiver.BillStack.AnyShouldDoNow && billGiver.UsableForBillsAfterFueling()) { LocalTargetInfo target = thing; if (pawn.CanReserve(target, 1, -1, null, forced) && !thing.IsBurning() && !thing.IsForbidden(pawn)) { CompRefillable compRefillable = thing.TryGetComp <CompRefillable>(); if (compRefillable is null || compRefillable.IsFull()) { billGiver.BillStack.RemoveIncompletableBills(); __result = (Job)AccessTools.Method(type: typeof(WorkGiver_DoBill), name: "StartOrResumeBillJob").Invoke(__instance, new object[] { pawn, billGiver }); return; } if (!RefillWorkGiverUtility.CanRefill(pawn, thing, forced)) { __result = null; return; } __result = RefillWorkGiverUtility.RefillJob(pawn, thing, forced); } } return; } }
public static void TryStartNewDoBillJob_Postfix(Pawn pawn, Bill bill, IBillGiver giver, List <ThingCount> chosenIngThings, Job haulOffJob, bool dontCreateJobIfHaulOffRequired, ref Job __result) { if (__result.def == JobDefOf.DoBill && bill.recipe == DissectionDefOf.DissectHumanRecipe) { __result.def = DissectionDefOf.DoDissectionBill; } }
// Simply displays a message in the log. Useful for testing? public static bool TestChanger(List <Thing> products, ModExtension_ModifyProduct modifyYieldExt, IBillGiver billGiver, Thing productMaker, RecipeDef recipeDef, Pawn worker, List <Thing> ingredients, Thing dominantIngredient) { products.Add(ThingMaker.MakeThing(ThingDefOf.MealNutrientPaste)); return(true); }
private Job StartOrResumeBillJob(Pawn pawn, IBillGiver giver) { for (int i = 0; i < giver.BillStack.Count; i++) { Bill bill = giver.BillStack[i]; if ((bill.recipe.requiredGiverWorkType != null && bill.recipe.requiredGiverWorkType != def.workType) || (Find.TickManager.TicksGame < bill.lastIngredientSearchFailTicks + ReCheckFailedBillTicksRange.RandomInRange && FloatMenuMakerMap.makingFor != pawn)) { continue; } bill.lastIngredientSearchFailTicks = 0; if (!bill.ShouldDoNow() || !bill.PawnAllowedToStartAnew(pawn)) { continue; } SkillRequirement skillRequirement = bill.recipe.FirstSkillRequirementPawnDoesntSatisfy(pawn); if (skillRequirement != null) { JobFailReason.Is("UnderRequiredSkill".Translate(skillRequirement.minLevel), bill.Label); continue; } Bill_ProductionWithUft bill_ProductionWithUft = bill as Bill_ProductionWithUft; if (bill_ProductionWithUft != null) { if (bill_ProductionWithUft.BoundUft != null) { if (bill_ProductionWithUft.BoundWorker == pawn && pawn.CanReserveAndReach(bill_ProductionWithUft.BoundUft, PathEndMode.Touch, Danger.Deadly) && !bill_ProductionWithUft.BoundUft.IsForbidden(pawn)) { return(FinishUftJob(pawn, bill_ProductionWithUft.BoundUft, bill_ProductionWithUft)); } continue; } UnfinishedThing unfinishedThing = ClosestUnfinishedThingForBill(pawn, bill_ProductionWithUft); if (unfinishedThing != null) { return(FinishUftJob(pawn, unfinishedThing, bill_ProductionWithUft)); } } if (!TryFindBestBillIngredients(bill, pawn, (Thing)giver, chosenIngThings)) { if (FloatMenuMakerMap.makingFor != pawn) { bill.lastIngredientSearchFailTicks = Find.TickManager.TicksGame; } else { JobFailReason.Is(MissingMaterialsTranslated, bill.Label); } chosenIngThings.Clear(); continue; } Job haulOffJob; Job result = TryStartNewDoBillJob(pawn, bill, giver, chosenIngThings, out haulOffJob); chosenIngThings.Clear(); return(result); } chosenIngThings.Clear(); return(null); }
protected override bool ValidateChosenWeapons(Bill bill, Pawn pawn, IBillGiver giver) { bool result = pawn.equipment.Primary != null && bill.ingredientFilter.AllowedThingDefs.Contains(pawn.equipment.Primary.def); if (!JobFailReason.HaveReason && !result) { JobFailReason.Is("NoWeaponEquipped".Translate(pawn), null); } return(result); }
private static IEnumerable <IntVec3> IngredientPlaceCellsInOrder(Thing destination) { yieldedIngPlaceCells.Clear(); try { _003CIngredientPlaceCellsInOrder_003Ec__Iterator0 _003CIngredientPlaceCellsInOrder_003Ec__Iterator = (_003CIngredientPlaceCellsInOrder_003Ec__Iterator0) /*Error near IL_0055: stateMachine*/; IntVec3 interactCell = destination.Position; IBillGiver billGiver = destination as IBillGiver; if (billGiver != null) { interactCell = ((Thing)billGiver).InteractionCell; using (IEnumerator <IntVec3> enumerator = (from c in billGiver.IngredientStackCells orderby(c - interactCell).LengthHorizontalSquared select c).GetEnumerator()) { if (enumerator.MoveNext()) { IntVec3 c3 = enumerator.Current; yieldedIngPlaceCells.Add(c3); yield return(c3); /*Error: Unable to find new state assignment for yield return*/; } } } int i = 0; IntVec3 c2; while (true) { if (i >= 200) { yield break; } c2 = interactCell + GenRadial.RadialPattern[i]; if (!yieldedIngPlaceCells.Contains(c2)) { Building ed = c2.GetEdifice(destination.Map); if (ed == null || ed.def.passability != Traversability.Impassable || ed.def.surfaceType != 0) { break; } } i++; } yield return(c2); /*Error: Unable to find new state assignment for yield return*/; } finally { ((_003CIngredientPlaceCellsInOrder_003Ec__Iterator0) /*Error near IL_024c: stateMachine*/)._003C_003E__Finally0(); } IL_025c: /*Error near IL_025d: Unexpected return in MoveNext()*/; }
} //end FindClosestIngForBill public static Thing FindClosestIngToBillGiver(Bill theBill, IngredientCount curIng) { IBillGiver billGiver = theBill.billStack.billGiver; IThingHolder holder = billGiver as IThingHolder; Thing building = billGiver as Thing; ThingOwner vatStoredIngredients = holder?.GetDirectlyHeldThings(); if (billGiver == null || building == null || billGiver == null || vatStoredIngredients == null) { return(null); } int storedCount = vatStoredIngredients.FirstOrDefault(thing => thing.def == curIng.FixedIngredient)?.stackCount ?? 0; int countNeededFromRecipe = (int)(curIng.CountRequiredOfFor(curIng.FixedIngredient, theBill.recipe) * QEESettings.instance.organTotalResourcesFloat); int countNeededForCrafting = countNeededFromRecipe - storedCount; countNeededForCrafting = countNeededForCrafting < 0 ? 0 : countNeededForCrafting; //only check the map for Things if the vat still needs some of this ingredient if (countNeededForCrafting > 0) { //find the closest accessible Thing of that ThingDef on the map ThingRequest tRequest = ThingRequest.ForDef(curIng.FixedIngredient); IEnumerable <Thing> searchSet = billGiver.Map.listerThings.ThingsMatching(tRequest); Thing result = GenClosest.ClosestThing_Global(building.Position, searchSet, validator : delegate(Thing testThing) { if (testThing.def.defName != curIng.FixedIngredient.defName) { return(false); } if (testThing.IsForbidden(building.Faction)) { return(false); } return(true); }); //return the Thing, if we found one if (result != null) { //QEEMod.TryLog("Ingredient found: " + curIng.FixedIngredient.label + " | stackCount: " + result.stackCount + " | recipe: " // + countNeededFromRecipe); return(result); } } return(null); } //end function FindClosestIngToBillGiver
private static IEnumerable <IntVec3> IngredientPlaceCellsInOrder(IBillGiver billGiver) { _003CIngredientPlaceCellsInOrder_003Ec__Iterator0 _003CIngredientPlaceCellsInOrder_003Ec__Iterator = (_003CIngredientPlaceCellsInOrder_003Ec__Iterator0) /*Error near IL_0038: stateMachine*/; Toils_JobTransforms.yieldedIngPlaceCells.Clear(); IntVec3 interactCell = ((Thing)billGiver).InteractionCell; using (IEnumerator <IntVec3> enumerator = (from c in billGiver.IngredientStackCells orderby(c - interactCell).LengthHorizontalSquared select c).GetEnumerator()) { if (enumerator.MoveNext()) { IntVec3 c3 = enumerator.Current; Toils_JobTransforms.yieldedIngPlaceCells.Add(c3); yield return(c3); /*Error: Unable to find new state assignment for yield return*/; } } int i = 0; IntVec3 c2; while (true) { if (i < 200) { c2 = interactCell + GenRadial.RadialPattern[i]; if (!Toils_JobTransforms.yieldedIngPlaceCells.Contains(c2)) { Building ed = c2.GetEdifice(billGiver.Map); if (ed == null) { break; } if (ed.def.passability != Traversability.Impassable) { break; } if (ed.def.surfaceType != 0) { break; } } i++; continue; } yield break; } yield return(c2); /*Error: Unable to find new state assignment for yield return*/; IL_0205: /*Error near IL_0206: Unexpected return in MoveNext()*/; }
private Job StartOrResumeBillJob(Pawn pawn, IBillGiver giver, LocalTargetInfo target) { for (int i = 0; i < giver.BillStack.Count; i++) { Bill bill = giver.BillStack[i]; if ((bill.recipe == TechDefOf.DocumentTech || bill.recipe == TechDefOf.DocumentTechDigital) && bill.ShouldDoNow() && bill.PawnAllowedToStartAnew(pawn)) { SkillRequirement skillRequirement = bill.recipe.FirstSkillRequirementPawnDoesntSatisfy(pawn); if (skillRequirement != null) { JobFailReason.Is("UnderRequiredSkill".Translate(skillRequirement.minLevel), bill.Label); } else { if (bill.recipe.UsesUnfinishedThing) { Bill_ProductionWithUft bill_ProductionWithUft = bill as Bill_ProductionWithUft; if (bill_ProductionWithUft != null) { if (bill_ProductionWithUft.BoundUft != null) { if (bill_ProductionWithUft.BoundWorker == pawn && pawn.CanReserveAndReach(bill_ProductionWithUft.BoundUft, PathEndMode.Touch, Danger.Deadly, 1, -1, null, false) && !bill_ProductionWithUft.BoundUft.IsForbidden(pawn)) { return(FinishUftJob(pawn, bill_ProductionWithUft.BoundUft, bill_ProductionWithUft)); } return(null); } else { MethodInfo ClosestUftInfo = AccessTools.Method(typeof(WorkGiver_DoBill), "ClosestUnfinishedThingForBill"); UnfinishedThing unfinishedThing = (UnfinishedThing)ClosestUftInfo.Invoke(this, new object[] { pawn, bill_ProductionWithUft }); if (unfinishedThing != null) { return(FinishUftJob(pawn, unfinishedThing, bill_ProductionWithUft)); } } } return(new Job(TechJobDefOf.DocumentTech, target) { bill = bill }); } else { return(new Job(TechJobDefOf.DocumentTechDigital, target) { bill = bill }); } } } } return(null); }
private Bill_Production RelevantBill() { if (Find.Selector.SingleSelectedThing != null && Find.Selector.SingleSelectedThing.def == this.def.thingDef) { IBillGiver billGiver = Find.Selector.SingleSelectedThing as IBillGiver; if (billGiver != null) { return((Bill_Production)billGiver.BillStack.Bills.FirstOrDefault((Bill b) => b.recipe == this.def.recipeDef)); } } return(null); }
public static Job HaulStuffOffBillGiverJob(Pawn pawn, IBillGiver giver, Thing thingToIgnore) { foreach (IntVec3 ingredientStackCell in giver.IngredientStackCells) { Thing thing = pawn.Map.thingGrid.ThingAt(ingredientStackCell, ThingCategory.Item); if (thing != null && thing != thingToIgnore) { return(HaulAIUtility.HaulAsideJobFor(pawn, thing)); } } return(null); }
private Job StartBillJob(Pawn pawn, IBillGiver giver) { //Log.Warning(pawn + " is trying to start a training job..."); for (int i = 0; i < giver.BillStack.Count; i++) { Bill bill = giver.BillStack[i]; if (bill.recipe.requiredGiverWorkType == null || bill.recipe.requiredGiverWorkType == def.workType) { IntRange range = (IntRange)rangeInfo.GetValue(this); if (Find.TickManager.TicksGame >= bill.lastIngredientSearchFailTicks + range.RandomInRange || FloatMenuMakerMap.makingFor == pawn) { bill.lastIngredientSearchFailTicks = 0; if (bill.ShouldDoNow() && bill.PawnAllowedToStartAnew(pawn)) { //if ((bool)BestIngredientsInfo.Invoke(this, new object[] { bill, pawn, giver, chosenIngThings })) //{ //Log.Message("...weapon found, chosen ingredients: " + chosenIngThings.Select(x => x.Thing).ToStringSafeEnumerable()); chosenIngThings.RemoveAll(x => !StudyWeapons(bill, pawn).Contains(x.Thing.def)); if (chosenIngThings.Any()) { Job result = TryStartNewDoBillJob(pawn, bill, giver); chosenIngThings.Clear(); return(result); } else if (!JobFailReason.HaveReason) { JobFailReason.Is("NoWeaponToLearn".Translate(pawn)); } //} if (FloatMenuMakerMap.makingFor != pawn) { //Log.Message("...float menu maker case"); bill.lastIngredientSearchFailTicks = Find.TickManager.TicksGame; } else { //reflection info FieldInfo MissingMaterialsTranslatedInfo = AccessTools.Field(typeof(WorkGiver_DoBill), "MissingMaterialsTranslated"); // //Log.Message("...missing materials"); JobFailReason.Is((string)MissingMaterialsTranslatedInfo.GetValue(this), bill.Label); } chosenIngThings.Clear(); } } } } //Log.Message("...job failed."); chosenIngThings.Clear(); return(null); }
private Job StartOrResumeBillJob(Pawn pawn, IBillGiver giver) { for (int i = 0; i < giver.BillStack.Count; i++) { Bill bill = giver.BillStack[i]; if ((bill.recipe.requiredGiverWorkType == null || bill.recipe.requiredGiverWorkType == base.def.workType) && (Find.TickManager.TicksGame >= bill.lastIngredientSearchFailTicks + WorkGiver_DoBill.ReCheckFailedBillTicksRange.RandomInRange || FloatMenuMakerMap.makingFor == pawn)) { bill.lastIngredientSearchFailTicks = 0; if (bill.ShouldDoNow() && bill.PawnAllowedToStartAnew(pawn)) { if (bill.recipe.PawnSatisfiesSkillRequirements(pawn)) { Bill_ProductionWithUft bill_ProductionWithUft = bill as Bill_ProductionWithUft; if (bill_ProductionWithUft != null) { if (bill_ProductionWithUft.BoundUft != null) { if (bill_ProductionWithUft.BoundWorker == pawn && pawn.CanReserveAndReach(bill_ProductionWithUft.BoundUft, PathEndMode.Touch, Danger.Deadly, 1, -1, null, false) && !bill_ProductionWithUft.BoundUft.IsForbidden(pawn)) { return(WorkGiver_DoBill.FinishUftJob(pawn, bill_ProductionWithUft.BoundUft, bill_ProductionWithUft)); } continue; } UnfinishedThing unfinishedThing = WorkGiver_DoBill.ClosestUnfinishedThingForBill(pawn, bill_ProductionWithUft); if (unfinishedThing != null) { return(WorkGiver_DoBill.FinishUftJob(pawn, unfinishedThing, bill_ProductionWithUft)); } } if (!WorkGiver_DoBill.TryFindBestBillIngredients(bill, pawn, (Thing)giver, this.chosenIngThings)) { if (FloatMenuMakerMap.makingFor != pawn) { bill.lastIngredientSearchFailTicks = Find.TickManager.TicksGame; } else { JobFailReason.Is(WorkGiver_DoBill.MissingMaterialsTranslated); } continue; } return(this.TryStartNewDoBillJob(pawn, bill, giver)); } JobFailReason.Is(WorkGiver_DoBill.MissingSkillTranslated); } } } return(null); }
public override Job JobOnThing(Pawn pawn, Thing thing, bool forced = false) { int tick = Find.TickManager.TicksGame; if (actualJob == null || lastVerifiedJobTick != tick || Find.TickManager.Paused) { actualJob = null; IBillGiver billGiver = thing as IBillGiver; if (billGiver != null && ThingIsUsableBillGiver(thing) && billGiver.BillStack.AnyShouldDoNow && billGiver.UsableForBillsAfterFueling()) { if (CheckLibrarySpace(thing)) //check library space { LocalTargetInfo target = thing; if (pawn.CanReserve(target, 1, -1, null, forced) && !thing.IsBurning() && !thing.IsForbidden(pawn)) //basic desk availabilty { CompKnowledge techComp = pawn.TryGetComp <CompKnowledge>(); IEnumerable <ResearchProjectDef> homework = techComp.homework; var intersection = techComp.knownTechs.Where(x => !x.IsFinished).Intersect(homework); if (intersection.Any()) //check homework { billGiver.BillStack.RemoveIncompletableBills(); foreach (Bill bill in RelevantBills(thing, pawn)) { if (bill.Allows(intersection)) //check bill filter vs. homework { actualJob = StartOrResumeBillJob(pawn, billGiver, target); lastVerifiedJobTick = tick; break; } else if (!JobFailReason.HaveReason) { JobFailReason.Is("ForbiddenAssignment".Translate()); } } } else if (!JobFailReason.HaveReason) { JobFailReason.Is("NoAssignment".Translate(pawn)); } } } else if (!JobFailReason.HaveReason) { JobFailReason.Is("NoSpaceInLibrary".Translate()); } } } return(actualJob); }