static void Prefix(Pawn pawn, Building_TurretGun gun)
        {
#if DEBUG
            Log.Warning("Find Ammo");
#endif
            if (pawn.IsColonist && pawn.Map == gun.Map)
            {
                StorageSettings allowedShellsSettings = gun.gun.TryGetComp <CompChangeableProjectile>().allowedShellsSettings;
                foreach (Building_InfiniteStorage storage in WorldComp.GetInfiniteStorages(gun.Map))
                {
#if DEBUG
                    Log.Warning("    Storeage: " + storage.Label);
#endif
                    List <Thing> l;
                    if (storage.TryRemove(allowedShellsSettings.filter, out l))
                    {
                        foreach (Thing t in l)
                        {
#if DEBUG
                            Log.Warning("        Ammo fouynd: " + t.Label);
#endif
                            List <Thing> dropped = new List <Thing>();
                            BuildingUtil.DropThing(t, t.stackCount, storage, storage.Map, dropped);
                        }
                    }
                }
            }
        }
        static void Postfix(ref bool __result, ItemAvailability __instance, ThingCountClass need, Pawn pawn)
        {
            if (!__result && pawn != null && pawn.Faction == Faction.OfPlayer)
            {
                foreach (Building_InfiniteStorage storage in WorldComp.GetInfiniteStorages(pawn.Map))
                {
                    if (storage.IsOperational &&
                        storage.Spawned &&
                        need != null && need.thing != null)
                    {
                        Thing thing;
                        if (storage.TryGetValue(need.thing.def, out thing))
                        {
                            if (thing.stackCount >= need.Count)
                            {
                                List <Thing> removed;
                                int          toDrop = (need.Count < thing.def.stackLimit) ? thing.def.stackLimit : need.Count;
                                if (storage.TryRemove(thing, toDrop, out removed))
                                {
                                    foreach (Thing t in removed)
                                    {
                                        BuildingUtil.DropThing(t, t.stackCount, storage, storage.Map);
                                    }

                                    __result = true;
                                    ((Dictionary <int, bool>)CachedResultsFI.GetValue(__instance))[Gen.HashCombine <Faction>(need.GetHashCode(), pawn.Faction)] = __result;
                                }
                                break;
                            }
                        }
                    }
                }
            }
        }
        static void Postfix(Thing __result, Pawn pawn)
        {
            bool found = false;

            if (pawn != null && __result == null)
            {
                foreach (Building_InfiniteStorage storage in WorldComp.GetInfiniteStorages(pawn.Map))
                {
                    if (storage.TryRemove(ThingDefOf.ComponentIndustrial, 1, out List <Thing> list))
                    {
                        found = true;
                        foreach (Thing t in list)
                        {
                            BuildingUtil.DropThing(t, 1, storage, storage.Map, null);
                        }
                    }
                }
                if (found)
                {
                    __result = GenClosest.ClosestThingReachable(
                        pawn.Position, pawn.Map, ThingRequest.ForDef(ThingDefOf.ComponentIndustrial), PathEndMode.InteractionCell, TraverseParms.For(pawn, pawn.NormalMaxDanger(),
                                                                                                                                                     TraverseMode.ByPawn, false), 9999f, (Thing x) => !x.IsForbidden(pawn) && pawn.CanReserve(x, 1, -1, null, false), null, 0, -1, false, RegionType.Set_Passable, false);
                }
            }
        }
        public override void SpawnSetup(Map map, bool respawningAfterLoad)
        {
            base.SpawnSetup(map, respawningAfterLoad);
            this.CurrentMap = map;

            if (settings == null)
            {
                base.settings = new StorageSettings(this);
                base.settings.CopyFrom(this.def.building.defaultStorageSettings);
                base.settings.filter.SetDisallowAll();
            }

            this.includeInWorldLookup = this.GetIncludeInWorldLookup();

            WorldComp.Add(map, this);

            this.compPowerTrader = this.GetComp <CompPowerTrader>();

            if (this.ToDumpOnSpawn != null)
            {
                foreach (Thing t in this.ToDumpOnSpawn)
                {
                    BuildingUtil.DropThing(t, t.stackCount, this, this.Map);
                }
                this.ToDumpOnSpawn.Clear();
                this.ToDumpOnSpawn = null;
            }
        }
            internal static void Prefix(Pawn pawn, Thing refuelable)
            {
                if (WorldComp.HasInfiniteStorages(refuelable.Map))
                {
                    droppedAndStorage = new Dictionary <Thing, Building_InfiniteStorage>();

                    ThingFilter filter = refuelable.TryGetComp <CompRefuelable>().Props.fuelFilter;

                    foreach (Building_InfiniteStorage storage in WorldComp.GetInfiniteStorages(refuelable.Map))
                    {
                        if (storage.Spawned && storage.Map == pawn.Map && storage.IsOperational)
                        {
                            List <Thing> removed;
                            if (storage.TryRemove(filter, out removed))
                            {
                                List <Thing> removedThings = new List <Thing>();
                                foreach (Thing t in removed)
                                {
                                    BuildingUtil.DropThing(t, t.def.stackLimit, storage, storage.Map, removedThings);
                                }

                                if (removedThings.Count > 0)
                                {
                                    droppedAndStorage.Add(removedThings[0], storage);
                                }
                            }
                        }
                    }
                }
            }
        public void Reclaim(bool respectReserved = true, List <ThingCount> chosen = null)
        {
            if (this.IsOperational && this.CanAutoCollect)
            {
                float powerAvailable = 0;
                if (this.UsesPower && Settings.EnableEnergyBuffer)
                {
                    powerAvailable = this.compPowerTrader.PowerNet.CurrentEnergyGainRate() / CompPower.WattsToWattDaysPerTick;
                    if (powerAvailable <= Settings.DesiredEnergyBuffer)
                    {
                        return;
                    }
                    powerAvailable -= Settings.DesiredEnergyBuffer;
                }

                foreach (Thing t in BuildingUtil.FindThingsOfTypeNextTo(base.Map, base.Position, 1))
                {
                    if (chosen == null || !this.ChosenContains(t, chosen))
                    {
                        if (this.UsesPower && Settings.EnableEnergyBuffer)
                        {
                            float newWeight = this.storedWeight + this.GetThingWeight(t, t.stackCount);
                            if (newWeight * Settings.EnergyFactor > powerAvailable)
                            {
                                continue;
                            }
                        }
                        this.Add(t);
                    }
                }
            }
        }
        public void Empty(List <Thing> droppedThings = null, bool force = false)
        {
            if (!force && !this.IsOperational && !Settings.EmptyOnPowerLoss)
            {
                return;
            }

            try
            {
                this.AllowAdds = false;
                foreach (LinkedList <Thing> l in this.storedThings.Values)
                {
                    foreach (Thing t in l)
                    {
                        BuildingUtil.DropThing(t, t.stackCount, this, this.CurrentMap, droppedThings);
                    }
                    l.Clear();
                }
                this.storedCount  = 0;
                this.storedWeight = 0;
            }
            finally
            {
                this.ResetAutoReclaimTime();
                this.AllowAdds = true;
            }
        }
        public bool TryGetFirstFilteredItemForMending(Bill bill, ThingFilter filter, bool remove, out Thing gotten)
        {
            gotten = null;
            foreach (LinkedList <Thing> l in this.storedThings.Values)
            {
                if (l != null && l.Count > 0)
                {
                    for (LinkedListNode <Thing> n = l.First; n.Next != null; n = n.Next)
                    {
                        Thing t = n.Value;
                        if (!bill.IsFixedOrAllowedIngredient(t.def) || !filter.Allows(t.def))
                        {
                            break;
                        }

                        if (bill.IsFixedOrAllowedIngredient(t) && filter.Allows(t))
                        {
                            if (t.HitPoints == t.MaxHitPoints)
                            {
                                continue;
                            }

                            l.Remove(n);
                            BuildingUtil.DropSingleThing(t, this, this.Map, out gotten);
                            return(true);
                        }
                    }
                }
            }
            return(gotten != null);
        }
示例#9
0
 static void Prefix(Pawn healer, Pawn patient)
 {
     foreach (Building_InfiniteStorage storage in WorldComp.GetInfiniteStorages(patient.Map))
     {
         IEnumerable <Thing> removed = storage.GetMedicalThings(false, true);
         foreach (Thing r in removed)
         {
             BuildingUtil.DropThing(r, r.stackCount, storage, storage.Map);                        //, dropped);
         }
     }
 }
 public override void Notify_ReceivedThing(Thing newItem)
 {
     if (!this.AllowAdds)
     {
         BuildingUtil.DropSingleThing(newItem, this, this.Map, out Thing result);
     }
     else if (!this.Add(newItem))
     {
         this.DropThing(newItem, null);
     }
 }
 static void Prefix(Map map)
 {
     foreach (Building_InfiniteStorage storage in WorldComp.GetInfiniteStorages(map))
     {
         if (storage.TryRemove(ThingDefOf.Silver, out IEnumerable <Thing> silver))
         {
             foreach (Thing s in silver)
             {
                 BuildingUtil.DropThing(s, s.stackCount, storage, storage.Map, null);
             }
         }
     }
 }
        public void ForceReclaim()
        {
            if (base.Map == null)
            {
                return;
            }

            foreach (Thing t in BuildingUtil.FindThingsOfTypeNextTo(base.Map, base.Position, 1))
            {
                if (!(t is Building_InfiniteStorage) && t != this && t.def.category == ThingCategory.Item)
                {
                    this.Add(t, true);
                }
            }
        }
示例#13
0
            static void Postfix(ref List <ThingCount> __result, Pawn healer, Pawn patient, ref int totalCount)
            {
                if (healer.Map != patient.Map)
                {
                    return;
                }

                foreach (Building_InfiniteStorage storage in WorldComp.GetInfiniteStoragesWithinRadius(healer.Map, patient.Position, 20))
                {
                    IEnumerable <Thing> removed = storage.GetMedicalThings(false, true);
                    foreach (Thing r in removed)
                    {
                        List <Thing> dropped = new List <Thing>();
                        BuildingUtil.DropThing(r, r.stackCount, storage, storage.Map, dropped);
                        foreach (Thing t in dropped)
                        {
                            __result.Add(new ThingCount(t, t.stackCount));
                            t.Map.reservationManager.CanReserveStack(healer, t, 1, ReservationLayerDefOf.Floor, true);
                        }
                    }
                }
            }
        private void Dispose()
        {
            try
            {
                this.AllowAdds = false;
                foreach (LinkedList <Thing> l in this.storedThings.Values)
                {
                    foreach (Thing t in l)
                    {
                        BuildingUtil.DropThing(t, t.stackCount, this, this.CurrentMap);
                    }
                }
                this.storedThings.Clear();
            }
            catch (Exception e)
            {
                Log.Error(
                    this.GetType().Name + ".Dispose\n" +
                    e.GetType().Name + " " + e.Message + "\n" +
                    e.StackTrace);
            }

            WorldComp.Remove(this.CurrentMap, this);
        }
 private void DropThing(Thing t, List <Thing> result)
 {
     BuildingUtil.DropThing(t, t.stackCount, this, this.CurrentMap, result);
 }