Example #1
0
        public void DropItem([NotNull] Thing item, IntVec3 position, bool forced = false)
        {
            var backupSound = item.def.soundDrop;

            try
            {
                item.def.soundDrop = null;

                if (!_container.Contains(item))
                    return;

                Thing droppedItem;
                if (!_container.TryDrop(item, position, ThingPlaceMode.Direct, out droppedItem) && !forced)
                {       
                    return;
                }
                // Might prevent those "has null owner" errors...
                else if (forced && _container.Contains(item) && !_container.TryDrop(item, position, ThingPlaceMode.Near, out droppedItem))
                {
                    _container.Remove(item);
                    item.holder = null;
                    return;
                }

                // Play the sound as that isn't handled by the ThingContainer anymore...
                if (backupSound != null)
                {
                    backupSound.PlayOneShot(position);
                }

                _thingCounter.Remove(item);
                item.holder = null;

                if (droppedItem is ThingWithComps)
                {
                    droppedItem.SetForbidden(false);
                }

                if (droppedItem.def.defName.Contains("Chunk") && Find.DesignationManager.DesignationOn(droppedItem, DesignationDefOf.Haul) == null)
                {
                    // If this is a chunk AND not already haulable ("designated twice" warning) make it haulable
                    Find.DesignationManager.AddDesignation(new Designation(droppedItem, DesignationDefOf.Haul));
                }
            }
            finally
            {
                // Stupid hack to make sure the drop sound is not played all the time
                item.def.soundDrop = backupSound;
            }
        }
Example #2
0
        public virtual void Unboard(Pawn pawn)
        {
            if (storage.Count(x => x is Pawn) <= 0)
            {
                return;
            }

            if (storage.Contains(pawn))
            {
                pawn.holder = null;
                pawn.jobs.StopAll();
                Thing dummy;
                storage.TryDrop(pawn, Position, ThingPlaceMode.Near, out dummy);
            }
        }