Ejemplo n.º 1
0
        public bool ThingsAvailableAnywhere(ThingCountClass need, Pawn pawn)
        {
            int  key = Gen.HashCombine <Faction>(need.GetHashCode(), pawn.Faction);
            bool flag;

            if (!this.cachedResults.TryGetValue(key, out flag))
            {
                List <Thing> list = this.map.listerThings.ThingsOfDef(need.thingDef);
                int          num  = 0;
                for (int i = 0; i < list.Count; i++)
                {
                    if (!list[i].IsForbidden(pawn))
                    {
                        num += list[i].stackCount;
                        if (num >= need.count)
                        {
                            break;
                        }
                    }
                }
                flag = (num >= need.count);
                this.cachedResults.Add(key, flag);
            }
            return(flag);
        }
        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;
                            }
                        }
                    }
                }
            }
        }