Beispiel #1
0
        private static bool DisplayTradeStats(StatRequest req)
        {
            ThingDef thingDef;

            if ((thingDef = req.Def as ThingDef) == null)
            {
                return(false);
            }
            if (req.HasThing && EquipmentUtility.IsBiocoded(req.Thing))
            {
                return(false);
            }
            if (thingDef.category == ThingCategory.Building && thingDef.Minifiable)
            {
                return(true);
            }
            if (TradeUtility.EverPlayerSellable(thingDef))
            {
                return(true);
            }
            if (thingDef.tradeability.TraderCanSell() && (thingDef.category == ThingCategory.Item || thingDef.category == ThingCategory.Pawn))
            {
                return(true);
            }
            return(false);
        }
Beispiel #2
0
        public static bool PlayerSellableNow(Thing t, ITrader trader)
        {
            t = t.GetInnerIfMinified();
            if (!EverPlayerSellable(t.def))
            {
                return(false);
            }
            if (t.IsNotFresh())
            {
                return(false);
            }
            Apparel apparel = t as Apparel;

            if (apparel != null && apparel.WornByCorpse)
            {
                return(false);
            }
            if (EquipmentUtility.IsBiocoded(t))
            {
                return(false);
            }
            Pawn pawn = t as Pawn;

            if (pawn != null && ((pawn.GetExtraHostFaction() != null && pawn.GetExtraHostFaction() == trader.Faction) || (pawn.IsQuestLodger() && pawn.GetExtraHomeFaction() == trader.Faction)))
            {
                return(false);
            }
            return(true);
        }
 private bool ShouldEquip(Thing newWep, Pawn pawn)
 {
     if (EquipmentUtility.CanEquip(newWep, pawn))
     {
         return(GetWeaponScore(newWep) > GetWeaponScore(pawn.equipment.Primary));
     }
     return(false);
 }
Beispiel #4
0
 public override bool Matches(Thing t)
 {
     if (!t.def.IsApparel)
     {
         return(false);
     }
     return(EquipmentUtility.IsBiocoded(t));
 }
Beispiel #5
0
 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);
     }
 }
        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 = false;
                if (SelPawnForGear.IsQuestLodger())
                {
                    flag2 = inventory || !EquipmentUtility.QuestLodgerCanUnequip(thing, SelPawnForGear);
                }
                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 (FoodUtility.WillIngestFromInventoryNow(SelPawnForGear, 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();
                        FoodUtility.IngestFromInventoryNow(SelPawnForGear, 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;
        }
Beispiel #7
0
        private Apparel FindGarmentSatisfyingTitleRequirement(Pawn pawn, RoyalTitleDef.ApparelRequirement req)
        {
            Room room = pawn.GetRoom();

            if (room.isPrisonCell)
            {
                foreach (IntVec3 cell in room.Cells)
                {
                    List <Thing> thingList = cell.GetThingList(pawn.Map);
                    for (int i = 0; i < thingList.Count; i++)
                    {
                        Apparel apparel = thingList[i] as Apparel;
                        if (apparel != null && req.ApparelMeetsRequirement(thingList[i].def, allowUnmatched: false) && pawn.CanReserve(apparel) && !apparel.IsBurning() && (!EquipmentUtility.IsBiocoded(apparel) || EquipmentUtility.IsBiocodedFor(apparel, pawn)) && ApparelUtility.HasPartsToWear(pawn, apparel.def))
                        {
                            return(apparel);
                        }
                    }
                }
            }
            return(null);
        }
Beispiel #8
0
        private Apparel FindGarmentCoveringPart(Pawn pawn, BodyPartGroupDef bodyPartGroupDef)
        {
            Room room = pawn.GetRoom();

            if (room.isPrisonCell)
            {
                foreach (IntVec3 cell in room.Cells)
                {
                    List <Thing> thingList = cell.GetThingList(pawn.Map);
                    for (int i = 0; i < thingList.Count; i++)
                    {
                        Apparel apparel = thingList[i] as Apparel;
                        if (apparel != null && apparel.def.apparel.bodyPartGroups.Contains(bodyPartGroupDef) && pawn.CanReserve(apparel) && !apparel.IsBurning() && (!EquipmentUtility.IsBiocoded(apparel) || EquipmentUtility.IsBiocodedFor(apparel, pawn)) && ApparelUtility.HasPartsToWear(pawn, apparel.def))
                        {
                            return(apparel);
                        }
                    }
                }
            }
            return(null);
        }
        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 (pawn.IsQuestLodger())
            {
                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]) && !pawn.apparel.IsLocked(wornApparel[num]))
                {
                    Job job = JobMaker.MakeJob(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() && (apparel.def.apparel.gender == Gender.None || apparel.def.apparel.gender == pawn.gender) && (!apparel.def.apparel.tags.Contains("Royal") || pawn.royalty.AllTitlesInEffectForReading.Count != 0))
                {
                    float num3 = ApparelScoreGain(pawn, apparel);
                    if (DebugViewSettings.debugApparelOptimize)
                    {
                        debugSb.AppendLine(apparel.LabelCap + ": " + num3.ToString("F2"));
                    }
                    if (!(num3 < 0.05f) && !(num3 < num2) && (!EquipmentUtility.IsBiocoded(apparel) || EquipmentUtility.IsBiocodedFor(apparel, pawn)) && 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(JobMaker.MakeJob(JobDefOf.Wear, thing));
        }