public static void PostFix(ref Func <int, int> __result, Thing destroyedThing, ref DestroyMode mode)
        {
            if (destroyedThing.def.defName != "MSRecoveryPod" || mode != DestroyMode.Deconstruct ||
                !(destroyedThing.def.resourcesFractionWhenDeconstructed >= 1f))
            {
                return;
            }

            if (!GenLeaving.CanBuildingLeaveResources(destroyedThing, mode))
            {
                __result = _ => 0;
                return;
            }

            if (mode == DestroyMode.Deconstruct && destroyedThing is Frame)
            {
                mode = DestroyMode.Cancel;
                return;
            }

            if (mode == DestroyMode.Deconstruct)
            {
                __result = count => count;
            }
        }
示例#2
0
            // Token: 0x06000003 RID: 3 RVA: 0x00002290 File Offset: 0x00000490
            public static Func <int, int> GBRLC(Thing t, DestroyMode d)
            {
                bool flag = !GenLeaving.CanBuildingLeaveResources(t, d);

                if (!flag)
                {
                    switch (d)
                    {
                    case DestroyMode.Vanish:
                        return((int count) => 0);

                    case DestroyMode.KillFinalize:
                        return((int count) => GenMath.RoundRandom((float)count * 0.5f));

                    case DestroyMode.Deconstruct:
                        return((int count) => GenMath.RoundRandom(Mathf.Min((float)count * t.def.resourcesFractionWhenDeconstructed, (float)count)));

                    case DestroyMode.FailConstruction:
                        return((int count) => GenMath.RoundRandom((float)count * 0.5f));

                    case DestroyMode.Cancel:
                        return((int count) => GenMath.RoundRandom((float)count * 1f));

                    case DestroyMode.Refund:
                        return((int count) => count);
                    }
                    throw new ArgumentException("Unknown destroy mode " + d + " (Deconstruct Return Fix error)");
                }
                return((int count) => 0);
            }
示例#3
0
        public static void DeconstructDropStuff(Thing oldThing)
        {
            if (Current.ProgramState != ProgramState.Playing)
            {
                return;
            }

            ThingDef oldDef   = oldThing.def;
            ThingDef stuffDef = oldThing.Stuff;

            //preferably GenLeaving.DoLeavingsFor here, but don't want to drop non-stuff things.
            if (GenLeaving.CanBuildingLeaveResources(oldThing, DestroyMode.Deconstruct))
            {
                int count      = TotalStuffNeeded(oldDef, stuffDef);
                int leaveCount = GetBuildingResourcesLeaveCalculator(oldThing, DestroyMode.Deconstruct)(count);
                if (leaveCount > 0)
                {
                    Thing leftThing = ThingMaker.MakeThing(stuffDef);
                    leftThing.stackCount = leaveCount;
#pragma warning disable CS0618 // Type or member is obsolete
                    GenDrop.TryDropSpawn(leftThing, oldThing.Position, oldThing.Map, ThingPlaceMode.Near, out Thing dummyThing);
#pragma warning restore CS0618 // Type or member is obsolete
                }
            }
        }
示例#4
0
            }//end DoLeavingsForPrefix

            public static Func <int, int> GBRLC(Thing t)
            {
                if (!GenLeaving.CanBuildingLeaveResources(t, DestroyMode.Deconstruct))
                {
                    return((int count) => 0);
                }
                return((int count) => GenMath.RoundRandom(Mathf.Min((float)count * t.def.resourcesFractionWhenDeconstructed, (float)(count)))); //other destroy modes deleted because I always know the mode
            }
示例#5
0
        private static Func <int, int> GetBuildingResourcesLeaveCalculator(Thing destroyedThing, DestroyMode mode)
        {
            if (!GenLeaving.CanBuildingLeaveResources(destroyedThing, mode))
            {
                return(_ => 0);
            }

            if (mode == DestroyMode.Deconstruct && destroyedThing is Frame)
            {
                mode = DestroyMode.Cancel;
            }

            switch (mode)
            {
            case DestroyMode.Vanish:
            {
                return(_ => 0);
            }

            case DestroyMode.WillReplace:
            {
                return(_ => 0);
            }

            case DestroyMode.KillFinalize:
            {
                return(count => GenMath.RoundRandom(count * 0.5f));
            }

            case DestroyMode.Deconstruct:
            {
                return(count =>
                       GenMath.RoundRandom(Math.Min(count * destroyedThing.def.resourcesFractionWhenDeconstructed,
                                                    count - 1)));
            }

            case DestroyMode.FailConstruction:
            {
                return(count => GenMath.RoundRandom(count * 0.5f));
            }

            case DestroyMode.Cancel:
            {
                return(count => GenMath.RoundRandom(count * 1f));
            }

            case DestroyMode.Refund:
            {
                return(count => count);
            }
            }

            throw new ArgumentException(string.Concat("Unknown destroy mode ", mode));
        }
示例#6
0
 public static void PostFix(ref Func <int, int> __result, Thing destroyedThing, DestroyMode mode)
 {
     if (destroyedThing.def.defName.StartsWith("MSMedicalMat") && mode == DestroyMode.Deconstruct && destroyedThing.def.resourcesFractionWhenDeconstructed >= 1f)
     {
         if (!GenLeaving.CanBuildingLeaveResources(destroyedThing, mode))
         {
             __result = ((int count) => 0);
             return;
         }
         if (mode == DestroyMode.Deconstruct && typeof(Frame).IsAssignableFrom(destroyedThing.GetType()))
         {
             mode = DestroyMode.Cancel;
             return;
         }
         if (mode == DestroyMode.Deconstruct)
         {
             __result = ((int count) => count);
             return;
         }
     }
 }
示例#7
0
            public static bool DoLeavingsForPrefix(Thing diedThing, Map map, DestroyMode mode, CellRect leavingsRect, Predicate <IntVec3> nearPlaceValidator = null)
            {
                if (mode != DestroyMode.Deconstruct)
                {
                    return(true);                                 //just to make it more readable
                }
                ThingOwner <Thing> thingOwner = new ThingOwner <Thing>();

                if (GenLeaving.CanBuildingLeaveResources(diedThing, mode))
                {
                    Frame frame = diedThing as Frame;
                    if (frame != null)
                    {
                        for (int frameResCt = frame.resourceContainer.Count - 1; frameResCt >= 0; frameResCt--)
                        {
                            int gblrc;
                            if ((gblrc = GBRLC(diedThing)(frame.resourceContainer[frameResCt].stackCount)) > 0)
                            {
                                frame.resourceContainer.TryTransferToContainer(frame.resourceContainer[frameResCt], thingOwner, gblrc, true);
                            }
                        }
                        frame.resourceContainer.ClearAndDestroyContents(mode);
                    }
                    else
                    {
                        // TODO: ModExtension specifying drop rates per ThingDef. Needs to be relatively optimized.
                        List <ThingDefCountClass> list = diedThing.CostListAdjusted();
                        for (int l = 0; l < list.Count; l++)
                        {
                            ThingDefCountClass tdcc = list[l];
                            int gblrc;
                            if ((gblrc = GBRLC(diedThing)(tdcc.count)) > 0)
                            {
                                Thing thing = ThingMaker.MakeThing(tdcc.thingDef, null);
                                thing.stackCount = gblrc;
                                thingOwner.TryAdd(thing, true);
                            }
                        }
                    }
                }
                List <IntVec3> cellList = leavingsRect.Cells.InRandomOrder(null).ToList();
                int            cellInd  = 0;

                while (true)
                {
                    if (thingOwner.Count > 0)
                    {
                        ThingOwner <Thing> thingOwner2 = thingOwner;
                        Thing          thing           = thingOwner[0];
                        IntVec3        dropLoc         = cellList[cellInd];
                        ThingPlaceMode mode2           = ThingPlaceMode.Near;
                        Thing          thing4          = default(Thing);
                        if (thingOwner2.TryDrop(thing, dropLoc, map, mode2, out thing4, null, nearPlaceValidator))
                        {
                            cellInd++;
                            if (cellInd >= cellList.Count)
                            {
                                cellInd = 0;
                            }
                            continue;
                        }
                        break;
                    }
                    return(false);
                }
                ULog.Warning("Deconstruct Return Fix: Failed to place all leavings for destroyed thing " + diedThing + " at " + leavingsRect.CenterCell, false);
                return(false);
            }//end DoLeavingsForPrefix
示例#8
0
            public static bool DoLeavingsForPrefix(Thing diedThing, Map map, DestroyMode mode, CellRect leavingsRect, Predicate <IntVec3> nearPlaceValidator = null, List <Thing> listOfLeavingsOut = null)
            {
                bool flag = mode == DestroyMode.Deconstruct;
                bool result;

                if (flag)
                {
                    ThingOwner <Thing> thingOwner = new ThingOwner <Thing>();
                    bool flag2 = GenLeaving.CanBuildingLeaveResources(diedThing, mode);
                    if (flag2)
                    {
                        Frame frame = diedThing as Frame;
                        bool  flag3 = frame != null;
                        if (flag3)
                        {
                            for (int i = frame.resourceContainer.Count - 1; i >= 0; i--)
                            {
                                int  num   = DeconstructReturnFix.CalcFix.GBRLC(diedThing, mode)(frame.resourceContainer[i].stackCount);
                                bool flag4 = num > 0;
                                if (flag4)
                                {
                                    frame.resourceContainer.TryTransferToContainer(frame.resourceContainer[i], thingOwner, num, true);
                                }
                            }
                            frame.resourceContainer.ClearAndDestroyContents(mode);
                        }
                        else
                        {
                            List <ThingDefCountClass> list = diedThing.CostListAdjusted();
                            for (int j = 0; j < list.Count; j++)
                            {
                                ThingDefCountClass thingDefCountClass = list[j];
                                int  num2  = DeconstructReturnFix.CalcFix.GBRLC(diedThing, mode)(thingDefCountClass.count);
                                bool flag5 = num2 > 0;
                                if (flag5)
                                {
                                    Thing thing = ThingMaker.MakeThing(thingDefCountClass.thingDef, null);
                                    thing.stackCount = num2;
                                    thingOwner.TryAdd(thing, true);
                                }
                            }
                        }
                    }
                    List <IntVec3> list2 = leavingsRect.Cells.InRandomOrder(null).ToList <IntVec3>();
                    int            num3  = 0;
                    for (;;)
                    {
                        bool flag6 = thingOwner.Count > 0;
                        if (!flag6)
                        {
                            goto IL_1B4;
                        }
                        ThingOwner <Thing> thingOwner2 = thingOwner;
                        Thing          thing2          = thingOwner[0];
                        IntVec3        dropLoc         = list2[num3];
                        ThingPlaceMode mode2           = ThingPlaceMode.Near;
                        Thing          thing3          = null;
                        bool           flag7           = thingOwner2.TryDrop(thing2, dropLoc, map, mode2, out thing3, null, nearPlaceValidator);
                        if (!flag7)
                        {
                            break;
                        }
                        num3++;
                        bool flag8 = num3 >= list2.Count;
                        if (flag8)
                        {
                            num3 = 0;
                        }
                    }
                    Log.Warning(string.Concat(new object[]
                    {
                        "Deconstruct Return Fix: Failed to place all leavings for destroyed thing ",
                        diedThing,
                        " at ",
                        leavingsRect.CenterCell
                    }), false);
                    return(false);

IL_1B4:
                    result = false;
                }
                else
                {
                    result = true;
                }
                return(result);
            }