コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AwesomeInventoryLoadout"/> class.
        /// </summary>
        /// <param name="pawn"> Initialize <see cref="AwesomeInventoryLoadout"/> with items on this <paramref name="pawn"/>. </param>
        public AwesomeInventoryLoadout(Pawn pawn)
        {
            ValidateArg.NotNull(pawn, nameof(pawn));

            this.AddItems(pawn.equipment?.AllEquipmentListForReading);
            this.AddItems(pawn.apparel?.WornApparel);
            this.AddItems(pawn.inventory?.innerContainer);

            if (pawn.outfits?.CurrentOutfit?.filter is ThingFilter filter)
            {
                this.filter.CopyAllowancesFrom(filter);
            }
            else
            {
                this.filter.SetAllow(ThingCategoryDefOf.Apparel, true);
            }

            this.uniqueId = Current.Game.outfitDatabase.AllOutfits.Max(o => o.uniqueId) + 1;
            CompAwesomeInventoryLoadout compLoadout = pawn.TryGetComp <CompAwesomeInventoryLoadout>();

            this.label = compLoadout?.Loadout == null
                ? AwesomeInventoryLoadout.GetDefaultLoadoutName(pawn)
                : LoadoutManager.GetIncrementalLabel(compLoadout.Loadout.label);

            pawn.SetLoadout(this);
        }
        /// <summary>
        /// Gives out a job if a proper apparel is found on the map.
        /// </summary>
        /// <param name="pawn"> The pawn in question. </param>
        /// <returns> A 9 to 5 job. </returns>
        protected override Job TryGiveJob(Pawn pawn)
        {
            ValidateArg.NotNull(pawn, nameof(pawn));
#if DEBUG
            Log.Message(pawn.Name + "Looking for apparels");
#endif

            CompAwesomeInventoryLoadout ailoadout = ((ThingWithComps)pawn).TryGetComp <CompAwesomeInventoryLoadout>();

            if (ailoadout == null || !ailoadout.NeedRestock)
            {
                return(null);
            }

            if (_parent == null)
            {
                if (parent is JobGiver_FindItemByRadius p)
                {
                    _parent = p;
                }
                else
                {
                    throw new InvalidOperationException(ErrorText.WrongTypeParentThinkNode);
                }
            }

            foreach (ThingGroupSelector groupSelector in ailoadout.ItemsToRestock.Select(p => p.Key))
            {
                if (groupSelector.AllowedThing.IsApparel)
                {
                    Thing targetA =
                        _parent.FindItem(
                            pawn
                            , pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.Apparel)
                            , (thing) => groupSelector.Allows(thing, out _)
                            &&
                            !ailoadout.Loadout.IncludedInBlacklist(thing));

                    if (targetA != null)
                    {
                        Job job = new DressJob(AwesomeInventory_JobDefOf.AwesomeInventory_Dress, targetA, false);
                        if (pawn.Reserve(targetA, job, errorOnFailed: false))
                        {
                            return(job);
                        }
                        else
                        {
                            JobMaker.ReturnToPool(job);
                            return(null);
                        }
                    }
                }
            }

            return(null);
        }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AwesomeInventoryLoadout"/> class.
        /// </summary>
        /// <param name="pawn"> Initialize <see cref="AwesomeInventoryLoadout"/> with items on this <paramref name="pawn"/>. </param>
        public AwesomeInventoryLoadout(Pawn pawn)
        {
            ValidateArg.NotNull(pawn, nameof(pawn));

            this.AddItems(pawn.equipment?.AllEquipmentListForReading);
            this.AddItems(pawn.apparel?.WornApparel);
            this.AddItems(pawn.inventory?.innerContainer);

            this.uniqueId = Current.Game.outfitDatabase.AllOutfits.Max(o => o.uniqueId) + 1;
            CompAwesomeInventoryLoadout compLoadout = pawn.TryGetComp <CompAwesomeInventoryLoadout>();

            this.label = compLoadout?.Loadout == null
                ? AwesomeInventoryLoadout.GetDefaultLoadoutName(pawn)
                : LoadoutManager.GetIncrementalLabel(compLoadout.Loadout.label);

            pawn.SetLoadout(this);
        }