예제 #1
0
        public int TryStartCarry(Thing item, int count, bool reserve = true)
        {
            if (this.pawn.Dead || this.pawn.Downed)
            {
                Log.Error(string.Concat(new object[]
                {
                    "Dead/downed pawn ",
                    this.pawn,
                    " tried to start carry ",
                    item.ToStringSafe <Thing>()
                }), false);
                return(0);
            }
            count = Mathf.Min(count, this.AvailableStackSpace(item.def));
            count = Mathf.Min(count, item.stackCount);
            int num = this.innerContainer.TryAdd(item.SplitOff(count), count, true);

            if (num > 0)
            {
                item.def.soundPickup.PlayOneShot(new TargetInfo(item.Position, this.pawn.Map, false));
                if (reserve)
                {
                    this.pawn.Reserve(this.CarriedThing, this.pawn.CurJob, 1, -1, null, true);
                }
            }
            return(num);
        }
예제 #2
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);
        }
 public int TryStartCarry(Thing item, int count, bool reserve = true)
 {
     if (!this.pawn.Dead && !this.pawn.Downed)
     {
         count = Mathf.Min(count, this.AvailableStackSpace(item.def));
         count = Mathf.Min(count, item.stackCount);
         int num = this.innerContainer.TryAdd(item.SplitOff(count), count, true);
         if (num > 0)
         {
             item.def.soundPickup.PlayOneShot(new TargetInfo(item.Position, this.pawn.Map, false));
             if (reserve)
             {
                 this.pawn.Reserve(this.CarriedThing, this.pawn.CurJob, 1, -1, null);
             }
         }
         return(num);
     }
     Log.Error("Dead/downed pawn " + this.pawn + " tried to start carry item.");
     return(0);
 }
예제 #5
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);
        }
        public int TryStartCarry(Thing item, int count, bool reserve = true)
        {
            if (pawn.Dead || pawn.Downed)
            {
                Log.Error(string.Concat("Dead/downed pawn ", pawn, " tried to start carry ", item.ToStringSafe()));
                return(0);
            }
            count = Mathf.Min(count, AvailableStackSpace(item.def));
            count = Mathf.Min(count, item.stackCount);
            int num = innerContainer.TryAdd(item.SplitOff(count), count);

            if (num > 0)
            {
                item.def.soundPickup.PlayOneShot(new TargetInfo(item.Position, pawn.Map));
                if (reserve)
                {
                    pawn.Reserve(CarriedThing, pawn.CurJob);
                }
            }
            return(num);
        }
        public override bool TryAdd(Thing item, bool canMergeWithExistingStacks = true)
        {
            if (item == null)
            {
                Log.Warning("Tried to add null item to ThingOwner.", false);
                return(false);
            }
            T t = item as T;

            if (t == null)
            {
                return(false);
            }
            if (base.Contains(item))
            {
                Log.Warning("Tried to add " + item.ToStringSafe <Thing>() + " to ThingOwner but this item is already here.", false);
                return(false);
            }
            if (item.holdingOwner != null)
            {
                Log.Warning(string.Concat(new string[]
                {
                    "Tried to add ",
                    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(false);
            }
            if (!base.CanAcceptAnyOf(item, canMergeWithExistingStacks))
            {
                return(false);
            }
            if (canMergeWithExistingStacks)
            {
                for (int i = 0; i < this.innerList.Count; i++)
                {
                    T t2 = this.innerList[i];
                    if (t2.CanStackWith(item))
                    {
                        int num = Mathf.Min(item.stackCount, t2.def.stackLimit - t2.stackCount);
                        if (num > 0)
                        {
                            Thing other      = item.SplitOff(num);
                            int   stackCount = t2.stackCount;
                            t2.TryAbsorbStack(other, true);
                            if (t2.stackCount > stackCount)
                            {
                                base.NotifyAddedAndMergedWith(t2, t2.stackCount - stackCount);
                            }
                            if (item.Destroyed || item.stackCount == 0)
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
            if (this.Count >= this.maxStacks)
            {
                return(false);
            }
            item.holdingOwner = this;
            this.innerList.Add(t);
            base.NotifyAdded(t);
            return(true);
        }
예제 #8
0
        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 = item as T;

            if (val == null)
            {
                return(false);
            }
            if (Contains(item))
            {
                Log.Warning("Tried to add " + item.ToStringSafe() + " to ThingOwner but this item is already here.");
                return(false);
            }
            if (item.holdingOwner != null)
            {
                Log.Warning("Tried to add " + 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(false);
            }
            if (!CanAcceptAnyOf(item, canMergeWithExistingStacks))
            {
                return(false);
            }
            if (canMergeWithExistingStacks)
            {
                for (int i = 0; i < innerList.Count; i++)
                {
                    T val2 = innerList[i];
                    if (val2.CanStackWith(item))
                    {
                        int num = Mathf.Min(item.stackCount, val2.def.stackLimit - val2.stackCount);
                        if (num > 0)
                        {
                            Thing other      = item.SplitOff(num);
                            int   stackCount = val2.stackCount;
                            val2.TryAbsorbStack(other, respectStackLimit: true);
                            if (val2.stackCount > stackCount)
                            {
                                NotifyAddedAndMergedWith(val2, val2.stackCount - stackCount);
                            }
                            if (item.Destroyed || item.stackCount == 0)
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
            if (Count >= maxStacks)
            {
                return(false);
            }
            item.holdingOwner = this;
            innerList.Add(val);
            NotifyAdded(val);
            return(true);
        }
예제 #9
0
        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);
        }