Exemplo n.º 1
0
        public void TransferItem([NotNull] Thing item, [NotNull] BeltItemContainer other)
        {
            _container.Remove(item);
            _thingCounter.Remove(item);

            other.AddItem(item);

            _parentComponent.OnItemTransfer(item, other._parentComponent);
        }
        internal static Thing Get(this ThingContainer _this, Thing thing, int count)
        {
            if (count > thing.stackCount)
            {
                Log.Error(string.Concat(new object[]
                {
                    "Tried to get ",
                    count,
                    " of ",
                    thing,
                    " while only having ",
                    thing.stackCount
                }));
                count = thing.stackCount;
            }
            if (count == thing.stackCount)
            {
                _this.Remove(thing);
                return(thing);
            }
            Thing thing2 = thing.SplitOff(count);

            thing2.holdingContainer = null;
            CR_Utility.TryUpdateInventory(_this.owner as Pawn_InventoryTracker);   // Item was taken from inventory, update
            return(thing2);
        }
        // swap selected equipment and primary equipment
        public void SwapEquipment(ThingWithComps thing)
        {
            // if pawn has equipped weapon
            if (owner.equipment.Primary != null)
            {
                ThingWithComps resultThing;
                // put weapon in slotter
                owner.equipment.TryTransferEquipmentToContainer(owner.equipment.Primary, slots, out resultThing);
            }
            // equip new weapon
            owner.equipment.AddEquipment(thing);
            // remove that equipment from slotter
            slots.Remove(thing);

            // interrupt current jobs to prevent random errors
            if (owner?.jobs.curJob != null)
            {
                owner.jobs.EndCurrentJob(JobCondition.InterruptForced);
            }
        }
 internal static bool TryDrop(this ThingContainer _this, Thing thing, IntVec3 dropLoc, Map map, ThingPlaceMode mode, int count, out Thing resultingThing, Action <Thing, int> placedAction = null)
 {
     if (thing.stackCount < count)
     {
         Log.Error(string.Concat(new object[]
         {
             "Tried to drop ",
             count,
             " of ",
             thing,
             " while only having ",
             thing.stackCount
         }));
         count = thing.stackCount;
     }
     if (count == thing.stackCount)
     {
         if (GenDrop.TryDropSpawn(thing, dropLoc, map, mode, out resultingThing, placedAction))
         {
             _this.Remove(thing);
             CR_Utility.TryUpdateInventory(_this.owner as Pawn_InventoryTracker);   // Thing dropped, update inventory
             return(true);
         }
         return(false);
     }
     else
     {
         Thing thing2 = thing.SplitOff(count);
         if (GenDrop.TryDropSpawn(thing2, dropLoc, map, mode, out resultingThing, placedAction))
         {
             CR_Utility.TryUpdateInventory(_this.owner as Pawn_InventoryTracker);   // Thing dropped, update inventory
             return(true);
         }
         thing.stackCount += thing2.stackCount;
         return(false);
     }
 }