예제 #1
0
        public static void SubvertBiocodedGear(Pawn target, Pawn subverter)
        {
            Pawn_EquipmentTracker eqTracker = target.equipment;

            foreach (Thing eq in eqTracker.AllEquipmentListForReading)
            {
                // if biocodable and biocoded, code to subverter
                CompBiocodable biocode = eq.TryGetComp <CompBiocodable>();
                if (biocode != null && biocode.Biocoded)
                {
                    biocode.CodeFor(subverter);
                    eqTracker.TryDropEquipment(eqTracker.Primary, out ThingWithComps dontcare, target.Position);
                }
            }
            Pawn_ApparelTracker apTracker = target.apparel;

            foreach (Apparel ap in apTracker.WornApparel)
            {
                CompBiocodable biocode = ap.TryGetComp <CompBiocodable>();
                if (biocode != null && biocode.Biocoded)
                {
                    biocode.CodeFor(subverter);
                    apTracker.TryDrop(ap);
                }
            }
        }
예제 #2
0
        private static void ValidateApparelForChangedPawn([NotNull] Pawn pawn, [NotNull] ThingDef oldRace)
        {
            Pawn_ApparelTracker apparel = pawn.apparel;

            if (apparel == null)
            {
                return;
            }

            _apparelCache.Clear();
            _apparelCache.AddRange(apparel.WornApparel.MakeSafe());


            foreach (Apparel ap in _apparelCache) //use a copy so we can remove them safely while iterating
            {
                if (!ApparelUtility.HasPartsToWear(pawn, ap.def))
                {
                    if (DebugLogUtils.ShouldLog(LogLevel.Messages))
                    {
                        Log.Message($"removing {ap.Label}");
                    }

                    if (apparel.TryDrop(ap))
                    {
                        apparel.Remove(ap);
                    }
                }
            }
        }
예제 #3
0
        internal static void Wear(this Pawn_ApparelTracker _this, Apparel newApparel, bool dropReplacedApparel = true)
        {
            SlotGroupUtility.Notify_TakingThing(newApparel);
            if (newApparel.Spawned)
            {
                newApparel.DeSpawn();
            }
            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."
                }));
                return;
            }
            for (int i = _this.WornApparel.Count - 1; i >= 0; i--)
            {
                Apparel apparel = _this.WornApparel[i];
                if (!ApparelUtility.CanWearTogether(newApparel.def, apparel.def))
                {
                    bool forbid = _this.pawn.Faction.HostileTo(Faction.OfPlayer);
                    if (dropReplacedApparel)
                    {
                        Apparel apparel2;
                        if (!_this.TryDrop(apparel, out apparel2, _this.pawn.Position, forbid))
                        {
                            Log.Error(_this.pawn + " could not drop " + apparel);
                            return;
                        }
                    }
                    else
                    {
                        _this.WornApparel.Remove(apparel);
                    }
                }
            }
            _this.WornApparel.Add(newApparel);
            newApparel.wearer = _this.pawn;
            _this.SortWornApparelIntoDrawOrder();
            _this.ApparelChanged();

            Utility.TryUpdateInventory(_this.pawn);     // Apparel was added, update inventory
            MethodInfo methodInfo = typeof(Pawn_ApparelTracker).GetMethod("SortWornApparelIntoDrawOrder", BindingFlags.Instance | BindingFlags.NonPublic);

            methodInfo.Invoke(_this, new object[] { });

            LongEventHandler.ExecuteWhenFinished(new Action(_this.ApparelChanged));
        }