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);
                }
            }
        }
        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);
                        }
                    }
                }
            }
        }
            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);
                                }
                            }
                        }
                    }
                }
            }
        static void Postfix(ResourceCounter __instance)
        {
            if (countedAmountsFI == null)
            {
                countedAmountsFI = typeof(ResourceCounter).GetField("countedAmounts", BindingFlags.Instance | BindingFlags.NonPublic);
            }

            Dictionary <ThingDef, int> countedAmounts = (Dictionary <ThingDef, int>)countedAmountsFI.GetValue(__instance);

            foreach (Building_InfiniteStorage ts in WorldComp.GetInfiniteStorages(Find.CurrentMap))
            {
                foreach (Thing thing in ts.StoredThings)
                {
                    if (thing.def.EverStorable(true) && thing.def.CountAsResource && !thing.IsNotFresh())
                    {
                        int count;
                        if (countedAmounts.TryGetValue(thing.def, out count))
                        {
                            count += thing.stackCount;
                        }
                        else
                        {
                            count = thing.stackCount;
                        }
                        countedAmounts[thing.def] = count;
                    }
                }
            }
        }
        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;
                            }
                        }
                    }
                }
            }
        }
Exemple #6
0
            static void Prefix()
            {
#if MED_DEBUG
                Log.Warning("HealthCardUtility.DrawMedOperationsTab");
#endif

                Patch_ListerThings_ThingsInGroup.AvailableMedicalThing.Clear();

                Map map = Find.CurrentMap;
                if (map != null)
                {
#if MED_DEBUG
                    Log.Warning("    Map is not null: " + (map != null).ToString());
#endif
                    long now = DateTime.Now.Ticks;
                    if (cache == null || now - lastUpdate > TimeSpan.TicksPerSecond)
                    {
                        cache.Clear();
                        foreach (Building_InfiniteStorage storage in WorldComp.GetInfiniteStorages(map))
                        {
#if MED_DEBUG
                            Log.Warning("    Storage: " + storage.Label);
#endif
                            if (storage.def.defName.Equals("IS_BodyPartStorage") ||
                                storage.def.defName.Equals("InfiniteStorage"))
                            {
                                cache.AddRange(storage.GetMedicalThings(true, false));
                            }
                        }
                        lastUpdate = now;
                    }
                    Patch_ListerThings_ThingsInGroup.AvailableMedicalThing.AddRange(cache);
                }
            }
            static void Postfix(WealthWatcher __instance)
            {
                Map map = (Map)__instance.GetType().GetField("map", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance);
                //float wealthBuildings = __instance.GetType().GetField("wealthBuildings", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance) as float;
                FieldInfo wealthItemsFI = __instance.GetType().GetField("wealthItems", BindingFlags.NonPublic | BindingFlags.Instance);
                float     wealthItems   = (float)wealthItemsFI.GetValue(__instance);

                wealthItems = TallyWealth(WorldComp.GetInfiniteStorages(map), wealthItems);
                //wealthItems = TallyWealth(WorldComp.GetNonGlobalInfiniteStorages(map), wealthItems);

                if (lastItemWealth < 1)
                {
                    lastItemWealth = wealthItems;
                }
                else if (wealthItems > lastItemWealth * 5)
                {
                    float temp = wealthItems;
                    wealthItems    = lastItemWealth;
                    lastItemWealth = temp;
                }
                else
                {
                    lastItemWealth = wealthItems;
                }

                wealthItemsFI.SetValue(__instance, wealthItems);
            }
Exemple #8
0
 static void Prefix(List <IngredientCount> ingredients, Pawn pawn, ref List <Pair <Building_InfiniteStorage, List <Thing> > > __state)
 {
     if (ingredients != null && pawn != null)
     {
         foreach (var s in WorldComp.GetInfiniteStorages(pawn.Map))
         {
             List <Thing> d = null;
             foreach (var i in ingredients)
             {
                 if (s.TryDropThings(i, out List <Thing> dropped))
                 {
                     if (d == null)
                     {
                         d = new List <Thing>();
                     }
                     d.AddRange(dropped);
                 }
             }
             if (d?.Count > 0)
             {
                 if (__state == null)
                 {
                     __state = new List <Pair <Building_InfiniteStorage, List <Thing> > >();
                 }
                 __state.Add(new Pair <Building_InfiniteStorage, List <Thing> >(s, d));
             }
         }
     }
 }
Exemple #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);
         }
     }
 }
 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 static IEnumerable <Thing> EmptyStorages(Map map)
        {
            List <Thing> l = new List <Thing>();

            foreach (Building_InfiniteStorage storage in WorldComp.GetInfiniteStorages(map))
            {
                if (storage.Map == map && storage.Spawned && storage.IncludeInTradeDeals)
                {
                    storage.Empty(l);
                }
            }
            return(l);
        }
        static void Prefix(Window __instance)
        {
            Type type = __instance.GetType();

            if (type == typeof(Dialog_FormCaravan))
            {
                Map map = __instance.GetType().GetField("map", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance) as Map;

                foreach (Building_InfiniteStorage storage in WorldComp.GetInfiniteStorages(map))
                {
                    storage.Empty();
                }
            }
        }
        static void Postfix(ref int __result, RecipeWorkerCounter __instance, Bill_Production bill)
        {
            List <ThingDefCountClass> products = __instance.recipe.products;

            if (WorldComp.HasInfiniteStorages(bill.Map) && products != null)
            {
                foreach (ThingDefCountClass product in products)
                {
                    ThingDef def = product.thingDef;
                    foreach (Building_InfiniteStorage s in WorldComp.GetInfiniteStorages(bill.Map))
                    {
                        __result += s.StoredThingCount(def, bill.ingredientFilter);
                    }
                }
            }
        }
Exemple #14
0
        static void Postfix(ref bool __result, Pawn pawn, List <IngredientCount> ingredients, List <ThingCount> chosen, ref List <Pair <Building_InfiniteStorage, List <Thing> > > __state)
        {
            /*
             * Log.Warning($"{pawn.Name.ToStringShort} Result: {__result}");
             * foreach (var c in chosen)
             *      Log.Warning($" - Chose: {c.Thing.def.defName} x{c.Count}");
             * foreach (var i in ingredients)
             *      Log.Warning($"- Ing: {i.GetBaseCount()}");
             */

            if (__result == false)
            {
                if (__state != null)
                {
                    foreach (var p in __state)
                    {
                        foreach (var t in p.Second)
                        {
                            p.First.Add(t);
                        }
                    }
                }
            }
            else if (pawn != null && ingredients != null && chosen != null)
            {
                Dictionary <int, int> chosenLookup = new Dictionary <int, int>();
                foreach (var t in chosen)
                {
                    chosenLookup.Add(t.Thing.thingIDNumber, t.Count);
                }
                foreach (var s in WorldComp.GetInfiniteStorages(pawn.Map))
                {
                    s.ReclaimFaster(true, chosenLookup);
                }
            }
        }
        static bool Prefix(Designator_Build __instance, Event ev)
        {
            if (entDefFI == null)
            {
                entDefFI     = typeof(Designator_Build).GetField("entDef", BindingFlags.NonPublic | BindingFlags.Instance);
                stuffDefFI   = typeof(Designator_Build).GetField("stuffDef", BindingFlags.NonPublic | BindingFlags.Instance);
                writeStuffFI = typeof(Designator_Build).GetField("writeStuff", BindingFlags.NonPublic | BindingFlags.Instance);
            }

            Map map = Find.CurrentMap;

            ThingDef thingDef = entDefFI.GetValue(__instance) as ThingDef;

            if (thingDef == null || !thingDef.MadeFromStuff || !WorldComp.HasInfiniteStorages(map))
            {
                return(true);
            }

            List <FloatMenuOption> list = new List <FloatMenuOption>();

            foreach (ThingDef current in map.resourceCounter.AllCountedAmounts.Keys)
            {
                if (current.IsStuff && current.stuffProps.CanMake(thingDef) && (DebugSettings.godMode || map.listerThings.ThingsOfDef(current).Count > 0))
                {
                    ThingDef localStuffDef = current;
                    string   labelCap      = localStuffDef.LabelCap;
                    list.Add(new FloatMenuOption(labelCap, delegate
                    {
                        __instance.ProcessInput(ev);
                        Find.DesignatorManager.Select(__instance);
                        stuffDefFI.SetValue(__instance, current);
                        writeStuffFI.SetValue(__instance, true);
                    }, MenuOptionPriority.Default, null, null, 0f, null, null));
                }
            }

            foreach (Building_InfiniteStorage storage in WorldComp.GetInfiniteStorages(map))
            {
                if (storage.Spawned)
                {
                    foreach (Thing t in storage.StoredThings)
                    {
                        ThingDef current = t.def;
                        if (current.IsStuff &&
                            current.stuffProps.CanMake(thingDef) &&
                            (DebugSettings.godMode || t.stackCount > 0))
                        {
                            string labelCap = current.LabelCap;
                            list.Add(new FloatMenuOption(labelCap, delegate
                            {
                                __instance.ProcessInput(ev);
                                Find.DesignatorManager.Select(__instance);
                                stuffDefFI.SetValue(__instance, current);
                                writeStuffFI.SetValue(__instance, true);
                            }, MenuOptionPriority.Default, null, null, 0f, null, null));
                        }
                    }
                }
            }

            if (list.Count == 0)
            {
                Messages.Message("NoStuffsToBuildWith".Translate(), MessageTypeDefOf.RejectInput);
            }
            else
            {
                FloatMenu floatMenu = new FloatMenu(list);
                floatMenu.vanishIfMouseDistant = true;
                Find.WindowStack.Add(floatMenu);
                Find.DesignatorManager.Select(__instance);
            }
            return(false);
        }