public static bool IsBiocodedFor(Thing thing, Pawn pawn) { CompBiocodable compBiocodable = thing.TryGetComp <CompBiocodable>(); if (compBiocodable != null) { return(compBiocodable.CodedPawn == pawn); } return(false); }
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 static void GenerateStartingApparelFor(Pawn pawn, PawnGenerationRequest request) { if (!pawn.RaceProps.ToolUser || !pawn.RaceProps.IsFlesh) { return; } pawn.apparel.DestroyAll(); float randomInRange = pawn.kindDef.apparelMoney.RandomInRange; float mapTemperature; NeededWarmth neededWarmth = ApparelWarmthNeededNow(pawn, request, out mapTemperature); bool allowHeadgear = Rand.Value < pawn.kindDef.apparelAllowHeadgearChance; debugSb = null; if (DebugViewSettings.logApparelGeneration) { debugSb = new StringBuilder(); debugSb.AppendLine("Generating apparel for " + pawn); debugSb.AppendLine("Money: " + randomInRange.ToString("F0")); debugSb.AppendLine("Needed warmth: " + neededWarmth); debugSb.AppendLine("Headgear allowed: " + allowHeadgear.ToString()); } int @int = Rand.Int; tmpApparelCandidates.Clear(); for (int i = 0; i < allApparelPairs.Count; i++) { ThingStuffPair thingStuffPair = allApparelPairs[i]; if (CanUsePair(thingStuffPair, pawn, randomInRange, allowHeadgear, @int)) { tmpApparelCandidates.Add(thingStuffPair); } } if (randomInRange < 0.001f) { GenerateWorkingPossibleApparelSetFor(pawn, randomInRange, tmpApparelCandidates); } else { int num = 0; while (true) { GenerateWorkingPossibleApparelSetFor(pawn, randomInRange, tmpApparelCandidates); if (DebugViewSettings.logApparelGeneration) { debugSb.Append(num.ToString().PadRight(5) + "Trying: " + workingSet.ToString()); } if (num < 10 && Rand.Value < 0.85f && randomInRange < 9999999f) { float num2 = Rand.Range(0.45f, 0.8f); float totalPrice = workingSet.TotalPrice; if (totalPrice < randomInRange * num2) { if (DebugViewSettings.logApparelGeneration) { debugSb.AppendLine(" -- Failed: Spent $" + totalPrice.ToString("F0") + ", < " + (num2 * 100f).ToString("F0") + "% of money."); } goto IL_037d; } } if (num < 20 && Rand.Value < 0.97f && !workingSet.Covers(BodyPartGroupDefOf.Torso)) { if (DebugViewSettings.logApparelGeneration) { debugSb.AppendLine(" -- Failed: Does not cover torso."); } } else if (num < 30 && Rand.Value < 0.8f && workingSet.CoatButNoShirt()) { if (DebugViewSettings.logApparelGeneration) { debugSb.AppendLine(" -- Failed: Coat but no shirt."); } } else { if (num < 50) { bool mustBeSafe = num < 17; if (!workingSet.SatisfiesNeededWarmth(neededWarmth, mustBeSafe, mapTemperature)) { if (DebugViewSettings.logApparelGeneration) { debugSb.AppendLine(" -- Failed: Wrong warmth."); } goto IL_037d; } } if (num >= 80 || !workingSet.IsNaked(pawn.gender)) { break; } if (DebugViewSettings.logApparelGeneration) { debugSb.AppendLine(" -- Failed: Naked."); } } goto IL_037d; IL_037d: num++; } if (DebugViewSettings.logApparelGeneration) { debugSb.Append(" -- Approved! Total price: $" + workingSet.TotalPrice.ToString("F0") + ", TotalInsulationCold: " + workingSet.TotalInsulationCold); } } if ((!pawn.kindDef.apparelIgnoreSeasons || request.ForceAddFreeWarmLayerIfNeeded) && !workingSet.SatisfiesNeededWarmth(neededWarmth, mustBeSafe: true, mapTemperature)) { workingSet.AddFreeWarmthAsNeeded(neededWarmth, mapTemperature); } if (DebugViewSettings.logApparelGeneration) { Log.Message(debugSb.ToString()); } workingSet.GiveToPawn(pawn); workingSet.Reset(null, null); if (pawn.kindDef.apparelColor != Color.white) { List <Apparel> wornApparel = pawn.apparel.WornApparel; for (int j = 0; j < wornApparel.Count; j++) { wornApparel[j].SetColor(pawn.kindDef.apparelColor, reportFailure: false); } } List <SpecificApparelRequirement> specificApparelRequirements = pawn.kindDef.specificApparelRequirements; if (specificApparelRequirements != null) { foreach (SpecificApparelRequirement item in specificApparelRequirements.Where((SpecificApparelRequirement x) => x.Color != default(Color))) { List <Apparel> wornApparel2 = pawn.apparel.WornApparel; for (int k = 0; k < wornApparel2.Count; k++) { if (ApparelRequirementHandlesThing(item, wornApparel2[k].def)) { wornApparel2[k].SetColor(item.Color, reportFailure: false); } } } } foreach (Apparel item2 in pawn.apparel.WornApparel) { CompBiocodable compBiocodable = item2.TryGetComp <CompBiocodable>(); if (compBiocodable != null && Rand.Chance(request.BiocodeApparelChance)) { compBiocodable.CodeFor(pawn); } } }
private void DrawThingRow(ref float y, float width, Thing thing, bool inventory = false) { Rect rect = new Rect(0f, y, width, 28f); Widgets.InfoCardButton(rect.width - 24f, y, thing); rect.width -= 24f; bool flag = false; if (CanControl && (inventory || CanControlColonist || (SelPawnForGear.Spawned && !SelPawnForGear.Map.IsPlayerHome))) { Rect rect2 = new Rect(rect.width - 24f, y, 24f, 24f); bool flag2; if (SelPawnForGear.IsQuestLodger()) { if (inventory) { flag2 = true; } else { CompBiocodable compBiocodable = thing.TryGetComp <CompBiocodable>(); if (compBiocodable != null && compBiocodable.Biocoded) { flag2 = true; } else { CompBladelinkWeapon compBladelinkWeapon = thing.TryGetComp <CompBladelinkWeapon>(); flag2 = (compBladelinkWeapon != null && compBladelinkWeapon.bondedPawn == SelPawnForGear); } } } else { flag2 = false; } Apparel apparel; bool flag3 = (apparel = (thing as Apparel)) != null && SelPawnForGear.apparel != null && SelPawnForGear.apparel.IsLocked(apparel); flag = (flag2 | flag3); if (Mouse.IsOver(rect2)) { if (flag3) { TooltipHandler.TipRegion(rect2, "DropThingLocked".Translate()); } else if (flag2) { TooltipHandler.TipRegion(rect2, "DropThingLodger".Translate()); } else { TooltipHandler.TipRegion(rect2, "DropThing".Translate()); } } Color color = flag ? Color.grey : Color.white; Color mouseoverColor = flag ? color : GenUI.MouseoverColor; if (Widgets.ButtonImage(rect2, TexButton.Drop, color, mouseoverColor, !flag) && !flag) { SoundDefOf.Tick_High.PlayOneShotOnCamera(); InterfaceDrop(thing); } rect.width -= 24f; } if (CanControlColonist) { if ((thing.def.IsNutritionGivingIngestible || thing.def.IsNonMedicalDrug) && thing.IngestibleNow && base.SelPawn.WillEat(thing)) { Rect rect3 = new Rect(rect.width - 24f, y, 24f, 24f); TooltipHandler.TipRegionByKey(rect3, "ConsumeThing", thing.LabelNoCount, thing); if (Widgets.ButtonImage(rect3, TexButton.Ingest)) { SoundDefOf.Tick_High.PlayOneShotOnCamera(); InterfaceIngest(thing); } } rect.width -= 24f; } Rect rect4 = rect; rect4.xMin = rect4.xMax - 60f; CaravanThingsTabUtility.DrawMass(thing, rect4); rect.width -= 60f; if (Mouse.IsOver(rect)) { GUI.color = HighlightColor; GUI.DrawTexture(rect, TexUI.HighlightTex); } if (thing.def.DrawMatSingle != null && thing.def.DrawMatSingle.mainTexture != null) { Widgets.ThingIcon(new Rect(4f, y, 28f, 28f), thing); } Text.Anchor = TextAnchor.MiddleLeft; GUI.color = ThingLabelColor; Rect rect5 = new Rect(36f, y, rect.width - 36f, rect.height); string text = thing.LabelCap; Apparel apparel2 = thing as Apparel; if (apparel2 != null && SelPawnForGear.outfits != null && SelPawnForGear.outfits.forcedHandler.IsForced(apparel2)) { text += ", " + "ApparelForcedLower".Translate(); } if (flag) { text += " (" + "ApparelLockedLower".Translate() + ")"; } Text.WordWrap = false; Widgets.Label(rect5, text.Truncate(rect5.width)); Text.WordWrap = true; if (Mouse.IsOver(rect)) { string text2 = thing.DescriptionDetailed; if (thing.def.useHitPoints) { text2 = text2 + "\n" + thing.HitPoints + " / " + thing.MaxHitPoints; } TooltipHandler.TipRegion(rect, text2); } y += 28f; }