コード例 #1
0
 public static bool TryDropSpawn(Thing thing, IntVec3 dropCell, Map map, ThingPlaceMode mode, out Thing resultingThing, Action <Thing, int> placedAction = null, Predicate <IntVec3> nearPlaceValidator = null)
 {
     if (map == null)
     {
         Log.Error("Dropped " + thing + " in a null map.");
         resultingThing = null;
         return(false);
     }
     if (!dropCell.InBounds(map))
     {
         Log.Error("Dropped " + thing + " out of bounds at " + dropCell);
         resultingThing = null;
         return(false);
     }
     if (thing.def.destroyOnDrop)
     {
         thing.Destroy();
         resultingThing = null;
         return(true);
     }
     if (thing.def.soundDrop != null)
     {
         thing.def.soundDrop.PlayOneShot(new TargetInfo(dropCell, map));
     }
     return(GenPlace.TryPlaceThing(thing, dropCell, map, mode, out resultingThing, placedAction, nearPlaceValidator));
 }
コード例 #2
0
ファイル: GenDrop.cs プロジェクト: sachdevs/RW-Decompile
 public static bool TryDropSpawn(Thing thing, IntVec3 dropCell, Map map, ThingPlaceMode mode, out Thing resultingThing, Action <Thing, int> placedAction = null)
 {
     if (map == null)
     {
         Log.Error("Dropped " + thing + " in a null map.");
         resultingThing = null;
         return(false);
     }
     if (!dropCell.InBounds(map))
     {
         Log.Error(string.Concat(new object[]
         {
             "Dropped ",
             thing,
             " out of bounds at ",
             dropCell
         }));
         resultingThing = null;
         return(false);
     }
     if (thing.def.destroyOnDrop)
     {
         thing.Destroy(DestroyMode.Vanish);
         resultingThing = null;
         return(true);
     }
     if (thing.def.soundDrop != null)
     {
         thing.def.soundDrop.PlayOneShot(new TargetInfo(dropCell, map, false));
     }
     return(GenPlace.TryPlaceThing(thing, dropCell, map, mode, out resultingThing, placedAction));
 }
コード例 #3
0
 // duplicated to make changes
 public bool TryDropSpawn(Thing thing, IntVec3 dropCell, ThingPlaceMode mode, out Thing resultingThing)
 {
     if (!dropCell.InBounds())
     {
         Log.Error(string.Concat(new object[]
         {
             "Dropped ",
             thing,
             " out of bounds at ",
             dropCell
         }));
         resultingThing = null;
         return(false);
     }
     if (thing.def.destroyOnDrop)
     {
         thing.Destroy(DestroyMode.Vanish);
         resultingThing = null;
         return(true);
     }
     if (thing.def.soundDrop != null)
     {
         thing.def.soundDrop.PlayOneShot(dropCell);
     }
     // call duplicated to make changes
     return(TryPlaceThing(thing, dropCell, mode, out resultingThing));
 }
コード例 #4
0
 public static void Postfix(Pawn_CarryTracker __instance, IntVec3 dropLoc, ThingPlaceMode mode,
                            Thing resultingThing, Action <Thing, int> placedAction = null)
 {
     if (resultingThing.IsForbidden(Faction.OfPlayer) && __instance.pawn.IsPrisonerOfColony)
     {
         resultingThing.SetForbidden(false);
     }
 }
コード例 #5
0
        static void Postfix(Thing thing, IntVec3 dropCell, Map map, ThingPlaceMode mode, Thing resultingThing, Action <Thing, int> placedAction, Predicate <IntVec3> nearPlaceValidator)
        {
            CompStripChecker UChecker = resultingThing.TryGetComp <CompStripChecker>();

            if (UChecker != null)
            {
                UChecker.ShouldStrip = false;
            }
        }
コード例 #6
0
        public static bool DropItem(this Pawn pawn, IntVec3 DropLoc, ThingPlaceMode mode, out Thing resultingThing, Action <Thing, int> placedAction = null)
        {
            if (pawn?.carryTracker?.CarriedThing != null)
            {
                return(pawn.carryTracker.TryDropCarriedThing(DropLoc, mode, out resultingThing, placedAction));
            }

            resultingThing = null;
            return(false);
        }
コード例 #7
0
ファイル: Patches_GenDrop.cs プロジェクト: Ratysz/RT_Storage
        static bool TryPlaceThing(Thing thing, IntVec3 dropCell, Map map, ThingPlaceMode mode,
                                  out Thing resultingThing, Action <Thing, int> placedAction = null)
        {
            Comp_StorageInput comp = dropCell.GetStorageComponent <Comp_StorageInput>(map);

            if (comp != null)
            {
                return(comp.Store(thing, out resultingThing, placedAction));
            }
            return(GenPlace.TryPlaceThing(thing, dropCell, map, mode, out resultingThing, placedAction));
        }
コード例 #8
0
ファイル: AQUtility.cs プロジェクト: Cody-Spring/Aquarium
 // Token: 0x0600000F RID: 15 RVA: 0x00002834 File Offset: 0x00000A34
 internal static void DoSpawnTropicalFishMeat(Thing parent, int age)
 {
     if (parent.Spawned && (parent?.Map) != null)
     {
         int            stack  = Math.Max(1, (int)Mathf.Lerp(1f, 10f, age / (float)CompAquarium.oldFishAge));
         ThingPlaceMode TPMode = ThingPlaceMode.Near;
         Thing          thing  = ThingMaker.MakeThing(ThingDef.Named("AQFishMeat"), null);
         thing.stackCount = Math.Min(thing.def.stackLimit, stack);
         GenPlace.TryPlaceThing(thing, parent.Position, parent.Map, TPMode, null, null, default);
     }
 }
コード例 #9
0
        public static bool TryPlaceThing(Thing thing, IntVec3 center, Map map, ThingPlaceMode mode, out Thing lastResultingThing, Action <Thing, int> placedAction = null, Predicate <IntVec3> nearPlaceValidator = null)
        {
            if (map == null)
            {
                Log.Error("Tried to place thing " + thing + " in a null map.", false);
                lastResultingThing = null;
                return(false);
            }
            if (thing.def.category == ThingCategory.Filth)
            {
                mode = ThingPlaceMode.Direct;
            }
            if (mode == ThingPlaceMode.Direct)
            {
                return(GenPlace.TryPlaceDirect(thing, center, map, out lastResultingThing, placedAction));
            }
            if (mode == ThingPlaceMode.Near)
            {
                lastResultingThing = null;
                for (;;)
                {
                    int     stackCount = thing.stackCount;
                    IntVec3 loc;
                    if (!GenPlace.TryFindPlaceSpotNear(center, map, thing, true, out loc, nearPlaceValidator))
                    {
                        break;
                    }
                    if (GenPlace.TryPlaceDirect(thing, loc, map, out lastResultingThing, placedAction))
                    {
                        return(true);
                    }
                    if (thing.stackCount == stackCount)
                    {
                        goto Block_7;
                    }
                }
                return(false);

Block_7:
                Log.Error(string.Concat(new object[]
                {
                    "Failed to place ",
                    thing,
                    " at ",
                    center,
                    " in mode ",
                    mode,
                    "."
                }), false);
                lastResultingThing = null;
                return(false);
            }
            throw new InvalidOperationException();
        }
コード例 #10
0
 public bool TryDropCarriedThing(IntVec3 dropLoc, int count, ThingPlaceMode mode, out Thing resultingThing, Action <Thing, int> placedAction = null)
 {
     if (this.innerContainer.TryDrop(this.CarriedThing, dropLoc, this.pawn.MapHeld, mode, count, out resultingThing, placedAction, null))
     {
         if (resultingThing != null && this.pawn.Faction.HostileTo(Faction.OfPlayer))
         {
             resultingThing.SetForbidden(true, false);
         }
         return(true);
     }
     return(false);
 }
コード例 #11
0
        public bool TryDrop(Thing thing, IntVec3 dropLoc, Map map, ThingPlaceMode mode, int count, out Thing resultingThing, Action <Thing, int> placedAction = null, Predicate <IntVec3> nearPlaceValidator = null)
        {
            bool result;

            if (!this.Contains(thing))
            {
                Log.Error("Tried to drop " + thing.ToStringSafe <Thing>() + " but it's not here.", false);
                resultingThing = null;
                result         = false;
            }
            else
            {
                if (thing.stackCount < count)
                {
                    Log.Error(string.Concat(new object[]
                    {
                        "Tried to drop ",
                        count,
                        " of ",
                        thing,
                        " while only having ",
                        thing.stackCount
                    }), false);
                    count = thing.stackCount;
                }
                if (count == thing.stackCount)
                {
                    if (GenDrop.TryDropSpawn(thing, dropLoc, map, mode, out resultingThing, placedAction, nearPlaceValidator))
                    {
                        this.Remove(thing);
                        result = true;
                    }
                    else
                    {
                        result = false;
                    }
                }
                else
                {
                    Thing thing2 = thing.SplitOff(count);
                    if (GenDrop.TryDropSpawn(thing2, dropLoc, map, mode, out resultingThing, placedAction, nearPlaceValidator))
                    {
                        result = true;
                    }
                    else
                    {
                        thing.TryAbsorbStack(thing2, false);
                        result = false;
                    }
                }
            }
            return(result);
        }
コード例 #12
0
 public bool TryDropCarriedThing(IntVec3 dropLoc, ThingPlaceMode mode, out Thing resultingThing, Action <Thing, int> placedAction = null)
 {
     if (innerContainer.TryDrop(CarriedThing, dropLoc, pawn.MapHeld, mode, out resultingThing, placedAction))
     {
         if (resultingThing != null && pawn.Faction.HostileTo(Faction.OfPlayer))
         {
             resultingThing.SetForbidden(value: true, warnOnFail: false);
         }
         return(true);
     }
     return(false);
 }
コード例 #13
0
 public static bool TryDropAndSetForbidden(Thing th, IntVec3 pos, Map map, ThingPlaceMode mode, out Thing resultingThing, bool forbidden)
 {
     if (GenDrop.TryDropSpawn(th, pos, map, ThingPlaceMode.Near, out resultingThing, (Action <Thing, int>)null))
     {
         if (resultingThing != null)
         {
             resultingThing.SetForbidden(forbidden, false);
         }
         return(true);
     }
     resultingThing = null;
     return(false);
 }
コード例 #14
0
 // duplicated to make changes
 public bool TryDropCarriedThing(Pawn actor, IntVec3 dropLoc, ThingPlaceMode mode, out Thing resultingThing)
 {
     // call duplicated to make changes
     if (TryDrop(actor, actor.carrier.CarriedThing, dropLoc, mode, out resultingThing))
     {
         if (actor.Faction.HostileTo(Faction.OfColony))
         {
             resultingThing.SetForbidden(true, false);
         }
         return(true);
     }
     return(false);
 }
コード例 #15
0
 public static bool TryDropAndSetForbidden(Thing th, IntVec3 pos, Map map, ThingPlaceMode mode, out Thing resultingThing, bool forbidden)
 {
     if (GenDrop.TryDropSpawn_NewTmp(th, pos, map, ThingPlaceMode.Near, out resultingThing))
     {
         if (resultingThing != null)
         {
             resultingThing.SetForbidden(forbidden, warnOnFail: false);
         }
         return(true);
     }
     resultingThing = null;
     return(false);
 }
コード例 #16
0
        public bool TryDrop(Thing thing, ThingPlaceMode mode, out Thing lastResultingThing, Action <Thing, int> placedAction = null, Predicate <IntVec3> nearPlaceValidator = null)
        {
            Map     rootMap      = ThingOwnerUtility.GetRootMap(this.owner);
            IntVec3 rootPosition = ThingOwnerUtility.GetRootPosition(this.owner);

            if (rootMap == null || !rootPosition.IsValid)
            {
                Log.Error("Cannot drop " + thing + " without a dropLoc and with an owner whose map is null.", false);
                lastResultingThing = null;
                return(false);
            }
            return(this.TryDrop(thing, rootPosition, rootMap, mode, out lastResultingThing, placedAction, nearPlaceValidator));
        }
コード例 #17
0
        public static Toil DropTheCarriedInCell(TargetIndex StoreCellInd, ThingPlaceMode placeMode, TargetIndex CarrierInd)
        {
            Toil toil = new Toil();

            toil.initAction = () =>
            {
                Pawn         actor   = toil.actor;
                Job          curJob  = actor.jobs.curJob;
                Vehicle_Cart carrier = actor.jobs.curJob.GetTarget(CarrierInd).Thing as Vehicle_Cart;
                if (carrier.storage.Count <= 0)
                {
                    return;
                }
                toil.actor.jobs.curJob.SetTarget(TargetIndex.A, carrier.storage.First());
                Thing   dropThing = toil.actor.jobs.curJob.targetA.Thing;
                IntVec3 destLoc   = actor.jobs.curJob.GetTarget(StoreCellInd).Cell;
                Thing   dummy;

                SlotGroup slotGroup = Find.SlotGroupManager.SlotGroupAt(destLoc);
                //    if (destLoc.GetStorable() == null)
                if (slotGroup != null && slotGroup.Settings.AllowedToAccept(dropThing))
                {
                    Find.DesignationManager.RemoveAllDesignationsOn(dropThing);
                    carrier.storage.TryDrop(dropThing, destLoc, placeMode, out dummy);
                }

                //Check cell queue is adjacent
                List <TargetInfo> cells = curJob.GetTargetQueue(StoreCellInd);
                for (int i = 0; i < cells.Count && i < carrier.storage.Count; i++)
                {
                    if (destLoc.AdjacentTo8Way(cells[i].Cell) && cells[i].Cell.GetStorable() == null)
                    {
                        Find.DesignationManager.RemoveAllDesignationsOn(carrier.storage[i]);
                        carrier.storage.TryDrop(carrier.storage[i], cells[i].Cell, ThingPlaceMode.Direct, out dummy);
                        cells.RemoveAt(i);
                        i--;
                    }
                }
                //Check item queue is valid storage for adjacent cell
                foreach (IntVec3 adjCell in GenAdj.CellsAdjacent8Way(destLoc))
                {
                    if (carrier.storage.Count > 0 && adjCell.GetStorable() == null && adjCell.IsValidStorageFor(carrier.storage.First()))
                    {
                        Find.DesignationManager.RemoveAllDesignationsOn(carrier.storage.First());
                        carrier.storage.TryDrop(carrier.storage.First(), adjCell, ThingPlaceMode.Direct, out dummy);
                    }
                }
            };
            toil.FailOnDestroyedOrNull(CarrierInd);
            return(toil);
        }
コード例 #18
0
        // duplicated to make changes
        public bool TryPlaceThing(Thing thing, IntVec3 center, ThingPlaceMode mode, out Thing lastResultingThing)
        {
            if (thing.def.category == ThingCategory.Filth)
            {
                mode = ThingPlaceMode.Direct;
            }
            if (mode == ThingPlaceMode.Direct)
            {
                // call duplicated to make changes
                return(TryPlaceDirect(thing, center, out lastResultingThing));
            }
            if (mode == ThingPlaceMode.Near)
            {
                lastResultingThing = null;
                while (true)
                {
                    int     stackCount = thing.stackCount;
                    IntVec3 loc;
                    // call duplicated cause vanilla is private
                    if (!TryFindPlaceSpotNear(center, thing, out loc))
                    {
                        break;
                    }
                    // call duplicated to make changes
                    if (TryPlaceDirect(thing, loc, out lastResultingThing))
                    {
                        return(true);
                    }
                    if (thing.stackCount == stackCount)
                    {
                        goto Block_6;
                    }
                }
                return(false);

Block_6:
                Log.Error(string.Concat(new object[]
                {
                    "Failed to place ",
                    thing,
                    " at ",
                    center,
                    " in mode ",
                    mode,
                    "."
                }));
                lastResultingThing = null;
                return(false);
            }
            throw new InvalidOperationException();
        }
コード例 #19
0
        public static Toil DropAllInCell(TargetIndex StoreCellInd, ThingPlaceMode placeMode)
        {
            Toil toil = new Toil();

            toil.initAction = () =>
            {
                Pawn    actor   = toil.actor;
                Job     curJob  = actor.jobs.curJob;
                IntVec3 destLoc = actor.jobs.curJob.GetTarget(StoreCellInd).Cell;

                actor.inventory.container.TryDropAll(destLoc, placeMode);
            };
            return(toil);
        }
コード例 #20
0
        public bool TryDropAll(IntVec3 dropLoc, Map map, ThingPlaceMode mode, Action <Thing, int> placeAction = null, Predicate <IntVec3> nearPlaceValidator = null)
        {
            bool result = true;

            for (int i = this.Count - 1; i >= 0; i--)
            {
                Thing thing;
                if (!this.TryDrop(this.GetAt(i), dropLoc, map, mode, out thing, placeAction, nearPlaceValidator))
                {
                    result = false;
                }
            }
            return(result);
        }
コード例 #21
0
        // Verse.Pawn_HealthTracker
        public static bool DontWarnOnNonExistingThings(ref bool __result, ref ThingOwner __instance, Thing thing,
                                                       IntVec3 dropLoc, Map map, ThingPlaceMode mode, out Thing lastResultingThing,
                                                       Action <Thing, int> placedAction = null, Predicate <IntVec3> nearPlaceValidator = null,
                                                       bool playDropSound = true)
        {
            lastResultingThing = null;
            if (!__instance.Contains(thing))
            {
                return(true);
            }

            __result = false;
            return(false);
        }
コード例 #22
0
 public bool TryDrop(Thing thing, IntVec3 dropLoc, Map map, ThingPlaceMode mode, out Thing lastResultingThing, Action <Thing, int> placedAction = null, Predicate <IntVec3> nearPlaceValidator = null)
 {
     if (!this.Contains(thing))
     {
         Log.Error(this.owner.ToStringSafe <IThingHolder>() + " container tried to drop  " + thing.ToStringSafe <Thing>() + " which it didn't contain.", false);
         lastResultingThing = null;
         return(false);
     }
     if (GenDrop.TryDropSpawn(thing, dropLoc, map, mode, out lastResultingThing, placedAction, nearPlaceValidator))
     {
         this.Remove(thing);
         return(true);
     }
     return(false);
 }
コード例 #23
0
        public static Toil DropTheCarriedInCell(TargetIndex StoreCellInd, ThingPlaceMode placeMode)
        {
            Toil toil = new Toil();

            toil.initAction = () =>
            {
                Pawn actor  = toil.actor;
                Job  curJob = actor.jobs.curJob;
                if (actor.inventory.container.Count <= 0)
                {
                    return;
                }
                toil.actor.jobs.curJob.SetTarget(TargetIndex.A, actor.inventory.container.First());
                Thing   dropThing = toil.actor.jobs.curJob.targetA.Thing;
                IntVec3 destLoc   = actor.jobs.curJob.GetTarget(StoreCellInd).Cell;
                Thing   dummy;

                if (destLoc.GetStorable() == null)
                {
                    Find.DesignationManager.RemoveAllDesignationsOn(dropThing);
                    actor.inventory.container.TryDrop(dropThing, destLoc, placeMode, out dummy);
                }

                //Check cell queue is adjacent
                List <TargetInfo> cells = curJob.GetTargetQueue(StoreCellInd);
                for (int i = 0; i < cells.Count && i < actor.inventory.container.Count; i++)
                {
                    if (destLoc.AdjacentTo8Way(cells[i].Cell) && cells[i].Cell.GetStorable() == null)
                    {
                        Find.DesignationManager.RemoveAllDesignationsOn(actor.inventory.container[i]);
                        actor.inventory.container.TryDrop(actor.inventory.container[i], cells[i].Cell, ThingPlaceMode.Direct, out dummy);
                        cells.RemoveAt(i);
                        i--;
                    }
                }
                //Check item queue is valid storage for adjacent cell
                foreach (IntVec3 adjCell in GenAdj.CellsAdjacent8Way(destLoc))
                {
                    if (actor.inventory.container.Count > 0 && adjCell.GetStorable() == null && StoreUtility.IsValidStorageFor(adjCell, actor.inventory.container.First()))
                    {
                        Find.DesignationManager.RemoveAllDesignationsOn(actor.inventory.container.First());
                        actor.inventory.container.TryDrop(actor.inventory.container.First(), adjCell, ThingPlaceMode.Direct, out dummy);
                    }
                }
            };
            return(toil);
        }
コード例 #24
0
        public static bool TryPlaceThing(Thing thing, IntVec3 center, Map map, ThingPlaceMode mode, out Thing lastResultingThing, Action <Thing, int> placedAction = null)
        {
            if (map == null)
            {
                Log.Error("Tried to place thing " + thing + " in a null map.");
                lastResultingThing = null;
                return(false);
            }
            if (thing.def.category == ThingCategory.Filth)
            {
                mode = ThingPlaceMode.Direct;
            }
            switch (mode)
            {
            case ThingPlaceMode.Direct:
                return(GenPlace.TryPlaceDirect(thing, center, map, out lastResultingThing, placedAction));

            case ThingPlaceMode.Near:
            {
                lastResultingThing = null;
                int num = -1;
                while (true)
                {
                    num = thing.stackCount;
                    IntVec3 loc = default(IntVec3);
                    if (!GenPlace.TryFindPlaceSpotNear(center, map, thing, true, out loc))
                    {
                        return(false);
                    }
                    if (GenPlace.TryPlaceDirect(thing, loc, map, out lastResultingThing, placedAction))
                    {
                        return(true);
                    }
                    if (thing.stackCount == num)
                    {
                        break;
                    }
                }
                Log.Error("Failed to place " + thing + " at " + center + " in mode " + mode + ".");
                lastResultingThing = null;
                return(false);
            }

            default:
                throw new InvalidOperationException();
            }
        }
コード例 #25
0
        public bool TryDrop(Thing thing, IntVec3 dropLoc, Map map, ThingPlaceMode mode, out T lastResultingThing, Action <T, int> placedAction = null, Predicate <IntVec3> nearPlaceValidator = null)
        {
            Action <Thing, int> placedAction2 = null;

            if (placedAction != null)
            {
                placedAction2 = delegate(Thing t, int c)
                {
                    placedAction((T)((object)t), c);
                };
            }
            Thing thing2;
            bool  result = base.TryDrop(thing, dropLoc, map, mode, out thing2, placedAction2, nearPlaceValidator);

            lastResultingThing = (T)((object)thing2);
            return(result);
        }
コード例 #26
0
        public bool TryDrop(Thing thing, IntVec3 dropLoc, Map map, ThingPlaceMode mode, out T lastResultingThing, Action <T, int> placedAction = null)
        {
            Action <Thing, int> placedAction2 = null;

            if (placedAction != null)
            {
                placedAction2 = delegate(Thing t, int c)
                {
                    placedAction((T)t, c);
                };
            }
            Thing thing2 = default(Thing);
            bool  result = base.TryDrop(thing, dropLoc, map, mode, out thing2, placedAction2);

            lastResultingThing = (T)thing2;
            return(result);
        }
コード例 #27
0
        public bool TryDrop(Thing thing, IntVec3 dropLoc, Map map, ThingPlaceMode mode, int count, out T resultingThing, Action <T, int> placedAction = null, Predicate <IntVec3> nearPlaceValidator = null)
        {
            Action <Thing, int> placedAction2 = null;

            if (placedAction != null)
            {
                placedAction2 = delegate(Thing t, int c)
                {
                    placedAction((T)t, c);
                };
            }
            Thing resultingThing2;
            bool  result = TryDrop(thing, dropLoc, map, mode, count, out resultingThing2, placedAction2, nearPlaceValidator);

            resultingThing = (T)resultingThing2;
            return(result);
        }
コード例 #28
0
        public bool SneakyMoveToInventory(IntVec3 dropLoc, ThingPlaceMode mode, out Thing resultingThing, Action <Thing, int> placedAction = null)
        {
            CompUnloadChecker cuc = CarriedThing.TryGetComp <CompUnloadChecker>();
            Thing             r   = null;
            bool b;

            if (cuc == null || !cuc.WasInInventory)
            {
                b = TryDropCarriedThing(dropLoc, mode, out r, placedAction);
                resultingThing = r;
                return(b);
            }

            b = innerContainer.TryTransferToContainer(CarriedThing, pawn.inventory.innerContainer, true);
            resultingThing = CarriedThing;
            return(b);
        }
コード例 #29
0
        public static Toil DropTheCarriedInCell(TargetIndex StoreCellInd, ThingPlaceMode placeMode, Thing lastItem)
        {
            Toil toil = new Toil();

            toil.initAction = () =>
            {
                Pawn actor  = toil.actor;
                Job  curJob = actor.jobs.curJob;
                if (actor.inventory.container.Count <= 0)
                {
                    return;
                }

                //Check dropThing is last item that should not be dropped
                Thing dropThing = null;
                if (lastItem != null)
                {
                    for (int i = 0; i + 1 < actor.inventory.container.Count; i++)
                    {
                        if (actor.inventory.container[i] == lastItem)
                        {
                            dropThing = actor.inventory.container[i + 1];
                        }
                        else if (lastItem == null && actor.inventory.container.Count > 0)
                        {
                            dropThing = actor.inventory.container.First();
                        }
                    }
                }

                if (dropThing == null)
                {
                    //Log.Error(toil.actor + "try drop null thing in " + actor.jobs.curJob.GetTarget(StoreCellInd).Cell);
                    return;
                }
                IntVec3 destLoc = actor.jobs.curJob.GetTarget(StoreCellInd).Cell;
                Thing   dummy;

                if (destLoc.GetStorable() == null)
                {
                    Find.DesignationManager.RemoveAllDesignationsOn(dropThing);
                    actor.inventory.container.TryDrop(dropThing, destLoc, placeMode, out dummy);
                }
            };
            return(toil);
        }
コード例 #30
0
        public bool TryDrop(Thing thing, ThingPlaceMode mode, out T lastResultingThing, Action <T, int> placedAction = null, Predicate <IntVec3> nearPlaceValidator = null)
        {
            Action <Thing, int> placedAction2 = null;

            if (placedAction != null)
            {
                placedAction2 = delegate(Thing t, int c)
                {
                    placedAction((T)t, c);
                };
            }
            Thing lastResultingThing2;
            bool  result = TryDrop(thing, mode, out lastResultingThing2, placedAction2, nearPlaceValidator);

            lastResultingThing = (T)lastResultingThing2;
            return(result);
        }
コード例 #31
0
ファイル: Toils_Collect.cs プロジェクト: BBream/ToolsForHaul
        public static Toil DropAllInCell(TargetIndex StoreCellInd, ThingPlaceMode placeMode)
        {
            Toil toil = new Toil();
            toil.initAction = () =>
            {
            Pawn actor = toil.actor;
            Job curJob = actor.jobs.curJob;
            IntVec3 destLoc = actor.jobs.curJob.GetTarget(StoreCellInd).Cell;

            actor.inventory.container.TryDropAll(destLoc, placeMode);
            };
            return toil;
        }
コード例 #32
0
 // duplicated to make changes
 public bool TryPlaceThing(Thing thing, IntVec3 center, ThingPlaceMode mode, out Thing lastResultingThing)
 {
     if (thing.def.category == ThingCategory.Filth)
     {
         mode = ThingPlaceMode.Direct;
     }
     if (mode == ThingPlaceMode.Direct)
     {
         // call duplicated to make changes
         return TryPlaceDirect(thing, center, out lastResultingThing);
     }
     if (mode == ThingPlaceMode.Near)
     {
         lastResultingThing = null;
         while (true)
         {
             int stackCount = thing.stackCount;
             IntVec3 loc;
             // call duplicated cause vanilla is private
             if (!TryFindPlaceSpotNear(center, thing, out loc))
             {
                 break;
             }
             // call duplicated to make changes
             if (TryPlaceDirect(thing, loc, out lastResultingThing))
             {
                 return true;
             }
             if (thing.stackCount == stackCount)
             {
                 goto Block_6;
             }
         }
         return false;
         Block_6:
         Log.Error(string.Concat(new object[]
         {
             "Failed to place ",
             thing,
             " at ",
             center,
             " in mode ",
             mode,
             "."
         }));
         lastResultingThing = null;
         return false;
     }
     throw new InvalidOperationException();
 }
コード例 #33
0
 // duplicated to make changes
 public bool TryDrop(Pawn actor, Thing thing, IntVec3 dropLoc, ThingPlaceMode mode, out Thing lastResultingThing)
 {
     if (!actor.carrier.container.Contains(thing))
     {
         Log.Error(string.Concat(new object[]
         {
             actor.carrier.container.owner,
             " container tried to drop  ",
             thing,
             " which it didn't contain."
         }));
         lastResultingThing = null;
         return false;
     }
     // call duplicated to make changes
     if (TryDropSpawn(thing, dropLoc, mode, out lastResultingThing))
     {
         actor.carrier.container.Remove(thing);
         return true;
     }
     return false;
 }
コード例 #34
0
 // duplicated to make changes
 public bool TryDropCarriedThing(Pawn actor, IntVec3 dropLoc, ThingPlaceMode mode, out Thing resultingThing)
 {
     // call duplicated to make changes
     if (TryDrop(actor, actor.carrier.CarriedThing, dropLoc, mode, out resultingThing))
     {
         if (actor.Faction.HostileTo(Faction.OfColony))
         {
             resultingThing.SetForbidden(true, false);
         }
         return true;
     }
     return false;
 }
コード例 #35
0
ファイル: Toils_Collect.cs プロジェクト: BBream/ToolsForHaul
        public static Toil DropTheCarriedInCell(TargetIndex StoreCellInd, ThingPlaceMode placeMode, Thing lastItem)
        {
            Toil toil = new Toil();
            toil.initAction = () =>
            {
            Pawn actor = toil.actor;
            Job curJob = actor.jobs.curJob;
            if (actor.inventory.container.Count <= 0)
                return;

            //Check dropThing is last item that should not be dropped
            Thing dropThing = null;
            if (lastItem != null)
                for (int i = 0; i + 1 < actor.inventory.container.Count; i++)
                    if (actor.inventory.container[i] == lastItem)
                        dropThing = actor.inventory.container[i + 1];
            else if (lastItem == null && actor.inventory.container.Count > 0)
                dropThing = actor.inventory.container.First();

            if (dropThing == null)
            {
                //Log.Error(toil.actor + "try drop null thing in " + actor.jobs.curJob.GetTarget(StoreCellInd).Cell);
                return;
            }
            IntVec3 destLoc = actor.jobs.curJob.GetTarget(StoreCellInd).Cell;
            Thing dummy;

            if (destLoc.GetStorable() == null)
            {
                Find.DesignationManager.RemoveAllDesignationsOn(dropThing);
                actor.inventory.container.TryDrop(dropThing, destLoc, placeMode, out dummy);
            }
            };
            return toil;
        }
コード例 #36
0
ファイル: Toils_Collect.cs プロジェクト: BBream/ToolsForHaul
        public static Toil DropTheCarriedInCell(TargetIndex StoreCellInd, ThingPlaceMode placeMode, TargetIndex CarrierInd)
        {
            Toil toil = new Toil();
            toil.initAction = () =>
            {
            Pawn actor = toil.actor;
            Job curJob = actor.jobs.curJob;
            Vehicle_Cart carrier = actor.jobs.curJob.GetTarget(CarrierInd).Thing as Vehicle_Cart;
            if (carrier.storage.Count <= 0)
                return;
            toil.actor.jobs.curJob.SetTarget(TargetIndex.A, carrier.storage.First());
            Thing dropThing = toil.actor.jobs.curJob.targetA.Thing;
            IntVec3 destLoc = actor.jobs.curJob.GetTarget(StoreCellInd).Cell;
            Thing dummy;

            if (destLoc.GetStorable() == null)
            {
                Find.DesignationManager.RemoveAllDesignationsOn(dropThing);
                carrier.storage.TryDrop(dropThing, destLoc, placeMode, out dummy);
            }

            //Check cell queue is adjacent
            List<TargetInfo> cells = curJob.GetTargetQueue(StoreCellInd);
            for (int i = 0; i < cells.Count && i < carrier.storage.Count; i++)
                if (destLoc.AdjacentTo8Way(cells[i].Cell) && cells[i].Cell.GetStorable() == null)
                {
                    Find.DesignationManager.RemoveAllDesignationsOn(carrier.storage[i]);
                    carrier.storage.TryDrop(carrier.storage[i], cells[i].Cell, ThingPlaceMode.Direct, out dummy);
                    cells.RemoveAt(i);
                    i--;
                }
            //Check item queue is valid storage for adjacent cell
            foreach (IntVec3 adjCell in GenAdj.CellsAdjacent8Way(destLoc))
                if (carrier.storage.Count > 0 && adjCell.GetStorable() == null && StoreUtility.IsValidStorageFor(adjCell, carrier.storage.First()))
                {
                    Find.DesignationManager.RemoveAllDesignationsOn(carrier.storage.First());
                    carrier.storage.TryDrop(carrier.storage.First(), adjCell, ThingPlaceMode.Direct, out dummy);
                }
            };
            toil.FailOnDespawned(CarrierInd);
            return toil;
        }
コード例 #37
0
 // duplicated to make changes
 public bool TryDropSpawn(Thing thing, IntVec3 dropCell, ThingPlaceMode mode, out Thing resultingThing)
 {
     if (!dropCell.InBounds())
     {
         Log.Error(string.Concat(new object[]
         {
             "Dropped ",
             thing,
             " out of bounds at ",
             dropCell
         }));
         resultingThing = null;
         return false;
     }
     if (thing.def.destroyOnDrop)
     {
         thing.Destroy(DestroyMode.Vanish);
         resultingThing = null;
         return true;
     }
     if (thing.def.soundDrop != null)
     {
         thing.def.soundDrop.PlayOneShot(dropCell);
     }
     // call duplicated to make changes
     return TryPlaceThing(thing, dropCell, mode, out resultingThing);
 }