protected override Job TryGiveJob(Pawn pawn) { Job result; if (pawn.outfits == null) { Log.ErrorOnce(pawn + " tried to run JobGiver_OptimizeApparel without an OutfitTracker", 5643897, false); result = null; } else if (pawn.Faction != Faction.OfPlayer) { Log.ErrorOnce("Non-colonist " + pawn + " tried to optimize apparel.", 764323, false); result = null; } else { if (!DebugViewSettings.debugApparelOptimize) { if (Find.TickManager.TicksGame < pawn.mindState.nextApparelOptimizeTick) { return(null); } } else { JobGiver_OptimizeApparel.debugSb = new StringBuilder(); JobGiver_OptimizeApparel.debugSb.AppendLine(string.Concat(new object[] { "Scanning for ", pawn, " at ", pawn.Position })); } Outfit currentOutfit = pawn.outfits.CurrentOutfit; List <Apparel> wornApparel = pawn.apparel.WornApparel; for (int i = wornApparel.Count - 1; i >= 0; i--) { if (!currentOutfit.filter.Allows(wornApparel[i]) && pawn.outfits.forcedHandler.AllowedToAutomaticallyDrop(wornApparel[i])) { return(new Job(JobDefOf.RemoveApparel, wornApparel[i]) { haulDroppedApparel = true }); } } Thing thing = null; float num = 0f; List <Thing> list = pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.Apparel); if (list.Count == 0) { this.SetNextOptimizeTick(pawn); result = null; } else { JobGiver_OptimizeApparel.neededWarmth = PawnApparelGenerator.CalculateNeededWarmth(pawn, pawn.Map.Tile, GenLocalDate.Twelfth(pawn)); for (int j = 0; j < list.Count; j++) { Apparel apparel = (Apparel)list[j]; if (currentOutfit.filter.Allows(apparel)) { if (apparel.IsInAnyStorage()) { if (!apparel.IsForbidden(pawn)) { float num2 = JobGiver_OptimizeApparel.ApparelScoreGain(pawn, apparel); if (DebugViewSettings.debugApparelOptimize) { JobGiver_OptimizeApparel.debugSb.AppendLine(apparel.LabelCap + ": " + num2.ToString("F2")); } if (num2 >= 0.05f && num2 >= num) { if (ApparelUtility.HasPartsToWear(pawn, apparel.def)) { if (pawn.CanReserveAndReach(apparel, PathEndMode.OnCell, pawn.NormalMaxDanger(), 1, -1, null, false)) { thing = apparel; num = num2; } } } } } } } if (DebugViewSettings.debugApparelOptimize) { JobGiver_OptimizeApparel.debugSb.AppendLine("BEST: " + thing); Log.Message(JobGiver_OptimizeApparel.debugSb.ToString(), false); JobGiver_OptimizeApparel.debugSb = null; } if (thing == null) { this.SetNextOptimizeTick(pawn); result = null; } else { result = new Job(JobDefOf.Wear, thing); } } } return(result); }
protected override Job TryGiveJob(Pawn pawn) { if (pawn.outfits == null) { Log.ErrorOnce(pawn + " tried to run JobGiver_OptimizeApparel without an OutfitTracker", 5643897); return(null); } if (pawn.Faction != Faction.OfPlayer) { Log.ErrorOnce("Non-colonist " + pawn + " tried to optimize apparel.", 764323); return(null); } if (!DebugViewSettings.debugApparelOptimize) { if (Find.TickManager.TicksGame < pawn.mindState.nextApparelOptimizeTick) { return(null); } } else { debugSb = new StringBuilder(); debugSb.AppendLine("Scanning for " + pawn + " at " + pawn.Position); } Outfit currentOutfit = pawn.outfits.CurrentOutfit; List <Apparel> wornApparel = pawn.apparel.WornApparel; for (int num = wornApparel.Count - 1; num >= 0; num--) { if (!currentOutfit.filter.Allows(wornApparel[num]) && pawn.outfits.forcedHandler.AllowedToAutomaticallyDrop(wornApparel[num])) { Job job = new Job(JobDefOf.RemoveApparel, wornApparel[num]); job.haulDroppedApparel = true; return(job); } } Thing thing = null; float num2 = 0f; List <Thing> list = pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.Apparel); if (list.Count == 0) { SetNextOptimizeTick(pawn); return(null); } neededWarmth = PawnApparelGenerator.CalculateNeededWarmth(pawn, pawn.Map.Tile, GenLocalDate.Twelfth(pawn)); for (int i = 0; i < list.Count; i++) { Apparel apparel = (Apparel)list[i]; if (currentOutfit.filter.Allows(apparel) && apparel.IsInAnyStorage() && !apparel.IsForbidden(pawn) && !apparel.IsBurning()) { float num3 = ApparelScoreGain(pawn, apparel); if (DebugViewSettings.debugApparelOptimize) { debugSb.AppendLine(apparel.LabelCap + ": " + num3.ToString("F2")); } if (!(num3 < 0.05f) && !(num3 < num2) && ApparelUtility.HasPartsToWear(pawn, apparel.def) && pawn.CanReserveAndReach(apparel, PathEndMode.OnCell, pawn.NormalMaxDanger())) { thing = apparel; num2 = num3; } } } if (DebugViewSettings.debugApparelOptimize) { debugSb.AppendLine("BEST: " + thing); Log.Message(debugSb.ToString()); debugSb = null; } if (thing == null) { SetNextOptimizeTick(pawn); return(null); } return(new Job(JobDefOf.Wear, thing)); }