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 (base.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 " + Gen.ToStringSafe <Thing>(item) + " to ThingOwner but this thing is already in another container. owner=" + Gen.ToStringSafe <IThingHolder>(base.owner) + ", current container owner=" + Gen.ToStringSafe <IThingHolder>(item.holdingOwner.Owner) + ". Use TryAddOrTransfer, TryTransferToContainer, or remove the item before adding it."); return(0); } if (!this.CanAcceptAnyOf(item, canMergeWithExistingStacks)) { return(0); } int stackCount = item.stackCount; int num = Mathf.Min(stackCount, count); Thing thing = item.SplitOff(num); if (!this.TryAdd((Thing)(object)(T)thing, canMergeWithExistingStacks)) { if (thing != item) { int result = stackCount - item.stackCount - thing.stackCount; item.TryAbsorbStack(thing, false); return(result); } return(stackCount - item.stackCount); } return(num); }
public override bool TryAdd(Thing item, bool canMergeWithExistingStacks = true) { if (item == null) { Log.Warning("Tried to add null item to ThingOwner."); return(false); } T val = (T)(item as T); if (val == null) { return(false); } if (base.Contains(item)) { Log.Warning("Tried to add " + Gen.ToStringSafe <Thing>(item) + " to ThingOwner but this item is already here."); return(false); } if (item.holdingOwner != null) { Log.Warning("Tried to add " + Gen.ToStringSafe <Thing>(item) + " to ThingOwner but this thing is already in another container. owner=" + Gen.ToStringSafe <IThingHolder>(base.owner) + ", current container owner=" + Gen.ToStringSafe <IThingHolder>(item.holdingOwner.Owner) + ". Use TryAddOrTransfer, TryTransferToContainer, or remove the item before adding it."); return(false); } if (!this.CanAcceptAnyOf(item, canMergeWithExistingStacks)) { return(false); } if (canMergeWithExistingStacks) { for (int i = 0; i < this.innerList.Count; i++) { T val2 = this.innerList[i]; if (val2.CanStackWith(item)) { int num = Mathf.Min(item.stackCount, ((Thing)(object)val2).def.stackLimit - ((Thing)(object)val2).stackCount); if (num > 0) { Thing other = item.SplitOff(num); int stackCount = ((Thing)(object)val2).stackCount; val2.TryAbsorbStack(other, true); if (((Thing)(object)val2).stackCount > stackCount) { base.NotifyAddedAndMergedWith((Thing)(object)val2, ((Thing)(object)val2).stackCount - stackCount); } if (!item.Destroyed && item.stackCount != 0) { continue; } return(true); } } } } if (this.Count >= base.maxStacks) { return(false); } item.holdingOwner = this; this.innerList.Add(val); base.NotifyAdded((Thing)(object)val); return(true); }