Exemple #1
0
        public override void PreOpen()
        {
            base.PreOpen();

            // Select all maps that are player homes
            IEnumerable <Map> homeMaps = Find.Maps.Where(map => map.IsPlayerHome);

            // Check whether we're configured to get everything or just grab from storage
            IEnumerable <Thing> things;

            if (Instance.AllItemsTradable)
            {
                // Get *everything*
                things = homeMaps.SelectMany(map => map.listerThings.AllThings);
            }
            else
            {
                // From each map, select all haul destinations
                IEnumerable <SlotGroup> haulDestinations = homeMaps.SelectMany(map => map.haulDestinationManager.AllGroups);

                // From each haul destination, select everything stored there
                things = haulDestinations.SelectMany(haulDestination => haulDestination.HeldThings);
            }

            // Group all items and cache them for later
            this.itemStacks = StackedThings.GroupThings(things.Where(thing => thing.def.category == ThingCategory.Item && !thing.def.IsCorpse));

            // Update both our and their offers
            UpdateOffers();
        }
Exemple #2
0
        /// <summary>
        /// Updates <see cref="ourOfferCache"/> and <see cref="theirOfferCache"/> with the items on offer for each party respectively.
        /// </summary>
        private void UpdateOffers()
        {
            // Try get our items on offer
            if (Instance.TryGetItemsOnOffer(tradeId, Instance.Uuid, out IEnumerable <ProtoThing> ourItems))
            {
                // Convert our items to their Verse equivalents
                Verse.Thing[] verseItems = ourItems.Select(TradingThingConverter.ConvertThingFromProtoOrUnknown).ToArray();

                lock (ourOfferCacheLock)
                {
                    // Update our cached offer
                    ourOfferCache = StackedThings.GroupThings(verseItems);
                }
            }
            else
            {
                lock (ourOfferCacheLock)
                {
                    // Just clear our cached offer
                    ourOfferCache.Clear();
                }
            }

            // Try get their UUID and items on offer
            if (Instance.TryGetOtherPartyUuid(tradeId, out string otherPartyUuid) &&
                Instance.TryGetItemsOnOffer(tradeId, otherPartyUuid, out IEnumerable <ProtoThing> theirItems))
            {
                // Convert their items to their Verse equivalents
                Verse.Thing[] verseItems = theirItems.Select(TradingThingConverter.ConvertThingFromProtoOrUnknown).ToArray();

                lock (theirOfferCacheLock)
                {
                    // Update their cached offer
                    theirOfferCache = StackedThings.GroupThings(verseItems);
                }
            }
            else
            {
                lock (theirOfferCacheLock)
                {
                    // Just clear their cached offer
                    theirOfferCache.Clear();
                }
            }
        }