Exemplo n.º 1
0
        private static bool TryPlaceDirect(Thing thing, IntVec3 loc, Map map, out Thing resultingThing, Action <Thing, int> placedAction = null)
        {
            Thing thing2 = thing;
            bool  flag   = false;

            if (thing.stackCount > thing.def.stackLimit)
            {
                thing = thing.SplitOff(thing.def.stackLimit);
                flag  = true;
            }
            Thing thing3;

            if (thing.def.stackLimit > 1)
            {
                List <Thing> thingList = loc.GetThingList(map);
                for (int i = 0; i < thingList.Count; i++)
                {
                    thing3 = thingList[i];
                    if (thing3.CanStackWith(thing))
                    {
                        goto IL_006a;
                    }
                }
            }
            resultingThing = GenSpawn.Spawn(thing, loc, map);
            if (placedAction != null)
            {
                placedAction(thing, thing.stackCount);
            }
            return(!flag);

IL_006a:
            int stackCount = thing.stackCount;

            if (thing3.TryAbsorbStack(thing, true))
            {
                resultingThing = thing3;
                if (placedAction != null)
                {
                    placedAction(thing3, stackCount);
                }
                return(!flag);
            }
            resultingThing = null;
            if (placedAction != null && stackCount != thing.stackCount)
            {
                placedAction(thing3, stackCount - thing.stackCount);
            }
            if (thing2 != thing)
            {
                thing2.TryAbsorbStack(thing, false);
            }
            return(false);
        }
        public override int TryAdd(Thing item, int count, bool canMergeWithExistingStacks = true)
        {
            if (count <= 0)
            {
                return(0);
            }
            if (item == null)
            {
                Log.Warning("Tried to add null item to ThingOwner.", false);
                return(0);
            }
            if (base.Contains(item))
            {
                Log.Warning("Tried to add " + item + " to ThingOwner but this item is already here.", false);
                return(0);
            }
            if (item.holdingOwner != null)
            {
                Log.Warning(string.Concat(new object[]
                {
                    "Tried to add ",
                    count,
                    " of ",
                    item.ToStringSafe <Thing>(),
                    " to ThingOwner but this thing is already in another container. owner=",
                    this.owner.ToStringSafe <IThingHolder>(),
                    ", current container owner=",
                    item.holdingOwner.Owner.ToStringSafe <IThingHolder>(),
                    ". Use TryAddOrTransfer, TryTransferToContainer, or remove the item before adding it."
                }), false);
                return(0);
            }
            if (!base.CanAcceptAnyOf(item, canMergeWithExistingStacks))
            {
                return(0);
            }
            int   stackCount = item.stackCount;
            int   num        = Mathf.Min(stackCount, count);
            Thing thing      = item.SplitOff(num);

            if (this.TryAdd((T)((object)thing), canMergeWithExistingStacks))
            {
                return(num);
            }
            if (thing != item)
            {
                int result = stackCount - item.stackCount - thing.stackCount;
                item.TryAbsorbStack(thing, false);
                return(result);
            }
            return(stackCount - item.stackCount);
        }
Exemplo n.º 3
0
        public override int TryAdd(Thing item, int count, bool canMergeWithExistingStacks = true)
        {
            if (count <= 0)
            {
                return(0);
            }
            if (item == null)
            {
                Log.Warning("Tried to add null item to ThingOwner.");
                return(0);
            }
            if (Contains(item))
            {
                Log.Warning("Tried to add " + item + " to ThingOwner but this item is already here.");
                return(0);
            }
            if (item.holdingOwner != null)
            {
                Log.Warning("Tried to add " + count + " of " + item.ToStringSafe() + " to ThingOwner but this thing is already in another container. owner=" + owner.ToStringSafe() + ", current container owner=" + item.holdingOwner.Owner.ToStringSafe() + ". Use TryAddOrTransfer, TryTransferToContainer, or remove the item before adding it.");
                return(0);
            }
            if (!CanAcceptAnyOf(item, canMergeWithExistingStacks))
            {
                return(0);
            }
            int   stackCount = item.stackCount;
            int   num        = Mathf.Min(stackCount, count);
            Thing thing      = item.SplitOff(num);

            if (!TryAdd((T)thing, canMergeWithExistingStacks))
            {
                if (thing != item)
                {
                    int result = stackCount - item.stackCount - thing.stackCount;
                    item.TryAbsorbStack(thing, respectStackLimit: false);
                    return(result);
                }
                return(stackCount - item.stackCount);
            }
            return(num);
        }