Esempio n. 1
0
        [HarmonyPriority(Priority.First)] // MUST execute, cannot be postfix,
                                          // as some elements already null (e.g., map)
        public static void Prefix(Building __instance)
        {
            CompDeepStorage cds;

            if ((cds = __instance.GetComp <CompDeepStorage>()) == null)
            {
                return;
            }
            Map map = __instance.Map;

            if (map == null)
            {
                Log.Error("DeepStorage despawning: Map is null; some assets may not display properly: "
                          + __instance.ToString()); return;
            }
            ISlotGroupParent DSU = __instance as Building_Storage;

            foreach (IntVec3 cell in DSU.AllSlotCells())
            {
                List <Thing> list = map.thingGrid.ThingsListAt(cell);
                Thing        t;
                for (int i = 0; i < list.Count; i++)
                {
                    t = list[i];
                    Utils.TopThingInDeepStorage.Remove(t); // just take them all, to be safe
                    if (t == null)
                    {
                        Log.Warning("DeepStorage despawning: tried to clean up null object"); continue;
                    }
                    if (!t.Spawned || !t.def.EverStorable(false))
                    {
                        continue;
                    }
                    if (t.def.drawerType != DrawerType.MapMeshOnly)
                    {   // should be safe to register even if already registered
                        map.dynamicDrawManager.RegisterDrawable(t);
                    }
                    // from the ListerThings code:
                    if (ThingRequestGroup.HasGUIOverlay.Includes(t.def))
                    {
                        if (!map.listerThings.ThingsInGroup(ThingRequestGroup.HasGUIOverlay).Contains(t))
                        {
                            map.listerThings.ThingsInGroup(ThingRequestGroup.HasGUIOverlay).Add(t);
                        }
                    }
                    // Just to make sure it's not in the tooltip list twice:
                    //    Is this ineffecient?  Yes.
                    //    It also means that if anything changes whether cds.showContents, nothing breaks
                    //    Also, this only happens rarely, so ineffecient is okay.
                    map.tooltipGiverList.Notify_ThingDespawned(t);
                    map.tooltipGiverList.Notify_ThingSpawned(t);
                } // end list of things at
            }     // end foreach cell of despawning DSU
        }         //end postfix
Esempio n. 2
0
        private List <Thing> SetStoredItems(ISlotGroupParent buildingStorage)
        {
            var slotCells = buildingStorage?.AllSlotCells().ToList();
            var thingGrid = Find.CurrentMap.thingGrid;

            if (slotCells == null || thingGrid == null || slotCells.OptimizedNullOrEmpty())
            {
                return(null);
            }

            slotCount = slotCells.Count;
            return(slotCells.SelectMany(slotCell => thingGrid.ThingsListAt(slotCell).Where(thing => thing.Spawned && thing.def.EverStorable(false))).ToList());
        }