private void TryUnequipSomething() { Apparel apparel = this.Apparel; List <Apparel> wornApparel = this.pawn.apparel.WornApparel; for (int i = wornApparel.Count - 1; i >= 0; i--) { if (!ApparelUtility.CanWearTogether(apparel.def, wornApparel[i].def, this.pawn.RaceProps.body)) { int num = (int)(wornApparel[i].GetStatValue(StatDefOf.EquipDelay, true) * 60f); if (this.unequipBuffer >= num) { bool forbid = this.pawn.Faction != null && this.pawn.Faction.HostileTo(Faction.OfPlayer); Apparel apparel2; if (!this.pawn.apparel.TryDrop(wornApparel[i], out apparel2, this.pawn.PositionHeld, forbid)) { Log.Error(this.pawn + " could not drop " + wornApparel[i].ToStringSafe <Apparel>(), false); base.EndJobWith(JobCondition.Errored); return; } } break; } } }
public static float ApparelScoreGain_NewTmp(Pawn pawn, Apparel ap, List <float> wornScoresCache) { if (ap is ShieldBelt && pawn.equipment.Primary != null && pawn.equipment.Primary.def.IsWeaponUsingProjectiles) { return(-1000f); } float num = ApparelScoreRaw(pawn, ap); List <Apparel> wornApparel = pawn.apparel.WornApparel; bool flag = false; for (int i = 0; i < wornApparel.Count; i++) { if (!ApparelUtility.CanWearTogether(wornApparel[i].def, ap.def, pawn.RaceProps.body)) { if (!pawn.outfits.forcedHandler.AllowedToAutomaticallyDrop(wornApparel[i]) || pawn.apparel.IsLocked(wornApparel[i])) { return(-1000f); } num -= wornScoresCache[i]; flag = true; } } if (!flag) { num *= 10f; } return(num); }
public void GiveToPawn(Pawn pawn) { for (int i = 0; i < this.aps.Count; i++) { Apparel apparel = (Apparel)ThingMaker.MakeThing(this.aps[i].thing, this.aps[i].stuff); PawnGenerator.PostProcessGeneratedGear(apparel, pawn); if (ApparelUtility.HasPartsToWear(pawn, apparel.def)) { pawn.apparel.Wear(apparel, false); } } for (int j = 0; j < this.aps.Count; j++) { for (int k = 0; k < this.aps.Count; k++) { if (j != k && !ApparelUtility.CanWearTogether(this.aps[j].thing, this.aps[k].thing, pawn.RaceProps.body)) { Log.Error(string.Concat(new object[] { pawn, " generated with apparel that cannot be worn together: ", this.aps[j], ", ", this.aps[k] }), false); return; } } } }
public static float ApparelScoreGain(Pawn pawn, Apparel ap) { if (ap.def == ThingDefOf.Apparel_ShieldBelt && pawn.equipment.Primary != null && pawn.equipment.Primary.def.IsRangedWeapon) { return(-1000f); } float num = JobGiver_OptimizeApparel.ApparelScoreRaw(pawn, ap); List <Apparel> wornApparel = pawn.apparel.WornApparel; bool flag = false; for (int i = 0; i < wornApparel.Count; i++) { if (!ApparelUtility.CanWearTogether(wornApparel[i].def, ap.def, pawn.RaceProps.body)) { if (!pawn.outfits.forcedHandler.AllowedToAutomaticallyDrop(wornApparel[i])) { return(-1000f); } num -= JobGiver_OptimizeApparel.ApparelScoreRaw(pawn, wornApparel[i]); flag = true; } } if (!flag) { num = (float)(num * 10.0); } return(num); }
public static float ApparelScoreGain(Pawn pawn, Apparel ap) { float result; if (ap is ShieldBelt && pawn.equipment.Primary != null && pawn.equipment.Primary.def.IsWeaponUsingProjectiles) { result = -1000f; } else { float num = JobGiver_OptimizeApparel.ApparelScoreRaw(pawn, ap); List <Apparel> wornApparel = pawn.apparel.WornApparel; bool flag = false; for (int i = 0; i < wornApparel.Count; i++) { if (!ApparelUtility.CanWearTogether(wornApparel[i].def, ap.def, pawn.RaceProps.body)) { if (!pawn.outfits.forcedHandler.AllowedToAutomaticallyDrop(wornApparel[i])) { return(-1000f); } num -= JobGiver_OptimizeApparel.ApparelScoreRaw(pawn, wornApparel[i]); flag = true; } } if (!flag) { num *= 10f; } result = num; } return(result); }
public void GiveToPawn(Pawn pawn) { for (int i = 0; i < aps.Count; i++) { ThingStuffPair thingStuffPair = aps[i]; ThingDef thing = thingStuffPair.thing; ThingStuffPair thingStuffPair2 = aps[i]; Apparel apparel = (Apparel)ThingMaker.MakeThing(thing, thingStuffPair2.stuff); PawnGenerator.PostProcessGeneratedGear(apparel, pawn); if (ApparelUtility.HasPartsToWear(pawn, apparel.def)) { pawn.apparel.Wear(apparel, dropReplacedApparel: false); } } for (int j = 0; j < aps.Count; j++) { for (int k = 0; k < aps.Count; k++) { if (j != k) { ThingStuffPair thingStuffPair3 = aps[j]; ThingDef thing2 = thingStuffPair3.thing; ThingStuffPair thingStuffPair4 = aps[k]; if (!ApparelUtility.CanWearTogether(thing2, thingStuffPair4.thing, pawn.RaceProps.body)) { Log.Error(pawn + " generated with apparel that cannot be worn together: " + aps[j] + ", " + aps[k]); return; } } } } }
private void TryUnequipSomething() { Apparel apparel = Apparel; List <Apparel> wornApparel = pawn.apparel.WornApparel; int num = wornApparel.Count - 1; while (true) { if (num >= 0) { if (!ApparelUtility.CanWearTogether(apparel.def, wornApparel[num].def, pawn.RaceProps.body)) { break; } num--; continue; } return; } int num2 = (int)(wornApparel[num].GetStatValue(StatDefOf.EquipDelay) * 60f); if (unequipBuffer >= num2) { bool forbid = pawn.Faction != null && pawn.Faction.HostileTo(Faction.OfPlayer); if (!pawn.apparel.TryDrop(wornApparel[num], out Apparel _, pawn.PositionHeld, forbid)) { Log.Error(pawn + " could not drop " + wornApparel[num].ToStringSafe()); EndJobWith(JobCondition.Errored); } } }
public bool CanWearWithoutDroppingAnything(ThingDef apDef) { for (int i = 0; i < this.wornApparel.Count; i++) { if (!ApparelUtility.CanWearTogether(apDef, this.wornApparel[i].def, this.pawn.RaceProps.body)) { return(false); } } return(true); }
public void Wear(Apparel newApparel, bool dropReplacedApparel = true) { if (newApparel.Spawned) { newApparel.DeSpawn(DestroyMode.Vanish); } if (!ApparelUtility.HasPartsToWear(this.pawn, newApparel.def)) { Log.Warning(string.Concat(new object[] { this.pawn, " tried to wear ", newApparel, " but he has no body parts required to wear it." }), false); } else { for (int i = this.wornApparel.Count - 1; i >= 0; i--) { Apparel apparel = this.wornApparel[i]; if (!ApparelUtility.CanWearTogether(newApparel.def, apparel.def, this.pawn.RaceProps.body)) { if (dropReplacedApparel) { bool forbid = this.pawn.Faction != null && this.pawn.Faction.HostileTo(Faction.OfPlayer); Apparel apparel2; if (!this.TryDrop(apparel, out apparel2, this.pawn.PositionHeld, forbid)) { Log.Error(this.pawn + " could not drop " + apparel, false); return; } } else { this.Remove(apparel); } } } if (newApparel.Wearer != null) { Log.Warning(string.Concat(new object[] { this.pawn, " is trying to wear ", newApparel, " but this apparel already has a wearer (", newApparel.Wearer, "). This may or may not cause bugs." }), false); } this.wornApparel.TryAdd(newApparel, false); } }
private float GetReplacedInsulationCold(ThingStuffPair newAp) { float num = 0f; for (int i = 0; i < aps.Count; i++) { if (!ApparelUtility.CanWearTogether(aps[i].thing, newAp.thing, body)) { num += aps[i].InsulationCold; } } return(num); }
public bool WouldReplaceLockedApparel(Apparel newApparel) { if (!AnyApparelLocked) { return(false); } for (int i = 0; i < lockedApparel.Count; i++) { if (!ApparelUtility.CanWearTogether(newApparel.def, lockedApparel[i].def, pawn.RaceProps.body)) { return(true); } } return(false); }
public override void Notify_Starting() { base.Notify_Starting(); this.duration = (int)(this.Apparel.GetStatValue(StatDefOf.EquipDelay, true) * 60f); Apparel apparel = this.Apparel; List <Apparel> wornApparel = this.pawn.apparel.WornApparel; for (int i = wornApparel.Count - 1; i >= 0; i--) { if (!ApparelUtility.CanWearTogether(apparel.def, wornApparel[i].def, this.pawn.RaceProps.body)) { this.duration += (int)(wornApparel[i].GetStatValue(StatDefOf.EquipDelay, true) * 60f); } } }
public override void Notify_Starting() { base.Notify_Starting(); duration = (int)(Apparel.GetStatValue(StatDefOf.EquipDelay) * 60f); Apparel apparel = Apparel; List <Apparel> wornApparel = pawn.apparel.WornApparel; for (int num = wornApparel.Count - 1; num >= 0; num--) { if (!ApparelUtility.CanWearTogether(apparel.def, wornApparel[num].def, pawn.RaceProps.body)) { duration += (int)(wornApparel[num].GetStatValue(StatDefOf.EquipDelay) * 60f); } } }
public void Wear(Apparel newApparel, bool dropReplacedApparel = true, bool locked = false) { if (newApparel.Spawned) { newApparel.DeSpawn(); } if (!ApparelUtility.HasPartsToWear(pawn, newApparel.def)) { Log.Warning(pawn + " tried to wear " + newApparel + " but he has no body parts required to wear it."); return; } if (EquipmentUtility.IsBiocoded(newApparel) && !EquipmentUtility.IsBiocodedFor(newApparel, pawn)) { CompBiocodable compBiocodable = newApparel.TryGetComp <CompBiocodable>(); Log.Warning(pawn + " tried to wear " + newApparel + " but it is biocoded for " + compBiocodable.CodedPawnLabel + " ."); return; } for (int num = wornApparel.Count - 1; num >= 0; num--) { Apparel apparel = wornApparel[num]; if (!ApparelUtility.CanWearTogether(newApparel.def, apparel.def, pawn.RaceProps.body)) { if (dropReplacedApparel) { bool forbid = pawn.Faction != null && pawn.Faction.HostileTo(Faction.OfPlayer); if (!TryDrop(apparel, out Apparel _, pawn.PositionHeld, forbid)) { Log.Error(pawn + " could not drop " + apparel); return; } } else { Remove(apparel); } } } if (newApparel.Wearer != null) { Log.Warning(pawn + " is trying to wear " + newApparel + " but this apparel already has a wearer (" + newApparel.Wearer + "). This may or may not cause bugs."); } wornApparel.TryAdd(newApparel, canMergeWithExistingStacks: false); if (locked) { Lock(newApparel); } }
public void Wear(Apparel newApparel, bool dropReplacedApparel = true) { if (newApparel.Spawned) { newApparel.DeSpawn(); } if (!ApparelUtility.HasPartsToWear(this.pawn, newApparel.def)) { Log.Warning(this.pawn + " tried to wear " + newApparel + " but he has no body parts required to wear it."); } else { for (int num = this.wornApparel.Count - 1; num >= 0; num--) { Apparel apparel = this.wornApparel[num]; if (!ApparelUtility.CanWearTogether(newApparel.def, apparel.def, this.pawn.RaceProps.body)) { if (dropReplacedApparel) { bool forbid = this.pawn.Faction.HostileTo(Faction.OfPlayer); Apparel apparel2 = default(Apparel); if (!this.TryDrop(apparel, out apparel2, this.pawn.Position, forbid)) { Log.Error(this.pawn + " could not drop " + apparel); return; } } else { this.Remove(apparel); } } } if (newApparel.Wearer != null) { Log.Warning(this.pawn + " is trying to wear " + newApparel + " but this apparel already has a wearer (" + newApparel.Wearer + "). This may or may not cause bugs."); } this.wornApparel.TryAdd(newApparel, false); } }
public void AddFreeWarmthAsNeeded(NeededWarmth warmth, float mapTemperature) { if (warmth == NeededWarmth.Any || warmth == NeededWarmth.Cool) { return; } if (DebugViewSettings.logApparelGeneration) { debugSb.AppendLine(); debugSb.AppendLine("Trying to give free warm layer."); } for (int i = 0; i < 3; i++) { if (!SatisfiesNeededWarmth(warmth, mustBeSafe: true, mapTemperature)) { if (DebugViewSettings.logApparelGeneration) { debugSb.AppendLine("Checking to give free torso-cover at max price " + freeWarmParkaMaxPrice); } Predicate <ThingStuffPair> parkaPairValidator = delegate(ThingStuffPair pa) { if (pa.Price > freeWarmParkaMaxPrice) { return(false); } if (pa.InsulationCold <= 0f) { return(false); } if (!pa.thing.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Torso)) { return(false); } if (!pa.thing.apparel.canBeGeneratedToSatisfyWarmth) { return(false); } return((!(GetReplacedInsulationCold(pa) >= pa.InsulationCold)) ? true : false); }; for (int j = 0; j < 2; j++) { ThingStuffPair candidate; if (j == 0) { if (!allApparelPairs.Where((ThingStuffPair pa) => parkaPairValidator(pa) && pa.InsulationCold < 40f).TryRandomElementByWeight((ThingStuffPair pa) => pa.Commonality / (pa.Price * pa.Price), out candidate)) { continue; } } else if (!allApparelPairs.Where((ThingStuffPair pa) => parkaPairValidator(pa)).TryMaxBy((ThingStuffPair x) => x.InsulationCold - GetReplacedInsulationCold(x), out candidate)) { continue; } if (DebugViewSettings.logApparelGeneration) { debugSb.AppendLine("Giving free torso-cover: " + candidate + " insulation=" + candidate.InsulationCold); foreach (ThingStuffPair item in aps.Where((ThingStuffPair a) => !ApparelUtility.CanWearTogether(a.thing, candidate.thing, body))) { debugSb.AppendLine(" -replaces " + item.ToString() + " InsulationCold=" + item.InsulationCold); } } aps.RemoveAll((ThingStuffPair pa) => !ApparelUtility.CanWearTogether(pa.thing, candidate.thing, body)); aps.Add(candidate); break; } } if (GenTemperature.SafeTemperatureRange(raceDef, aps).Includes(mapTemperature)) { break; } } if (!SatisfiesNeededWarmth(warmth, mustBeSafe: true, mapTemperature)) { if (DebugViewSettings.logApparelGeneration) { debugSb.AppendLine("Checking to give free hat at max price " + freeWarmHatMaxPrice); } Predicate <ThingStuffPair> hatPairValidator = delegate(ThingStuffPair pa) { if (pa.Price > freeWarmHatMaxPrice) { return(false); } if (pa.InsulationCold < 7f) { return(false); } if (!pa.thing.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.FullHead) && !pa.thing.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.UpperHead)) { return(false); } return((!(GetReplacedInsulationCold(pa) >= pa.InsulationCold)) ? true : false); }; if (allApparelPairs.Where((ThingStuffPair pa) => hatPairValidator(pa)).TryRandomElementByWeight((ThingStuffPair pa) => pa.Commonality / (pa.Price * pa.Price), out ThingStuffPair hatPair)) { if (DebugViewSettings.logApparelGeneration) { debugSb.AppendLine("Giving free hat: " + hatPair + " insulation=" + hatPair.InsulationCold); foreach (ThingStuffPair item2 in aps.Where((ThingStuffPair a) => !ApparelUtility.CanWearTogether(a.thing, hatPair.thing, body))) { debugSb.AppendLine(" -replaces " + item2.ToString() + " InsulationCold=" + item2.InsulationCold); } } aps.RemoveAll((ThingStuffPair pa) => !ApparelUtility.CanWearTogether(pa.thing, hatPair.thing, body)); aps.Add(hatPair); } } if (DebugViewSettings.logApparelGeneration) { debugSb.AppendLine("New TotalInsulationCold: " + TotalInsulationCold); } }
public void AddFreeWarmthAsNeeded(NeededWarmth warmth) { if (warmth != 0 && warmth != NeededWarmth.Cool) { if (DebugViewSettings.logApparelGeneration) { PawnApparelGenerator.debugSb.AppendLine(); PawnApparelGenerator.debugSb.AppendLine("Trying to give free warm layer."); } if (!this.SatisfiesNeededWarmth(warmth, false, 21f)) { if (DebugViewSettings.logApparelGeneration) { PawnApparelGenerator.debugSb.AppendLine("Checking to give free torso-cover at max price " + PawnApparelGenerator.freeWarmParkaMaxPrice); } Predicate <ThingStuffPair> parkaPairValidator = delegate(ThingStuffPair pa) { if (pa.Price > PawnApparelGenerator.freeWarmParkaMaxPrice) { return(false); } if (pa.InsulationCold > -40.0) { return(false); } return(true); }; ThingStuffPair parkaPair; if ((from pa in PawnApparelGenerator.allApparelPairs where parkaPairValidator(pa) select pa).TryRandomElementByWeight <ThingStuffPair>((Func <ThingStuffPair, float>)((ThingStuffPair pa) => pa.Commonality / (pa.Price * pa.Price)), out parkaPair)) { if (DebugViewSettings.logApparelGeneration) { PawnApparelGenerator.debugSb.AppendLine("Giving free torso-cover: " + parkaPair + " insulation=" + parkaPair.InsulationCold); foreach (ThingStuffPair item in from a in this.aps where !ApparelUtility.CanWearTogether(a.thing, parkaPair.thing, this.body) select a) { PawnApparelGenerator.debugSb.AppendLine(" -replaces " + item.ToString() + " InsulationCold=" + item.InsulationCold); } } this.aps.RemoveAll((ThingStuffPair pa) => !ApparelUtility.CanWearTogether(pa.thing, parkaPair.thing, this.body)); this.aps.Add(parkaPair); } } if (!this.SatisfiesNeededWarmth(warmth, false, 21f)) { if (DebugViewSettings.logApparelGeneration) { PawnApparelGenerator.debugSb.AppendLine("Checking to give free hat at max price " + PawnApparelGenerator.freeWarmHatMaxPrice); } Predicate <ThingStuffPair> hatPairValidator = delegate(ThingStuffPair pa) { if (pa.Price > PawnApparelGenerator.freeWarmHatMaxPrice) { return(false); } if (pa.InsulationCold > -7.0) { return(false); } if (!pa.thing.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.FullHead) && !pa.thing.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.UpperHead)) { return(false); } return(true); }; ThingStuffPair hatPair; if ((from pa in PawnApparelGenerator.allApparelPairs where hatPairValidator(pa) select pa).TryRandomElementByWeight <ThingStuffPair>((Func <ThingStuffPair, float>)((ThingStuffPair pa) => pa.Commonality / (pa.Price * pa.Price)), out hatPair)) { if (DebugViewSettings.logApparelGeneration) { PawnApparelGenerator.debugSb.AppendLine("Giving free hat: " + hatPair + " insulation=" + hatPair.InsulationCold); foreach (ThingStuffPair item2 in from a in this.aps where !ApparelUtility.CanWearTogether(a.thing, hatPair.thing, this.body) select a) { PawnApparelGenerator.debugSb.AppendLine(" -replaces " + item2.ToString() + " InsulationCold=" + item2.InsulationCold); } } this.aps.RemoveAll((ThingStuffPair pa) => !ApparelUtility.CanWearTogether(pa.thing, hatPair.thing, this.body)); this.aps.Add(hatPair); } } if (DebugViewSettings.logApparelGeneration) { PawnApparelGenerator.debugSb.AppendLine("New TotalInsulationCold: " + this.TotalInsulationCold); } } }
public void AddFreeWarmthAsNeeded(NeededWarmth warmth) { if (warmth == NeededWarmth.Any) { return; } if (warmth == NeededWarmth.Cool) { return; } if (DebugViewSettings.logApparelGeneration) { PawnApparelGenerator.debugSb.AppendLine(); PawnApparelGenerator.debugSb.AppendLine("Trying to give free warm layer."); } if (!this.SatisfiesNeededWarmth(warmth, false, 21f)) { if (DebugViewSettings.logApparelGeneration) { PawnApparelGenerator.debugSb.AppendLine("Checking to give free torso-cover at max price " + PawnApparelGenerator.freeWarmParkaMaxPrice); } Predicate <ThingStuffPair> parkaPairValidator = (ThingStuffPair pa) => pa.Price <= PawnApparelGenerator.freeWarmParkaMaxPrice && pa.InsulationCold <= -40f; ThingStuffPair parkaPair; if ((from pa in PawnApparelGenerator.allApparelPairs where parkaPairValidator(pa) select pa).TryRandomElementByWeight((ThingStuffPair pa) => pa.Commonality / (pa.Price * pa.Price), out parkaPair)) { if (DebugViewSettings.logApparelGeneration) { PawnApparelGenerator.debugSb.AppendLine(string.Concat(new object[] { "Giving free torso-cover: ", parkaPair, " insulation=", parkaPair.InsulationCold })); foreach (ThingStuffPair current in from a in this.aps where !ApparelUtility.CanWearTogether(a.thing, parkaPair.thing, this.body) select a) { PawnApparelGenerator.debugSb.AppendLine(string.Concat(new object[] { " -replaces ", current.ToString(), " InsulationCold=", current.InsulationCold })); } } this.aps.RemoveAll((ThingStuffPair pa) => !ApparelUtility.CanWearTogether(pa.thing, parkaPair.thing, this.body)); this.aps.Add(parkaPair); } } if (!this.SatisfiesNeededWarmth(warmth, false, 21f)) { if (DebugViewSettings.logApparelGeneration) { PawnApparelGenerator.debugSb.AppendLine("Checking to give free hat at max price " + PawnApparelGenerator.freeWarmHatMaxPrice); } Predicate <ThingStuffPair> hatPairValidator = (ThingStuffPair pa) => pa.Price <= PawnApparelGenerator.freeWarmHatMaxPrice && pa.InsulationCold <= -7f && (pa.thing.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.FullHead) || pa.thing.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.UpperHead)); ThingStuffPair hatPair; if ((from pa in PawnApparelGenerator.allApparelPairs where hatPairValidator(pa) select pa).TryRandomElementByWeight((ThingStuffPair pa) => pa.Commonality / (pa.Price * pa.Price), out hatPair)) { if (DebugViewSettings.logApparelGeneration) { PawnApparelGenerator.debugSb.AppendLine(string.Concat(new object[] { "Giving free hat: ", hatPair, " insulation=", hatPair.InsulationCold })); foreach (ThingStuffPair current2 in from a in this.aps where !ApparelUtility.CanWearTogether(a.thing, hatPair.thing, this.body) select a) { PawnApparelGenerator.debugSb.AppendLine(string.Concat(new object[] { " -replaces ", current2.ToString(), " InsulationCold=", current2.InsulationCold })); } } this.aps.RemoveAll((ThingStuffPair pa) => !ApparelUtility.CanWearTogether(pa.thing, hatPair.thing, this.body)); this.aps.Add(hatPair); } } if (DebugViewSettings.logApparelGeneration) { PawnApparelGenerator.debugSb.AppendLine("New TotalInsulationCold: " + this.TotalInsulationCold); } }
public void AddFreeWarmthAsNeeded(NeededWarmth warmth, float mapTemperature) { if (warmth == NeededWarmth.Any) { return; } if (warmth == NeededWarmth.Cool) { return; } if (DebugViewSettings.logApparelGeneration) { PawnApparelGenerator.debugSb.AppendLine(); PawnApparelGenerator.debugSb.AppendLine("Trying to give free warm layer."); } for (int i = 0; i < 3; i++) { if (!this.SatisfiesNeededWarmth(warmth, true, mapTemperature)) { if (DebugViewSettings.logApparelGeneration) { PawnApparelGenerator.debugSb.AppendLine("Checking to give free torso-cover at max price " + PawnApparelGenerator.freeWarmParkaMaxPrice); } Predicate <ThingStuffPair> parkaPairValidator = delegate(ThingStuffPair pa) { if (pa.Price > PawnApparelGenerator.freeWarmParkaMaxPrice) { return(false); } if (pa.InsulationCold <= 0f) { return(false); } if (!pa.thing.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Torso)) { return(false); } float replacedInsulationCold = this.GetReplacedInsulationCold(pa); return(replacedInsulationCold < pa.InsulationCold); }; int j = 0; while (j < 2) { ThingStuffPair candidate; if (j == 0) { if ((from pa in PawnApparelGenerator.allApparelPairs where parkaPairValidator(pa) && pa.InsulationCold < 40f select pa).TryRandomElementByWeight((ThingStuffPair pa) => pa.Commonality / (pa.Price * pa.Price), out candidate)) { goto IL_12F; } } else if ((from pa in PawnApparelGenerator.allApparelPairs where parkaPairValidator(pa) select pa).TryMaxBy((ThingStuffPair x) => x.InsulationCold - this.GetReplacedInsulationCold(x), out candidate)) { goto IL_12F; } j++; continue; IL_12F: if (DebugViewSettings.logApparelGeneration) { PawnApparelGenerator.debugSb.AppendLine(string.Concat(new object[] { "Giving free torso-cover: ", candidate, " insulation=", candidate.InsulationCold })); foreach (ThingStuffPair thingStuffPair in from a in this.aps where !ApparelUtility.CanWearTogether(a.thing, candidate.thing, this.body) select a) { PawnApparelGenerator.debugSb.AppendLine(string.Concat(new object[] { " -replaces ", thingStuffPair.ToString(), " InsulationCold=", thingStuffPair.InsulationCold })); } } this.aps.RemoveAll((ThingStuffPair pa) => !ApparelUtility.CanWearTogether(pa.thing, candidate.thing, this.body)); this.aps.Add(candidate); break; } } if (GenTemperature.SafeTemperatureRange(this.raceDef, this.aps).Includes(mapTemperature)) { break; } } if (!this.SatisfiesNeededWarmth(warmth, true, mapTemperature)) { if (DebugViewSettings.logApparelGeneration) { PawnApparelGenerator.debugSb.AppendLine("Checking to give free hat at max price " + PawnApparelGenerator.freeWarmHatMaxPrice); } Predicate <ThingStuffPair> hatPairValidator = delegate(ThingStuffPair pa) { if (pa.Price > PawnApparelGenerator.freeWarmHatMaxPrice) { return(false); } if (pa.InsulationCold < 7f) { return(false); } if (!pa.thing.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.FullHead) && !pa.thing.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.UpperHead)) { return(false); } float replacedInsulationCold = this.GetReplacedInsulationCold(pa); return(replacedInsulationCold < pa.InsulationCold); }; ThingStuffPair hatPair; if ((from pa in PawnApparelGenerator.allApparelPairs where hatPairValidator(pa) select pa).TryRandomElementByWeight((ThingStuffPair pa) => pa.Commonality / (pa.Price * pa.Price), out hatPair)) { if (DebugViewSettings.logApparelGeneration) { PawnApparelGenerator.debugSb.AppendLine(string.Concat(new object[] { "Giving free hat: ", hatPair, " insulation=", hatPair.InsulationCold })); foreach (ThingStuffPair thingStuffPair2 in from a in this.aps where !ApparelUtility.CanWearTogether(a.thing, hatPair.thing, this.body) select a) { PawnApparelGenerator.debugSb.AppendLine(string.Concat(new object[] { " -replaces ", thingStuffPair2.ToString(), " InsulationCold=", thingStuffPair2.InsulationCold })); } } this.aps.RemoveAll((ThingStuffPair pa) => !ApparelUtility.CanWearTogether(pa.thing, hatPair.thing, this.body)); this.aps.Add(hatPair); } } if (DebugViewSettings.logApparelGeneration) { PawnApparelGenerator.debugSb.AppendLine("New TotalInsulationCold: " + this.TotalInsulationCold); } }